From 0a2f3ecc63a35cf0afec86f7233c15cf67f9922b Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Wed, 17 Jun 2020 12:02:14 +0300 Subject: [PATCH] fix(hoist): don't fail on issues with lockfile ref #2636 --- .changeset/tender-mugs-float.md | 5 +++++ packages/hoist/src/index.ts | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .changeset/tender-mugs-float.md diff --git a/.changeset/tender-mugs-float.md b/.changeset/tender-mugs-float.md new file mode 100644 index 0000000000..760e78e6a6 --- /dev/null +++ b/.changeset/tender-mugs-float.md @@ -0,0 +1,5 @@ +--- +"@pnpm/hoist": patch +--- + +Hoisting should not fail if some of the aliases cannot be hoisted due to issues with the lockfile. diff --git a/packages/hoist/src/index.ts b/packages/hoist/src/index.ts index 8008440858..06c2f68e07 100644 --- a/packages/hoist/src/index.ts +++ b/packages/hoist/src/index.ts @@ -5,7 +5,7 @@ import { nameVerFromPkgSnapshot, } from '@pnpm/lockfile-utils' import lockfileWalker, { LockfileWalkerStep } from '@pnpm/lockfile-walker' -import logger from '@pnpm/logger' +import logger, { globalWarn } from '@pnpm/logger' import matcher from '@pnpm/matcher' import pkgIdToFilename from '@pnpm/pkgid-to-filename' import symlinkDependency from '@pnpm/symlink-dependency' @@ -192,7 +192,13 @@ async function symlinkHoistedDependencies ( await Promise.all( Object.entries(hoistedDependencies) .map(async ([depPath, pkgAliases]) => { - const pkgName = nameVerFromPkgSnapshot(depPath, opts.lockfile.packages![depPath]).name + const pkgSnapshot = opts.lockfile.packages![depPath] + if (!pkgSnapshot) { + globalWarn(`Failed to find "${depPath}" in lockfile during hoisting. ` + + `Next aliases will not be hoisted: ${Object.keys(pkgAliases).join(', ')}`) + return + } + const pkgName = nameVerFromPkgSnapshot(depPath, pkgSnapshot).name const modules = path.join(opts.virtualStoreDir, pkgIdToFilename(depPath, opts.lockfileDir), 'node_modules') const depLocation = path.join(modules, pkgName) await Promise.all(Object.entries(pkgAliases).map(async ([pkgAlias, hoistType]) => {