mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-19 22:31:16 -04:00
fix: "pnpm store add" should read the registries of scoped pkgs
close #1737
This commit is contained in:
committed by
Zoltan Kochan
parent
0d8a7bef88
commit
714ca05d84
5
packages/package-store/typings/index.d.ts
vendored
5
packages/package-store/typings/index.d.ts
vendored
@@ -208,11 +208,6 @@ declare module 'is-subdir' {
|
||||
export = anything;
|
||||
}
|
||||
|
||||
declare module 'normalize-registry-url' {
|
||||
function normalizeRegistryUrl (registry: string): string
|
||||
export = normalizeRegistryUrl;
|
||||
}
|
||||
|
||||
declare module 'rename-overwrite' {
|
||||
const anything: any;
|
||||
export = anything;
|
||||
|
||||
@@ -37,7 +37,7 @@ export default async function (input: string[], opts: PnpmOptions) {
|
||||
store = await createStoreController(opts)
|
||||
return storeAdd(input.slice(1), {
|
||||
prefix: opts.prefix,
|
||||
registry: opts.registry,
|
||||
registries: opts.registries,
|
||||
reporter: opts.reporter,
|
||||
storeController: store.ctrl,
|
||||
tag: opts.tag,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
LogBase,
|
||||
PackageManifest,
|
||||
Registries,
|
||||
} from '@pnpm/types'
|
||||
|
||||
export type ReadPackageHook = (pkg: PackageManifest) => PackageManifest
|
||||
@@ -35,6 +36,7 @@ export interface PnpmOptions {
|
||||
engineStrict?: boolean,
|
||||
nodeVersion?: string,
|
||||
offline?: boolean,
|
||||
registries?: Registries,
|
||||
registry?: string,
|
||||
optional?: boolean,
|
||||
unsafePerm?: boolean,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { tempDir } from '@pnpm/prepare'
|
||||
import fs = require('mz/fs')
|
||||
import loadJsonFile from 'load-json-file'
|
||||
import path = require('path')
|
||||
import exists = require('path-exists')
|
||||
@@ -7,6 +8,7 @@ import promisifyTape from 'tape-promise'
|
||||
import { execPnpm } from './utils'
|
||||
|
||||
const test = promisifyTape(tape)
|
||||
const testOnly = promisifyTape(tape.only)
|
||||
|
||||
test('pnpm store add express@4.16.3', async function (t: tape.Test) {
|
||||
tempDir(t)
|
||||
@@ -27,3 +29,24 @@ test('pnpm store add express@4.16.3', async function (t: tape.Test) {
|
||||
'package has been added to the store index',
|
||||
)
|
||||
})
|
||||
|
||||
test('pnpm store add scoped package that uses not the standard registry', async function (t: tape.Test) {
|
||||
tempDir(t)
|
||||
await fs.writeFile('.npmrc', '@foo:registry=http://localhost:4873/', 'utf8')
|
||||
|
||||
const storeDir = path.resolve('store')
|
||||
|
||||
await execPnpm('store', 'add', '@foo/no-deps@1.0.0', '--registry', 'https://registry.npmjs.org/', '--store', storeDir)
|
||||
|
||||
const pathToCheck = path.join(storeDir, '2', 'localhost+4873', '@foo', 'no-deps', '1.0.0')
|
||||
t.ok(await exists(pathToCheck), `@foo/no-deps@1.0.0 is in store (at ${pathToCheck})`)
|
||||
|
||||
const storeIndex = await loadJsonFile(path.join(storeDir, '2', 'store.json'))
|
||||
t.deepEqual(
|
||||
storeIndex,
|
||||
{
|
||||
'localhost+4873/@foo/no-deps/1.0.0': [],
|
||||
},
|
||||
'package has been added to the store index',
|
||||
)
|
||||
})
|
||||
|
||||
5
packages/pnpm/typings/local.d.ts
vendored
5
packages/pnpm/typings/local.d.ts
vendored
@@ -213,11 +213,6 @@ declare module 'is-subdir' {
|
||||
export = anything;
|
||||
}
|
||||
|
||||
declare module 'normalize-registry-url' {
|
||||
function normalizeRegistryUrl (registry: string): string
|
||||
export = normalizeRegistryUrl;
|
||||
}
|
||||
|
||||
declare module 'encode-registry' {
|
||||
function encodeRegistry (registry: string): string
|
||||
export = encodeRegistry;
|
||||
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
createNodeId,
|
||||
getNonDevWantedDependencies,
|
||||
nodeIdContainsSequence,
|
||||
pickRegistryForPackage,
|
||||
splitNodeId,
|
||||
WantedDependency,
|
||||
} from '@pnpm/utils'
|
||||
@@ -433,9 +434,6 @@ async function resolveDependency (
|
||||
return null
|
||||
}
|
||||
|
||||
const scope = wantedDependency.alias && getScope(wantedDependency.alias)
|
||||
const registry = scope && ctx.registries[scope] || ctx.registries.default
|
||||
|
||||
let pkgResponse!: PackageResponse
|
||||
try {
|
||||
pkgResponse = await ctx.storeController.requestPackage(wantedDependency, {
|
||||
@@ -447,7 +445,7 @@ async function resolveDependency (
|
||||
lockfileDirectory: ctx.lockfileDirectory,
|
||||
preferredVersions: ctx.preferredVersions,
|
||||
prefix: ctx.prefix,
|
||||
registry,
|
||||
registry: wantedDependency.alias && pickRegistryForPackage(ctx.registries, wantedDependency.alias) || ctx.registries.default,
|
||||
sideEffectsCache: ctx.sideEffectsCache,
|
||||
// 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
|
||||
@@ -715,13 +713,6 @@ function getResolvedPackage (
|
||||
}
|
||||
}
|
||||
|
||||
function getScope (pkgName: string): string | null {
|
||||
if (pkgName[0] === '@') {
|
||||
return pkgName.substr(0, pkgName.indexOf('/'))
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function peerDependenciesWithoutOwn (pkg: PackageManifest) {
|
||||
if (!pkg.peerDependencies) return pkg.peerDependencies
|
||||
const ownDeps = new Set(
|
||||
|
||||
@@ -69,7 +69,6 @@
|
||||
"mkdirp-promise": "5.0.1",
|
||||
"mz": "2.7.0",
|
||||
"normalize-path": "3.0.0",
|
||||
"normalize-registry-url": "1.0.0",
|
||||
"p-every": "2.0.0",
|
||||
"p-filter": "2.0.0",
|
||||
"p-limit": "2.2.0",
|
||||
|
||||
@@ -3,7 +3,8 @@ import {
|
||||
streamParser,
|
||||
} from '@pnpm/logger'
|
||||
import { StoreController } from '@pnpm/store-controller-types'
|
||||
import normalizeRegistryUrl = require('normalize-registry-url')
|
||||
import { Registries } from '@pnpm/types'
|
||||
import { pickRegistryForPackage } from '@pnpm/utils'
|
||||
import parseWantedDependencies from './parseWantedDependencies'
|
||||
import { ReporterFunction } from './types'
|
||||
|
||||
@@ -11,7 +12,7 @@ export default async function (
|
||||
fuzzyDeps: string[],
|
||||
opts: {
|
||||
prefix?: string,
|
||||
registry?: string,
|
||||
registries?: Registries,
|
||||
reporter?: ReporterFunction,
|
||||
storeController: StoreController,
|
||||
tag?: string,
|
||||
@@ -34,6 +35,9 @@ export default async function (
|
||||
|
||||
let hasFailures = false
|
||||
const prefix = opts.prefix || process.cwd()
|
||||
const registries = opts.registries || {
|
||||
default: 'https://registry.npmjs.org/',
|
||||
}
|
||||
await Promise.all(deps.map(async (dep) => {
|
||||
try {
|
||||
const pkgResponse = await opts.storeController.requestPackage(dep, {
|
||||
@@ -41,7 +45,7 @@ export default async function (
|
||||
lockfileDirectory: prefix,
|
||||
preferredVersions: {},
|
||||
prefix,
|
||||
registry: normalizeRegistryUrl(opts.registry || 'https://registry.npmjs.org/'),
|
||||
registry: dep.alias && pickRegistryForPackage(registries, dep.alias) || registries.default,
|
||||
})
|
||||
await pkgResponse['fetchingFiles'] // tslint:disable-line:no-string-literal
|
||||
storeLogger.info(`+ ${pkgResponse.body.id}`)
|
||||
|
||||
@@ -110,7 +110,7 @@ test('find usages for package in store but not in any projects', async (t: tape.
|
||||
|
||||
// Add dependency directly to store (not to the project)
|
||||
await storeAdd(['is-negative'], {
|
||||
registry: registries.default,
|
||||
registries,
|
||||
tag: '2.1.0',
|
||||
...opts
|
||||
})
|
||||
@@ -142,13 +142,13 @@ test('find usages for multiple packages in store but not in any projects', async
|
||||
|
||||
// Add dependencies directly to store (not to the project). Note we add different versions of the same package
|
||||
await storeAdd(['is-negative'], {
|
||||
registry: registries.default,
|
||||
registries,
|
||||
tag: '2.0.0',
|
||||
...opts
|
||||
})
|
||||
await store.storeHas('is-negative', '2.0.0')
|
||||
await storeAdd(['is-negative'], {
|
||||
registry: registries.default,
|
||||
registries,
|
||||
tag: '2.1.0',
|
||||
...opts
|
||||
})
|
||||
|
||||
5
packages/supi/typings/local.d.ts
vendored
5
packages/supi/typings/local.d.ts
vendored
@@ -207,11 +207,6 @@ declare module 'is-subdir' {
|
||||
export = anything;
|
||||
}
|
||||
|
||||
declare module 'normalize-registry-url' {
|
||||
function normalizeRegistryUrl (registry: string): string
|
||||
export = normalizeRegistryUrl;
|
||||
}
|
||||
|
||||
declare module 'rename-overwrite' {
|
||||
const anything: any;
|
||||
export = anything;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import getAllDependenciesFromPackage from './getAllDependenciesFromPackage'
|
||||
import getSaveType from './getSaveType'
|
||||
import normalizeRegistries, { DEFAULT_REGISTRIES } from './normalizeRegistries'
|
||||
import pickRegistryForPackage from './pickRegistryForPackage'
|
||||
import realNodeModulesDir from './realNodeModulesDir'
|
||||
import safeReadPackage, { fromDir as safeReadPackageFromDir } from './safeReadPkg'
|
||||
|
||||
@@ -11,6 +12,7 @@ export {
|
||||
getAllDependenciesFromPackage,
|
||||
getSaveType,
|
||||
normalizeRegistries,
|
||||
pickRegistryForPackage,
|
||||
realNodeModulesDir,
|
||||
safeReadPackage,
|
||||
safeReadPackageFromDir,
|
||||
|
||||
13
packages/utils/src/pickRegistryForPackage.ts
Normal file
13
packages/utils/src/pickRegistryForPackage.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Registries } from '@pnpm/types'
|
||||
|
||||
export default (registries: Registries, packageName: string) => {
|
||||
const scope = getScope(packageName)
|
||||
return scope && registries[scope] || registries.default
|
||||
}
|
||||
|
||||
function getScope (pkgName: string): string | null {
|
||||
if (pkgName[0] === '@') {
|
||||
return pkgName.substr(0, pkgName.indexOf('/'))
|
||||
}
|
||||
return null
|
||||
}
|
||||
2
pnpm-lock.yaml
generated
2
pnpm-lock.yaml
generated
@@ -1836,7 +1836,6 @@ importers:
|
||||
mkdirp-promise: 5.0.1
|
||||
mz: 2.7.0
|
||||
normalize-path: 3.0.0
|
||||
normalize-registry-url: 1.0.0
|
||||
p-every: 2.0.0
|
||||
p-filter: 2.0.0
|
||||
p-limit: 2.2.0
|
||||
@@ -1971,7 +1970,6 @@ importers:
|
||||
mz: 2.7.0
|
||||
ncp: 2.0.0
|
||||
normalize-path: 3.0.0
|
||||
normalize-registry-url: 1.0.0
|
||||
npm-run-all: 4.1.5
|
||||
npm-scripts-info: 0.3.9
|
||||
p-every: 2.0.0
|
||||
|
||||
Reference in New Issue
Block a user