Skip to content

Commit

Permalink
Allow custom registries without trailing slash (#1440)
Browse files Browse the repository at this point in the history
  • Loading branch information
swantzter authored Aug 5, 2024
1 parent 1dfe89d commit c226e38
Showing 1 changed file with 18 additions and 1 deletion.
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

0 comments on commit c226e38

Please sign in to comment.