diff --git a/.changeset/green-eagles-clean.md b/.changeset/green-eagles-clean.md new file mode 100644 index 0000000000..c8c944eb33 --- /dev/null +++ b/.changeset/green-eagles-clean.md @@ -0,0 +1,5 @@ +--- +"@pnpm/plugin-commands-rebuild": patch +--- + +The pnpm rebuild command should not incorrectly add package information to `ignoredBuilds`. diff --git a/exec/plugin-commands-rebuild/package.json b/exec/plugin-commands-rebuild/package.json index d4d6958cba..8e0fdbaa53 100644 --- a/exec/plugin-commands-rebuild/package.json +++ b/exec/plugin-commands-rebuild/package.json @@ -41,6 +41,7 @@ "@pnpm/dependency-path": "workspace:*", "@pnpm/deps.graph-sequencer": "workspace:*", "@pnpm/error": "workspace:*", + "@pnpm/exec.pkg-requires-build": "workspace:*", "@pnpm/get-context": "workspace:*", "@pnpm/lifecycle": "workspace:*", "@pnpm/link-bins": "workspace:*", @@ -50,6 +51,7 @@ "@pnpm/modules-yaml": "workspace:*", "@pnpm/normalize-registries": "workspace:*", "@pnpm/npm-package-arg": "catalog:", + "@pnpm/read-package-json": "workspace:*", "@pnpm/sort-packages": "workspace:*", "@pnpm/store-connection-manager": "workspace:*", "@pnpm/store-controller-types": "workspace:*", diff --git a/exec/plugin-commands-rebuild/src/implementation/index.ts b/exec/plugin-commands-rebuild/src/implementation/index.ts index b925e4b863..629e7cf377 100644 --- a/exec/plugin-commands-rebuild/src/implementation/index.ts +++ b/exec/plugin-commands-rebuild/src/implementation/index.ts @@ -28,7 +28,9 @@ import { writeModulesManifest } from '@pnpm/modules-yaml' import { createOrConnectStoreController } from '@pnpm/store-connection-manager' import { type DepPath, type ProjectManifest, type ProjectId, type ProjectRootDir } from '@pnpm/types' import { createAllowBuildFunction } from '@pnpm/builder.policy' +import { pkgRequiresBuild } from '@pnpm/exec.pkg-requires-build' import * as dp from '@pnpm/dependency-path' +import { safeReadPackageJsonFromDir } from '@pnpm/read-package-json' import { hardLinkDir } from '@pnpm/worker' import loadJsonFile from 'load-json-file' import runGroups from 'run-groups' @@ -350,8 +352,15 @@ async function _rebuild ( return } } + let requiresBuild = true + const pgkManifest = await safeReadPackageJsonFromDir(pkgRoot) + if (pgkManifest != null) { + // This won't return the correct result for packages with binding.gyp as we don't pass the filesIndex to the function. + // However, currently rebuild doesn't work for such packages at all, which should be fixed. + requiresBuild = pkgRequiresBuild(pgkManifest, {}) + } - const hasSideEffects = allowBuild(pkgInfo.name) && await runPostinstallHooks({ + const hasSideEffects = requiresBuild && allowBuild(pkgInfo.name) && await runPostinstallHooks({ depPath, extraBinPaths, extraEnv: opts.extraEnv, diff --git a/exec/plugin-commands-rebuild/tsconfig.json b/exec/plugin-commands-rebuild/tsconfig.json index c9116b530f..c74f6d7afa 100644 --- a/exec/plugin-commands-rebuild/tsconfig.json +++ b/exec/plugin-commands-rebuild/tsconfig.json @@ -78,6 +78,9 @@ { "path": "../../pkg-manager/modules-yaml" }, + { + "path": "../../pkg-manifest/read-package-json" + }, { "path": "../../store/cafs" }, @@ -101,6 +104,9 @@ }, { "path": "../lifecycle" + }, + { + "path": "../pkg-requires-build" } ] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b425e6fa64..d960842962 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2395,6 +2395,9 @@ importers: '@pnpm/error': specifier: workspace:* version: link:../../packages/error + '@pnpm/exec.pkg-requires-build': + specifier: workspace:* + version: link:../pkg-requires-build '@pnpm/get-context': specifier: workspace:* version: link:../../pkg-manager/get-context @@ -2422,6 +2425,9 @@ importers: '@pnpm/npm-package-arg': specifier: 'catalog:' version: 1.0.0 + '@pnpm/read-package-json': + specifier: workspace:* + version: link:../../pkg-manifest/read-package-json '@pnpm/sort-packages': specifier: workspace:* version: link:../../workspace/sort-packages