+98
-2
lines changedFilter options
+98
-2
lines changed Original file line number Diff line number Diff line change
@@ -220,7 +220,12 @@ class Publish extends BaseCommand {
220
220
})
221
221
}
222
222
if (manifest.publishConfig) {
223
-
flatten(manifest.publishConfig, opts)
223
+
const cliFlags = this.npm.config.data.get('cli').raw
224
+
// Filter out properties set in CLI flags to prioritize them over
225
+
// corresponding `publishConfig` settings
226
+
const filteredPublishConfig = Object.fromEntries(
227
+
Object.entries(manifest.publishConfig).filter(([key]) => !(key in cliFlags)))
228
+
flatten(filteredPublishConfig, opts)
224
229
}
225
230
return manifest
226
231
}
Original file line number Diff line number Diff line change
@@ -141,7 +141,12 @@ class Unpublish extends BaseCommand {
141
141
// If localPrefix has a package.json with a name that matches the package
142
142
// being unpublished, load up the publishConfig
143
143
if (manifest?.name === spec.name && manifest.publishConfig) {
144
-
flatten(manifest.publishConfig, opts)
144
+
const cliFlags = this.npm.config.data.get('cli').raw
145
+
// Filter out properties set in CLI flags to prioritize them over
146
+
// corresponding `publishConfig` settings
147
+
const filteredPublishConfig = Object.fromEntries(
148
+
Object.entries(manifest.publishConfig).filter(([key]) => !(key in cliFlags)))
149
+
flatten(filteredPublishConfig, opts)
145
150
}
146
151
147
152
const versions = await Unpublish.getKeysOfVersions(spec.name, opts)
Original file line number Diff line number Diff line change
@@ -452,6 +452,10 @@ exports[`test/lib/commands/publish.js TAP restricted access > new package versio
452
452
+ @npm/test-package@1.0.0
453
453
`
454
454
455
+
exports[`test/lib/commands/publish.js TAP prioritize CLI flags over publishConfig > new package version 1`] = `
456
+
+ test-package@1.0.0
457
+
`
458
+
455
459
exports[`test/lib/commands/publish.js TAP scoped _auth config scoped registry > new package version 1`] = `
456
460
+ @npm/test-package@1.0.0
457
461
`
Original file line number Diff line number Diff line change
@@ -131,6 +131,58 @@ t.test('re-loads publishConfig.registry if added during script process', async t
131
131
t.matchSnapshot(joinedOutput(), 'new package version')
132
132
})
133
133
134
+
t.test('prioritize CLI flags over publishConfig', async t => {
135
+
const publishConfig = { registry: 'http://publishconfig' }
136
+
const { joinedOutput, npm } = await loadMockNpm(t, {
137
+
config: {
138
+
[`${alternateRegistry.slice(6)}/:_authToken`]: 'test-other-token',
139
+
},
140
+
prefixDir: {
141
+
'package.json': JSON.stringify({
142
+
...pkgJson,
143
+
scripts: {
144
+
prepare: 'cp new.json package.json',
145
+
},
146
+
}, null, 2),
147
+
'new.json': JSON.stringify({
148
+
...pkgJson,
149
+
publishConfig,
150
+
}),
151
+
},
152
+
argv: ['--registry', alternateRegistry],
153
+
})
154
+
const registry = new MockRegistry({
155
+
tap: t,
156
+
registry: alternateRegistry,
157
+
authorization: 'test-other-token',
158
+
})
159
+
registry.nock.put(`/${pkg}`, body => {
160
+
return t.match(body, {
161
+
_id: pkg,
162
+
name: pkg,
163
+
'dist-tags': { latest: '1.0.0' },
164
+
access: null,
165
+
versions: {
166
+
'1.0.0': {
167
+
name: pkg,
168
+
version: '1.0.0',
169
+
_id: `${pkg}@1.0.0`,
170
+
dist: {
171
+
shasum: /\.*/,
172
+
tarball: `http:${alternateRegistry.slice(6)}/test-package/-/test-package-1.0.0.tgz`,
173
+
},
174
+
publishConfig,
175
+
},
176
+
},
177
+
_attachments: {
178
+
[`${pkg}-1.0.0.tgz`]: {},
179
+
},
180
+
})
181
+
}).reply(200, {})
182
+
await npm.exec('publish', [])
183
+
t.matchSnapshot(joinedOutput(), 'new package version')
184
+
})
185
+
134
186
t.test('json', async t => {
135
187
const { joinedOutput, npm, logs } = await loadMockNpm(t, {
136
188
config: {
Original file line number Diff line number Diff line change
@@ -408,6 +408,36 @@ t.test('publishConfig no spec', async t => {
408
408
t.equal(joinedOutput(), '- test-package')
409
409
})
410
410
411
+
t.test('prioritize CLI flags over publishConfig no spec', async t => {
412
+
const alternateRegistry = 'https://other.registry.npmjs.org'
413
+
const publishConfig = { registry: 'http://publishconfig' }
414
+
const { joinedOutput, npm } = await loadMockNpm(t, {
415
+
config: {
416
+
force: true,
417
+
'//other.registry.npmjs.org/:_authToken': 'test-other-token',
418
+
},
419
+
prefixDir: {
420
+
'package.json': JSON.stringify({
421
+
name: pkg,
422
+
version: '1.0.0',
423
+
publishConfig,
424
+
}, null, 2),
425
+
},
426
+
argv: ['--registry', alternateRegistry],
427
+
})
428
+
429
+
const registry = new MockRegistry({
430
+
tap: t,
431
+
registry: alternateRegistry,
432
+
authorization: 'test-other-token',
433
+
})
434
+
const manifest = registry.manifest({ name: pkg })
435
+
await registry.package({ manifest, query: { write: true }, times: 2 })
436
+
registry.unpublish({ manifest })
437
+
await npm.exec('unpublish', [])
438
+
t.equal(joinedOutput(), '- test-package')
439
+
})
440
+
411
441
t.test('publishConfig with spec', async t => {
412
442
const alternateRegistry = 'https://other.registry.npmjs.org'
413
443
const { joinedOutput, npm } = await loadMockNpm(t, {
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4