mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-25 10:31:55 -04:00
fix: optional dependency that does not exist should be skipped
ref pnpm/pnpm#1004
This commit is contained in:
@@ -8,6 +8,7 @@ import url = require('url')
|
||||
import {
|
||||
PackageFilesResponse,
|
||||
Resolution,
|
||||
PackageResponse,
|
||||
} from '@pnpm/package-requester'
|
||||
import {InstallContext, InstalledPackages} from '../api/install'
|
||||
import {
|
||||
@@ -272,19 +273,35 @@ async function install (
|
||||
pkg: loggedPkg,
|
||||
})
|
||||
|
||||
const pkgResponse = await ctx.storeController.requestPackage(wantedDependency, {
|
||||
loggedPkg,
|
||||
update: options.update,
|
||||
registry,
|
||||
prefix: ctx.prefix,
|
||||
shrinkwrapResolution: options.shrinkwrapResolution,
|
||||
currentPkgId: options.pkgId,
|
||||
verifyStoreIntegrity: ctx.verifyStoreInegrity,
|
||||
downloadPriority: -options.currentDepth,
|
||||
preferredVersions: ctx.preferredVersions,
|
||||
skipFetch: ctx.dryRun,
|
||||
sideEffectsCache: options.sideEffectsCache
|
||||
})
|
||||
let pkgResponse: PackageResponse | undefined
|
||||
try {
|
||||
pkgResponse = await ctx.storeController.requestPackage(wantedDependency, {
|
||||
loggedPkg,
|
||||
update: options.update,
|
||||
registry,
|
||||
prefix: ctx.prefix,
|
||||
shrinkwrapResolution: options.shrinkwrapResolution,
|
||||
currentPkgId: options.pkgId,
|
||||
verifyStoreIntegrity: ctx.verifyStoreInegrity,
|
||||
downloadPriority: -options.currentDepth,
|
||||
preferredVersions: ctx.preferredVersions,
|
||||
skipFetch: ctx.dryRun,
|
||||
sideEffectsCache: options.sideEffectsCache
|
||||
})
|
||||
} catch (err) {
|
||||
if (wantedDependency.optional) {
|
||||
logger.warn({
|
||||
message: `Skipping optional dependency ${wantedDependency.raw}. ${err.toString()}`,
|
||||
err,
|
||||
})
|
||||
return null
|
||||
}
|
||||
throw err
|
||||
}
|
||||
|
||||
if (!pkgResponse) {
|
||||
throw new Error(`Store returned nothing for ${wantedDependency.raw} request`)
|
||||
}
|
||||
|
||||
pkgResponse.body.id = encodePkgId(pkgResponse.body.id)
|
||||
|
||||
|
||||
@@ -30,6 +30,29 @@ test('skip failing optional dependencies', async (t: tape.Test) => {
|
||||
t.ok(m(-1), 'package with failed optional dependency has the dependencies installed correctly')
|
||||
})
|
||||
|
||||
test('skip non-existing optional dependency', async (t: tape.Test) => {
|
||||
const project = prepare(t, {
|
||||
dependencies: {
|
||||
'is-positive': '*',
|
||||
},
|
||||
optionalDependencies: {
|
||||
'i-do-not-exist': '1000',
|
||||
},
|
||||
})
|
||||
|
||||
const reporter = sinon.spy()
|
||||
await install(await testDefaults({reporter}))
|
||||
|
||||
t.ok(reporter.calledWithMatch({
|
||||
name: 'pnpm',
|
||||
level: 'warn',
|
||||
message: 'Skipping optional dependency i-do-not-exist@1000. Error: 404 Not Found: i-do-not-exist',
|
||||
}), 'warning reported')
|
||||
|
||||
const m = project.requireModule('is-positive')
|
||||
t.ok(m, 'installation succeded')
|
||||
})
|
||||
|
||||
test('skip optional dependency that does not support the current OS', async (t: tape.Test) => {
|
||||
const project = prepare(t, {
|
||||
optionalDependencies: {
|
||||
|
||||
Reference in New Issue
Block a user