Skip to content

Commit

Permalink
feat(cli): provide a way to override the native package name
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Dec 22, 2021
1 parent 46168ee commit 046f75d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion cli/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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)}`)
Expand Down
4 changes: 2 additions & 2 deletions cli/src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down

0 comments on commit 046f75d

Please sign in to comment.