mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-24 23:58:07 -05:00
feat!: don't include registry URL in package ID (#7476)
This commit is contained in:
15
.changeset/eight-shoes-dream.md
Normal file
15
.changeset/eight-shoes-dream.md
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
"@pnpm/resolve-dependencies": major
|
||||
"@pnpm/package-requester": major
|
||||
"@pnpm/modules-cleaner": major
|
||||
"@pnpm/plugin-commands-store": major
|
||||
"@pnpm/dependency-path": major
|
||||
"@pnpm/lockfile-utils": major
|
||||
"@pnpm/npm-resolver": major
|
||||
"@pnpm/headless": major
|
||||
"@pnpm/core": major
|
||||
"@pnpm/server": major
|
||||
"@pnpm/deps.graph-builder": minor
|
||||
---
|
||||
|
||||
Package ID does not contain the registry domain.
|
||||
4
deps/graph-builder/src/lockfileToDepGraph.ts
vendored
4
deps/graph-builder/src/lockfileToDepGraph.ts
vendored
@@ -106,7 +106,7 @@ export async function lockfileToDepGraph (
|
||||
// TODO: optimize. This info can be already returned by pkgSnapshotToResolution()
|
||||
const { name: pkgName, version: pkgVersion } = nameVerFromPkgSnapshot(depPath, pkgSnapshot)
|
||||
const modules = path.join(opts.virtualStoreDir, dp.depPathToFilename(depPath), 'node_modules')
|
||||
const packageId = packageIdFromSnapshot(depPath, pkgSnapshot, opts.registries)
|
||||
const packageId = packageIdFromSnapshot(depPath, pkgSnapshot)
|
||||
|
||||
const pkg = {
|
||||
name: pkgName,
|
||||
@@ -256,7 +256,7 @@ function getChildrenPaths (
|
||||
) {
|
||||
const children: { [alias: string]: string } = {}
|
||||
for (const [alias, ref] of Object.entries(allDeps)) {
|
||||
const childDepPath = dp.refToAbsolute(ref, alias, ctx.registries)
|
||||
const childDepPath = dp.refToRelative(ref, alias)
|
||||
if (childDepPath === null) {
|
||||
children[alias] = path.resolve(ctx.lockfileDir, importerId, ref.slice(5))
|
||||
continue
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { type PackageSnapshot } from '@pnpm/lockfile-types'
|
||||
import { type Registries } from '@pnpm/types'
|
||||
import * as dp from '@pnpm/dependency-path'
|
||||
|
||||
export function packageIdFromSnapshot (
|
||||
depPath: string,
|
||||
pkgSnapshot: PackageSnapshot,
|
||||
registries: Registries
|
||||
pkgSnapshot: PackageSnapshot
|
||||
) {
|
||||
if (pkgSnapshot.id) return pkgSnapshot.id
|
||||
return dp.tryGetPackageId(registries, depPath) ?? depPath
|
||||
return dp.tryGetPackageId(depPath) ?? depPath
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
"dependencies": {
|
||||
"@pnpm/crypto.base32-hash": "workspace:*",
|
||||
"@pnpm/types": "workspace:*",
|
||||
"encode-registry": "^3.0.1",
|
||||
"semver": "^7.5.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,31 +1,11 @@
|
||||
import { createBase32Hash } from '@pnpm/crypto.base32-hash'
|
||||
import { type Registries } from '@pnpm/types'
|
||||
import encodeRegistry from 'encode-registry'
|
||||
import semver from 'semver'
|
||||
|
||||
export function isAbsolute (dependencyPath: string) {
|
||||
return dependencyPath[0] !== '/'
|
||||
}
|
||||
|
||||
export function resolve (
|
||||
registries: Registries,
|
||||
resolutionLocation: string
|
||||
) {
|
||||
if (!isAbsolute(resolutionLocation)) {
|
||||
let registryUrl!: string
|
||||
if (resolutionLocation[1] === '@') {
|
||||
const slashIndex = resolutionLocation.indexOf('/', 1)
|
||||
const scope = resolutionLocation.slice(1, slashIndex !== -1 ? slashIndex : 0)
|
||||
registryUrl = registries[scope] || registries.default
|
||||
} else {
|
||||
registryUrl = registries.default
|
||||
}
|
||||
const registryDirectory = encodeRegistry(registryUrl)
|
||||
return `${registryDirectory}${resolutionLocation}`
|
||||
}
|
||||
return resolutionLocation
|
||||
}
|
||||
|
||||
export function indexOfPeersSuffix (depPath: string) {
|
||||
if (!depPath.endsWith(')')) return -1
|
||||
let open = true
|
||||
@@ -42,32 +22,15 @@ export function indexOfPeersSuffix (depPath: string) {
|
||||
return -1
|
||||
}
|
||||
|
||||
export function tryGetPackageId (registries: Registries, relDepPath: string) {
|
||||
export function tryGetPackageId (relDepPath: string) {
|
||||
if (relDepPath[0] !== '/') {
|
||||
return null
|
||||
}
|
||||
const sepIndex = indexOfPeersSuffix(relDepPath)
|
||||
if (sepIndex !== -1) {
|
||||
return resolve(registries, relDepPath.substring(0, sepIndex))
|
||||
return relDepPath.substring(0, sepIndex)
|
||||
}
|
||||
return resolve(registries, relDepPath)
|
||||
}
|
||||
|
||||
export function refToAbsolute (
|
||||
reference: string,
|
||||
pkgName: string,
|
||||
registries: Registries
|
||||
) {
|
||||
if (reference.startsWith('link:')) {
|
||||
return null
|
||||
}
|
||||
if (!reference.includes('/') || reference.includes('(') && reference.lastIndexOf('/', reference.indexOf('(')) === -1) {
|
||||
const registryName = encodeRegistry(getRegistryByPackageName(registries, pkgName))
|
||||
return `${registryName}/${pkgName}/${reference}`
|
||||
}
|
||||
if (reference[0] !== '/') return reference
|
||||
const registryName = encodeRegistry(getRegistryByPackageName(registries, pkgName))
|
||||
return `${registryName}${reference}`
|
||||
return relDepPath
|
||||
}
|
||||
|
||||
export function getRegistryByPackageName (registries: Registries, packageName: string) {
|
||||
@@ -76,19 +39,6 @@ export function getRegistryByPackageName (registries: Registries, packageName: s
|
||||
return registries[scope] || registries.default
|
||||
}
|
||||
|
||||
export function relative (
|
||||
registries: Registries,
|
||||
packageName: string,
|
||||
absoluteResolutionLoc: string
|
||||
) {
|
||||
const registryName = encodeRegistry(getRegistryByPackageName(registries, packageName))
|
||||
|
||||
if (absoluteResolutionLoc.startsWith(`${registryName}/`)) {
|
||||
return absoluteResolutionLoc.slice(absoluteResolutionLoc.indexOf('/'))
|
||||
}
|
||||
return absoluteResolutionLoc
|
||||
}
|
||||
|
||||
export function refToRelative (
|
||||
reference: string,
|
||||
pkgName: string
|
||||
|
||||
@@ -3,10 +3,7 @@ import {
|
||||
depPathToFilename,
|
||||
isAbsolute,
|
||||
parse,
|
||||
refToAbsolute,
|
||||
refToRelative,
|
||||
relative,
|
||||
resolve,
|
||||
tryGetPackageId,
|
||||
} from '@pnpm/dependency-path'
|
||||
|
||||
@@ -52,22 +49,6 @@ test('parse()', () => {
|
||||
})
|
||||
})
|
||||
|
||||
test('refToAbsolute()', () => {
|
||||
const registries = {
|
||||
'@foo': 'http://foo.com/',
|
||||
default: 'https://registry.npmjs.org/',
|
||||
}
|
||||
expect(refToAbsolute('1.0.0', 'foo', registries)).toEqual('registry.npmjs.org/foo/1.0.0')
|
||||
expect(refToAbsolute('1.0.0', '@foo/foo', registries)).toEqual('foo.com/@foo/foo/1.0.0')
|
||||
expect(refToAbsolute('registry.npmjs.org/foo/1.0.0', 'foo', registries)).toEqual('registry.npmjs.org/foo/1.0.0')
|
||||
expect(refToAbsolute('/foo/1.0.0', 'foo', registries)).toEqual('registry.npmjs.org/foo/1.0.0')
|
||||
expect(refToAbsolute('/@foo/foo/1.0.0', '@foo/foo', registries)).toEqual('foo.com/@foo/foo/1.0.0')
|
||||
expect(refToAbsolute('/@foo/foo@1.0.0(@foo/bar@1.0.0)', '@foo/foo', registries)).toEqual('foo.com/@foo/foo@1.0.0(@foo/bar@1.0.0)')
|
||||
expect(refToAbsolute('/@foo/foo@1.0.0(@foo/bar@1.0.0)(@foo/qar@1.0.0)', '@foo/foo', registries)).toEqual('foo.com/@foo/foo@1.0.0(@foo/bar@1.0.0)(@foo/qar@1.0.0)')
|
||||
// linked dependencies don't have an absolute path
|
||||
expect(refToAbsolute('link:../foo', 'foo', registries)).toBeNull()
|
||||
})
|
||||
|
||||
test('refToRelative()', () => {
|
||||
expect(refToRelative('/@most/multicast/1.3.0/most@1.7.3', '@most/multicast')).toEqual('/@most/multicast/1.3.0/most@1.7.3')
|
||||
expect(refToRelative('/@most/multicast/1.3.0/most@1.7.3(@foo/bar@1.0.0)', '@most/multicast')).toEqual('/@most/multicast/1.3.0/most@1.7.3(@foo/bar@1.0.0)')
|
||||
@@ -79,27 +60,6 @@ test('refToRelative()', () => {
|
||||
expect(refToRelative('1.3.0(@foo/bar@1.0.0)(@foo/qar@1.0.0)', '@qar/bar')).toEqual('/@qar/bar@1.3.0(@foo/bar@1.0.0)(@foo/qar@1.0.0)')
|
||||
})
|
||||
|
||||
test('relative()', () => {
|
||||
const registries = {
|
||||
'@foo': 'http://localhost:4873/',
|
||||
default: 'https://registry.npmjs.org/',
|
||||
}
|
||||
expect(relative(registries, 'foo', 'registry.npmjs.org/foo/1.0.0')).toEqual('/foo/1.0.0')
|
||||
expect(relative(registries, '@foo/foo', 'localhost+4873/@foo/foo/1.0.0')).toEqual('/@foo/foo/1.0.0')
|
||||
expect(relative(registries, 'foo', 'registry.npmjs.org/foo/1.0.0/PeLdniYiO858gXNY39o5wISKyw')).toEqual('/foo/1.0.0/PeLdniYiO858gXNY39o5wISKyw')
|
||||
})
|
||||
|
||||
test('resolve()', () => {
|
||||
const registries = {
|
||||
'@bar': 'https://bar.com/',
|
||||
default: 'https://foo.com/',
|
||||
}
|
||||
expect(resolve(registries, '/foo/1.0.0')).toEqual('foo.com/foo/1.0.0')
|
||||
expect(resolve(registries, '/@bar/bar/1.0.0')).toEqual('bar.com/@bar/bar/1.0.0')
|
||||
expect(resolve(registries, '/@qar/qar/1.0.0')).toEqual('foo.com/@qar/qar/1.0.0')
|
||||
expect(resolve(registries, 'qar.com/foo/1.0.0')).toEqual('qar.com/foo/1.0.0')
|
||||
})
|
||||
|
||||
test('depPathToFilename()', () => {
|
||||
expect(depPathToFilename('/foo@1.0.0')).toBe('foo@1.0.0')
|
||||
expect(depPathToFilename('/@foo/bar@1.0.0')).toBe('@foo+bar@1.0.0')
|
||||
@@ -116,6 +76,6 @@ test('depPathToFilename()', () => {
|
||||
})
|
||||
|
||||
test('tryGetPackageId', () => {
|
||||
expect(tryGetPackageId({ default: 'https://registry.npmjs.org/' }, '/foo@1.0.0(@types/babel__core@7.1.14)')).toEqual('registry.npmjs.org/foo@1.0.0')
|
||||
expect(tryGetPackageId({ default: 'https://registry.npmjs.org/' }, '/@(-.-)/foo@1.0.0(@types/babel__core@7.1.14)')).toEqual('registry.npmjs.org/@(-.-)/foo@1.0.0')
|
||||
expect(tryGetPackageId('/foo@1.0.0(@types/babel__core@7.1.14)')).toEqual('/foo@1.0.0')
|
||||
expect(tryGetPackageId('/@(-.-)/foo@1.0.0(@types/babel__core@7.1.14)')).toEqual('/@(-.-)/foo@1.0.0')
|
||||
})
|
||||
|
||||
@@ -115,7 +115,6 @@ export async function linkPackages (
|
||||
pruneStore: opts.pruneStore,
|
||||
pruneVirtualStore: opts.pruneVirtualStore,
|
||||
publicHoistedModulesDir: (opts.publicHoistPattern != null) ? opts.rootModulesDir : undefined,
|
||||
registries: opts.registries,
|
||||
skipped: opts.skipped,
|
||||
storeController: opts.storeController,
|
||||
virtualStoreDir: opts.virtualStoreDir,
|
||||
|
||||
@@ -32,7 +32,7 @@ test('fail if none of the available resolvers support a version spec', async ()
|
||||
expect(err.pkgsStack).toStrictEqual(
|
||||
[
|
||||
{
|
||||
id: `localhost+${REGISTRY_MOCK_PORT}/@types/plotly.js@1.44.29`,
|
||||
id: '/@types/plotly.js@1.44.29',
|
||||
name: '@types/plotly.js',
|
||||
version: '1.44.29',
|
||||
},
|
||||
@@ -70,7 +70,7 @@ test('fail if a package cannot be fetched', async () => {
|
||||
expect(err.pkgsStack).toStrictEqual(
|
||||
[
|
||||
{
|
||||
id: `localhost+${REGISTRY_MOCK_PORT}/@pnpm.e2e/pkg-with-1-dep@100.0.0`,
|
||||
id: '/@pnpm.e2e/pkg-with-1-dep@100.0.0',
|
||||
name: '@pnpm.e2e/pkg-with-1-dep',
|
||||
version: '100.0.0',
|
||||
},
|
||||
|
||||
@@ -695,13 +695,13 @@ test('lockfile locks npm dependencies', async () => {
|
||||
expect(reporter.calledWithMatch({
|
||||
level: 'debug',
|
||||
name: 'pnpm:progress',
|
||||
packageId: `localhost+${REGISTRY_MOCK_PORT}/@pnpm.e2e/pkg-with-1-dep@100.0.0`,
|
||||
packageId: '/@pnpm.e2e/pkg-with-1-dep@100.0.0',
|
||||
requester: process.cwd(),
|
||||
status: 'resolved',
|
||||
} as ProgressLog)).toBeTruthy()
|
||||
expect(reporter.calledWithMatch({
|
||||
level: 'debug',
|
||||
packageId: `localhost+${REGISTRY_MOCK_PORT}/@pnpm.e2e/pkg-with-1-dep@100.0.0`,
|
||||
packageId: '/@pnpm.e2e/pkg-with-1-dep@100.0.0',
|
||||
requester: process.cwd(),
|
||||
status: 'fetched',
|
||||
} as ProgressLog)).toBeTruthy()
|
||||
@@ -717,13 +717,13 @@ test('lockfile locks npm dependencies', async () => {
|
||||
|
||||
expect(reporter.calledWithMatch({
|
||||
level: 'debug',
|
||||
packageId: `localhost+${REGISTRY_MOCK_PORT}/@pnpm.e2e/pkg-with-1-dep@100.0.0`,
|
||||
packageId: '/@pnpm.e2e/pkg-with-1-dep@100.0.0',
|
||||
requester: process.cwd(),
|
||||
status: 'resolved',
|
||||
} as ProgressLog)).toBeTruthy()
|
||||
expect(reporter.calledWithMatch({
|
||||
level: 'debug',
|
||||
packageId: `localhost+${REGISTRY_MOCK_PORT}/@pnpm.e2e/pkg-with-1-dep@100.0.0`,
|
||||
packageId: '/@pnpm.e2e/pkg-with-1-dep@100.0.0',
|
||||
requester: process.cwd(),
|
||||
status: 'found_in_store',
|
||||
} as ProgressLog)).toBeTruthy()
|
||||
|
||||
@@ -2,7 +2,6 @@ import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { type Lockfile } from '@pnpm/lockfile-file'
|
||||
import { prepareEmpty, preparePackages } from '@pnpm/prepare'
|
||||
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
|
||||
import deepRequireCwd from 'deep-require-cwd'
|
||||
import readYamlFile from 'read-yaml-file'
|
||||
import {
|
||||
@@ -95,7 +94,7 @@ test('skip optional dependency that does not support the current OS', async () =
|
||||
|
||||
const logMatcher = sinon.match({
|
||||
package: {
|
||||
id: `localhost+${REGISTRY_MOCK_PORT}/@pnpm.e2e/not-compatible-with-any-os@1.0.0`,
|
||||
id: '/@pnpm.e2e/not-compatible-with-any-os@1.0.0',
|
||||
name: '@pnpm.e2e/not-compatible-with-any-os',
|
||||
version: '1.0.0',
|
||||
},
|
||||
@@ -147,7 +146,7 @@ test('skip optional dependency that does not support the current Node version',
|
||||
|
||||
const logMatcher = sinon.match({
|
||||
package: {
|
||||
id: `localhost+${REGISTRY_MOCK_PORT}/@pnpm.e2e/for-legacy-node@1.0.0`,
|
||||
id: '/@pnpm.e2e/for-legacy-node@1.0.0',
|
||||
name: '@pnpm.e2e/for-legacy-node',
|
||||
version: '1.0.0',
|
||||
},
|
||||
@@ -176,7 +175,7 @@ test('skip optional dependency that does not support the current pnpm version',
|
||||
|
||||
const logMatcher = sinon.match({
|
||||
package: {
|
||||
id: `localhost+${REGISTRY_MOCK_PORT}/@pnpm.e2e/for-legacy-pnpm@1.0.0`,
|
||||
id: '/@pnpm.e2e/for-legacy-pnpm@1.0.0',
|
||||
name: '@pnpm.e2e/for-legacy-pnpm',
|
||||
version: '1.0.0',
|
||||
},
|
||||
@@ -286,7 +285,7 @@ test('optional subdependency is skipped', async () => {
|
||||
|
||||
const logMatcher = sinon.match({
|
||||
package: {
|
||||
id: `localhost+${REGISTRY_MOCK_PORT}/@pnpm.e2e/not-compatible-with-any-os@1.0.0`,
|
||||
id: '/@pnpm.e2e/not-compatible-with-any-os@1.0.0',
|
||||
name: '@pnpm.e2e/not-compatible-with-any-os',
|
||||
version: '1.0.0',
|
||||
},
|
||||
|
||||
@@ -29,7 +29,7 @@ test("don't fail when peer dependency is fetched from GitHub", async () => {
|
||||
await addDependenciesToPackage({}, ['@pnpm.e2e/test-pnpm-peer-deps'], await testDefaults())
|
||||
})
|
||||
|
||||
test('peer dependency is grouped with dependency when peer is resolved not from a top dependency', async () => {
|
||||
test('peer dependency is grouped with dependency when peer is resolved not from a top dependency 1', async () => {
|
||||
const project = prepareEmpty()
|
||||
const opts = await testDefaults()
|
||||
let manifest = await addDependenciesToPackage({}, ['@pnpm.e2e/using-ajv'], opts)
|
||||
@@ -1239,7 +1239,7 @@ test('peer dependency that is resolved by a dev dependency', async () => {
|
||||
await project.hasNot('@types/mongoose')
|
||||
})
|
||||
|
||||
test('peer dependency is grouped with dependency when peer is resolved not from a top dependency', async () => {
|
||||
test('peer dependency is grouped with dependency when peer is resolved not from a top dependency 2', async () => {
|
||||
const project1Manifest = {
|
||||
name: 'project-1',
|
||||
version: '1.0.0',
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { type DeprecationLog } from '@pnpm/core-loggers'
|
||||
import { prepareEmpty } from '@pnpm/prepare'
|
||||
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
|
||||
import {
|
||||
addDependenciesToPackage,
|
||||
} from '@pnpm/core'
|
||||
@@ -17,7 +16,7 @@ test('reports warning when installing deprecated packages', async () => {
|
||||
deprecated: 'express 0.x series is deprecated',
|
||||
level: 'debug',
|
||||
name: 'pnpm:deprecation',
|
||||
pkgId: `localhost+${REGISTRY_MOCK_PORT}/express@0.14.1`,
|
||||
pkgId: '/express@0.14.1',
|
||||
} as DeprecationLog))
|
||||
|
||||
const lockfile = await project.readLockfile()
|
||||
|
||||
@@ -245,7 +245,6 @@ export async function headlessInstall (opts: HeadlessOptions): Promise<Installat
|
||||
pruneStore: opts.pruneStore,
|
||||
pruneVirtualStore: opts.pruneVirtualStore,
|
||||
publicHoistedModulesDir: (opts.publicHoistPattern == null) ? undefined : publicHoistedModulesDir,
|
||||
registries: opts.registries,
|
||||
skipped,
|
||||
storeController: opts.storeController,
|
||||
virtualStoreDir,
|
||||
@@ -787,7 +786,7 @@ async function getRootPackagesToLink (
|
||||
if (depPath === null) return
|
||||
const pkgSnapshot = lockfile.packages?.[depPath]
|
||||
if (pkgSnapshot == null) return // this won't ever happen. Just making typescript happy
|
||||
const pkgId = pkgSnapshot.id ?? dp.refToAbsolute(ref, alias, opts.registries) ?? undefined
|
||||
const pkgId = pkgSnapshot.id ?? dp.refToRelative(ref, alias) ?? undefined
|
||||
const pkgInfo = nameVerFromPkgSnapshot(depPath, pkgSnapshot)
|
||||
return {
|
||||
alias,
|
||||
|
||||
@@ -169,7 +169,7 @@ async function fetchDeps (
|
||||
return
|
||||
}
|
||||
const { name: pkgName, version: pkgVersion } = nameVerFromPkgSnapshot(depPath, pkgSnapshot)
|
||||
const packageId = packageIdFromSnapshot(depPath, pkgSnapshot, opts.registries)
|
||||
const packageId = packageIdFromSnapshot(depPath, pkgSnapshot)
|
||||
|
||||
const pkg = {
|
||||
name: pkgName,
|
||||
|
||||
@@ -14,7 +14,7 @@ import { headlessInstall } from '@pnpm/headless'
|
||||
import { readWantedLockfile } from '@pnpm/lockfile-file'
|
||||
import { readModulesManifest } from '@pnpm/modules-yaml'
|
||||
import { tempDir } from '@pnpm/prepare'
|
||||
import { getIntegrity, REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
|
||||
import { getIntegrity } from '@pnpm/registry-mock'
|
||||
import { fixtures } from '@pnpm/test-fixtures'
|
||||
import { createTestIpcServer } from '@pnpm/test-ipc-server'
|
||||
import rimraf from '@zkochan/rimraf'
|
||||
@@ -73,7 +73,7 @@ test('installing a simple project', async () => {
|
||||
} as StageLog)).toBeTruthy()
|
||||
expect(reporter.calledWithMatch({
|
||||
level: 'debug',
|
||||
packageId: `localhost+${REGISTRY_MOCK_PORT}/is-negative@2.1.0`,
|
||||
packageId: '/is-negative@2.1.0',
|
||||
requester: prefix,
|
||||
status: 'resolved',
|
||||
})).toBeTruthy()
|
||||
@@ -425,13 +425,13 @@ test('available packages are used when node_modules is not clean', async () => {
|
||||
|
||||
expect(reporter.calledWithMatch({
|
||||
level: 'debug',
|
||||
packageId: `localhost+${REGISTRY_MOCK_PORT}/balanced-match@1.0.2`,
|
||||
packageId: '/balanced-match@1.0.2',
|
||||
requester: projectDir,
|
||||
status: 'resolved',
|
||||
})).toBeFalsy()
|
||||
expect(reporter.calledWithMatch({
|
||||
level: 'debug',
|
||||
packageId: `localhost+${REGISTRY_MOCK_PORT}/rimraf@2.7.1`,
|
||||
packageId: '/rimraf@2.7.1',
|
||||
requester: projectDir,
|
||||
status: 'resolved',
|
||||
})).toBeTruthy()
|
||||
@@ -462,13 +462,13 @@ test('available packages are relinked during forced install', async () => {
|
||||
|
||||
expect(reporter.calledWithMatch({
|
||||
level: 'debug',
|
||||
packageId: `localhost+${REGISTRY_MOCK_PORT}/balanced-match@1.0.2`,
|
||||
packageId: '/balanced-match@1.0.2',
|
||||
requester: projectDir,
|
||||
status: 'resolved',
|
||||
})).toBeTruthy()
|
||||
expect(reporter.calledWithMatch({
|
||||
level: 'debug',
|
||||
packageId: `localhost+${REGISTRY_MOCK_PORT}/rimraf@2.7.1`,
|
||||
packageId: '/rimraf@2.7.1',
|
||||
requester: projectDir,
|
||||
status: 'resolved',
|
||||
})).toBeTruthy()
|
||||
@@ -585,7 +585,7 @@ test('installing with hoistPattern=*', async () => {
|
||||
} as StageLog))
|
||||
expect(reporter).toBeCalledWith(expect.objectContaining({
|
||||
level: 'debug',
|
||||
packageId: `localhost+${REGISTRY_MOCK_PORT}/is-negative@2.1.0`,
|
||||
packageId: '/is-negative@2.1.0',
|
||||
requester: prefix,
|
||||
status: 'resolved',
|
||||
}))
|
||||
@@ -641,7 +641,7 @@ test('installing with publicHoistPattern=*', async () => {
|
||||
} as StageLog)).toBeTruthy()
|
||||
expect(reporter.calledWithMatch({
|
||||
level: 'debug',
|
||||
packageId: `localhost+${REGISTRY_MOCK_PORT}/is-negative@2.1.0`,
|
||||
packageId: '/is-negative@2.1.0',
|
||||
requester: prefix,
|
||||
status: 'resolved',
|
||||
})).toBeTruthy()
|
||||
@@ -724,7 +724,7 @@ test.skip('using side effects cache and hoistPattern=*', async () => {
|
||||
const project = assertProject(lockfileDir)
|
||||
await project.has('.pnpm/node_modules/es6-promise') // verifying that a flat node_modules was created
|
||||
|
||||
const cacheBuildDir = path.join(opts.storeDir, `localhost+${REGISTRY_MOCK_PORT}/diskusage@1.1.3/side_effects/${ENGINE_DIR}/package/build`)
|
||||
const cacheBuildDir = path.join(opts.storeDir, `diskusage@1.1.3/side_effects/${ENGINE_DIR}/package/build`)
|
||||
writeFileSync(path.join(cacheBuildDir, 'new-file.txt'), 'some new content')
|
||||
|
||||
await rimraf(path.join(lockfileDir, 'node_modules'))
|
||||
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
type DependenciesField,
|
||||
DEPENDENCIES_FIELDS,
|
||||
type HoistedDependencies,
|
||||
type Registries,
|
||||
} from '@pnpm/types'
|
||||
import { depPathToFilename } from '@pnpm/dependency-path'
|
||||
import rimraf from '@zkochan/rimraf'
|
||||
@@ -48,7 +47,6 @@ export async function prune (
|
||||
currentLockfile: Lockfile
|
||||
pruneStore?: boolean
|
||||
pruneVirtualStore?: boolean
|
||||
registries: Registries
|
||||
skipped: Set<string>
|
||||
virtualStoreDir: string
|
||||
lockfileDir: string
|
||||
@@ -127,9 +125,9 @@ export async function prune (
|
||||
// we may only prune dependencies that are used only by that subset of importers.
|
||||
// Otherwise, we would break the node_modules.
|
||||
const currentPkgIdsByDepPaths = equals(selectedImporterIds, Object.keys(opts.wantedLockfile.importers))
|
||||
? getPkgsDepPaths(opts.registries, opts.currentLockfile.packages ?? {}, opts.skipped)
|
||||
: getPkgsDepPathsOwnedOnlyByImporters(selectedImporterIds, opts.registries, opts.currentLockfile, opts.include, opts.skipped)
|
||||
const wantedPkgIdsByDepPaths = getPkgsDepPaths(opts.registries, wantedLockfile.packages ?? {}, opts.skipped)
|
||||
? getPkgsDepPaths(opts.currentLockfile.packages ?? {}, opts.skipped)
|
||||
: getPkgsDepPathsOwnedOnlyByImporters(selectedImporterIds, opts.currentLockfile, opts.include, opts.skipped)
|
||||
const wantedPkgIdsByDepPaths = getPkgsDepPaths(wantedLockfile.packages ?? {}, opts.skipped)
|
||||
|
||||
const orphanDepPaths = Object.keys(currentPkgIdsByDepPaths).filter(path => !wantedPkgIdsByDepPaths[path])
|
||||
const orphanPkgIds = new Set(orphanDepPaths.map(path => currentPkgIdsByDepPaths[path]))
|
||||
@@ -234,20 +232,18 @@ function mergeDependencies (projectSnapshot: ProjectSnapshot): { [depName: strin
|
||||
}
|
||||
|
||||
function getPkgsDepPaths (
|
||||
registries: Registries,
|
||||
packages: PackageSnapshots,
|
||||
skipped: Set<string>
|
||||
): Record<string, string> {
|
||||
return Object.entries(packages).reduce((acc, [depPath, pkg]) => {
|
||||
if (skipped.has(depPath)) return acc
|
||||
acc[depPath] = packageIdFromSnapshot(depPath, pkg, registries)
|
||||
acc[depPath] = packageIdFromSnapshot(depPath, pkg)
|
||||
return acc
|
||||
}, {} as Record<string, string>)
|
||||
}
|
||||
|
||||
function getPkgsDepPathsOwnedOnlyByImporters (
|
||||
importerIds: string[],
|
||||
registries: Registries,
|
||||
lockfile: Lockfile,
|
||||
include: { [dependenciesField in DependenciesField]: boolean },
|
||||
skipped: Set<string>
|
||||
@@ -270,7 +266,7 @@ function getPkgsDepPathsOwnedOnlyByImporters (
|
||||
difference(Object.keys(selected.packages!), Object.keys(other.packages!)),
|
||||
selected.packages!
|
||||
) as PackageSnapshots
|
||||
return getPkgsDepPaths(registries, packagesOfSelectedOnly, skipped)
|
||||
return getPkgsDepPaths(packagesOfSelectedOnly, skipped)
|
||||
}
|
||||
|
||||
function getPubliclyHoistedDependencies (hoistedDependencies: HoistedDependencies): Set<string> {
|
||||
|
||||
@@ -54,7 +54,7 @@ test('request package', async () => {
|
||||
expect(pkgResponse).toBeTruthy()
|
||||
expect(pkgResponse.body).toBeTruthy()
|
||||
|
||||
expect(pkgResponse.body.id).toBe(`localhost+${REGISTRY_MOCK_PORT}/is-positive@1.0.0`)
|
||||
expect(pkgResponse.body.id).toBe('/is-positive@1.0.0')
|
||||
expect(pkgResponse.body.resolvedVia).toBe('npm-registry')
|
||||
expect(pkgResponse.body.isLocal).toBe(false)
|
||||
expect(typeof pkgResponse.body.latest).toBe('string')
|
||||
@@ -96,7 +96,7 @@ test('request package but skip fetching', async () => {
|
||||
expect(pkgResponse).toBeTruthy()
|
||||
expect(pkgResponse.body).toBeTruthy()
|
||||
|
||||
expect(pkgResponse.body.id).toBe(`localhost+${REGISTRY_MOCK_PORT}/is-positive@1.0.0`)
|
||||
expect(pkgResponse.body.id).toBe('/is-positive@1.0.0')
|
||||
expect(pkgResponse.body.isLocal).toBe(false)
|
||||
expect(typeof pkgResponse.body.latest).toBe('string')
|
||||
expect(pkgResponse.body.manifest?.name).toBe('is-positive')
|
||||
@@ -125,7 +125,7 @@ test('request package but skip fetching, when resolution is already available',
|
||||
const projectDir = tempy.directory()
|
||||
const pkgResponse = await requestPackage({ alias: 'is-positive', pref: '1.0.0' }, {
|
||||
currentPkg: {
|
||||
id: `localhost+${REGISTRY_MOCK_PORT}/is-positive/1.0.0`,
|
||||
id: '/is-positive/1.0.0',
|
||||
resolution: {
|
||||
integrity: 'sha512-xxzPGZ4P2uN6rROUa5N9Z7zTX6ERuE0hs6GUOc/cKBLF2NqKc16UwqHMt3tFg4CO6EBTE5UecUasg+3jZx3Ckg==',
|
||||
tarball: `http://localhost:${REGISTRY_MOCK_PORT}/is-positive/-/is-positive-1.0.0.tgz`,
|
||||
@@ -148,7 +148,7 @@ test('request package but skip fetching, when resolution is already available',
|
||||
expect(pkgResponse).toBeTruthy()
|
||||
expect(pkgResponse.body).toBeTruthy()
|
||||
|
||||
expect(pkgResponse.body.id).toBe(`localhost+${REGISTRY_MOCK_PORT}/is-positive@1.0.0`)
|
||||
expect(pkgResponse.body.id).toBe('/is-positive@1.0.0')
|
||||
expect(pkgResponse.body.isLocal).toBe(false)
|
||||
expect(typeof pkgResponse.body.latest).toBe('string')
|
||||
expect(pkgResponse.body.manifest.name).toBe('is-positive')
|
||||
@@ -356,7 +356,7 @@ test('fetchPackageToStore()', async () => {
|
||||
verifyStoreIntegrity: true,
|
||||
})
|
||||
|
||||
const pkgId = `localhost+${REGISTRY_MOCK_PORT}/is-positive/1.0.0`
|
||||
const pkgId = '/is-positive/1.0.0'
|
||||
const fetchResult = packageRequester.fetchPackageToStore({
|
||||
force: false,
|
||||
lockfileDir: tempy.directory(),
|
||||
@@ -421,7 +421,7 @@ test('fetchPackageToStore() concurrency check', async () => {
|
||||
verifyStoreIntegrity: true,
|
||||
})
|
||||
|
||||
const pkgId = `localhost+${REGISTRY_MOCK_PORT}/is-positive/1.0.0`
|
||||
const pkgId = '/is-positive/1.0.0'
|
||||
const projectDir1 = tempy.directory()
|
||||
const projectDir2 = tempy.directory()
|
||||
const fetchResults = await Promise.all([
|
||||
@@ -506,7 +506,7 @@ test('fetchPackageToStore() does not cache errors', async () => {
|
||||
verifyStoreIntegrity: true,
|
||||
})
|
||||
|
||||
const pkgId = `localhost+${REGISTRY_MOCK_PORT}/is-positive/1.0.0`
|
||||
const pkgId = '/is-positive/1.0.0'
|
||||
|
||||
const badRequest = packageRequester.fetchPackageToStore({
|
||||
force: false,
|
||||
@@ -575,7 +575,7 @@ test('always return a package manifest in the response', async () => {
|
||||
{
|
||||
const pkgResponse = await requestPackage({ alias: 'is-positive', pref: '1.0.0' }, {
|
||||
currentPkg: {
|
||||
id: `localhost+${REGISTRY_MOCK_PORT}/is-positive/1.0.0`,
|
||||
id: '/is-positive/1.0.0',
|
||||
resolution: {
|
||||
integrity: 'sha512-xxzPGZ4P2uN6rROUa5N9Z7zTX6ERuE0hs6GUOc/cKBLF2NqKc16UwqHMt3tFg4CO6EBTE5UecUasg+3jZx3Ckg==',
|
||||
tarball: `http://localhost:${REGISTRY_MOCK_PORT}/is-positive/-/is-positive-1.0.0.tgz`,
|
||||
@@ -619,7 +619,7 @@ test('fetchPackageToStore() fetch raw manifest of cached package', async () => {
|
||||
verifyStoreIntegrity: true,
|
||||
})
|
||||
|
||||
const pkgId = `localhost+${REGISTRY_MOCK_PORT}/is-positive/1.0.0`
|
||||
const pkgId = '/is-positive/1.0.0'
|
||||
const resolution = {
|
||||
tarball: `http://localhost:${REGISTRY_MOCK_PORT}/is-positive/-/is-positive-1.0.0.tgz`,
|
||||
}
|
||||
@@ -656,7 +656,7 @@ test('refetch package to store if it has been modified', async () => {
|
||||
const storeDir = tempy.directory()
|
||||
const lockfileDir = tempy.directory()
|
||||
|
||||
const pkgId = `localhost+${REGISTRY_MOCK_PORT}/magic-hook/2.0.0`
|
||||
const pkgId = '/magic-hook/2.0.0'
|
||||
const resolution = {
|
||||
tarball: `http://localhost:${REGISTRY_MOCK_PORT}/magic-hook/-/magic-hook-2.0.0.tgz`,
|
||||
}
|
||||
@@ -764,7 +764,7 @@ test('do not fetch an optional package that is not installable', async () => {
|
||||
expect(pkgResponse.body).toBeTruthy()
|
||||
|
||||
expect(pkgResponse.body.isInstallable).toBe(false)
|
||||
expect(pkgResponse.body.id).toBe(`localhost+${REGISTRY_MOCK_PORT}/@pnpm.e2e/not-compatible-with-any-os@1.0.0`)
|
||||
expect(pkgResponse.body.id).toBe('/@pnpm.e2e/not-compatible-with-any-os@1.0.0')
|
||||
|
||||
expect(pkgResponse.fetching).toBeFalsy()
|
||||
})
|
||||
|
||||
@@ -47,7 +47,6 @@
|
||||
"@pnpm/types": "workspace:*",
|
||||
"@pnpm/which-version-is-pinned": "workspace:*",
|
||||
"@yarnpkg/core": "4.0.2",
|
||||
"encode-registry": "^3.0.1",
|
||||
"filenamify": "^4.3.0",
|
||||
"get-npm-tarball-url": "^2.1.0",
|
||||
"is-inner-link": "^4.0.0",
|
||||
|
||||
@@ -1,23 +1,15 @@
|
||||
import { type Resolution } from '@pnpm/resolver-base'
|
||||
import { type Registries } from '@pnpm/types'
|
||||
import { getRegistryByPackageName } from '@pnpm/dependency-path'
|
||||
import encodeRegistry from 'encode-registry'
|
||||
|
||||
export function depPathToRef (
|
||||
depPath: string,
|
||||
opts: {
|
||||
alias: string
|
||||
realName: string
|
||||
registries: Registries
|
||||
resolution: Resolution
|
||||
}
|
||||
) {
|
||||
if (opts.resolution.type) return depPath
|
||||
|
||||
const registryName = encodeRegistry(getRegistryByPackageName(opts.registries, opts.realName))
|
||||
if (depPath.startsWith(`${registryName}/`)) {
|
||||
depPath = depPath.replace(`${registryName}/`, '/')
|
||||
}
|
||||
if (depPath[0] === '/' && opts.alias === opts.realName) {
|
||||
const ref = depPath.replace(`/${opts.realName}@`, '')
|
||||
if (!ref.includes('/') || !ref.replace(/(\([^)]+\))+$/, '').includes('/')) return ref
|
||||
|
||||
@@ -20,7 +20,6 @@ import {
|
||||
DEPENDENCIES_FIELDS,
|
||||
type DependencyManifest,
|
||||
type ProjectManifest,
|
||||
type Registries,
|
||||
} from '@pnpm/types'
|
||||
import promiseShare from 'promise-share'
|
||||
import difference from 'ramda/src/difference'
|
||||
@@ -226,7 +225,6 @@ export async function resolveDependencies (
|
||||
projectSnapshot,
|
||||
resolvedImporter.linkedDependencies,
|
||||
resolvedImporter.directDependencies,
|
||||
opts.registries,
|
||||
opts.excludeLinksFromLockfile
|
||||
)
|
||||
}
|
||||
@@ -244,7 +242,6 @@ export async function resolveDependencies (
|
||||
const ref = depPathToRef(depPath, {
|
||||
alias,
|
||||
realName: depNode.name,
|
||||
registries: opts.registries,
|
||||
resolution: depNode.resolution,
|
||||
})
|
||||
if (projectSnapshot.dependencies?.[alias]) {
|
||||
@@ -387,7 +384,6 @@ function addDirectDependenciesToLockfile (
|
||||
projectSnapshot: ProjectSnapshot,
|
||||
linkedPackages: Array<{ alias: string }>,
|
||||
directDependencies: ResolvedDirectDependency[],
|
||||
registries: Registries,
|
||||
excludeLinksFromLockfile?: boolean
|
||||
): ProjectSnapshot {
|
||||
const newProjectSnapshot: ProjectSnapshot & Required<Pick<ProjectSnapshot, 'dependencies' | 'devDependencies' | 'optionalDependencies'>> = {
|
||||
@@ -426,7 +422,6 @@ function addDirectDependenciesToLockfile (
|
||||
const ref = depPathToRef(dep.pkgId, {
|
||||
alias: dep.alias,
|
||||
realName: dep.name,
|
||||
registries,
|
||||
resolution: dep.resolution,
|
||||
})
|
||||
if (dep.dev) {
|
||||
|
||||
@@ -985,7 +985,7 @@ function getInfoFromLockfile (
|
||||
...nameVerFromPkgSnapshot(depPath, dependencyLockfile),
|
||||
dependencyLockfile,
|
||||
depPath,
|
||||
pkgId: packageIdFromSnapshot(depPath, dependencyLockfile, registries),
|
||||
pkgId: packageIdFromSnapshot(depPath, dependencyLockfile),
|
||||
// resolution may not exist if lockfile is broken, and an unexpected error will be thrown
|
||||
// if resolution does not exist, return undefined so it can be autofixed later
|
||||
resolution: dependencyLockfile.resolution && pkgSnapshotToResolution(depPath, dependencyLockfile, registries),
|
||||
@@ -993,7 +993,7 @@ function getInfoFromLockfile (
|
||||
} else {
|
||||
return {
|
||||
depPath,
|
||||
pkgId: dp.tryGetPackageId(registries, depPath) ?? depPath, // Does it make sense to set pkgId when we're not sure?
|
||||
pkgId: dp.tryGetPackageId(depPath) ?? depPath, // Does it make sense to set pkgId when we're not sure?
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1187,7 +1187,7 @@ async function resolveDependency (
|
||||
if (!pkg.name) { // TODO: don't fail on optional dependencies
|
||||
throw new PnpmError('MISSING_PACKAGE_NAME', `Can't install ${wantedDependency.pref}: Missing package name`)
|
||||
}
|
||||
let depPath = dp.relative(ctx.registries, pkg.name, pkgResponse.body.id)
|
||||
let depPath = pkgResponse.body.id
|
||||
const nameAndVersion = `${pkg.name}@${pkg.version}`
|
||||
const patchFile = ctx.patchedDependencies?.[nameAndVersion]
|
||||
if (patchFile) {
|
||||
|
||||
@@ -81,13 +81,11 @@ function toLockfileDependency (
|
||||
const newResolvedDeps = updateResolvedDeps(
|
||||
opts.prevSnapshot?.dependencies ?? {},
|
||||
opts.updatedDeps,
|
||||
opts.registries,
|
||||
opts.depGraph
|
||||
)
|
||||
const newResolvedOptionalDeps = updateResolvedDeps(
|
||||
opts.prevSnapshot?.optionalDependencies ?? {},
|
||||
opts.updatedOptionalDeps,
|
||||
opts.registries,
|
||||
opts.depGraph
|
||||
)
|
||||
const result = {
|
||||
@@ -197,7 +195,6 @@ function toLockfileDependency (
|
||||
function updateResolvedDeps (
|
||||
prevResolvedDeps: ResolvedDependencies,
|
||||
updatedDeps: Array<{ alias: string, depPath: string }>,
|
||||
registries: Registries,
|
||||
depGraph: DependenciesGraph
|
||||
) {
|
||||
const newResolvedDeps = Object.fromEntries(
|
||||
@@ -212,7 +209,6 @@ function updateResolvedDeps (
|
||||
depPathToRef(depNode.depPath, {
|
||||
alias,
|
||||
realName: depNode.name,
|
||||
registries,
|
||||
resolution: depNode.resolution,
|
||||
}),
|
||||
]
|
||||
|
||||
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
@@ -2497,9 +2497,6 @@ importers:
|
||||
'@pnpm/types':
|
||||
specifier: workspace:*
|
||||
version: link:../types
|
||||
encode-registry:
|
||||
specifier: ^3.0.1
|
||||
version: 3.0.1
|
||||
semver:
|
||||
specifier: ^7.5.4
|
||||
version: 7.5.4
|
||||
@@ -4111,9 +4108,6 @@ importers:
|
||||
'@yarnpkg/core':
|
||||
specifier: 4.0.2
|
||||
version: 4.0.2(typanion@3.14.0)
|
||||
encode-registry:
|
||||
specifier: ^3.0.1
|
||||
version: 3.0.1
|
||||
filenamify:
|
||||
specifier: ^4.3.0
|
||||
version: 4.3.0
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import encodeRegistry from 'encode-registry'
|
||||
|
||||
export function createPkgId (
|
||||
registry: string,
|
||||
pkgName: string,
|
||||
pkgVersion: string
|
||||
): string {
|
||||
const escapedRegistryHost = encodeRegistry(registry)
|
||||
return `${escapedRegistryHost}/${pkgName}@${pkgVersion}`
|
||||
}
|
||||
@@ -31,7 +31,6 @@ import {
|
||||
type RegistryPackageSpec,
|
||||
} from './parsePref'
|
||||
import { fromRegistry, RegistryResponseError } from './fetch'
|
||||
import { createPkgId } from './createNpmPkgId'
|
||||
import { workspacePrefToNpm } from './workspacePrefToNpm'
|
||||
|
||||
export class NoMatchingVersionError extends PnpmError {
|
||||
@@ -219,7 +218,7 @@ async function resolveNpm (
|
||||
}
|
||||
}
|
||||
|
||||
const id = createPkgId(opts.registry, pickedPackage.name, pickedPackage.version)
|
||||
const id = `/${pickedPackage.name}@${pickedPackage.version}`
|
||||
const resolution = {
|
||||
integrity: getIntegrity(pickedPackage.dist),
|
||||
tarball: pickedPackage.dist.tarball,
|
||||
|
||||
@@ -73,7 +73,7 @@ test('resolveFromNpm()', async () => {
|
||||
})
|
||||
|
||||
expect(resolveResult!.resolvedVia).toBe('npm-registry')
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@1.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@1.0.0')
|
||||
expect(resolveResult!.latest!.split('.').length).toBe(3)
|
||||
expect(resolveResult!.resolution).toStrictEqual({
|
||||
integrity: 'sha512-9cI+DmhNhA8ioT/3EJFnt0s1yehnAECyIOXdT+2uQGzcEEBaj8oNmVWj33+ZjPndMIFRQh8JeJlEu1uv5/J7pQ==',
|
||||
@@ -105,7 +105,7 @@ test('resolveFromNpm() should save metadata to a unique file when the package na
|
||||
})
|
||||
|
||||
expect(resolveResult!.resolvedVia).toBe('npm-registry')
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/JSON@1.0.0')
|
||||
expect(resolveResult!.id).toBe('/JSON@1.0.0')
|
||||
|
||||
// The resolve function does not wait for the package meta cache file to be saved
|
||||
// so we must delay for a bit in order to read it
|
||||
@@ -142,7 +142,7 @@ test('dry run', async () => {
|
||||
registry,
|
||||
})
|
||||
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@1.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@1.0.0')
|
||||
expect(resolveResult!.latest!.split('.').length).toBe(3)
|
||||
expect(resolveResult!.resolution).toStrictEqual({
|
||||
integrity: 'sha512-9cI+DmhNhA8ioT/3EJFnt0s1yehnAECyIOXdT+2uQGzcEEBaj8oNmVWj33+ZjPndMIFRQh8JeJlEu1uv5/J7pQ==',
|
||||
@@ -169,7 +169,7 @@ test('resolve to latest when no pref specified', async () => {
|
||||
const resolveResult = await resolveFromNpm({ alias: 'is-positive' }, {
|
||||
registry,
|
||||
})
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.1.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.1.0')
|
||||
})
|
||||
|
||||
test('resolve to defaultTag when no pref specified', async () => {
|
||||
@@ -184,7 +184,7 @@ test('resolve to defaultTag when no pref specified', async () => {
|
||||
defaultTag: 'stable',
|
||||
registry,
|
||||
})
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.0.0')
|
||||
})
|
||||
|
||||
test('resolve to biggest non-deprecated version that satisfies the range', async () => {
|
||||
@@ -198,7 +198,7 @@ test('resolve to biggest non-deprecated version that satisfies the range', async
|
||||
const resolveResult = await resolveFromNpm({ alias: 'is-positive', pref: '3' }, {
|
||||
registry,
|
||||
})
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.0.0')
|
||||
})
|
||||
|
||||
test('resolve to a deprecated version if there are no non-deprecated ones that satisfy the range', async () => {
|
||||
@@ -212,7 +212,7 @@ test('resolve to a deprecated version if there are no non-deprecated ones that s
|
||||
const resolveResult = await resolveFromNpm({ alias: 'is-positive', pref: '2' }, {
|
||||
registry,
|
||||
})
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@2.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@2.0.0')
|
||||
})
|
||||
|
||||
test('can resolve aliased dependency', async () => {
|
||||
@@ -226,7 +226,7 @@ test('can resolve aliased dependency', async () => {
|
||||
const resolveResult = await resolveFromNpm({ alias: 'positive', pref: 'npm:is-positive@1.0.0' }, {
|
||||
registry,
|
||||
})
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@1.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@1.0.0')
|
||||
})
|
||||
|
||||
test('can resolve aliased dependency w/o version specifier', async () => {
|
||||
@@ -240,7 +240,7 @@ test('can resolve aliased dependency w/o version specifier', async () => {
|
||||
const resolveResult = await resolveFromNpm({ alias: 'positive', pref: 'npm:is-positive' }, {
|
||||
registry,
|
||||
})
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.1.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.1.0')
|
||||
})
|
||||
|
||||
test('can resolve aliased dependency w/o version specifier to default tag', async () => {
|
||||
@@ -255,7 +255,7 @@ test('can resolve aliased dependency w/o version specifier to default tag', asyn
|
||||
defaultTag: 'stable',
|
||||
registry,
|
||||
})
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.0.0')
|
||||
})
|
||||
|
||||
test('can resolve aliased scoped dependency', async () => {
|
||||
@@ -269,7 +269,7 @@ test('can resolve aliased scoped dependency', async () => {
|
||||
const resolveResult = await resolveFromNpm({ alias: 'is', pref: 'npm:@sindresorhus/is@0.6.0' }, {
|
||||
registry,
|
||||
})
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/@sindresorhus/is@0.6.0')
|
||||
expect(resolveResult!.id).toBe('/@sindresorhus/is@0.6.0')
|
||||
})
|
||||
|
||||
test('can resolve aliased scoped dependency w/o version specifier', async () => {
|
||||
@@ -283,7 +283,7 @@ test('can resolve aliased scoped dependency w/o version specifier', async () =>
|
||||
const resolveResult = await resolveFromNpm({ alias: 'is', pref: 'npm:@sindresorhus/is' }, {
|
||||
registry,
|
||||
})
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/@sindresorhus/is@0.7.0')
|
||||
expect(resolveResult!.id).toBe('/@sindresorhus/is@0.7.0')
|
||||
})
|
||||
|
||||
test('can resolve package with version prefixed with v', async () => {
|
||||
@@ -297,7 +297,7 @@ test('can resolve package with version prefixed with v', async () => {
|
||||
const resolveResult = await resolveFromNpm({ alias: 'is-positive', pref: 'v1.0.0' }, {
|
||||
registry,
|
||||
})
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@1.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@1.0.0')
|
||||
})
|
||||
|
||||
test('can resolve package version loosely', async () => {
|
||||
@@ -311,7 +311,7 @@ test('can resolve package version loosely', async () => {
|
||||
const resolveResult = await resolveFromNpm({ alias: 'is-positive', pref: '= 1.0.0' }, {
|
||||
registry,
|
||||
})
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@1.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@1.0.0')
|
||||
})
|
||||
|
||||
test("resolves to latest if it's inside the wanted range. Even if there are newer versions available inside the range", async () => {
|
||||
@@ -333,7 +333,7 @@ test("resolves to latest if it's inside the wanted range. Even if there are newe
|
||||
})
|
||||
|
||||
// 3.1.0 is available but latest is 3.0.0, so preferring it
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.0.0')
|
||||
})
|
||||
|
||||
test("resolves to latest if it's inside the preferred range. Even if there are newer versions available inside the preferred range", async () => {
|
||||
@@ -358,7 +358,7 @@ test("resolves to latest if it's inside the preferred range. Even if there are n
|
||||
})
|
||||
|
||||
// 3.1.0 is available but latest is 3.0.0, so preferring it
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.0.0')
|
||||
})
|
||||
|
||||
test("resolve using the wanted range, when it doesn't intersect with the preferred range. Even if the preferred range contains the latest version", async () => {
|
||||
@@ -382,7 +382,7 @@ test("resolve using the wanted range, when it doesn't intersect with the preferr
|
||||
registry,
|
||||
})
|
||||
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.1.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.1.0')
|
||||
})
|
||||
|
||||
test("use the preferred version if it's inside the wanted range", async () => {
|
||||
@@ -407,7 +407,7 @@ test("use the preferred version if it's inside the wanted range", async () => {
|
||||
})
|
||||
|
||||
// 3.1.0 is the latest but we prefer the 3.0.0
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.0.0')
|
||||
})
|
||||
|
||||
test("ignore the preferred version if it's not inside the wanted range", async () => {
|
||||
@@ -430,7 +430,7 @@ test("ignore the preferred version if it's not inside the wanted range", async (
|
||||
},
|
||||
registry,
|
||||
})
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.1.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.1.0')
|
||||
})
|
||||
|
||||
test('use the preferred range if it intersects with the wanted range', async () => {
|
||||
@@ -455,7 +455,7 @@ test('use the preferred range if it intersects with the wanted range', async ()
|
||||
})
|
||||
|
||||
// 1.0.0 is the latest but we prefer a version that is also in the preferred range
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.1.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.1.0')
|
||||
})
|
||||
|
||||
test('use the preferred range if it intersects with the wanted range (an array of preferred versions is passed)', async () => {
|
||||
@@ -483,7 +483,7 @@ test('use the preferred range if it intersects with the wanted range (an array o
|
||||
})
|
||||
|
||||
// 1.0.0 is the latest but we prefer a version that is also in the preferred range
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.1.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.1.0')
|
||||
})
|
||||
|
||||
test("ignore the preferred range if it doesn't intersect with the wanted range", async () => {
|
||||
@@ -506,7 +506,7 @@ test("ignore the preferred range if it doesn't intersect with the wanted range",
|
||||
},
|
||||
registry,
|
||||
})
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.1.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.1.0')
|
||||
})
|
||||
|
||||
test("use the preferred dist-tag if it's inside the wanted range", async () => {
|
||||
@@ -532,7 +532,7 @@ test("use the preferred dist-tag if it's inside the wanted range", async () => {
|
||||
},
|
||||
registry,
|
||||
})
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.0.0')
|
||||
})
|
||||
|
||||
test("ignore the preferred dist-tag if it's not inside the wanted range", async () => {
|
||||
@@ -558,7 +558,7 @@ test("ignore the preferred dist-tag if it's not inside the wanted range", async
|
||||
},
|
||||
registry,
|
||||
})
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.1.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.1.0')
|
||||
})
|
||||
|
||||
test("prefer a version that is both inside the wanted and preferred ranges. Even if it's not the latest of any of them", async () => {
|
||||
@@ -583,7 +583,7 @@ test("prefer a version that is both inside the wanted and preferred ranges. Even
|
||||
},
|
||||
registry,
|
||||
})
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@1.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@1.0.0')
|
||||
})
|
||||
|
||||
test('prefer the version that is matched by more preferred selectors', async () => {
|
||||
@@ -604,7 +604,7 @@ test('prefer the version that is matched by more preferred selectors', async ()
|
||||
registry,
|
||||
})
|
||||
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.0.0')
|
||||
})
|
||||
|
||||
test('prefer the version that has bigger weight in preferred selectors', async () => {
|
||||
@@ -629,7 +629,7 @@ test('prefer the version that has bigger weight in preferred selectors', async (
|
||||
registry,
|
||||
})
|
||||
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.0.0')
|
||||
})
|
||||
|
||||
test('offline resolution fails when package meta not found in the store', async () => {
|
||||
@@ -669,7 +669,7 @@ test('offline resolution succeeds when package meta is found in the store', asyn
|
||||
})
|
||||
|
||||
const resolveResult = await resolve({ alias: 'is-positive', pref: '1.0.0' }, { registry })
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@1.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@1.0.0')
|
||||
}
|
||||
})
|
||||
|
||||
@@ -684,7 +684,7 @@ test('prefer offline resolution does not fail when package meta not found in the
|
||||
})
|
||||
|
||||
const resolveResult = await resolve({ alias: 'is-positive', pref: '1.0.0' }, { registry })
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@1.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@1.0.0')
|
||||
})
|
||||
|
||||
test('when prefer offline is used, meta from store is used, where latest might be out-of-date', async () => {
|
||||
@@ -720,7 +720,7 @@ test('when prefer offline is used, meta from store is used, where latest might b
|
||||
})
|
||||
|
||||
const resolveResult = await resolve({ alias: 'is-positive', pref: '^3.0.0' }, { registry })
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.0.0')
|
||||
}
|
||||
|
||||
nock.cleanAll()
|
||||
@@ -914,7 +914,7 @@ test('resolve when tarball URL is requested from the registry', async () => {
|
||||
})
|
||||
|
||||
expect(resolveResult!.resolvedVia).toBe('npm-registry')
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@1.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@1.0.0')
|
||||
expect(resolveResult!.latest!.split('.').length).toBe(3)
|
||||
expect(resolveResult!.resolution).toStrictEqual({
|
||||
integrity: 'sha512-9cI+DmhNhA8ioT/3EJFnt0s1yehnAECyIOXdT+2uQGzcEEBaj8oNmVWj33+ZjPndMIFRQh8JeJlEu1uv5/J7pQ==',
|
||||
@@ -947,7 +947,7 @@ test('resolve when tarball URL is requested from the registry and alias is not s
|
||||
})
|
||||
|
||||
expect(resolveResult!.resolvedVia).toBe('npm-registry')
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@1.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@1.0.0')
|
||||
expect(resolveResult!.latest!.split('.').length).toBe(3)
|
||||
expect(resolveResult!.resolution).toStrictEqual({
|
||||
integrity: 'sha512-9cI+DmhNhA8ioT/3EJFnt0s1yehnAECyIOXdT+2uQGzcEEBaj8oNmVWj33+ZjPndMIFRQh8JeJlEu1uv5/J7pQ==',
|
||||
@@ -1068,7 +1068,7 @@ test('do not resolve from local directory when alwaysTryWorkspacePackages is fal
|
||||
})
|
||||
|
||||
expect(resolveResult!.resolvedVia).toBe('npm-registry')
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@1.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@1.0.0')
|
||||
expect(resolveResult!.latest!.split('.').length).toBe(3)
|
||||
expect(resolveResult!.resolution).toStrictEqual({
|
||||
integrity: 'sha512-9cI+DmhNhA8ioT/3EJFnt0s1yehnAECyIOXdT+2uQGzcEEBaj8oNmVWj33+ZjPndMIFRQh8JeJlEu1uv5/J7pQ==',
|
||||
@@ -1176,7 +1176,7 @@ test('use version from the registry if it is newer than the local one', async ()
|
||||
})
|
||||
|
||||
expect(resolveResult!.resolvedVia).toBe('npm-registry')
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.1.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.1.0')
|
||||
expect(resolveResult!.latest!.split('.').length).toBe(3)
|
||||
expect(resolveResult!.resolution).toStrictEqual({
|
||||
integrity: 'sha512-9Qa5b+9n69IEuxk4FiNcavXqkixb9lD03BLtdTeu2bbORnLZQrw+pR/exiSg7SoODeu08yxS47mdZa9ddodNwQ==',
|
||||
@@ -1592,7 +1592,7 @@ test("workspace protocol: don't resolve from local package that has a pre-releas
|
||||
})
|
||||
|
||||
expect(resolveResult!.resolvedVia).toBe('npm-registry')
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@2.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@2.0.0')
|
||||
expect(resolveResult!.latest).toBeTruthy()
|
||||
expect(resolveResult!.manifest).toBeTruthy()
|
||||
expect(resolveResult!.manifest!.name).toBe('is-positive')
|
||||
@@ -1699,7 +1699,7 @@ test('resolveFromNpm() should always return the name of the package that is spec
|
||||
})
|
||||
|
||||
expect(resolveResult!.resolvedVia).toBe('npm-registry')
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@3.1.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@3.1.0')
|
||||
expect(resolveResult!.latest!.split('.').length).toBe(3)
|
||||
expect(resolveResult!.resolution).toStrictEqual({
|
||||
integrity: 'sha512-9Qa5b+9n69IEuxk4FiNcavXqkixb9lD03BLtdTeu2bbORnLZQrw+pR/exiSg7SoODeu08yxS47mdZa9ddodNwQ==',
|
||||
@@ -1736,7 +1736,7 @@ test('request to metadata is retried if the received JSON is broken', async () =
|
||||
registry,
|
||||
})!
|
||||
|
||||
expect(resolveResult?.id).toBe('registry1.com/is-positive@1.0.0')
|
||||
expect(resolveResult?.id).toBe('/is-positive@1.0.0')
|
||||
})
|
||||
|
||||
test('request to a package with unpublished versions', async () => {
|
||||
@@ -1796,7 +1796,7 @@ test('resolveFromNpm() does not fail if the meta file contains no integrity info
|
||||
})
|
||||
|
||||
expect(resolveResult!.resolvedVia).toBe('npm-registry')
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@2.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@2.0.0')
|
||||
expect(resolveResult!.latest!.split('.').length).toBe(3)
|
||||
expect(resolveResult!.resolution).toStrictEqual({
|
||||
integrity: undefined,
|
||||
@@ -1835,7 +1835,7 @@ test('resolveFromNpm() should normalize the registry', async () => {
|
||||
})
|
||||
|
||||
expect(resolveResult!.resolvedVia).toBe('npm-registry')
|
||||
expect(resolveResult!.id).toBe('reg.com/is-positive@1.0.0')
|
||||
expect(resolveResult!.id).toBe('/is-positive@1.0.0')
|
||||
expect(resolveResult!.latest!.split('.').length).toBe(3)
|
||||
expect(resolveResult!.resolution).toStrictEqual({
|
||||
integrity: 'sha512-9cI+DmhNhA8ioT/3EJFnt0s1yehnAECyIOXdT+2uQGzcEEBaj8oNmVWj33+ZjPndMIFRQh8JeJlEu1uv5/J7pQ==',
|
||||
@@ -1874,7 +1874,7 @@ test('pick lowest version by * when there are only prerelease versions', async (
|
||||
})
|
||||
|
||||
expect(resolveResult!.resolvedVia).toBe('npm-registry')
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/is-positive@1.0.0-alpha.1')
|
||||
expect(resolveResult!.id).toBe('/is-positive@1.0.0-alpha.1')
|
||||
expect(resolveResult!.manifest!.name).toBe('is-positive')
|
||||
expect(resolveResult!.manifest!.version).toBe('1.0.0-alpha.1')
|
||||
})
|
||||
|
||||
@@ -44,7 +44,7 @@ test('fall back to a newer version if there is no version published by the given
|
||||
})
|
||||
|
||||
expect(resolveResult!.resolvedVia).toBe('npm-registry')
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/bad-dates@1.0.0')
|
||||
expect(resolveResult!.id).toBe('/bad-dates@1.0.0')
|
||||
})
|
||||
|
||||
test('request metadata when the one in cache does not have a version satisfying the range', async () => {
|
||||
@@ -73,5 +73,5 @@ test('request metadata when the one in cache does not have a version satisfying
|
||||
})
|
||||
|
||||
expect(resolveResult!.resolvedVia).toBe('npm-registry')
|
||||
expect(resolveResult!.id).toBe('registry.npmjs.org/bad-dates@1.0.0')
|
||||
expect(resolveResult!.id).toBe('/bad-dates@1.0.0')
|
||||
})
|
||||
|
||||
@@ -23,7 +23,6 @@ export async function storeStatus (maybeOpts: StoreStatusOptions) {
|
||||
}
|
||||
const opts = await extendStoreStatusOptions(maybeOpts)
|
||||
const {
|
||||
registries,
|
||||
storeDir,
|
||||
skipped,
|
||||
virtualStoreDir,
|
||||
@@ -37,12 +36,12 @@ export async function storeStatus (maybeOpts: StoreStatusOptions) {
|
||||
const pkgs = Object.entries(wantedLockfile.packages ?? {})
|
||||
.filter(([depPath]) => !skipped.has(depPath))
|
||||
.map(([depPath, pkgSnapshot]) => {
|
||||
const id = packageIdFromSnapshot(depPath, pkgSnapshot, registries)
|
||||
const id = packageIdFromSnapshot(depPath, pkgSnapshot)
|
||||
return {
|
||||
depPath,
|
||||
id,
|
||||
integrity: (pkgSnapshot.resolution as TarballResolution).integrity,
|
||||
pkgPath: dp.resolve(registries, depPath),
|
||||
pkgPath: depPath,
|
||||
...nameVerFromPkgSnapshot(depPath, pkgSnapshot),
|
||||
}
|
||||
})
|
||||
|
||||
@@ -58,7 +58,7 @@ test('server', async () => {
|
||||
|
||||
const { bundledManifest, files } = await response.fetching!()
|
||||
expect(bundledManifest?.name).toBe('is-positive')
|
||||
expect(response.body.id).toBe('registry.npmjs.org/is-positive@1.0.0')
|
||||
expect(response.body.id).toBe('/is-positive@1.0.0')
|
||||
|
||||
expect(response.body.manifest!.name).toBe('is-positive')
|
||||
expect(response.body.manifest!.version).toBe('1.0.0')
|
||||
|
||||
Reference in New Issue
Block a user