From 046f75dc29f8ea2319311006b2743749427d7ed4 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Wed, 22 Dec 2021 20:24:15 +0800 Subject: [PATCH] feat(cli): provide a way to override the native package name --- cli/src/build.ts | 14 +++++++++++++- cli/src/consts.ts | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cli/src/build.ts b/cli/src/build.ts index 9896863b..1e228a96 100644 --- a/cli/src/build.ts +++ b/cli/src/build.ts @@ -79,6 +79,13 @@ export class BuildCommand extends Command { )} to disable it. Only affect if ${chalk.green('--target')} specified.`, }) + jsPackageName = Option.String('--js-package-name', { + description: `Package name in generated js binding file, Only affect if ${chalk.green( + '--target', + )} specified and ${chalk.green('--js')} is not false.`, + required: false, + }) + cargoCwd?: string = Option.String('--cargo-cwd', { description: `The cwd of ${chalk.underline( chalk.yellow('Cargo.toml'), @@ -304,7 +311,12 @@ export class BuildCommand extends Command { this.appendPlatformToFilename ? join(process.cwd(), this.jsBinding) : null - await writeJsBinding(binaryName, packageName, jsBindingFilePath, idents) + await writeJsBinding( + binaryName, + this.jsPackageName ?? packageName, + jsBindingFilePath, + idents, + ) if (this.pipe && jsBindingFilePath) { const pipeCommand = `${this.pipe} ${jsBindingFilePath}` console.info(`Run ${chalk.green(pipeCommand)}`) diff --git a/cli/src/consts.ts b/cli/src/consts.ts index 973a6512..66c74912 100644 --- a/cli/src/consts.ts +++ b/cli/src/consts.ts @@ -18,10 +18,10 @@ export function getNapiConfig( const platforms = [...defaultPlatforms, ...additionPlatforms] const releaseVersion = process.env.RELEASE_VERSION const releaseVersionWithoutPrefix = releaseVersion?.startsWith('v') - ? releaseVersion.substr(1) + ? releaseVersion.substring(1) : releaseVersion const version = releaseVersionWithoutPrefix ?? packageVersion - const packageName = name + const packageName = napi?.package?.name ?? name const binaryName: string = napi?.name ?? 'index'