From 3c7deaee893c96c42423bbec7ce227255dbf9093 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 4 Dec 2021 16:28:07 +0200 Subject: [PATCH] Revert "revert: "fix: don't add trailing slash to registry URLs (#4032)" (#4059)" This reverts commit 46aaf7108d64757de164d9a5fa6c608a406ae568. --- packages/config/package.json | 1 + packages/config/src/getScopeRegistries.ts | 8 +++---- packages/config/src/index.ts | 5 ++-- packages/config/test/index.ts | 4 +++- packages/config/test/scoped-registries.ini | 1 + packages/lockfile-utils/package.json | 2 +- packages/normalize-registries/package.json | 2 +- packages/resolve-dependencies/package.json | 2 +- pnpm-lock.yaml | 27 +++++++++------------- 9 files changed, 25 insertions(+), 27 deletions(-) diff --git a/packages/config/package.json b/packages/config/package.json index e0d2e95a720..7f65344f80e 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -42,6 +42,7 @@ "camelcase": "^6.2.0", "can-write-to-dir": "^1.1.1", "is-subdir": "^1.1.1", + "normalize-registry-url": "2.0.0", "ramda": "^0.27.1", "realpath-missing": "^1.1.0", "which": "^2.0.2" diff --git a/packages/config/src/getScopeRegistries.ts b/packages/config/src/getScopeRegistries.ts index 710cc74168d..dafa323fe17 100644 --- a/packages/config/src/getScopeRegistries.ts +++ b/packages/config/src/getScopeRegistries.ts @@ -1,13 +1,11 @@ +import normalizeRegistryUrl from 'normalize-registry-url' + export default function getScopeRegistries (rawConfig: Object) { const registries = {} for (const configKey of Object.keys(rawConfig)) { if (configKey[0] === '@' && configKey.endsWith(':registry')) { - registries[configKey.substr(0, configKey.indexOf(':'))] = normalizeRegistry(rawConfig[configKey]) + registries[configKey.substr(0, configKey.indexOf(':'))] = normalizeRegistryUrl(rawConfig[configKey]) } } return registries } - -export function normalizeRegistry (registry: string) { - return registry.endsWith('/') ? registry : `${registry}/` -} diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index ad70faa0176..eea1032a77d 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -10,10 +10,11 @@ import camelcase from 'camelcase' import loadNpmConf from '@zkochan/npm-conf' import npmTypes from '@zkochan/npm-conf/lib/types' import { sync as canWriteToDir } from 'can-write-to-dir' +import normalizeRegistryUrl from 'normalize-registry-url' import fromPairs from 'ramda/src/fromPairs' import realpathMissing from 'realpath-missing' import whichcb from 'which' -import getScopeRegistries, { normalizeRegistry } from './getScopeRegistries' +import getScopeRegistries from './getScopeRegistries' import findBestGlobalPrefix from './findBestGlobalPrefix' import { getCacheDir, getConfigDir, getDataDir, getStateDir } from './dirs' import { @@ -250,7 +251,7 @@ export default async ( { 'user-agent': pnpmConfig.userAgent }, ] as any) // eslint-disable-line @typescript-eslint/no-explicit-any pnpmConfig.registries = { - default: normalizeRegistry(pnpmConfig.rawConfig.registry), + default: normalizeRegistryUrl(pnpmConfig.rawConfig.registry), ...getScopeRegistries(pnpmConfig.rawConfig), } pnpmConfig.lockfileDir = pnpmConfig.lockfileDir ?? pnpmConfig.lockfileDirectory ?? pnpmConfig.shrinkwrapDirectory diff --git a/packages/config/test/index.ts b/packages/config/test/index.ts index 1d830965768..a09b362b482 100644 --- a/packages/config/test/index.ts +++ b/packages/config/test/index.ts @@ -178,7 +178,7 @@ test('when using --global, link-workspace-packages, shared-workspace-shrinwrap a } }) -test('registries of scoped packages are read', async () => { +test('registries of scoped packages are read and normalized', async () => { const { config } = await getConfig({ cliOptions: { userconfig: path.join(__dirname, 'scoped-registries.ini'), @@ -193,6 +193,7 @@ test('registries of scoped packages are read', async () => { default: 'https://default.com/', '@foo': 'https://foo.com/', '@bar': 'https://bar.com/', + '@qar': 'https://qar.com/qar', }) }) @@ -215,6 +216,7 @@ test('registries in current directory\'s .npmrc have bigger priority then global default: 'https://pnpm.io/', '@foo': 'https://foo.com/', '@bar': 'https://bar.com/', + '@qar': 'https://qar.com/qar', }) }) diff --git a/packages/config/test/scoped-registries.ini b/packages/config/test/scoped-registries.ini index 946a21fbd8c..ce97b843d09 100644 --- a/packages/config/test/scoped-registries.ini +++ b/packages/config/test/scoped-registries.ini @@ -1,3 +1,4 @@ @foo:registry=https://foo.com @bar:registry=https://bar.com +@qar:registry=https://qar.com/qar registry=https://default.com diff --git a/packages/lockfile-utils/package.json b/packages/lockfile-utils/package.json index 853a707986c..7abb56e9896 100644 --- a/packages/lockfile-utils/package.json +++ b/packages/lockfile-utils/package.json @@ -42,7 +42,7 @@ "@pnpm/resolver-base": "workspace:8.1.1", "@pnpm/types": "workspace:7.6.0", "dependency-path": "workspace:8.0.6", - "get-npm-tarball-url": "2.0.2", + "get-npm-tarball-url": "^2.0.3", "ramda": "^0.27.1" }, "funding": "https://opencollective.com/pnpm" diff --git a/packages/normalize-registries/package.json b/packages/normalize-registries/package.json index d1c8f3092e6..9e48c799989 100644 --- a/packages/normalize-registries/package.json +++ b/packages/normalize-registries/package.json @@ -27,7 +27,7 @@ }, "dependencies": { "@pnpm/types": "workspace:7.6.0", - "normalize-registry-url": "1.0.0" + "normalize-registry-url": "2.0.0" }, "homepage": "https://github.com/pnpm/pnpm/blob/master/packages/normalize-registries#readme", "funding": "https://opencollective.com/pnpm" diff --git a/packages/resolve-dependencies/package.json b/packages/resolve-dependencies/package.json index 7fa39fe0c60..55ed2e6d72b 100644 --- a/packages/resolve-dependencies/package.json +++ b/packages/resolve-dependencies/package.json @@ -44,7 +44,7 @@ "@pnpm/types": "workspace:7.6.0", "dependency-path": "workspace:8.0.6", "encode-registry": "^3.0.0", - "get-npm-tarball-url": "2.0.2", + "get-npm-tarball-url": "^2.0.3", "path-exists": "^4.0.0", "ramda": "^0.27.1", "replace-string": "^3.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index abad9d32c36..281b6b54ea8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -338,6 +338,7 @@ importers: camelcase: ^6.2.0 can-write-to-dir: ^1.1.1 is-subdir: ^1.1.1 + normalize-registry-url: 2.0.0 ramda: ^0.27.1 realpath-missing: ^1.1.0 symlink-dir: ^5.0.0 @@ -353,6 +354,7 @@ importers: camelcase: 6.2.1 can-write-to-dir: 1.1.1 is-subdir: 1.2.0 + normalize-registry-url: 2.0.0 ramda: 0.27.1 realpath-missing: 1.1.0 which: 2.0.2 @@ -1414,7 +1416,7 @@ importers: '@types/js-yaml': ^4.0.0 '@types/ramda': 0.27.39 dependency-path: workspace:8.0.6 - get-npm-tarball-url: 2.0.2 + get-npm-tarball-url: ^2.0.3 ramda: ^0.27.1 tempy: ^1.0.0 write-yaml-file: ^4.2.0 @@ -1424,7 +1426,7 @@ importers: '@pnpm/resolver-base': link:../resolver-base '@pnpm/types': link:../types dependency-path: link:../dependency-path - get-npm-tarball-url: 2.0.2 + get-npm-tarball-url: 2.0.3 ramda: 0.27.1 devDependencies: '@pnpm/lockfile-utils': 'link:' @@ -1619,10 +1621,10 @@ importers: specifiers: '@pnpm/normalize-registries': 'link:' '@pnpm/types': workspace:7.6.0 - normalize-registry-url: 1.0.0 + normalize-registry-url: 2.0.0 dependencies: '@pnpm/types': link:../types - normalize-registry-url: 1.0.0 + normalize-registry-url: 2.0.0 devDependencies: '@pnpm/normalize-registries': 'link:' @@ -3060,7 +3062,7 @@ importers: '@types/semver': ^7.3.4 dependency-path: workspace:8.0.6 encode-registry: ^3.0.0 - get-npm-tarball-url: 2.0.2 + get-npm-tarball-url: ^2.0.3 path-exists: ^4.0.0 ramda: ^0.27.1 replace-string: ^3.1.0 @@ -3082,7 +3084,7 @@ importers: '@pnpm/types': link:../types dependency-path: link:../dependency-path encode-registry: 3.0.0 - get-npm-tarball-url: 2.0.2 + get-npm-tarball-url: 2.0.3 path-exists: 4.0.0 ramda: 0.27.1 replace-string: 3.1.0 @@ -9306,11 +9308,9 @@ packages: has: 1.0.3 has-symbols: 1.0.2 - /get-npm-tarball-url/2.0.2: - resolution: {integrity: sha512-2dPhgT0K4pVyciTqdS0gr9nEwyCQwt9ql1/t5MCUMvcjWjAysjGJgT7Sx4n6oq3tFBjBN238mxX4RfTjT3838Q==} - engines: {node: '>=4'} - dependencies: - normalize-registry-url: 1.0.0 + /get-npm-tarball-url/2.0.3: + resolution: {integrity: sha512-R/PW6RqyaBQNWYaSyfrh54/qtcnOp22FHCCiRhSSZj0FP3KQWCsxxt0DzIdVTbwTqe9CtQfvl/FPD4UIPt4pqw==} + engines: {node: '>=12.17'} dev: false /get-package-type/0.1.0: @@ -12202,13 +12202,8 @@ packages: resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==} engines: {node: '>=0.10.0'} - /normalize-registry-url/1.0.0: - resolution: {integrity: sha512-0v6T4851b72ykk5zEtFoN4QX/Fqyk7pouIj9xZyAvAe9jlDhAwT4z6FlwsoQCHjeuK2EGUoAwy/F4y4B1uZq9A==} - dev: false - /normalize-registry-url/2.0.0: resolution: {integrity: sha512-3e9FwDyRAhbxXw4slm4Tjv40u78yPwMc/WZkACpqNQOs5sM7wic853AeTLkMFEVhivZkclGYlse8iYsklz0Yvg==} - dev: true /normalize-url/6.1.0: resolution: {integrity: sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==}