diff --git a/src/pre-publish.ts b/src/pre-publish.ts index 4e2ecdd2..0e067cb6 100644 --- a/src/pre-publish.ts +++ b/src/pre-publish.ts @@ -9,6 +9,7 @@ import { debugFactory } from './debug' import { spawn } from './spawn' import { updatePackageJson } from './update-package' import { readFileAsync, writeFileAsync } from './utils' +import { VersionCommand } from './version' const debug = debugFactory('prepublish') @@ -48,6 +49,7 @@ export class PrePublishCommand extends Command { } = getNapiConfig(this.configFileName) debug(`Update optionalDependencies in [${packageJsonPath}]`) if (!this.isDryRun) { + await VersionCommand.updatePackageJson(this.prefix, this.configFileName) await updatePackageJson(packageJsonPath, { optionalDependencies: platforms.reduce( (acc: Record, cur: NodeJS.Platform) => { diff --git a/src/version.ts b/src/version.ts index 7a186655..b8eba150 100644 --- a/src/version.ts +++ b/src/version.ts @@ -11,19 +11,10 @@ import { updatePackageJson } from './update-package' const debug = debugFactory('version') export class VersionCommand extends Command { - @Command.String(`-p,--prefix`) - prefix = 'npm' - - @Command.String('-c,--config') - configFileName?: string - - @Command.Path('version') - async execute() { - const { muslPlatforms, version, platforms } = getNapiConfig( - this.configFileName, - ) + static async updatePackageJson(prefix: string, configFileName?: string) { + const { muslPlatforms, version, platforms } = getNapiConfig(configFileName) for (const name of [...platforms, ...muslPlatforms]) { - const pkgDir = join(process.cwd(), this.prefix, name) + const pkgDir = join(process.cwd(), prefix, name) debug( `Update version to ${chalk.greenBright( version, @@ -33,6 +24,17 @@ export class VersionCommand extends Command { version, }) } + } + + @Command.String(`-p,--prefix`) + prefix = 'npm' + + @Command.String('-c,--config') + configFileName?: string + + @Command.Path('version') + async execute() { + await VersionCommand.updatePackageJson(this.prefix, this.configFileName) await spawn('git add .') } }