Skip to content

Commit

Permalink
fix(plugin-npm): normalize registry
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed Jul 15, 2023
1 parent aceeef9 commit bde16f0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
24 changes: 24 additions & 0 deletions .yarn/versions/4a8968a1.yml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion packages/plugin-npm/sources/npmHttpUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']}) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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`]) {
Expand All @@ -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);
});
}
}
Expand Down

0 comments on commit bde16f0

Please sign in to comment.