From c034e1e4f01c2947dfc53fa9d5066e2e1fa113b7 Mon Sep 17 00:00:00 2001 From: Kingsword Date: Thu, 4 Sep 2025 16:12:31 +0800 Subject: [PATCH] fix(cli): fix misuse of configPath as readNapiConfig first argument (#2900) Co-authored-by: LongYinan --- cli/src/api/artifacts.ts | 11 +++++++---- cli/src/api/build.ts | 4 +--- cli/src/utils/read-config.ts | 4 +--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cli/src/api/artifacts.ts b/cli/src/api/artifacts.ts index 862e33de..1e2a2dc6 100644 --- a/cli/src/api/artifacts.ts +++ b/cli/src/api/artifacts.ts @@ -1,4 +1,4 @@ -import { join, parse } from 'node:path' +import { join, resolve, parse } from 'node:path' import * as colors from 'colorette' @@ -20,9 +20,12 @@ const debug = debugFactory('artifacts') export async function collectArtifacts(userOptions: ArtifactsOptions) { const options = applyDefaultArtifactsOptions(userOptions) - const packageJsonPath = join(options.cwd, options.packageJsonPath) - const { targets, binaryName, packageName } = - await readNapiConfig(packageJsonPath) + const resolvePath = (...paths: string[]) => resolve(options.cwd, ...paths) + const packageJsonPath = resolvePath(options.packageJsonPath) + const { targets, binaryName, packageName } = await readNapiConfig( + packageJsonPath, + options.configPath ? resolvePath(options.configPath) : undefined, + ) const distDirs = targets.map((platform) => join(options.cwd, options.npmDir, platform.platformArchABI), diff --git a/cli/src/api/build.ts b/cli/src/api/build.ts index 7f095711..c852dc1c 100644 --- a/cli/src/api/build.ts +++ b/cli/src/api/build.ts @@ -82,9 +82,7 @@ export async function buildProject(rawOptions: BuildOptions) { ) } const config = await readNapiConfig( - resolvePath( - options.configPath ?? options.packageJsonPath ?? 'package.json', - ), + resolvePath(options.packageJsonPath ?? 'package.json'), options.configPath ? resolvePath(options.configPath) : undefined, ) diff --git a/cli/src/utils/read-config.ts b/cli/src/utils/read-config.ts index 76bba7af..e7183505 100644 --- a/cli/src/utils/read-config.ts +++ b/cli/src/utils/read-config.ts @@ -11,9 +11,7 @@ interface MinimalNapiOptions { export async function readConfig(options: MinimalNapiOptions) { const resolvePath = (...paths: string[]) => resolve(options.cwd, ...paths) const config = await readNapiConfig( - resolvePath( - options.configPath ?? options.packageJsonPath ?? 'package.json', - ), + resolvePath(options.packageJsonPath ?? 'package.json'), options.configPath ? resolvePath(options.configPath) : undefined, ) return config