mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-24 07:38:12 -05:00
fix: print the dependency chain to a pkg that failed to be fetched (#7265)
This commit is contained in:
9
.changeset/silver-lemons-hug.md
Normal file
9
.changeset/silver-lemons-hug.md
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
"@pnpm/resolve-dependencies": patch
|
||||
"@pnpm/package-requester": patch
|
||||
"@pnpm/store-controller-types": patch
|
||||
"@pnpm/core": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
If a package's tarball cannot be fetched, print the dependency chain that leads to the failed package [#7265](https://github.com/pnpm/pnpm/pull/7265).
|
||||
78
pkg-manager/core/test/fixtures/dep-of-pkg-with-1-dep.json
vendored
Normal file
78
pkg-manager/core/test/fixtures/dep-of-pkg-with-1-dep.json
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
{
|
||||
"name": "@pnpm.e2e/dep-of-pkg-with-1-dep",
|
||||
"versions": {
|
||||
"100.0.0": {
|
||||
"name": "@pnpm.e2e/dep-of-pkg-with-1-dep",
|
||||
"version": "100.0.0",
|
||||
"gitHead": "ddcb263bd46ec8dc5f2b1bcdf43d3ec93052c2db",
|
||||
"_id": "@pnpm.e2e/dep-of-pkg-with-1-dep@100.0.0",
|
||||
"_nodeVersion": "18.18.2",
|
||||
"_npmVersion": "8.9.0",
|
||||
"dist": {
|
||||
"integrity": "sha512-KUmwlEiE3pzpmPCfrLkoOO7fmL4Tft+dcm6YQlUfOUJvHO73xlcKVoA/xOHP/ayUO8GiPlIqWRbKHrsxvXGE8g==",
|
||||
"shasum": "a95f834b4a4d9661623a0cf2bd76acbc213192fc",
|
||||
"tarball": "http://localhost:4873/@pnpm.e2e/dep-of-pkg-with-1-dep/-/@pnpm.e2e/dep-of-pkg-with-1-dep-100.0.0.tgz"
|
||||
},
|
||||
"contributors": []
|
||||
},
|
||||
"100.1.0": {
|
||||
"name": "@pnpm.e2e/dep-of-pkg-with-1-dep",
|
||||
"version": "100.1.0",
|
||||
"gitHead": "ddcb263bd46ec8dc5f2b1bcdf43d3ec93052c2db",
|
||||
"_id": "@pnpm.e2e/dep-of-pkg-with-1-dep@100.1.0",
|
||||
"_nodeVersion": "18.18.2",
|
||||
"_npmVersion": "8.9.0",
|
||||
"dist": {
|
||||
"integrity": "sha512-CAF68U5SjOQOT2dubJxAxauvQwm0G2IWS+Si7xP6Za79ZAt2VmCG5LMoSfv7GkbKk0RvSm/EMpT4BQVGy1yCpg==",
|
||||
"shasum": "7647e89d79edff3ea46b0b04e390e2c820995be6",
|
||||
"tarball": "http://localhost:4873/@pnpm.e2e/dep-of-pkg-with-1-dep/-/@pnpm.e2e/dep-of-pkg-with-1-dep-100.1.0.tgz"
|
||||
},
|
||||
"contributors": []
|
||||
},
|
||||
"101.0.0": {
|
||||
"name": "@pnpm.e2e/dep-of-pkg-with-1-dep",
|
||||
"version": "101.0.0",
|
||||
"gitHead": "ddcb263bd46ec8dc5f2b1bcdf43d3ec93052c2db",
|
||||
"_id": "@pnpm.e2e/dep-of-pkg-with-1-dep@101.0.0",
|
||||
"_nodeVersion": "18.18.2",
|
||||
"_npmVersion": "8.9.0",
|
||||
"dist": {
|
||||
"integrity": "sha512-v/FQPTv+Y6j/J5a7ymlifFIhJa28wROyiTfg1vcAVKdJ9S94E32CHVUbzgvdcu9pAkLqe7INiwJ2ynqmgiTiiw==",
|
||||
"shasum": "0cd58112bc509221dc3dfd97736a1feae3872b69",
|
||||
"tarball": "http://localhost:4873/@pnpm.e2e/dep-of-pkg-with-1-dep/-/@pnpm.e2e/dep-of-pkg-with-1-dep-101.0.0.tgz"
|
||||
},
|
||||
"contributors": []
|
||||
}
|
||||
},
|
||||
"time": {
|
||||
"modified": "2023-10-23T01:37:53.217Z",
|
||||
"created": "2023-10-23T01:37:52.413Z",
|
||||
"100.0.0": "2023-10-23T01:37:52.413Z",
|
||||
"100.1.0": "2023-10-23T01:37:52.821Z",
|
||||
"101.0.0": "2023-10-23T01:37:53.217Z"
|
||||
},
|
||||
"users": {},
|
||||
"dist-tags": {
|
||||
"latest": "101.0.0"
|
||||
},
|
||||
"_uplinks": {},
|
||||
"_distfiles": {},
|
||||
"_attachments": {
|
||||
"dep-of-pkg-with-1-dep-100.0.0.tgz": {
|
||||
"shasum": "a95f834b4a4d9661623a0cf2bd76acbc213192fc",
|
||||
"version": "100.0.0"
|
||||
},
|
||||
"dep-of-pkg-with-1-dep-100.1.0.tgz": {
|
||||
"shasum": "7647e89d79edff3ea46b0b04e390e2c820995be6",
|
||||
"version": "100.1.0"
|
||||
},
|
||||
"dep-of-pkg-with-1-dep-101.0.0.tgz": {
|
||||
"shasum": "0cd58112bc509221dc3dfd97736a1feae3872b69",
|
||||
"version": "101.0.0"
|
||||
}
|
||||
},
|
||||
"_rev": "9-80b71b86430e1c83",
|
||||
"_id": "@pnpm.e2e/dep-of-pkg-with-1-dep",
|
||||
"readme": "ERROR: No README data found!"
|
||||
}
|
||||
|
||||
BIN
pkg-manager/core/test/fixtures/pkg-with-1-dep-100.0.0.tgz
vendored
Normal file
BIN
pkg-manager/core/test/fixtures/pkg-with-1-dep-100.0.0.tgz
vendored
Normal file
Binary file not shown.
65
pkg-manager/core/test/fixtures/pkg-with-1-dep.json
vendored
Normal file
65
pkg-manager/core/test/fixtures/pkg-with-1-dep.json
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"name": "@pnpm.e2e/pkg-with-1-dep",
|
||||
"versions": {
|
||||
"100.0.0": {
|
||||
"name": "@pnpm.e2e/pkg-with-1-dep",
|
||||
"version": "100.0.0",
|
||||
"dependencies": {
|
||||
"@pnpm.e2e/dep-of-pkg-with-1-dep": "^100.0.0"
|
||||
},
|
||||
"gitHead": "ddcb263bd46ec8dc5f2b1bcdf43d3ec93052c2db",
|
||||
"_id": "@pnpm.e2e/pkg-with-1-dep@100.0.0",
|
||||
"_nodeVersion": "18.18.2",
|
||||
"_npmVersion": "8.9.0",
|
||||
"dist": {
|
||||
"integrity": "sha512-IGrkh3wu1jOzTFzi/S+XOkuhEwhV03qRaH7tcwPoPJ+AQo2cAuhgOBwczq2y8DPfob+BlzSmZXjEvEqoXKio7A==",
|
||||
"shasum": "b78a05932d20b071b84d42b6964621a197118870",
|
||||
"tarball": "http://localhost:4873/@pnpm.e2e/pkg-with-1-dep/-/@pnpm.e2e/pkg-with-1-dep-100.0.0.tgz"
|
||||
},
|
||||
"contributors": []
|
||||
},
|
||||
"100.1.0": {
|
||||
"name": "@pnpm.e2e/pkg-with-1-dep",
|
||||
"version": "100.1.0",
|
||||
"dependencies": {
|
||||
"@pnpm.e2e/dep-of-pkg-with-1-dep": "^100.0.0"
|
||||
},
|
||||
"gitHead": "ddcb263bd46ec8dc5f2b1bcdf43d3ec93052c2db",
|
||||
"_id": "@pnpm.e2e/pkg-with-1-dep@100.1.0",
|
||||
"_nodeVersion": "18.18.2",
|
||||
"_npmVersion": "8.9.0",
|
||||
"dist": {
|
||||
"integrity": "sha512-fdlqYHFD2EY3e1Lf2x2V3gVJdNkybtPiQ8DLUZCJjxyMl0oxymB0EQSHqSjvBYoDss7Jj9eGLx9+utpOuXRX7A==",
|
||||
"shasum": "2d2293b5595718890bd322da51359ec25334b85e",
|
||||
"tarball": "http://localhost:4873/@pnpm.e2e/pkg-with-1-dep/-/@pnpm.e2e/pkg-with-1-dep-100.1.0.tgz"
|
||||
},
|
||||
"contributors": []
|
||||
}
|
||||
},
|
||||
"time": {
|
||||
"modified": "2023-10-23T01:38:37.289Z",
|
||||
"created": "2023-10-23T01:38:36.876Z",
|
||||
"100.0.0": "2023-10-23T01:38:36.876Z",
|
||||
"100.1.0": "2023-10-23T01:38:37.289Z"
|
||||
},
|
||||
"users": {},
|
||||
"dist-tags": {
|
||||
"latest": "100.0.0"
|
||||
},
|
||||
"_uplinks": {},
|
||||
"_distfiles": {},
|
||||
"_attachments": {
|
||||
"pkg-with-1-dep-100.0.0.tgz": {
|
||||
"shasum": "b78a05932d20b071b84d42b6964621a197118870",
|
||||
"version": "100.0.0"
|
||||
},
|
||||
"pkg-with-1-dep-100.1.0.tgz": {
|
||||
"shasum": "2d2293b5595718890bd322da51359ec25334b85e",
|
||||
"version": "100.1.0"
|
||||
}
|
||||
},
|
||||
"_rev": "6-6c950763d3e9e87f",
|
||||
"_id": "@pnpm.e2e/pkg-with-1-dep",
|
||||
"readme": "ERROR: No README data found!"
|
||||
}
|
||||
|
||||
79
pkg-manager/core/test/install/errors.ts
Normal file
79
pkg-manager/core/test/install/errors.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import { type PnpmError } from '@pnpm/error'
|
||||
import { prepareEmpty } from '@pnpm/prepare'
|
||||
import { addDependenciesToPackage, mutateModulesInSingleProject } from '@pnpm/core'
|
||||
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
|
||||
import { fixtures } from '@pnpm/test-fixtures'
|
||||
import loadJsonFile from 'load-json-file'
|
||||
import nock from 'nock'
|
||||
import { testDefaults } from '../utils'
|
||||
|
||||
const f = fixtures(__dirname)
|
||||
|
||||
test('fail if none of the available resolvers support a version spec', async () => {
|
||||
prepareEmpty()
|
||||
|
||||
let err!: PnpmError
|
||||
try {
|
||||
await mutateModulesInSingleProject({
|
||||
manifest: {
|
||||
dependencies: {
|
||||
'@types/plotly.js': '1.44.29',
|
||||
},
|
||||
},
|
||||
mutation: 'install',
|
||||
rootDir: process.cwd(),
|
||||
}, await testDefaults())
|
||||
throw new Error('should have failed')
|
||||
} catch (_err: any) { // eslint-disable-line
|
||||
err = _err
|
||||
}
|
||||
expect(err.code).toBe('ERR_PNPM_SPEC_NOT_SUPPORTED_BY_ANY_RESOLVER')
|
||||
expect(err.prefix).toBe(process.cwd())
|
||||
expect(err.pkgsStack).toStrictEqual(
|
||||
[
|
||||
{
|
||||
id: `localhost+${REGISTRY_MOCK_PORT}/@types/plotly.js/1.44.29`,
|
||||
name: '@types/plotly.js',
|
||||
version: '1.44.29',
|
||||
},
|
||||
]
|
||||
)
|
||||
})
|
||||
|
||||
test('fail if a package cannot be fetched', async () => {
|
||||
prepareEmpty()
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
nock(`http://localhost:${REGISTRY_MOCK_PORT}/`)
|
||||
.get('/@pnpm.e2e%2Fpkg-with-1-dep') // cspell:disable-line
|
||||
.reply(200, loadJsonFile.sync<any>(f.find('pkg-with-1-dep.json')))
|
||||
nock(`http://localhost:${REGISTRY_MOCK_PORT}/`)
|
||||
.get('/@pnpm.e2e%2Fdep-of-pkg-with-1-dep') // cspell:disable-line
|
||||
.reply(200, loadJsonFile.sync<any>(f.find('dep-of-pkg-with-1-dep.json')))
|
||||
/* eslint-enable @typescript-eslint/no-explicit-any */
|
||||
nock(`http://localhost:${REGISTRY_MOCK_PORT}/`)
|
||||
.get('/@pnpm.e2e/pkg-with-1-dep/-/@pnpm.e2e/pkg-with-1-dep-100.0.0.tgz')
|
||||
.replyWithFile(200, f.find('pkg-with-1-dep-100.0.0.tgz'))
|
||||
nock(`http://localhost:${REGISTRY_MOCK_PORT}/`)
|
||||
.get('/@pnpm.e2e/dep-of-pkg-with-1-dep/-/@pnpm.e2e/dep-of-pkg-with-1-dep-100.1.0.tgz')
|
||||
.reply(403)
|
||||
|
||||
let err!: PnpmError
|
||||
try {
|
||||
await addDependenciesToPackage({}, ['@pnpm.e2e/pkg-with-1-dep@100.0.0'], await testDefaults({}, {}, { retry: { retries: 0 } }))
|
||||
throw new Error('should have failed')
|
||||
} catch (_err: any) { // eslint-disable-line
|
||||
nock.restore()
|
||||
err = _err
|
||||
}
|
||||
expect(err.code).toBe('ERR_PNPM_FETCH_403')
|
||||
expect(err.prefix).toBe(process.cwd())
|
||||
expect(err.pkgsStack).toStrictEqual(
|
||||
[
|
||||
{
|
||||
id: `localhost+${REGISTRY_MOCK_PORT}/@pnpm.e2e/pkg-with-1-dep/100.0.0`,
|
||||
name: '@pnpm.e2e/pkg-with-1-dep',
|
||||
version: '100.0.0',
|
||||
},
|
||||
]
|
||||
)
|
||||
})
|
||||
@@ -1,7 +1,6 @@
|
||||
import * as path from 'path'
|
||||
import { promises as fs } from 'fs'
|
||||
import { prepare, prepareEmpty, preparePackages } from '@pnpm/prepare'
|
||||
import { type PnpmError } from '@pnpm/error'
|
||||
import {
|
||||
type PackageManifestLog,
|
||||
type ProgressLog,
|
||||
@@ -1080,37 +1079,6 @@ test('subdep symlinks are updated if the lockfile has new subdep versions specif
|
||||
expect(await exists(path.resolve('node_modules/.pnpm/@pnpm.e2e+pkg-with-1-dep@100.0.0/node_modules/@pnpm.e2e/dep-of-pkg-with-1-dep/package.json'))).toBeTruthy()
|
||||
})
|
||||
|
||||
test('fail if none of the available resolvers support a version spec', async () => {
|
||||
prepareEmpty()
|
||||
|
||||
let err!: PnpmError
|
||||
try {
|
||||
await mutateModulesInSingleProject({
|
||||
manifest: {
|
||||
dependencies: {
|
||||
'@types/plotly.js': '1.44.29',
|
||||
},
|
||||
},
|
||||
mutation: 'install',
|
||||
rootDir: process.cwd(),
|
||||
}, await testDefaults())
|
||||
throw new Error('should have failed')
|
||||
} catch (_err: any) { // eslint-disable-line
|
||||
err = _err
|
||||
}
|
||||
expect(err.code).toBe('ERR_PNPM_SPEC_NOT_SUPPORTED_BY_ANY_RESOLVER')
|
||||
expect(err.prefix).toBe(process.cwd())
|
||||
expect(err.pkgsStack).toStrictEqual(
|
||||
[
|
||||
{
|
||||
id: `localhost+${REGISTRY_MOCK_PORT}/@types/plotly.js/1.44.29`,
|
||||
name: '@types/plotly.js',
|
||||
version: '1.44.29',
|
||||
},
|
||||
]
|
||||
)
|
||||
})
|
||||
|
||||
test('globally installed package which don\'t have bins should log warning message', async () => {
|
||||
prepareEmpty()
|
||||
const reporter = sinon.spy()
|
||||
|
||||
@@ -268,6 +268,7 @@ async function resolveAndFetch (
|
||||
expectedPkg: options.expectedPkg?.name != null
|
||||
? (updated ? { name: options.expectedPkg.name, version: pkg.version } : options.expectedPkg)
|
||||
: pkg,
|
||||
onFetchError: options.onFetchError,
|
||||
})
|
||||
|
||||
return {
|
||||
@@ -429,6 +430,9 @@ function fetchToStore (
|
||||
return await p
|
||||
} catch (err: any) { // eslint-disable-line
|
||||
ctx.fetchingLocker.delete(opts.pkg.id)
|
||||
if (opts.onFetchError) {
|
||||
throw opts.onFetchError(err)
|
||||
}
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1092,6 +1092,11 @@ async function resolveDependency (
|
||||
update: options.update,
|
||||
workspacePackages: ctx.workspacePackages,
|
||||
supportedArchitectures: options.supportedArchitectures,
|
||||
onFetchError: (err: any) => { // eslint-disable-line
|
||||
err.prefix = options.prefix
|
||||
err.pkgsStack = nodeIdToParents(options.parentPkg.nodeId, ctx.resolvedPackagesByDepPath)
|
||||
return err
|
||||
},
|
||||
})
|
||||
} catch (err: any) { // eslint-disable-line
|
||||
if (wantedDependency.optional) {
|
||||
|
||||
@@ -97,8 +97,11 @@ export interface FetchPackageToStoreOptions {
|
||||
* Expected package is the package name and version that are found in the lockfile.
|
||||
*/
|
||||
expectedPkg?: PkgNameVersion
|
||||
onFetchError?: OnFetchError
|
||||
}
|
||||
|
||||
export type OnFetchError = (error: Error) => Error
|
||||
|
||||
export type RequestPackageFunction = (
|
||||
wantedDependency: WantedDependency & { optional?: boolean },
|
||||
options: RequestPackageOptions
|
||||
@@ -130,6 +133,7 @@ export interface RequestPackageOptions {
|
||||
workspacePackages?: WorkspacePackages
|
||||
forceResolve?: boolean
|
||||
supportedArchitectures?: SupportedArchitectures
|
||||
onFetchError?: OnFetchError
|
||||
}
|
||||
|
||||
export type BundledManifestFunction = () => Promise<BundledManifest | undefined>
|
||||
|
||||
Reference in New Issue
Block a user