feat: update package.json again in prepublish
This commit is contained in:
parent
b61629cf34
commit
15cb7e5765
2 changed files with 16 additions and 12 deletions
|
@ -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<string, string>, cur: NodeJS.Platform) => {
|
||||
|
|
|
@ -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 .')
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue