Skip to content

Commit

Permalink
fix: rebuild should print a better error message
Browse files Browse the repository at this point in the history
close #5815
  • Loading branch information
zkochan committed Dec 22, 2022
1 parent d7ea8b4 commit c8d3853
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/few-dancers-exist.md
@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-rebuild": patch
"pnpm": patch
---

`pnpm rebuild` should not fail if node_modules was created by pnpm version 7.18 or older [#5815](https://github.com/pnpm/pnpm/issues/5815).
6 changes: 6 additions & 0 deletions .changeset/nervous-avocados-end.md
@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-rebuild": patch
"pnpm": patch
---

`pnpm rebuild` should print a better error message when a hoisted dependency is not found [#5815](https://github.com/pnpm/pnpm/issues/5815).
1 change: 1 addition & 0 deletions exec/plugin-commands-rebuild/package.json
Expand Up @@ -34,6 +34,7 @@
"homepage": "https://github.com/pnpm/pnpm/blob/main/exec/plugin-commands-rebuild#readme",
"devDependencies": {
"@pnpm/assert-project": "workspace:*",
"@pnpm/error": "workspace:*",
"@pnpm/filter-workspace-packages": "workspace:*",
"@pnpm/plugin-commands-rebuild": "workspace:*",
"@pnpm/prepare": "workspace:*",
Expand Down
6 changes: 6 additions & 0 deletions exec/plugin-commands-rebuild/src/implementation/index.ts
Expand Up @@ -4,6 +4,7 @@ import {
WANTED_LOCKFILE,
} from '@pnpm/constants'
import { skippedOptionalDependencyLogger } from '@pnpm/core-loggers'
import { PnpmError } from '@pnpm/error'
import { getContext, PnpmContext } from '@pnpm/get-context'
import {
runLifecycleHooksConcurrently,
Expand Down Expand Up @@ -276,6 +277,11 @@ async function _rebuild (
const pkgRoots = opts.nodeLinker === 'hoisted'
? (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"',
})
}
const pkgRoot = pkgRoots[0]
try {
const extraBinPaths = ctx.extraBinPaths
Expand Down
3 changes: 3 additions & 0 deletions exec/plugin-commands-rebuild/tsconfig.json
Expand Up @@ -48,6 +48,9 @@
{
"path": "../../packages/dependency-path"
},
{
"path": "../../packages/error"
},
{
"path": "../../packages/types"
},
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c8d3853

Please sign in to comment.