From c96a30868ac0938f8d98ae85742a82a524e9521b Mon Sep 17 00:00:00 2001 From: chnliquan Date: Fri, 8 Nov 2024 11:21:16 +0800 Subject: [PATCH] refactor(release): pkg init detect --- packages/release/src/core/init.ts | 18 +++++++++--------- packages/utils/src/project/pkg.ts | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/release/src/core/init.ts b/packages/release/src/core/init.ts index 01329b4..1a3fe71 100644 --- a/packages/release/src/core/init.ts +++ b/packages/release/src/core/init.ts @@ -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) } diff --git a/packages/utils/src/project/pkg.ts b/packages/utils/src/project/pkg.ts index ee39019..2d19b38 100644 --- a/packages/utils/src/project/pkg.ts +++ b/packages/utils/src/project/pkg.ts @@ -14,7 +14,7 @@ const cache = new Map() * @param relative 是否展示相对路径 */ export async function getPkgPaths( - cwd = process.cwd(), + cwd: string, relative = false, ): Promise { const cacheKey = `pkg_paths_${cwd}` @@ -43,7 +43,7 @@ export async function getPkgPaths( // yarn | npm | bun const pkgJSONPath = path.resolve(cwd, 'package.json') const pkgJSON = await readJSON(pkgJSONPath) - workspaces = (pkgJSON.workspaces as string[]) || [] + workspaces = (pkgJSON?.workspaces as string[]) || [] } if (workspaces?.length > 0) {