Skip to content

Commit

Permalink
refactor(release): pkg init detect
Browse files Browse the repository at this point in the history
  • Loading branch information
chnliquan committed Nov 8, 2024
1 parent 1926f02 commit c96a308
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions packages/release/src/core/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,27 @@ export async function init(cwd: string) {
const pkgJSON: PkgJSON = readJSONSync(pkgJSONPath)

if (!pkgJSON.name) {
logger.warn(`Detect ${chalk.cyanBright(pkgJSONPath)} has no name field.`)
return
} else if (!pkgJSON.version) {
logger.warn(
`Detect ${chalk.cyanBright(pkgJSONPath)} has no version field.`,
`Detect ${chalk.cyanBright(pkgJSONPath)} has no name field, skipped.`,
)
} else {
pkgJSONPaths.push(pkgJSONPath)
pkgJSONs.push(pkgJSON)
pkgNames.push(pkgJSON.name)
return
}

if (!pkgJSON.private) {
publishPkgDirs.push(pkgPath)
publishPkgNames.push(pkgJSON.name as string)
}

pkgJSONPaths.push(pkgJSONPath)
pkgJSONs.push(pkgJSON)
pkgNames.push(pkgJSON.name)
})

if (publishPkgNames.length === 0) {
logger.warn(
`Detect ${chalk.bold.cyanBright(cwd)} has no available package.`,
`Detect ${chalk.bold.cyanBright(
cwd,
)} has no available package to publish.`,
)
process.exit(0)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/project/pkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const cache = new Map()
* @param relative 是否展示相对路径
*/
export async function getPkgPaths(
cwd = process.cwd(),
cwd: string,
relative = false,
): Promise<string[]> {
const cacheKey = `pkg_paths_${cwd}`
Expand Down Expand Up @@ -43,7 +43,7 @@ export async function getPkgPaths(
// yarn | npm | bun
const pkgJSONPath = path.resolve(cwd, 'package.json')
const pkgJSON = await readJSON<PkgJSON>(pkgJSONPath)
workspaces = (pkgJSON.workspaces as string[]) || []
workspaces = (pkgJSON?.workspaces as string[]) || []
}

if (workspaces?.length > 0) {
Expand Down

0 comments on commit c96a308

Please sign in to comment.