From d5a58c21df7fdb5259567c2344398ad9cc409fcd Mon Sep 17 00:00:00 2001 From: Douglas Ward Date: Tue, 16 May 2023 17:40:41 +0200 Subject: [PATCH] do not throw MISSING_HOISTED_LOCATIONS for optional packages --- .../src/implementation/index.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/exec/plugin-commands-rebuild/src/implementation/index.ts b/exec/plugin-commands-rebuild/src/implementation/index.ts index 18e4a0962df..03f5882acec 100644 --- a/exec/plugin-commands-rebuild/src/implementation/index.ts +++ b/exec/plugin-commands-rebuild/src/implementation/index.ts @@ -281,9 +281,13 @@ async function _rebuild ( ? (ctx.modulesFile?.hoistedLocations?.[depPath] ?? []).map((hoistedLocation) => path.join(opts.lockfileDir, hoistedLocation)) : [path.join(ctx.virtualStoreDir, dp.depPathToFilename(depPath), 'node_modules', pkgInfo.name)] if (pkgRoots.length === 0) { - throw new PnpmError('MISSING_HOISTED_LOCATIONS', `${depPath} is not found in hoistedLocations inside node_modules/.modules.yaml`, { - hint: 'If you installed your node_modules with pnpm older than v7.19.0, you may need to remove it and run "pnpm install"', - }) + if (pkgSnapshot.optional) { + return + } else { + throw new PnpmError('MISSING_HOISTED_LOCATIONS', `${depPath} is not found in hoistedLocations inside node_modules/.modules.yaml`, { + hint: 'If you installed your node_modules with pnpm older than v7.19.0, you may need to remove it and run "pnpm install"', + }) + } } const pkgRoot = pkgRoots[0] try {