2
2
* Reminder that this script is meant to be runnable without installing
3
3
* dependencies. It can therefore not rely on any external libraries.
4
4
*/
5
- import { promises as fs } from "node:fs" ;
6
- import * as os from "node:os" ;
5
+ import * as fs from "node:fs" ;
7
6
import * as path from "node:path" ;
8
7
import * as util from "node:util" ;
9
8
import {
@@ -14,6 +13,7 @@ import {
14
13
v ,
15
14
} from "../helpers.js" ;
16
15
import type { Manifest } from "../types.js" ;
16
+ import { writeJSONFile } from "../utils/filesystem.mjs" ;
17
17
import { fetchPackageMetadata , npmRegistryBaseURL } from "../utils/npm.mjs" ;
18
18
19
19
const VALID_TAGS = [ "canary-macos" , "canary-windows" , "nightly" ] ;
@@ -36,12 +36,12 @@ function searchReplaceInFile(
36
36
filename : string ,
37
37
searchValue : string | RegExp ,
38
38
replaceValue : string
39
- ) : Promise < void > {
39
+ ) : void {
40
40
const current = readTextFile ( filename ) ;
41
41
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
+ }
45
45
}
46
46
47
47
/**
@@ -331,7 +331,6 @@ export async function setReactVersion(
331
331
coreOnly : boolean ,
332
332
overrides : Record < string , string > = { }
333
333
) : Promise < void > {
334
- let fd : fs . FileHandle | undefined ;
335
334
try {
336
335
const profile = { ...( await getProfile ( version , coreOnly ) ) , ...overrides } ;
337
336
console . dir ( profile , { depth : null } ) ;
@@ -363,18 +362,12 @@ export async function setReactVersion(
363
362
}
364
363
365
364
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 ) ;
372
367
}
373
368
} catch ( e ) {
374
369
console . error ( e ) ;
375
370
process . exitCode = 1 ;
376
- } finally {
377
- fd ?. close ( ) ;
378
371
}
379
372
}
380
373
0 commit comments