diff options
author | Nathan Fritz <fritzy@github.com> | 2022-08-03 00:44:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-03 00:44:59 +0300 |
commit | 703dbbf2a8149dff72c848d60600889a76779828 (patch) | |
tree | 8af1d5cda4ec0a7d6dabbef6d4084916b782931f /workspaces/arborist/lib | |
parent | fd030c86b1e01b7df1b9d73fda07496742a4737f (diff) |
feat: add --replace-registry-host=<npmjs|always|never> (#4860)
feat: add --replace-registry-host=<npmjs|always|never>|<hostname>
Diffstat (limited to 'workspaces/arborist/lib')
-rw-r--r-- | workspaces/arborist/lib/arborist/index.js | 4 | ||||
-rw-r--r-- | workspaces/arborist/lib/arborist/reify.js | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/workspaces/arborist/lib/arborist/index.js b/workspaces/arborist/lib/arborist/index.js index cb6ef1e0c..9564f7648 100644 --- a/workspaces/arborist/lib/arborist/index.js +++ b/workspaces/arborist/lib/arborist/index.js @@ -74,8 +74,12 @@ class Arborist extends Base { cache: options.cache || `${homedir()}/.npm/_cacache`, packumentCache: options.packumentCache || new Map(), workspacesEnabled: options.workspacesEnabled !== false, + replaceRegistryHost: options.replaceRegistryHost, lockfileVersion: lockfileVersion(options.lockfileVersion), } + this.replaceRegistryHost = this.options.replaceRegistryHost = + (!this.options.replaceRegistryHost || this.options.replaceRegistryHost === 'npmjs') ? + 'registry.npmjs.org' : this.options.replaceRegistryHost this[_workspacesEnabled] = this.options.workspacesEnabled diff --git a/workspaces/arborist/lib/arborist/reify.js b/workspaces/arborist/lib/arborist/reify.js index 4f1061e4a..7663a3a34 100644 --- a/workspaces/arborist/lib/arborist/reify.js +++ b/workspaces/arborist/lib/arborist/reify.js @@ -712,13 +712,19 @@ module.exports = cls => class Reifier extends cls { [_registryResolved] (resolved) { // the default registry url is a magic value meaning "the currently // configured registry". + // `resolved` must never be falsey. // // XXX: use a magic string that isn't also a valid value, like // ${REGISTRY} or something. This has to be threaded through the // Shrinkwrap and Node classes carefully, so for now, just treat // the default reg as the magical animal that it has been. - return resolved && resolved - .replace(/^https?:\/\/registry\.npmjs\.org\//, this.registry) + const resolvedURL = new URL(resolved) + if ((this.options.replaceRegistryHost === resolvedURL.hostname) + || this.options.replaceRegistryHost === 'always') { + // this.registry always has a trailing slash + resolved = `${this.registry.slice(0, -1)}${resolvedURL.pathname}${resolvedURL.searchParams}` + } + return resolved } // bundles are *sort of* like shrinkwraps, in that the branch is defined |