Skip to content
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

fix: don't add trailing slash to registry URLs #4032

Merged
merged 1 commit into from Nov 23, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/forty-yaks-cheat.md
@@ -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 changes: 12 additions & 0 deletions .changeset/silent-kangaroos-whisper.md
@@ -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>
```
1 change: 1 addition & 0 deletions packages/config/package.json
Expand Up @@ -41,6 +41,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"
Expand Down
8 changes: 3 additions & 5 deletions 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}/`
}
5 changes: 3 additions & 2 deletions packages/config/src/index.ts
Expand Up @@ -9,10 +9,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 {
Expand Down Expand Up @@ -249,7 +250,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
Expand Down
4 changes: 3 additions & 1 deletion packages/config/test/index.ts
Expand Up @@ -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'),
Expand All @@ -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',
})
})

Expand All @@ -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',
})
})

Expand Down
1 change: 1 addition & 0 deletions 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
2 changes: 1 addition & 1 deletion packages/lockfile-utils/package.json
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion packages/normalize-registries/package.json
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion packages/resolve-dependencies/package.json
Expand Up @@ -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",
Expand Down
26 changes: 13 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.