Skip to content

Commit acd4bc1

Browse files
committed
[workers-utils] Address review: document params, simplify registry URL
1 parent 10f5450 commit acd4bc1

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

packages/workers-utils/src/update-check.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ async function getLatestVersion(
106106
/**
107107
* Pick the version to recommend from a packument.
108108
*
109+
* @param packument - The package's abbreviated packument from the npm registry
110+
* @param distTag - The dist tag whose version should be recommended
109111
* @returns The version behind `distTag`, unless it has been deprecated, in
110112
* which case the newest non-deprecated stable release below it — or `null`
111113
* when there is nothing suitable to recommend.
@@ -144,10 +146,7 @@ function pickLatestVersion(
144146
}
145147

146148
async function fetchPackument(name: string): Promise<AbbreviatedPackument> {
147-
const packageUrl = new URL(
148-
encodeURIComponent(name).replace(/^%40/, "@"),
149-
NPM_REGISTRY_URL
150-
);
149+
const packageUrl = new URL(encodeURIComponent(name), NPM_REGISTRY_URL);
151150
const response = await fetch(packageUrl, {
152151
headers: {
153152
accept:

packages/workers-utils/tests/update-check.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe("fetchLatestNpmVersion", () => {
5656
mockAgent
5757
.get(REGISTRY_ORIGIN)
5858
.intercept({
59-
path: `/${encodeURIComponent(name).replace(/^%40/, "@")}`,
59+
path: `/${encodeURIComponent(name)}`,
6060
method: "GET",
6161
})
6262
.reply(status, body)

0 commit comments

Comments
 (0)