@@ -12,7 +12,6 @@ import { suppressMaxListenersWarning } from './utils/suppress-warnings.mjs'
1212import ENV from '../registry/dist/lib/constants/ENV.js'
1313import spinner from '../registry/dist/lib/constants/spinner.js'
1414import WIN32 from '../registry/dist/lib/constants/WIN32.js'
15- import { readPackageJson } from '../registry/dist/lib/packages.js'
1615import { pEach } from '../registry/dist/lib/promises.js'
1716import { LOG_SYMBOLS , logger } from '../registry/dist/lib/logger.js'
1817import { spawn } from '../registry/dist/lib/spawn.js'
@@ -131,17 +130,20 @@ async function installPackage(packageInfo) {
131130 } )
132131
133132 // Restore scripts and devDependencies after copying.
134- // Re-read the package.json after copy to get fresh editable instance .
135- const restoredPkgJson = await readPackageJson ( installedPath , {
136- editable : true ,
137- } )
133+ // Read the package.json after copy and restore the saved data .
134+ const restoredPkgJson = JSON . parse (
135+ await fs . readFile ( packageJsonPath , 'utf8' ) ,
136+ )
138137 if ( savedScripts ) {
139138 restoredPkgJson . scripts = savedScripts
140139 }
141140 if ( savedDevDeps ) {
142141 restoredPkgJson . devDependencies = savedDevDeps
143142 }
144- await restoredPkgJson . save ( )
143+ await fs . writeFile (
144+ packageJsonPath ,
145+ JSON . stringify ( restoredPkgJson , null , 2 ) ,
146+ )
145147
146148 // Check mark for cached with refreshed overrides.
147149 writeProgress ( '✓' )
@@ -195,9 +197,9 @@ async function installPackage(packageInfo) {
195197 let originalPkgJson = { }
196198 let originalScripts = { }
197199 try {
198- originalPkgJson = await readPackageJson ( installedPath , {
199- normalize : true ,
200- } )
200+ originalPkgJson = JSON . parse (
201+ await fs . readFile ( path . join ( installedPath , 'package.json' ) , 'utf8' ) ,
202+ )
201203 originalScripts = originalPkgJson . scripts || { }
202204 } catch {
203205 // Package.json might not exist in the symlink location for some packages.
@@ -211,9 +213,9 @@ async function installPackage(packageInfo) {
211213 origPkgName ,
212214 )
213215 try {
214- originalPkgJson = await readPackageJson ( pnpmStorePath , {
215- normalize : true ,
216- } )
216+ originalPkgJson = JSON . parse (
217+ await fs . readFile ( path . join ( pnpmStorePath , 'package.json' ) , 'utf8' ) ,
218+ )
217219 originalScripts = originalPkgJson . scripts || { }
218220 } catch {
219221 // If we still can't read it, that's okay - we'll use the override's package.json.
@@ -229,18 +231,17 @@ async function installPackage(packageInfo) {
229231 } )
230232
231233 // Merge back the test scripts and devDependencies if they existed.
232- const editablePkgJson = await readPackageJson ( installedPath , {
233- editable : true ,
234- } )
234+ const pkgJsonPath = path . join ( installedPath , 'package.json' )
235+ const pkgJson = JSON . parse ( await fs . readFile ( pkgJsonPath , 'utf8' ) )
235236
236237 // Preserve devDependencies from original.
237238 if ( originalPkgJson . devDependencies ) {
238- editablePkgJson . devDependencies = originalPkgJson . devDependencies
239+ pkgJson . devDependencies = originalPkgJson . devDependencies
239240 }
240241
241242 // Preserve test scripts.
242243 if ( originalScripts ) {
243- editablePkgJson . scripts = editablePkgJson . scripts || { }
244+ pkgJson . scripts = pkgJson . scripts || { }
244245
245246 // Look for actual test runner in scripts.
246247 const additionalTestRunners = [ ...testRunners , 'test:stock' , 'test:all' ]
@@ -258,35 +259,35 @@ async function installPackage(packageInfo) {
258259
259260 // Use the actual test script or cleaned version.
260261 if ( actualTestScript && originalScripts [ actualTestScript ] ) {
261- editablePkgJson . scripts . test = cleanTestScript (
262+ pkgJson . scripts . test = cleanTestScript (
262263 originalScripts [ actualTestScript ] ,
263264 )
264265 // Also preserve the actual script if it's referenced.
265266 if ( actualTestScript !== 'test' ) {
266- editablePkgJson . scripts [ actualTestScript ] = cleanTestScript (
267+ pkgJson . scripts [ actualTestScript ] = cleanTestScript (
267268 originalScripts [ actualTestScript ] ,
268269 )
269270 }
270271 } else if ( originalScripts . test ) {
271272 // Fallback to simple test script if it exists.
272- editablePkgJson . scripts . test = cleanTestScript ( originalScripts . test )
273+ pkgJson . scripts . test = cleanTestScript ( originalScripts . test )
273274 }
274275
275276 // Preserve any test:* and tests-* scripts that might be referenced.
276277 for ( const [ key , value ] of Object . entries ( originalScripts ) ) {
277278 if (
278279 ( key . startsWith ( 'test:' ) || key . startsWith ( 'tests' ) ) &&
279- ! editablePkgJson . scripts [ key ]
280+ ! pkgJson . scripts [ key ]
280281 ) {
281- editablePkgJson . scripts [ key ] = cleanTestScript ( value )
282+ pkgJson . scripts [ key ] = cleanTestScript ( value )
282283 }
283284 }
284285 }
285286
286- await editablePkgJson . save ( )
287+ await fs . writeFile ( pkgJsonPath , JSON . stringify ( pkgJson , null , 2 ) )
287288
288289 // Check for test script.
289- const testScript = editablePkgJson . scripts ?. test
290+ const testScript = pkgJson . scripts ?. test
290291
291292 if ( ! testScript ) {
292293 writeProgress ( LOG_SYMBOLS . warn )
0 commit comments