Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/commands/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ ${defData}

if (!this.npm.global) {
const { content } = await pkgJson.normalize(this.npm.prefix).catch(() => ({ content: {} }))

if (content.publishConfig) {
const ignorePublishConfig = this.npm.config.get('ignore-publish-config')
if (!ignorePublishConfig && content.publishConfig) {
const pkgPath = resolve(this.npm.prefix, 'package.json')
msg.push(`; "publishConfig" from ${pkgPath}`)
msg.push('; This set of config values will be used at publish-time.', '')
Expand Down
4 changes: 3 additions & 1 deletion lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Publish extends BaseCommand {
'workspaces',
'include-workspace-root',
'provenance',
'ignore-publish-config',
]

static usage = ['<package-spec>']
Expand Down Expand Up @@ -219,7 +220,8 @@ class Publish extends BaseCommand {
fullReadJson: true,
})
}
if (manifest.publishConfig) {
const ignorePublishConfig = this.npm.config.get('ignore-publish-config')
if (!ignorePublishConfig && manifest.publishConfig) {
flatten(manifest.publishConfig, opts)
}
return manifest
Expand Down
5 changes: 3 additions & 2 deletions lib/commands/unpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const BaseCommand = require('../base-command.js')
class Unpublish extends BaseCommand {
static description = 'Remove a package from the registry'
static name = 'unpublish'
static params = ['dry-run', 'force', 'workspace', 'workspaces']
static params = ['dry-run', 'force', 'workspace', 'workspaces', 'ignore-publish-config']
static usage = ['[<package-spec>]']
static workspaces = true
static ignoreImplicitWorkspace = false
Expand Down Expand Up @@ -140,7 +140,8 @@ class Unpublish extends BaseCommand {

// If localPrefix has a package.json with a name that matches the package
// being unpublished, load up the publishConfig
if (manifest?.name === spec.name && manifest.publishConfig) {
const ignorePublishConfig = this.npm.config.get('ignore-publish-config')
if (!ignorePublishConfig && manifest?.name === spec.name && manifest.publishConfig) {
flatten(manifest.publishConfig, opts)
}

Expand Down
2 changes: 2 additions & 0 deletions tap-snapshots/test/lib/commands/config.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exports[`test/lib/commands/config.js TAP config list --json > output matches sna
"userloaded": "yes",
"globalloaded": "yes",
"access": null,
"ignore-publish-config": false,
"all": false,
"allow-same-version": false,
"also": null,
Expand Down Expand Up @@ -228,6 +229,7 @@ globalconfig = "{GLOBALPREFIX}/npmrc"
heading = "npm"
https-proxy = null
if-present = false
ignore-publish-config = false
ignore-scripts = false
include = []
include-staged = false
Expand Down
21 changes: 19 additions & 2 deletions tap-snapshots/test/lib/docs.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,18 @@ CI setup.

This value is not exported to the environment for child processes.

#### \`ignore-publish-config\`

* Default: false
* Type: Boolean

When using \`npm publish\`, the \`--ignore-publish-config\` flag overrides the
registry URL specified in the package's \`publishConfig\` field, allowing
users to publish to a different repository. Similarly, when executing \`npm
unpublish\`



#### \`ignore-scripts\`

* Default: false
Expand Down Expand Up @@ -2058,6 +2070,7 @@ exports[`test/lib/docs.js TAP config > all keys 1`] = `
Array [
"_auth",
"access",
"ignore-publish-config",
"all",
"allow-same-version",
"also",
Expand Down Expand Up @@ -2218,6 +2231,7 @@ exports[`test/lib/docs.js TAP config > keys that are flattened 1`] = `
Array [
"_auth",
"access",
"ignore-publish-config",
"all",
"allow-same-version",
"also",
Expand Down Expand Up @@ -2423,6 +2437,7 @@ Object {
"heading": "npm",
"httpsProxy": null,
"ifPresent": false,
"ignorePublishConfig": false,
"ignoreScripts": false,
"includeStaged": false,
"includeWorkspaceRoot": false,
Expand Down Expand Up @@ -3864,7 +3879,7 @@ Options:
[--tag <tag>] [--access <restricted|public>] [--dry-run] [--otp <otp>]
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces] [--include-workspace-root]
[--provenance|--provenance-file <file>]
[--provenance|--provenance-file <file>] [--ignore-publish-config]

Run "npm help publish" for more info

Expand All @@ -3881,6 +3896,7 @@ npm publish <package-spec>
#### \`include-workspace-root\`
#### \`provenance\`
#### \`provenance-file\`
#### \`ignore-publish-config\`
`

exports[`test/lib/docs.js TAP usage query > must match snapshot 1`] = `
Expand Down Expand Up @@ -4338,7 +4354,7 @@ npm unpublish [<package-spec>]
Options:
[--dry-run] [-f|--force]
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces]
[-ws|--workspaces] [--ignore-publish-config]

Run "npm help unpublish" for more info

Expand All @@ -4350,6 +4366,7 @@ npm unpublish [<package-spec>]
#### \`force\`
#### \`workspace\`
#### \`workspaces\`
#### \`ignore-publish-config\`
`

exports[`test/lib/docs.js TAP usage unstar > must match snapshot 1`] = `
Expand Down
12 changes: 12 additions & 0 deletions workspaces/config/lib/definitions/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ define('access', {
flatten,
})

define('ignore-publish-config', {
default: false,
type: Boolean,
description: `
When using \`npm publish\`, the \`--ignore-publish-config\` flag overrides the registry URL
specified in the package's \`publishConfig\` field, allowing users to publish to a different
repository.
Similarly, when executing \`npm unpublish\`
`,
flatten,
})

define('all', {
default: false,
type: Boolean,
Expand Down