Skip to content

Commit 6210c73

Browse files
committed
fix: preserve registry path when replacing a host
1 parent 7eca19c commit 6210c73

File tree

1 file changed

+12
-0
lines changed
  • workspaces/arborist/lib/arborist

1 file changed

+12
-0
lines changed

Diff for: workspaces/arborist/lib/arborist/reify.js

+12
Original file line numberDiff line numberDiff line change
@@ -895,9 +895,21 @@ module.exports = cls => class Reifier extends cls {
895895
if ((this.options.replaceRegistryHost === resolvedURL.hostname) ||
896896
this.options.replaceRegistryHost === 'always') {
897897
const registryURL = new URL(this.registry)
898+
898899
// Replace the host with the registry host while keeping the path intact
899900
resolvedURL.hostname = registryURL.hostname
900901
resolvedURL.port = registryURL.port
902+
903+
// Make sure we don't double-include the path if it's already there
904+
const registryPath = registryURL.pathname.endsWith('/')
905+
? registryURL.pathname.slice(0, -1)
906+
: registryURL.pathname
907+
908+
if (registryPath && registryPath !== '/' && !resolvedURL.pathname.startsWith(registryPath)) {
909+
// Since hostname is changed, we need to ensure the registry path is included
910+
resolvedURL.pathname = registryPath + resolvedURL.pathname
911+
}
912+
901913
return resolvedURL.toString()
902914
}
903915
return resolved

0 commit comments

Comments
 (0)