fix: pnpm rebuild causes approve build list error (#9324)

* fix: pnpm rebuild causes approve build list error

* fix: update

* refactor(rebuild): use read-package-json

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
btea
2025-03-24 09:16:39 +08:00
committed by GitHub
parent 8425092e57
commit a2903a04ec
5 changed files with 29 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-rebuild": patch
---
The pnpm rebuild command should not incorrectly add package information to `ignoredBuilds`.

View File

@@ -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:*",

View File

@@ -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,

View File

@@ -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"
}
]
}

6
pnpm-lock.yaml generated
View File

@@ -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