diff --git a/__tests__/commands/install/integration.js b/__tests__/commands/install/integration.js index 297ba9cec5..389c2ca002 100644 --- a/__tests__/commands/install/integration.js +++ b/__tests__/commands/install/integration.js @@ -668,6 +668,20 @@ test('install a scoped module from authed private registry', (): Promise = }); }); +test('install a scoped module from authed private registry with a missing trailing slash', (): Promise => { + return runInstall({noLockfile: true}, 'install-from-authed-private-registry-no-slash', async (config) => { + const authedRequests = request.__getAuthedRequests(); + assert.equal(authedRequests[0].url, 'https://registry.yarnpkg.com/@types%2flodash'); + assert.equal(authedRequests[0].headers.authorization, 'Bearer abc123'); + assert.equal(authedRequests[1].url, 'https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.37.tgz'); + assert.equal(authedRequests[1].headers.authorization, 'Bearer abc123'); + assert.equal( + (await fs.readFile(path.join(config.cwd, 'node_modules', '@types', 'lodash', 'index.d.ts'))).split('\n')[0], + '// Type definitions for Lo-Dash 4.14', + ); + }); +}); + test.concurrent('install a module with incompatible optional dependency should skip dependency', (): Promise => { return runInstall({}, 'install-should-skip-incompatible-optional-dep', async (config) => { diff --git a/__tests__/fixtures/install/install-from-authed-private-registry-no-slash/.npmrc b/__tests__/fixtures/install/install-from-authed-private-registry-no-slash/.npmrc new file mode 100644 index 0000000000..d64920ea68 --- /dev/null +++ b/__tests__/fixtures/install/install-from-authed-private-registry-no-slash/.npmrc @@ -0,0 +1,2 @@ +//registry.yarnpkg.com/:_authToken=abc123 +@types:registry=https://registry.yarnpkg.com diff --git a/__tests__/fixtures/install/install-from-authed-private-registry-no-slash/package.json b/__tests__/fixtures/install/install-from-authed-private-registry-no-slash/package.json new file mode 100644 index 0000000000..a02c5b41b4 --- /dev/null +++ b/__tests__/fixtures/install/install-from-authed-private-registry-no-slash/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "@types/lodash": "4.14.37" + } +} diff --git a/src/registries/npm-registry.js b/src/registries/npm-registry.js index 437c30445f..fa3146e43a 100644 --- a/src/registries/npm-registry.js +++ b/src/registries/npm-registry.js @@ -172,7 +172,7 @@ export default class NpmRegistry extends Registry { registry = registry.replace(/^https?:/, ''); // Check for bearer token. - let auth = this.getScopedOption(registry, '_authToken'); + let auth = this.getScopedOption(registry.replace(/\/?$/, '/'), '_authToken'); if (auth) { return `Bearer ${String(auth)}`; }