Skip to content

Commit 416fcf8

Browse files
committed
Fixes invalid url concatenation
1 parent 6aa0817 commit 416fcf8

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

packages/berry-core/sources/Configuration.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ export class Configuration {
466466
* one listed on /foo/bar/.yarnrc, but not the other way around).
467467
*/
468468

469-
static async find(startingCwd: PortablePath, pluginConfiguration: PluginConfiguration | null, {strict = true}: {strict?: boolean} = {}) {
469+
static async find(startingCwd: PortablePath, pluginConfiguration: PluginConfiguration | null, {strict = true, useRc = true}: {strict?: boolean, useRc?: boolean} = {}) {
470470
const environmentSettings = getEnvironmentSettings();
471471
delete environmentSettings.rcFilename;
472472

@@ -486,6 +486,8 @@ export class Configuration {
486486
const dynamicPlugins = new Set();
487487

488488
for (const {path, cwd, data} of rcFiles) {
489+
if (!useRc)
490+
continue;
489491
if (!Array.isArray(data.plugins))
490492
continue;
491493

packages/berry-core/sources/execUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export type ExecvpOptions = {
5656
strict?: boolean,
5757
};
5858

59-
export async function execvp(fileName: string, args: Array<string>, opts: ExecvpOptions & {encoding: `buffer`}): Promise<{code: number, stdout: Buffer, stderr: Buffer}>;
59+
export async function execvp(fileName: string, args: Array<string>, opts: ExecvpOptions & {encoding: 'buffer'}): Promise<{code: number, stdout: Buffer, stderr: Buffer}>;
6060
export async function execvp(fileName: string, args: Array<string>, opts: ExecvpOptions & {encoding: string}): Promise<{code: number, stdout: string, stderr: string}>;
6161
export async function execvp(fileName: string, args: Array<string>, opts: ExecvpOptions): Promise<{code: number, stdout: string, stderr: string}>;
6262

packages/plugin-npm/sources/NpmFetcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class NpmFetcher implements Fetcher {
5151
});
5252
} catch (error) {
5353
// The npm registry doesn't always support %2f when fetching the package tarballs 🤡
54-
// Ex: https://registry.yarnpkg.com/@emotion%2fbabel-preset-css-prop/-/babel-preset-css-prop-10.0.7.tgz0
54+
// Ex: https://registry.yarnpkg.com/@emotion%2fbabel-preset-css-prop/-/babel-preset-css-prop-10.0.7.tgz
5555
sourceBuffer = await npmHttpUtils.get(this.getLocatorUrl(locator, opts).replace(/%2f/g, `/`), {
5656
configuration: opts.project.configuration,
5757
ident: locator,

packages/plugin-npm/sources/npmHttpUtils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {Configuration, Ident, httpUtils} from '@berry/core';
22
import {MessageName, ReportError} from '@berry/core';
33
import inquirer from 'inquirer';
4-
import {resolve as resolveUrl} from 'url';
54

65
import * as npmConfigUtils from './npmConfigUtils';
76
import {MapLike} from './npmConfigUtils';
@@ -76,6 +75,10 @@ export async function put(path: string, body: httpUtils.Body, {configuration, he
7675
}
7776
}
7877

78+
function resolveUrl(registry: string, path: string) {
79+
return registry.replace(/\/+$/, ``) + path;
80+
}
81+
7982
function getAuthenticationHeader(registry: string, {authType = AuthType.CONFIGURATION, configuration}: {authType?: AuthType, configuration: Configuration}) {
8083
const registryConfiguration = npmConfigUtils.getRegistryConfiguration(registry, {configuration});
8184
const effectiveConfiguration = registryConfiguration || configuration;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {Configuration, httpUtils} from '@berry/core';
2+
import {get} from '@berry/plugin-npm/sources/npmHttpUtils';
3+
4+
jest.mock(`@berry/core`, () => ({
5+
... require.requireActual(`@berry/core`),
6+
httpUtils: {
7+
... require.requireActual(`@berry/core`).httpUtils,
8+
get: jest.fn(() => Promise.resolve()),
9+
},
10+
}));
11+
12+
const makeConfiguration = () => Configuration.find(__dirname, {
13+
modules: new Map([
14+
[`@berry/core`, require(`@berry/core`)],
15+
[`@berry/fslib`, require(`@berry/core`)],
16+
[`@berry/plugin-npm`, require(`@berry/plugin-npm`)],
17+
]),
18+
plugins: new Set([
19+
`@berry/plugin-npm`,
20+
]),
21+
}, {
22+
useRc: false,
23+
strict: false,
24+
});
25+
26+
describe(`npmHttpUtils.get`, () => {
27+
for (const registry of [`https://example.org`, `https://example.org/`, `https://example.org/foo`, `https://example.org/foo/`]) {
28+
for (const path of [`/bar`]) {
29+
const expected = registry.replace(/\/+$/, ``) + path;
30+
31+
it(`should craft the final path correctly (${registry} + ${path} = ${expected})`, async () => {
32+
const configuration = await makeConfiguration();
33+
34+
await get(path, {
35+
configuration,
36+
registry,
37+
});
38+
39+
expect(httpUtils.get).toHaveBeenCalledWith(expected, expect.anything());
40+
});
41+
}
42+
}
43+
});

0 commit comments

Comments
 (0)