fix: installing optional dependencies

This commit is contained in:
Zoltan Kochan
2021-08-20 16:28:34 +03:00
parent f815dabd99
commit 31e01d9a93
4 changed files with 36 additions and 15 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/package-requester": patch
---
isInstallable should be always returned by `packageRequester()`.

View File

@@ -0,0 +1,5 @@
---
"@pnpm/resolve-dependencies": patch
---
Fetch a package if it is not installable as optional but also exists as not optional.

View File

@@ -248,6 +248,7 @@ async function resolveAndFetch (
body: {
id,
isLocal: false as const,
isInstallable: isInstallable ?? undefined,
latest,
manifest,
normalizedPref,

View File

@@ -764,21 +764,7 @@ async function resolveDependency (
requester: ctx.lockfileDir,
status: 'resolved',
})
if (pkgResponse.files != null) {
pkgResponse.files()
.then((fetchResult: PackageFilesResponse) => {
progressLogger.debug({
packageId: pkgResponse.body.id,
requester: ctx.lockfileDir,
status: fetchResult.fromStore
? 'found_in_store'
: 'fetched',
})
})
.catch(() => {
// Ignore
})
}
logFetchResult(pkgResponse, ctx.lockfileDir)
ctx.resolvedPackagesByDepPath[depPath] = getResolvedPackage({
dependencyLockfile: currentPkg.dependencyLockfile,
@@ -795,6 +781,13 @@ async function resolveDependency (
ctx.resolvedPackagesByDepPath[depPath].prod = ctx.resolvedPackagesByDepPath[depPath].prod || !wantedDependency.dev && !wantedDependency.optional
ctx.resolvedPackagesByDepPath[depPath].dev = ctx.resolvedPackagesByDepPath[depPath].dev || wantedDependency.dev
ctx.resolvedPackagesByDepPath[depPath].optional = ctx.resolvedPackagesByDepPath[depPath].optional && wantedDependency.optional
if (ctx.resolvedPackagesByDepPath[depPath].fetchingFiles == null && pkgResponse.files != null) {
logFetchResult(pkgResponse, ctx.lockfileDir)
ctx.resolvedPackagesByDepPath[depPath].fetchingFiles = pkgResponse.files
ctx.resolvedPackagesByDepPath[depPath].filesIndexFile = pkgResponse.filesIndexFile!
ctx.resolvedPackagesByDepPath[depPath].finishing = pkgResponse.finishing!
ctx.resolvedPackagesByDepPath[depPath].fetchingBundledManifest = pkgResponse.bundledManifest!
}
if (ctx.dependenciesTree[nodeId]) {
ctx.dependenciesTree[nodeId].depth = Math.min(ctx.dependenciesTree[nodeId].depth, options.currentDepth)
@@ -826,6 +819,23 @@ async function resolveDependency (
}
}
function logFetchResult (pkgResponse: PackageResponse, lockfileDir: string) {
if (pkgResponse.files == null) return
pkgResponse.files()
.then((fetchResult: PackageFilesResponse) => {
progressLogger.debug({
packageId: pkgResponse.body.id,
requester: lockfileDir,
status: fetchResult.fromStore
? 'found_in_store'
: 'fetched',
})
})
.catch(() => {
// Ignore
})
}
function pkgIsLeaf (pkg: PackageManifest) {
return isEmpty(pkg.dependencies ?? {}) &&
isEmpty(pkg.optionalDependencies ?? {}) &&