|
1 | | -const { fixer } = require('normalize-package-data') |
2 | 1 | const npmFetch = require('npm-registry-fetch') |
3 | 2 | const npa = require('npm-package-arg') |
| 3 | +const PackageJson = require('@npmcli/package-json') |
4 | 4 | const { log } = require('proc-log') |
5 | 5 | const semver = require('semver') |
6 | 6 | const { URL } = require('node:url') |
@@ -31,7 +31,7 @@ Remove the 'private' field from the package.json to publish it.`), |
31 | 31 | } |
32 | 32 |
|
33 | 33 | const reg = npmFetch.pickRegistry(spec, opts) |
34 | | - const pubManifest = patchManifest(manifest, opts) |
| 34 | + const pubManifest = await patchManifest(manifest, opts) |
35 | 35 |
|
36 | 36 | // registry-frontdoor cares about the access level, |
37 | 37 | // which is only configurable for scoped packages |
@@ -62,17 +62,18 @@ Remove the 'private' field from the package.json to publish it.`), |
62 | 62 | return res |
63 | 63 | } |
64 | 64 |
|
65 | | -const patchManifest = (_manifest, opts) => { |
| 65 | +const patchManifest = async (_manifest, opts) => { |
66 | 66 | const { npmVersion } = opts |
67 | | - // we only update top-level fields, so a shallow clone is fine |
68 | | - const manifest = { ..._manifest } |
69 | | - |
70 | | - manifest._nodeVersion = process.versions.node |
71 | | - if (npmVersion) { |
72 | | - manifest._npmVersion = npmVersion |
| 67 | + const steps = ['fixName'] |
| 68 | + const manifestInput = { ..._manifest, _nodeVersion: process.versions.node } |
| 69 | + if (npmVersion != null) { |
| 70 | + manifestInput._npmVersion = npmVersion |
73 | 71 | } |
| 72 | + const manifest = await new PackageJson() |
| 73 | + .fromContent(manifestInput) |
| 74 | + .normalize({ steps }) |
| 75 | + .then(p => p.content) |
74 | 76 |
|
75 | | - fixer.fixNameField(manifest, { strict: true, allowLegacyCase: true }) |
76 | 77 | const version = semver.clean(manifest.version) |
77 | 78 | if (!version) { |
78 | 79 | throw Object.assign( |
|
0 commit comments