1+ import { readJSONFileSync , writeJSONFileSync } from '@rnx-kit/tools-filesystem' ;
12import { spawnSync } from 'node:child_process' ;
23import { existsSync , mkdirSync , readFileSync , statSync , writeFileSync } from 'node:fs' ;
34import { mkdir } from 'node:fs/promises' ;
@@ -7,7 +8,7 @@ import { gzipSync } from 'node:zlib';
78
89const workspaceRoot = dirname ( dirname ( fileURLToPath ( import . meta. url ) ) ) ;
910const repositoryRoot = dirname ( dirname ( workspaceRoot ) ) ;
10- const yarnVersion = JSON . parse ( readFileSync ( join ( repositoryRoot , 'package.json' ) , 'utf8 ') ) . packageManager . split ( '@' ) [ 1 ] ;
11+ const yarnVersion = readJSONFileSync ( join ( repositoryRoot , 'package.json' ) ) . packageManager . split ( '@' ) [ 1 ] ;
1112const yarnPath = join ( repositoryRoot , '.yarn' , 'releases' , `yarn-${ yarnVersion } .cjs` ) ;
1213const configPath = join ( workspaceRoot , 'scenarios.json' ) ;
1314const defaultBaselinePath = join ( workspaceRoot , 'baseline.json' ) ;
@@ -68,7 +69,7 @@ function getWorkspacePackage(source) {
6869 while ( directory . startsWith ( packagesRoot ) ) {
6970 const manifestPath = join ( directory , 'package.json' ) ;
7071 if ( existsSync ( manifestPath ) ) {
71- return JSON . parse ( readFileSync ( manifestPath , 'utf8' ) ) . name ;
72+ return readJSONFileSync ( manifestPath ) . name ;
7273 }
7374 directory = dirname ( directory ) ;
7475 }
@@ -153,8 +154,8 @@ function runBundle(platform, scenario, resetCache) {
153154 }
154155
155156 const bundle = readFileSync ( bundlePath ) ;
156- const sourceMap = JSON . parse ( readFileSync ( sourceMapPath , 'utf8' ) ) ;
157- const metafile = JSON . parse ( readFileSync ( metafilePath , 'utf8' ) ) ;
157+ const sourceMap = readJSONFileSync ( sourceMapPath ) ;
158+ const metafile = readJSONFileSync ( metafilePath ) ;
158159 const contributions = getWorkspaceContributions ( metafile ) ;
159160
160161 return {
@@ -263,7 +264,7 @@ const {
263264if ( updateBaseline && selectedPlatforms ) {
264265 throw new Error ( 'Baseline updates must include every configured platform; omit --platform' ) ;
265266}
266- const selectedConfig = JSON . parse ( readFileSync ( selectedConfigPath , 'utf8' ) ) ;
267+ const selectedConfig = readJSONFileSync ( selectedConfigPath ) ;
267268const platforms = selectedPlatforms ?? selectedConfig . platforms ;
268269
269270await mkdir ( entryRoot , { recursive : true } ) ;
@@ -284,12 +285,10 @@ const currentBaseline = {
284285 results : measurements . map ( baselineResult ) ,
285286} ;
286287if ( updateBaseline ) {
287- writeFileSync ( selectedBaselinePath , ` ${ JSON . stringify ( currentBaseline , null , 2 ) } \n` ) ;
288+ writeJSONFileSync ( selectedBaselinePath , currentBaseline ) ;
288289}
289290
290- const baseline = existsSync ( selectedBaselinePath )
291- ? JSON . parse ( readFileSync ( selectedBaselinePath , 'utf8' ) )
292- : { schemaVersion : 1 , results : [ ] } ;
291+ const baseline = existsSync ( selectedBaselinePath ) ? readJSONFileSync ( selectedBaselinePath ) : { schemaVersion : 1 , results : [ ] } ;
293292if ( baseline . schemaVersion !== 1 ) {
294293 throw new Error ( `Unsupported baseline schema version: ${ baseline . schemaVersion } ` ) ;
295294}
@@ -315,7 +314,7 @@ const report = {
315314} ;
316315const reportPath = join ( outputRoot , 'results.json' ) ;
317316const markdownReportPath = join ( outputRoot , 'report.md' ) ;
318- writeFileSync ( reportPath , ` ${ JSON . stringify ( report , null , 2 ) } \n` ) ;
317+ writeJSONFileSync ( reportPath , report ) ;
319318writeFileSync ( markdownReportPath , createMarkdownReport ( results ) ) ;
320319
321320console . table ( results ) ;
0 commit comments