mirror of
https://github.com/pnpm/pnpm.git
synced 2026-02-01 10:42:28 -05:00
fix: return correct scoped registry for alias dependency (#3140)
close #3103 Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
5
.changeset/funny-goats-drum.md
Normal file
5
.changeset/funny-goats-drum.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/resolve-dependencies": patch
|
||||
---
|
||||
|
||||
fix scoped registry for aliased dependency
|
||||
6
.changeset/gold-fishes-grow.md
Normal file
6
.changeset/gold-fishes-grow.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/outdated": patch
|
||||
"@pnpm/plugin-commands-publishing": patch
|
||||
---
|
||||
|
||||
add pref to pick registries
|
||||
5
.changeset/swift-jobs-accept.md
Normal file
5
.changeset/swift-jobs-accept.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/pick-registry-for-package": minor
|
||||
---
|
||||
|
||||
add pref to pick registry
|
||||
@@ -34,7 +34,7 @@ export async function getManifest (
|
||||
lockfileDir: opts.lockfileDir,
|
||||
preferredVersions: {},
|
||||
projectDir: opts.dir,
|
||||
registry: pickRegistryForPackage(opts.registries, packageName),
|
||||
registry: pickRegistryForPackage(opts.registries, packageName, pref),
|
||||
})
|
||||
return resolution?.manifest ?? null
|
||||
}
|
||||
|
||||
1
packages/pick-registry-for-package/jest.config.js
Normal file
1
packages/pick-registry-for-package/jest.config.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('../../jest.config')
|
||||
@@ -19,8 +19,9 @@
|
||||
},
|
||||
"repository": "https://github.com/pnpm/pnpm/blob/master/packages/pick-registry-for-package",
|
||||
"scripts": {
|
||||
"test": "pnpm run compile",
|
||||
"lint": "eslint -c ../../eslint.json src/**/*.ts",
|
||||
"_test": "jest",
|
||||
"test": "pnpm run compile && pnpm run _test",
|
||||
"lint": "eslint -c ../../eslint.json src/**/*.ts test/**/*.ts",
|
||||
"prepublishOnly": "pnpm run compile",
|
||||
"compile": "rimraf lib tsconfig.tsbuildinfo && tsc --build"
|
||||
},
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import { Registries } from '@pnpm/types'
|
||||
|
||||
export default (registries: Registries, packageName: string) => {
|
||||
const scope = getScope(packageName)
|
||||
export default (registries: Registries, packageName: string, pref?: string) => {
|
||||
const scope = getScope(packageName, pref)
|
||||
return (scope && registries[scope]) ?? registries.default
|
||||
}
|
||||
|
||||
function getScope (pkgName: string): string | null {
|
||||
function getScope (pkgName: string, pref?: string): string | null {
|
||||
if (pref?.startsWith('npm:')) {
|
||||
pref = pref.substr(4)
|
||||
if (pref[0] === '@') {
|
||||
return pref.substr(0, pref.indexOf('/'))
|
||||
}
|
||||
}
|
||||
if (pkgName[0] === '@') {
|
||||
return pkgName.substr(0, pkgName.indexOf('/'))
|
||||
}
|
||||
|
||||
11
packages/pick-registry-for-package/test/index.spec.ts
Normal file
11
packages/pick-registry-for-package/test/index.spec.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import pickRegistryForPackage from '@pnpm/pick-registry-for-package'
|
||||
|
||||
test('pick correct scope', () => {
|
||||
const registries = {
|
||||
default: 'https://registry.npmjs.org/',
|
||||
'@private': 'https://private.registry.com/',
|
||||
}
|
||||
expect(pickRegistryForPackage(registries, '@private/lodash')).toBe('https://private.registry.com/')
|
||||
expect(pickRegistryForPackage(registries, '@random/lodash')).toBe('https://registry.npmjs.org/')
|
||||
expect(pickRegistryForPackage(registries, '@random/lodash', 'npm:@private/lodash@1')).toBe('https://private.registry.com/')
|
||||
})
|
||||
@@ -120,7 +120,7 @@ async function isAlreadyPublished (
|
||||
lockfileDir: opts.lockfileDir,
|
||||
preferredVersions: {},
|
||||
projectDir: opts.dir,
|
||||
registry: pickRegistryForPackage(opts.registries, pkgName),
|
||||
registry: pickRegistryForPackage(opts.registries, pkgName, pkgVersion),
|
||||
})
|
||||
return true
|
||||
} catch (err) {
|
||||
|
||||
@@ -596,7 +596,7 @@ async function resolveDependency (
|
||||
preferredVersions: options.preferredVersions,
|
||||
preferWorkspacePackages: ctx.preferWorkspacePackages,
|
||||
projectDir: options.currentDepth > 0 ? ctx.lockfileDir : ctx.prefix,
|
||||
registry: wantedDependency.alias && pickRegistryForPackage(ctx.registries, wantedDependency.alias) || ctx.registries.default,
|
||||
registry: wantedDependency.alias && pickRegistryForPackage(ctx.registries, wantedDependency.alias, wantedDependency.pref) || ctx.registries.default,
|
||||
// Unfortunately, even when run with --lockfile-only, we need the *real* package.json
|
||||
// so fetching of the tarball cannot be ever avoided. Related issue: https://github.com/pnpm/pnpm/issues/1176
|
||||
skipFetch: false,
|
||||
|
||||
Reference in New Issue
Block a user