From d5a58c21df7fdb5259567c2344398ad9cc409fcd Mon Sep 17 00:00:00 2001 From: Douglas Ward Date: Tue, 16 May 2023 17:40:41 +0200 Subject: [PATCH 1/2] 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 { From c23f8d6ca78faae3d8fa5fef6b01224f9af2acb3 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Wed, 17 May 2023 01:37:04 +0300 Subject: [PATCH 2/2] docs: add changesets --- .changeset/kind-windows-reflect.md | 6 ++++++ .../src/implementation/index.ts | 11 ++++------- 2 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 .changeset/kind-windows-reflect.md diff --git a/.changeset/kind-windows-reflect.md b/.changeset/kind-windows-reflect.md new file mode 100644 index 00000000000..473639c316d --- /dev/null +++ b/.changeset/kind-windows-reflect.md @@ -0,0 +1,6 @@ +--- +"@pnpm/plugin-commands-rebuild": patch +"pnpm": patch +--- + +`pnpm rebuild` should not fail when `node-linker` is set to `hoisted` and there are skipped optional dependencies [#6553](https://github.com/pnpm/pnpm/pull/6553). diff --git a/exec/plugin-commands-rebuild/src/implementation/index.ts b/exec/plugin-commands-rebuild/src/implementation/index.ts index 03f5882acec..c0794effa5f 100644 --- a/exec/plugin-commands-rebuild/src/implementation/index.ts +++ b/exec/plugin-commands-rebuild/src/implementation/index.ts @@ -281,13 +281,10 @@ 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) { - 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"', - }) - } + if (pkgSnapshot.optional) return + 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 {