Skip to content

Commit b8c65e0

Browse files
committed
Fix stack overflow in npm package install script
1 parent 26631bc commit b8c65e0

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

scripts/install-npm-packages.mjs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ async function installPackage(packageInfo) {
103103
// Check if installation is complete and valid.
104104
if (existsSync(installMarkerPath) && existsSync(packageJsonPath)) {
105105
try {
106-
const existingPkgJson = JSON.parse(
107-
await fs.readFile(packageJsonPath, 'utf8'),
108-
)
106+
// Read non-editable version for checking to avoid circular reference issues.
107+
const existingPkgJson = await readPackageJson(installedPath, {
108+
normalize: true,
109+
})
109110
const markerData = JSON.parse(
110111
await fs.readFile(installMarkerPath, 'utf8'),
111112
)
@@ -130,16 +131,17 @@ async function installPackage(packageInfo) {
130131
})
131132

132133
// Restore scripts and devDependencies after copying.
133-
const editablePkgJson = await readPackageJson(installedPath, {
134+
// Re-read the package.json after copy to get fresh editable instance.
135+
const restoredPkgJson = await readPackageJson(installedPath, {
134136
editable: true,
135137
})
136138
if (savedScripts) {
137-
editablePkgJson.scripts = savedScripts
139+
restoredPkgJson.scripts = savedScripts
138140
}
139141
if (savedDevDeps) {
140-
editablePkgJson.devDependencies = savedDevDeps
142+
restoredPkgJson.devDependencies = savedDevDeps
141143
}
142-
await editablePkgJson.save()
144+
await restoredPkgJson.save()
143145

144146
// Check mark for cached with refreshed overrides.
145147
writeProgress('✓')

0 commit comments

Comments
 (0)