GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(arborist): extend replace-registry-host with URL prefix matching (#6110) by u2mejc · Pull Request #9672 · npm/cli

Conversation

@u2mejc

@u2mejc u2mejc commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Resolves where registries with a path component (e.g. https://myregistry.example.com/npm/b) caused resolved URLs in the lockfile to have their path duplicated when reify rewrote them.

Rewrote #registryResolved to unify all match-and-rewrite logic into a single pass. A single new URL() parse of replaceRegistryHost now drives all three match modes:

  • Keyword / bare hostname (never, always, npmjs, registry.npmjs.org): behaviour unchanged. new URL() throws for keywords, leaving matchURL null and falling through to the existing host-comparison or keyword short-circuit.
  • Host-only URL (e.g. https://old.example.com/): trailing slash normalises to an empty matchPath; treated identically to a bare hostname — only the host is replaced, and the registry path is prepended if not already present.
  • Full URL with path (e.g. https://old.example.com/npm/b): when the resolved URL's host and path both match the prefix, the entire matched prefix is replaced with the configured registry's full URL (host + path). The remainder of the resolved path is appended without duplication. If the resolved URL's path does not start with the configured prefix, #registryResolved returns the URL unchanged.

Updated the hint and description for replace-registry-host to document the new full-URL-with-path mode and the host-only-URL mode.

Added three integration tests using tnock (mismatched URL → nock throws, making URL assertions implicit and precise):

  1. Full URL prefix match: replaceRegistryHost=https://old.example.com/npm/b, registry https://new.example.com/npm/a — verifies the old /npm/b prefix is replaced with /npm/a, not doubled to /npm/a/npm/b/….
  2. Host-only URL: replaceRegistryHost=https://old.example.com/ — verifies only the host is swapped and the resolved path is preserved.
  3. Path mismatch: replaceRegistryHost=https://old.example.com/npm/c but tarball under /npm/b — verifies the URL is left unchanged when the path prefix does not match.

References

  • Fixes [BUG] replace-registry-host doesn't support when two different registries have paths #6110

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@u2mejc
feat(arborist): extend replace-registry-host to URL prefix matching (n…
1802ef6
…pm#6110)

Resolves where registries with a path component (e.g.
https://myregistry.example.com/npm/b) caused resolved URLs in the
lockfile to have their path duplicated when reify rewrote them.

Rewrote `#registryResolved` to unify all match-and-rewrite logic into a
single pass. A single `new URL()` parse of `replaceRegistryHost` now
drives all three match modes:
- **Keyword / bare hostname** (`never`, `always`, `npmjs`,
  `registry.npmjs.org`): behaviour unchanged. `new URL()` throws for
  keywords, leaving `matchURL` null and falling through to the existing
  host-comparison or keyword short-circuit.
- **Host-only URL** (e.g. `https://old.example.com/`): trailing slash
  normalises to an empty `matchPath`; treated identically to a bare
  hostname — only the host is replaced, and the registry path is
  prepended if not already present.
- **Full URL with path** (e.g. `https://old.example.com/npm/b`): when
  the resolved URL's host and path both match the prefix, the entire
  matched prefix is replaced with the configured registry's full URL
  (host + path). The remainder of the resolved path is appended without
  duplication.
If the resolved URL's path does not start with the configured prefix,
`#registryResolved` returns the URL unchanged.

Updated the `hint` and `description` for `replace-registry-host` to
document the new full-URL-with-path mode and the host-only-URL mode.

Added three integration tests using `tnock` (mismatched URL → nock
throws, making URL assertions implicit and precise):
1. Full URL prefix match: `replaceRegistryHost=https://old.example.com/npm/b`,
   registry `https://new.example.com/npm/a` — verifies the old `/npm/b`
   prefix is replaced with `/npm/a`, not doubled to `/npm/a/npm/b/…`.
2. Host-only URL: `replaceRegistryHost=https://old.example.com/` —
   verifies only the host is swapped and the resolved path is preserved.
3. Path mismatch: `replaceRegistryHost=https://old.example.com/npm/c`
   but tarball under `/npm/b` — verifies the URL is left unchanged when
   the path prefix does not match.
@u2mejc
u2mejc requested review from a team as code owners June 26, 2026 06:24
@owlstronaut owlstronaut added the backport:v11 label Jun 29, 2026
owlstronaut
owlstronaut approved these changes Jun 29, 2026
View reviewed changes
@owlstronaut
owlstronaut merged commit b51d156 into npm:latest Jun 29, 2026
66 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Jun 29, 2026
feat(arborist): extend replace-registry-host with URL prefix matching (#6110) #9694
Merged
@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

🎉 Backport to release/v11 created: #9694

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Jun 29, 2026
chore: release 12.0.0-pre.2 #9594
Merged
owlstronaut pushed a commit that referenced this pull request Jun 29, 2026
@github-actions @u2mejc
feat(arborist): extend replace-registry-host with URL prefix matching (…
3021ad6
…#6110) (#9694)

Backport of #9672 to `release/v11`.

Co-authored-by: Justin Clark <[email protected]>
@schmitch schmitch mentioned this pull request Oct 29, 2026
npm guide: moving clients and their lockfiles from Nexus or Verdaccio, with replace-registry-host and omit-lockfile-registry-resolved forgepkg/forge#655
Open
6 tasks
@rldyourmnd rldyourmnd mentioned this pull request Nov 1, 2026
fix(npm): serve locked tarballs that lost the registry prefix NDDev-Technocracy-OpenNetwork-NDS/nddev-device-sync-cache#99
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@owlstronaut owlstronaut owlstronaut approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

backport:v11

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[BUG] replace-registry-host doesn't support when two different registries have paths

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@u2mejc @owlstronaut
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.