Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom registries without trailing slash #1440

Merged
merged 1 commit into from
Aug 5, 2024
Merged
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
19 changes: 18 additions & 1 deletion src/package-managers/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,24 @@ const fetchPartialPackument = async (
accept: opts.fullMetadata ? fullDoc : corgiDoc,
...opts.headers,
}
const url = new URL(encodeURIComponent(name), registry)
const url = new URL(
// since the registry API expects /package or /package/version encoding
// scoped packages is needed as to not treat the package scope as the full
// package name and the actual package name as the version/dist-tag
encodeURIComponent(name),
// the WhatWG URL standard, when given a base URL to place the first
// parameter relative to, will find the dirname of the base, treating the
// last segment as a file name and not a directory name if it isn't
// terminated by a / and thus remove it before adding the first argument
// to the URL.
// this is undesirable for registries configured without a trailing slash
// in the npm config since, for example looking up the package @foo/bar
// will give the following results given these configured registry URL:s
// https://example.com/npm => https://example.com/%40foo%2fbar
// https://example.com/npm/ => https://example.com/npm/%40foo%2fbar
// however, like npm itself does there should be leniency allowed in this.
registry.endsWith('/') ? registry : `${registry}/`,
)
if (version) {
url.pathname += `/${version}`
}
Expand Down
Loading