Skip to content

Commit

Permalink
refactor: rename some variables
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Nov 29, 2022
1 parent 605e0d2 commit 3a70dcd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
20 changes: 7 additions & 13 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { fileURLToPath } from 'url'
import SemanticRelease from 'semantic-release'
import { getLogger } from './logger.js'
import { releasePackages } from './release.js'
import { Context, SRMOptions } from './types.js'
import { Context, SRMOptions as Options } from './types.js'
import { getManifest, getManifestPaths } from './manifest.js'
import { enableDebugger, getDebugger } from './debugger.js'

const debug = getDebugger('options')
function release(
srmOptions: SRMOptions = {},

async function release(
srmOptions: Options = {},
srOptions: SemanticRelease.Options = {},
context: Context = {
cwd: process.cwd(),
Expand All @@ -32,22 +33,15 @@ function release(
debug(`srm options: ${JSON.stringify(srmOptions, null, 2)}`)

const paths = getManifestPaths(context.cwd, srmOptions.ignorePackages)
releasePackages(paths, srOptions, srmOptions, context, logger).then(
() => {
process.exit(0)
},
(error) => {
logger.error(`[srm]:`, error)
process.exit(1)
},
)
await releasePackages(paths, srOptions, srmOptions, context, logger)
process.exit(0)
} catch (error) {
logger.error(`[srm]:`, error)
process.exit(1)
}
}

export { SRMOptions }
export { Options }
export { release }

export default release
3 changes: 2 additions & 1 deletion packages/core/src/local-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,11 @@ export function updateManifestDeps(
const release = dep.nextRelease || dep.lastRelease

// Cannot establish version.
if (!release || !release.version)
if (!release || !release.version) {
throw Error(
`Cannot release because dependency ${dep.name} has not been released`,
)
}

// update changed dependencies
const {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function getManifestPaths(cwd: string, ignorePackages?: string[]) {
packages.push(...ignorePackages.map((p) => `!${p}`))
}

const workspacePackages = globbySync(
const workspacePackagePaths = globbySync(
packages.map((p) => unixify(p)), // convert Windows file paths to unix paths
{
cwd,
Expand All @@ -104,9 +104,9 @@ export function getManifestPaths(cwd: string, ignorePackages?: string[]) {
},
).filter((f) => /\/package\.json$/.test(f))

if (!workspacePackages.length) {
if (!workspacePackagePaths.length) {
throw new TypeError('Project must contain one or more workspace-packages')
}

return workspacePackages
return workspacePackagePaths
}
11 changes: 6 additions & 5 deletions packages/core/src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { getOptions, getSuccessComment, getFailComment } from './options.js'

export async function releasePackages(
paths: string[],
inputOptions: semanticRelease.Options,
localOptions: semanticRelease.Options,
srmOptions: SRMOptions,
{ cwd, env, stdout, stderr }: Context,
logger: Signale,
Expand All @@ -49,12 +49,12 @@ export async function releasePackages(

const globalOptions = await getOptions(cwd)
const context: SRMContext = {
globalOptions,
inputOptions,
cwd,
env,
stdout,
stderr,
localOptions,
globalOptions,
}

// Load packages from paths
Expand Down Expand Up @@ -144,7 +144,7 @@ async function releasePackage(

async function loadPackage(
path: string,
{ globalOptions, inputOptions, env, cwd, stdout, stderr }: SRMContext,
{ globalOptions, localOptions, env, cwd, stdout, stderr }: SRMContext,
srmOptions: SRMOptions,
): Promise<Package> {
// eslint-disable-next-line no-param-reassign
Expand All @@ -169,7 +169,7 @@ async function loadPackage(
const finalOptions = {
...globalOptions,
...pkgOptions,
...inputOptions,
...localOptions,
}

// Make a fake logger so semantic-release's get-config doesn't fail.
Expand Down Expand Up @@ -234,6 +234,7 @@ function makePushToGitMethod(

const bodyTemplate =
srmOptions.combinedMessageBody ||
// eslint-disable-next-line no-template-curly-in-string
'[${nextRelease.gitTag}](${nextRelease.url})'

const headerTemplate =
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export interface Context {
}

export interface SRMContext extends Context {
localOptions: SemanticRelease.Options
globalOptions: SemanticRelease.Options
inputOptions: SemanticRelease.Options
}

/**
Expand Down

0 comments on commit 3a70dcd

Please sign in to comment.