22 * Reminder that this script is meant to be runnable without installing
33 * dependencies. It can therefore not rely on any external libraries.
44 */
5- import { promises as fs } from "node:fs" ;
6- import * as os from "node:os" ;
5+ import * as fs from "node:fs" ;
76import * as path from "node:path" ;
87import * as util from "node:util" ;
98import {
@@ -14,6 +13,7 @@ import {
1413 v ,
1514} from "../helpers.js" ;
1615import type { Manifest } from "../types.js" ;
16+ import { writeJSONFile } from "../utils/filesystem.mjs" ;
1717import { fetchPackageMetadata , npmRegistryBaseURL } from "../utils/npm.mjs" ;
1818
1919const VALID_TAGS = [ "canary-macos" , "canary-windows" , "nightly" ] ;
@@ -36,12 +36,12 @@ function searchReplaceInFile(
3636 filename : string ,
3737 searchValue : string | RegExp ,
3838 replaceValue : string
39- ) : Promise < void > {
39+ ) : void {
4040 const current = readTextFile ( filename ) ;
4141 const updated = current . replace ( searchValue , replaceValue ) ;
42- return updated === current
43- ? Promise . resolve ( )
44- : fs . writeFile ( filename , updated ) ;
42+ if ( updated !== current ) {
43+ fs . writeFileSync ( filename , updated ) ;
44+ }
4545}
4646
4747/**
@@ -331,7 +331,6 @@ export async function setReactVersion(
331331 coreOnly : boolean ,
332332 overrides : Record < string , string > = { }
333333) : Promise < void > {
334- let fd : fs . FileHandle | undefined ;
335334 try {
336335 const profile = { ...( await getProfile ( version , coreOnly ) ) , ...overrides } ;
337336 console . dir ( profile , { depth : null } ) ;
@@ -363,18 +362,12 @@ export async function setReactVersion(
363362 }
364363
365364 const tmpFile = manifestPath + ".tmp" ;
366- fd = await fs . open ( tmpFile , "w" , 0o644 ) ;
367- await fd . write ( JSON . stringify ( manifest , undefined , 2 ) ) ;
368- await fd . write ( os . EOL ) ;
369- await fd . close ( ) ;
370- fd = undefined ;
371- await fs . rename ( tmpFile , manifestPath ) ;
365+ writeJSONFile ( tmpFile , manifest ) ;
366+ fs . renameSync ( tmpFile , manifestPath ) ;
372367 }
373368 } catch ( e ) {
374369 console . error ( e ) ;
375370 process . exitCode = 1 ;
376- } finally {
377- fd ?. close ( ) ;
378371 }
379372}
380373
0 commit comments