Skip to content

feat(arborist): extend replace-registry-host with URL prefix matching (#6110)#9694

Merged
owlstronaut merged 1 commit into
release/v11from
backport/v11/9672
Jun 29, 2026
Merged

feat(arborist): extend replace-registry-host with URL prefix matching (#6110)#9694
owlstronaut merged 1 commit into
release/v11from
backport/v11/9672

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Backport of #9672 to release/v11.

…#6110) (#9672)

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.

<!-- What / Why -->
<!-- Describe the request in detail. What it does and why it's being
changed. -->

## References
- Fixes #6110

(cherry picked from commit b51d156)
@owlstronaut owlstronaut merged commit 3021ad6 into release/v11 Jun 29, 2026
63 checks passed
@owlstronaut owlstronaut deleted the backport/v11/9672 branch June 29, 2026 15:47
@github-actions github-actions Bot mentioned this pull request Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants