From 990bfcc4847b7d251f5226c5ffcbbdc7e571bc42 Mon Sep 17 00:00:00 2001 From: merceyz Date: Sat, 15 Jul 2023 21:03:35 +0200 Subject: [PATCH] fix(plugin-npm): normalize registry --- .yarn/versions/4a8968a1.yml | 24 +++++++++++++++++++ packages/plugin-npm/sources/npmHttpUtils.ts | 2 +- ...HttpUtils.test.js => npmHttpUtils.test.ts} | 17 ++++++------- 3 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 .yarn/versions/4a8968a1.yml rename packages/plugin-npm/tests/{npmHttpUtils.test.js => npmHttpUtils.test.ts} (66%) diff --git a/.yarn/versions/4a8968a1.yml b/.yarn/versions/4a8968a1.yml new file mode 100644 index 000000000000..f198b962fb44 --- /dev/null +++ b/.yarn/versions/4a8968a1.yml @@ -0,0 +1,24 @@ +releases: + "@yarnpkg/cli": patch + "@yarnpkg/plugin-npm": patch + +declined: + - "@yarnpkg/plugin-compat" + - "@yarnpkg/plugin-constraints" + - "@yarnpkg/plugin-dlx" + - "@yarnpkg/plugin-essentials" + - "@yarnpkg/plugin-init" + - "@yarnpkg/plugin-interactive-tools" + - "@yarnpkg/plugin-nm" + - "@yarnpkg/plugin-npm-cli" + - "@yarnpkg/plugin-pack" + - "@yarnpkg/plugin-patch" + - "@yarnpkg/plugin-pnp" + - "@yarnpkg/plugin-pnpm" + - "@yarnpkg/plugin-stage" + - "@yarnpkg/plugin-typescript" + - "@yarnpkg/plugin-version" + - "@yarnpkg/plugin-workspace-tools" + - "@yarnpkg/builder" + - "@yarnpkg/core" + - "@yarnpkg/doctor" diff --git a/packages/plugin-npm/sources/npmHttpUtils.ts b/packages/plugin-npm/sources/npmHttpUtils.ts index b76239a8cb8e..2f6a877f3a89 100644 --- a/packages/plugin-npm/sources/npmHttpUtils.ts +++ b/packages/plugin-npm/sources/npmHttpUtils.ts @@ -353,7 +353,7 @@ function normalizeRegistry(configuration: Configuration, {ident, registry}: Part if (typeof registry !== `string`) throw new Error(`Assertion failed: The registry should be a string`); - return registry; + return npmConfigUtils.normalizeRegistry(registry); } async function getAuthenticationHeader(registry: string, {authType = AuthType.CONFIGURATION, configuration, ident}: {authType?: AuthType, configuration: Configuration, ident: RegistryOptions['ident']}) { diff --git a/packages/plugin-npm/tests/npmHttpUtils.test.js b/packages/plugin-npm/tests/npmHttpUtils.test.ts similarity index 66% rename from packages/plugin-npm/tests/npmHttpUtils.test.js rename to packages/plugin-npm/tests/npmHttpUtils.test.ts index 1e6137228de2..7a36dea88355 100644 --- a/packages/plugin-npm/tests/npmHttpUtils.test.js +++ b/packages/plugin-npm/tests/npmHttpUtils.test.ts @@ -1,16 +1,7 @@ -import {httpUtils} from '@yarnpkg/core'; import {npmHttpUtils} from '@yarnpkg/plugin-npm'; import {makeConfiguration} from './_makeConfiguration'; -jest.mock(`@yarnpkg/core`, () => ({ - ...jest.requireActual(`@yarnpkg/core`), - httpUtils: { - ...jest.requireActual(`@yarnpkg/core`).httpUtils, - get: jest.fn(() => Promise.resolve()), - }, -})); - describe(`npmHttpUtils.get`, () => { for (const registry of [`https://example.org`, `https://example.org/`, `https://example.org/foo`, `https://example.org/foo/`]) { for (const path of [`/bar`]) { @@ -19,12 +10,18 @@ describe(`npmHttpUtils.get`, () => { it(`should craft the final path correctly (${registry} + ${path} = ${expected})`, async () => { const configuration = await makeConfiguration(); + let actualTarget: string | undefined; await npmHttpUtils.get(path, { configuration, registry, + async wrapNetworkRequest(executor, extra) { + actualTarget = extra.target.toString(); + + return () => Promise.resolve({body: {}, headers: {}, statusCode: 200}); + }, }); - expect(httpUtils.get).toHaveBeenCalledWith(expected, expect.anything()); + expect(actualTarget).toEqual(expected); }); } }