Skip to content

Fixes invalid url concatenation #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/berry-core/sources/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export class Configuration {
* one listed on /foo/bar/.yarnrc, but not the other way around).
*/

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

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

for (const {path, cwd, data} of rcFiles) {
if (!useRc)
continue;
if (!Array.isArray(data.plugins))
continue;

Expand Down
2 changes: 1 addition & 1 deletion packages/berry-core/sources/execUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export type ExecvpOptions = {
strict?: boolean,
};

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

Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-npm/sources/NpmFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class NpmFetcher implements Fetcher {
});
} catch (error) {
// The npm registry doesn't always support %2f when fetching the package tarballs 🤡
// Ex: https://registry.yarnpkg.com/@emotion%2fbabel-preset-css-prop/-/babel-preset-css-prop-10.0.7.tgz0
// Ex: https://registry.yarnpkg.com/@emotion%2fbabel-preset-css-prop/-/babel-preset-css-prop-10.0.7.tgz
sourceBuffer = await npmHttpUtils.get(this.getLocatorUrl(locator, opts).replace(/%2f/g, `/`), {
configuration: opts.project.configuration,
ident: locator,
Expand Down
5 changes: 4 additions & 1 deletion packages/plugin-npm/sources/npmHttpUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {Configuration, Ident, httpUtils} from '@berry/core';
import {MessageName, ReportError} from '@berry/core';
import inquirer from 'inquirer';
import {resolve as resolveUrl} from 'url';

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

function resolveUrl(registry: string, path: string) {
return registry.replace(/\/+$/, ``) + path;
}

function getAuthenticationHeader(registry: string, {authType = AuthType.CONFIGURATION, configuration}: {authType?: AuthType, configuration: Configuration}) {
const registryConfiguration = npmConfigUtils.getRegistryConfiguration(registry, {configuration});
const effectiveConfiguration = registryConfiguration || configuration;
Expand Down
43 changes: 43 additions & 0 deletions packages/plugin-npm/tests/npmHttpUtils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {Configuration, httpUtils} from '@berry/core';
import {get} from '@berry/plugin-npm/sources/npmHttpUtils';

jest.mock(`@berry/core`, () => ({
... require.requireActual(`@berry/core`),
httpUtils: {
... require.requireActual(`@berry/core`).httpUtils,
get: jest.fn(() => Promise.resolve()),
},
}));

const makeConfiguration = () => Configuration.find(__dirname, {
modules: new Map([
[`@berry/core`, require(`@berry/core`)],
[`@berry/fslib`, require(`@berry/core`)],
[`@berry/plugin-npm`, require(`@berry/plugin-npm`)],
]),
plugins: new Set([
`@berry/plugin-npm`,
]),
}, {
useRc: false,
strict: false,
});

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`]) {
const expected = registry.replace(/\/+$/, ``) + path;

it(`should craft the final path correctly (${registry} + ${path} = ${expected})`, async () => {
const configuration = await makeConfiguration();

await get(path, {
configuration,
registry,
});

expect(httpUtils.get).toHaveBeenCalledWith(expected, expect.anything());
});
}
}
});