Skip to content

Commit 6cd3cd0

Browse files
isaacsdarcyclarke
authored andcommitted
Support *all* conf keys in publishConfig
This adds a flatOptions.flatten() method, which takes an object full of config keys, and turns it into an options object. This method expects an object that already inherits from npm's defaults, and is thus expected to be internal only. This commit also removes some config keys which were used by npm dependencies at the start of the v7 beta process, but are no longer: - all lockfile configs (since we don't use lockfiles any more! for anything! and good riddance, they're a rats' nest of race conditions) - cacheMax/cacheMin (we only use preferOffline/offline/online now, so these are strictly legacy support as input and never shared with deps) Once this lands in cli, we can remove the publishConfig handling logic in npm-registry-fetch, as it will be redundant.
1 parent 48ee8d0 commit 6cd3cd0

5 files changed

Lines changed: 306 additions & 231 deletions

File tree

lib/publish.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const output = require('./utils/output.js')
1212
const otplease = require('./utils/otplease.js')
1313
const { getContents, logTar } = require('./utils/tar.js')
1414

15+
// this is the only case in the CLI where we use the old full slow
16+
// 'read-package-json' module, because we want to pull in all the
17+
// defaults and metadata, like git sha's and default scripts and all that.
1518
const readJson = util.promisify(require('read-package-json'))
1619

1720
const completion = require('./utils/completion/none.js')
@@ -46,9 +49,22 @@ const publish = async args => {
4649
return tarball
4750
}
4851

52+
// for historical reasons, publishConfig in package.json can contain
53+
// ANY config keys that npm supports in .npmrc files and elsewhere.
54+
// We *may* want to revisit this at some point, and have a minimal set
55+
// that's a SemVer-major change that ought to get a RFC written on it.
56+
const { flatten } = require('./utils/flat-options.js')
57+
const publishConfigToOpts = publishConfig =>
58+
// create a new object that inherits from the config stack
59+
// then squash the css-case into camelCase opts, like we do
60+
flatten(Object.assign(Object.create(npm.config.list[0]), publishConfig))
61+
4962
const publish_ = async (arg, opts) => {
5063
const { unicode, dryRun, json } = opts
51-
let manifest = await readJson(`${arg}/package.json`)
64+
const manifest = await readJson(`${arg}/package.json`)
65+
66+
if (manifest.publishConfig)
67+
Object.assign(opts, publishConfigToOpts(manifest.publishConfig))
5268

5369
// prepublishOnly
5470
await runScript({
@@ -58,7 +74,7 @@ const publish_ = async (arg, opts) => {
5874
pkg: manifest,
5975
})
6076

61-
const tarballData = await pack(arg)
77+
const tarballData = await pack(arg, opts)
6278
const pkgContents = await getContents(manifest, tarballData)
6379

6480
if (!json)
@@ -67,9 +83,11 @@ const publish_ = async (arg, opts) => {
6783
if (!dryRun) {
6884
// The purpose of re-reading the manifest is in case it changed,
6985
// so that we send the latest and greatest thing to the registry
70-
manifest = await readJson(`${arg}/package.json`)
71-
const { publishConfig } = manifest
72-
await otplease(opts, opts => libpub(arg, manifest, { ...opts, publishConfig }))
86+
// note that publishConfig might have changed as well!
87+
const manifest = await readJson(`${arg}/package.json`, opts)
88+
if (manifest.publishConfig)
89+
Object.assign(opts, publishConfigToOpts(manifest.publishConfig))
90+
await otplease(opts, opts => libpub(arg, manifest, opts))
7391
}
7492

7593
// publish

0 commit comments

Comments
 (0)