mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-06 14:08:27 -05:00
fix: don't add trailing slash to registry URLs (#4032)
ref #2933 close #4034
This commit is contained in:
10
.changeset/forty-yaks-cheat.md
Normal file
10
.changeset/forty-yaks-cheat.md
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
"@pnpm/config": patch
|
||||||
|
"@pnpm/normalize-registries": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
When normalizing registry URLs, a trailing slash should only be added if the registry URL has no path.
|
||||||
|
|
||||||
|
So `https://registry.npmjs.org` is changed to `https://registry.npmjs.org/` but `https://npm.pkg.github.com/owner` is unchanged.
|
||||||
|
|
||||||
|
Related issue: [#4034](https://github.com/pnpm/pnpm/issues/4034).
|
||||||
12
.changeset/silent-kangaroos-whisper.md
Normal file
12
.changeset/silent-kangaroos-whisper.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
"pnpm": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
pnpm should read the auth token of a github-registry-hosted package, when the registry path contains the owner [#4034](https://github.com/pnpm/pnpm/issues/4034).
|
||||||
|
|
||||||
|
So this should work:
|
||||||
|
|
||||||
|
```
|
||||||
|
@owner:registry=https://npm.pkg.github.com/owner
|
||||||
|
//npm.pkg.github.com/:_authToken=<token>
|
||||||
|
```
|
||||||
@@ -41,6 +41,7 @@
|
|||||||
"camelcase": "^6.2.0",
|
"camelcase": "^6.2.0",
|
||||||
"can-write-to-dir": "^1.1.1",
|
"can-write-to-dir": "^1.1.1",
|
||||||
"is-subdir": "^1.1.1",
|
"is-subdir": "^1.1.1",
|
||||||
|
"normalize-registry-url": "2.0.0",
|
||||||
"ramda": "^0.27.1",
|
"ramda": "^0.27.1",
|
||||||
"realpath-missing": "^1.1.0",
|
"realpath-missing": "^1.1.0",
|
||||||
"which": "^2.0.2"
|
"which": "^2.0.2"
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
|
import normalizeRegistryUrl from 'normalize-registry-url'
|
||||||
|
|
||||||
export default function getScopeRegistries (rawConfig: Object) {
|
export default function getScopeRegistries (rawConfig: Object) {
|
||||||
const registries = {}
|
const registries = {}
|
||||||
for (const configKey of Object.keys(rawConfig)) {
|
for (const configKey of Object.keys(rawConfig)) {
|
||||||
if (configKey[0] === '@' && configKey.endsWith(':registry')) {
|
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
|
return registries
|
||||||
}
|
}
|
||||||
|
|
||||||
export function normalizeRegistry (registry: string) {
|
|
||||||
return registry.endsWith('/') ? registry : `${registry}/`
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ import camelcase from 'camelcase'
|
|||||||
import loadNpmConf from '@zkochan/npm-conf'
|
import loadNpmConf from '@zkochan/npm-conf'
|
||||||
import npmTypes from '@zkochan/npm-conf/lib/types'
|
import npmTypes from '@zkochan/npm-conf/lib/types'
|
||||||
import { sync as canWriteToDir } from 'can-write-to-dir'
|
import { sync as canWriteToDir } from 'can-write-to-dir'
|
||||||
|
import normalizeRegistryUrl from 'normalize-registry-url'
|
||||||
import fromPairs from 'ramda/src/fromPairs'
|
import fromPairs from 'ramda/src/fromPairs'
|
||||||
import realpathMissing from 'realpath-missing'
|
import realpathMissing from 'realpath-missing'
|
||||||
import whichcb from 'which'
|
import whichcb from 'which'
|
||||||
import getScopeRegistries, { normalizeRegistry } from './getScopeRegistries'
|
import getScopeRegistries from './getScopeRegistries'
|
||||||
import findBestGlobalPrefix from './findBestGlobalPrefix'
|
import findBestGlobalPrefix from './findBestGlobalPrefix'
|
||||||
import { getCacheDir, getConfigDir, getDataDir, getStateDir } from './dirs'
|
import { getCacheDir, getConfigDir, getDataDir, getStateDir } from './dirs'
|
||||||
import {
|
import {
|
||||||
@@ -249,7 +250,7 @@ export default async (
|
|||||||
{ 'user-agent': pnpmConfig.userAgent },
|
{ 'user-agent': pnpmConfig.userAgent },
|
||||||
] as any) // eslint-disable-line @typescript-eslint/no-explicit-any
|
] as any) // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||||
pnpmConfig.registries = {
|
pnpmConfig.registries = {
|
||||||
default: normalizeRegistry(pnpmConfig.rawConfig.registry),
|
default: normalizeRegistryUrl(pnpmConfig.rawConfig.registry),
|
||||||
...getScopeRegistries(pnpmConfig.rawConfig),
|
...getScopeRegistries(pnpmConfig.rawConfig),
|
||||||
}
|
}
|
||||||
pnpmConfig.lockfileDir = pnpmConfig.lockfileDir ?? pnpmConfig.lockfileDirectory ?? pnpmConfig.shrinkwrapDirectory
|
pnpmConfig.lockfileDir = pnpmConfig.lockfileDir ?? pnpmConfig.lockfileDirectory ?? pnpmConfig.shrinkwrapDirectory
|
||||||
|
|||||||
@@ -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({
|
const { config } = await getConfig({
|
||||||
cliOptions: {
|
cliOptions: {
|
||||||
userconfig: path.join(__dirname, 'scoped-registries.ini'),
|
userconfig: path.join(__dirname, 'scoped-registries.ini'),
|
||||||
@@ -193,6 +193,7 @@ test('registries of scoped packages are read', async () => {
|
|||||||
default: 'https://default.com/',
|
default: 'https://default.com/',
|
||||||
'@foo': 'https://foo.com/',
|
'@foo': 'https://foo.com/',
|
||||||
'@bar': 'https://bar.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/',
|
default: 'https://pnpm.io/',
|
||||||
'@foo': 'https://foo.com/',
|
'@foo': 'https://foo.com/',
|
||||||
'@bar': 'https://bar.com/',
|
'@bar': 'https://bar.com/',
|
||||||
|
'@qar': 'https://qar.com/qar',
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
@foo:registry=https://foo.com
|
@foo:registry=https://foo.com
|
||||||
@bar:registry=https://bar.com
|
@bar:registry=https://bar.com
|
||||||
|
@qar:registry=https://qar.com/qar
|
||||||
registry=https://default.com
|
registry=https://default.com
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
"@pnpm/resolver-base": "workspace:8.1.1",
|
"@pnpm/resolver-base": "workspace:8.1.1",
|
||||||
"@pnpm/types": "workspace:7.6.0",
|
"@pnpm/types": "workspace:7.6.0",
|
||||||
"dependency-path": "workspace:8.0.6",
|
"dependency-path": "workspace:8.0.6",
|
||||||
"get-npm-tarball-url": "^2.0.2",
|
"get-npm-tarball-url": "^2.0.3",
|
||||||
"ramda": "^0.27.1"
|
"ramda": "^0.27.1"
|
||||||
},
|
},
|
||||||
"funding": "https://opencollective.com/pnpm"
|
"funding": "https://opencollective.com/pnpm"
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pnpm/types": "workspace:7.6.0",
|
"@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",
|
"homepage": "https://github.com/pnpm/pnpm/blob/master/packages/normalize-registries#readme",
|
||||||
"funding": "https://opencollective.com/pnpm"
|
"funding": "https://opencollective.com/pnpm"
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
"@pnpm/types": "workspace:7.6.0",
|
"@pnpm/types": "workspace:7.6.0",
|
||||||
"dependency-path": "workspace:8.0.6",
|
"dependency-path": "workspace:8.0.6",
|
||||||
"encode-registry": "^3.0.0",
|
"encode-registry": "^3.0.0",
|
||||||
"get-npm-tarball-url": "^2.0.2",
|
"get-npm-tarball-url": "^2.0.3",
|
||||||
"path-exists": "^4.0.0",
|
"path-exists": "^4.0.0",
|
||||||
"ramda": "^0.27.1",
|
"ramda": "^0.27.1",
|
||||||
"replace-string": "^3.1.0",
|
"replace-string": "^3.1.0",
|
||||||
|
|||||||
26
pnpm-lock.yaml
generated
26
pnpm-lock.yaml
generated
@@ -337,6 +337,7 @@ importers:
|
|||||||
camelcase: ^6.2.0
|
camelcase: ^6.2.0
|
||||||
can-write-to-dir: ^1.1.1
|
can-write-to-dir: ^1.1.1
|
||||||
is-subdir: ^1.1.1
|
is-subdir: ^1.1.1
|
||||||
|
normalize-registry-url: 2.0.0
|
||||||
ramda: ^0.27.1
|
ramda: ^0.27.1
|
||||||
realpath-missing: ^1.1.0
|
realpath-missing: ^1.1.0
|
||||||
symlink-dir: ^5.0.0
|
symlink-dir: ^5.0.0
|
||||||
@@ -351,6 +352,7 @@ importers:
|
|||||||
camelcase: 6.2.1
|
camelcase: 6.2.1
|
||||||
can-write-to-dir: 1.1.1
|
can-write-to-dir: 1.1.1
|
||||||
is-subdir: 1.2.0
|
is-subdir: 1.2.0
|
||||||
|
normalize-registry-url: 2.0.0
|
||||||
ramda: 0.27.1
|
ramda: 0.27.1
|
||||||
realpath-missing: 1.1.0
|
realpath-missing: 1.1.0
|
||||||
which: 2.0.2
|
which: 2.0.2
|
||||||
@@ -1412,7 +1414,7 @@ importers:
|
|||||||
'@types/js-yaml': ^4.0.0
|
'@types/js-yaml': ^4.0.0
|
||||||
'@types/ramda': 0.27.39
|
'@types/ramda': 0.27.39
|
||||||
dependency-path: workspace:8.0.6
|
dependency-path: workspace:8.0.6
|
||||||
get-npm-tarball-url: ^2.0.2
|
get-npm-tarball-url: ^2.0.3
|
||||||
ramda: ^0.27.1
|
ramda: ^0.27.1
|
||||||
tempy: ^1.0.0
|
tempy: ^1.0.0
|
||||||
write-yaml-file: ^4.2.0
|
write-yaml-file: ^4.2.0
|
||||||
@@ -1422,7 +1424,7 @@ importers:
|
|||||||
'@pnpm/resolver-base': link:../resolver-base
|
'@pnpm/resolver-base': link:../resolver-base
|
||||||
'@pnpm/types': link:../types
|
'@pnpm/types': link:../types
|
||||||
dependency-path: link:../dependency-path
|
dependency-path: link:../dependency-path
|
||||||
get-npm-tarball-url: 2.0.2
|
get-npm-tarball-url: 2.0.3
|
||||||
ramda: 0.27.1
|
ramda: 0.27.1
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@pnpm/lockfile-utils': 'link:'
|
'@pnpm/lockfile-utils': 'link:'
|
||||||
@@ -1617,10 +1619,10 @@ importers:
|
|||||||
specifiers:
|
specifiers:
|
||||||
'@pnpm/normalize-registries': 'link:'
|
'@pnpm/normalize-registries': 'link:'
|
||||||
'@pnpm/types': workspace:7.6.0
|
'@pnpm/types': workspace:7.6.0
|
||||||
normalize-registry-url: 1.0.0
|
normalize-registry-url: 2.0.0
|
||||||
dependencies:
|
dependencies:
|
||||||
'@pnpm/types': link:../types
|
'@pnpm/types': link:../types
|
||||||
normalize-registry-url: 1.0.0
|
normalize-registry-url: 2.0.0
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@pnpm/normalize-registries': 'link:'
|
'@pnpm/normalize-registries': 'link:'
|
||||||
|
|
||||||
@@ -3050,7 +3052,7 @@ importers:
|
|||||||
'@types/semver': ^7.3.4
|
'@types/semver': ^7.3.4
|
||||||
dependency-path: workspace:8.0.6
|
dependency-path: workspace:8.0.6
|
||||||
encode-registry: ^3.0.0
|
encode-registry: ^3.0.0
|
||||||
get-npm-tarball-url: ^2.0.2
|
get-npm-tarball-url: ^2.0.3
|
||||||
path-exists: ^4.0.0
|
path-exists: ^4.0.0
|
||||||
ramda: ^0.27.1
|
ramda: ^0.27.1
|
||||||
replace-string: ^3.1.0
|
replace-string: ^3.1.0
|
||||||
@@ -3072,7 +3074,7 @@ importers:
|
|||||||
'@pnpm/types': link:../types
|
'@pnpm/types': link:../types
|
||||||
dependency-path: link:../dependency-path
|
dependency-path: link:../dependency-path
|
||||||
encode-registry: 3.0.0
|
encode-registry: 3.0.0
|
||||||
get-npm-tarball-url: 2.0.2
|
get-npm-tarball-url: 2.0.3
|
||||||
path-exists: 4.0.0
|
path-exists: 4.0.0
|
||||||
ramda: 0.27.1
|
ramda: 0.27.1
|
||||||
replace-string: 3.1.0
|
replace-string: 3.1.0
|
||||||
@@ -9052,11 +9054,9 @@ packages:
|
|||||||
has: 1.0.3
|
has: 1.0.3
|
||||||
has-symbols: 1.0.2
|
has-symbols: 1.0.2
|
||||||
|
|
||||||
/get-npm-tarball-url/2.0.2:
|
/get-npm-tarball-url/2.0.3:
|
||||||
resolution: {integrity: sha512-2dPhgT0K4pVyciTqdS0gr9nEwyCQwt9ql1/t5MCUMvcjWjAysjGJgT7Sx4n6oq3tFBjBN238mxX4RfTjT3838Q==}
|
resolution: {integrity: sha512-R/PW6RqyaBQNWYaSyfrh54/qtcnOp22FHCCiRhSSZj0FP3KQWCsxxt0DzIdVTbwTqe9CtQfvl/FPD4UIPt4pqw==}
|
||||||
engines: {node: '>=4'}
|
engines: {node: '>=12.17'}
|
||||||
dependencies:
|
|
||||||
normalize-registry-url: 1.0.0
|
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/get-package-type/0.1.0:
|
/get-package-type/0.1.0:
|
||||||
@@ -11868,8 +11868,8 @@ packages:
|
|||||||
resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==}
|
resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==}
|
||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
|
|
||||||
/normalize-registry-url/1.0.0:
|
/normalize-registry-url/2.0.0:
|
||||||
resolution: {integrity: sha512-0v6T4851b72ykk5zEtFoN4QX/Fqyk7pouIj9xZyAvAe9jlDhAwT4z6FlwsoQCHjeuK2EGUoAwy/F4y4B1uZq9A==}
|
resolution: {integrity: sha512-3e9FwDyRAhbxXw4slm4Tjv40u78yPwMc/WZkACpqNQOs5sM7wic853AeTLkMFEVhivZkclGYlse8iYsklz0Yvg==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/now-and-later/2.0.1:
|
/now-and-later/2.0.1:
|
||||||
|
|||||||
Reference in New Issue
Block a user