11import { versions } from "@arethetypeswrong/core/versions" ;
22import cliProgress from "cli-progress" ;
33import { appendFileSync , createReadStream , createWriteStream } from "fs" ;
4- import { open , readFile , rename , unlink , writeFile } from "fs/promises" ;
4+ import { open , readFile , rename , stat , unlink , writeFile } from "fs/promises" ;
55import { createRequire } from "module" ;
66import fetch from "node-fetch" ;
77import { npmHighImpact } from "npm-high-impact" ;
@@ -26,6 +26,8 @@ const excludePackages = [
2626
2727const excludedSpecs = [
2828 "[email protected] " , // File not found: /node_modules/next/dist/styled-jsx-types/global.ts 29+ "[email protected] " , // Invalid gzip data 30+ "[email protected] " , // Invalid gzip data 2931] ;
3032
3133// Array of month starts from 2022-01-01 until the first of this month
@@ -161,40 +163,48 @@ for (const date of Object.keys(existingDates.dates)) {
161163 }
162164 }
163165}
164- const outFh = await open ( outJsonFileName , "r" ) ;
165- const newSpecs = new Set < string > ( ) ;
166- for await ( const line of outFh . readLines ( ) ) {
167- const result : FullJsonLine = JSON . parse ( line ) ;
168- if ( allSpecs . has ( result . packageSpec ) ) {
169- newSpecs . add ( result . packageSpec ) ;
170- appendFileSync ( cleanedFileName , `${ JSON . stringify ( result , ( key , value ) => ( key === "trace" ? [ ] : value ) ) } \n` ) ;
171- fullModified = true ;
166+
167+ if (
168+ await stat ( outJsonFileName ) . then (
169+ ( ) => true ,
170+ ( ) => false
171+ )
172+ ) {
173+ const outFh = await open ( outJsonFileName , "r" ) ;
174+ const newSpecs = new Set < string > ( ) ;
175+ for await ( const line of outFh . readLines ( ) ) {
176+ const result : FullJsonLine = JSON . parse ( line ) ;
177+ if ( allSpecs . has ( result . packageSpec ) ) {
178+ newSpecs . add ( result . packageSpec ) ;
179+ appendFileSync ( cleanedFileName , `${ JSON . stringify ( result , ( key , value ) => ( key === "trace" ? [ ] : value ) ) } \n` ) ;
180+ fullModified = true ;
181+ }
172182 }
173- }
174- await outFh . close ( ) ;
175-
176- const fullFh = await open ( fullJsonFileName , "r" ) ;
177- for await ( const line of fullFh . readLines ( ) ) {
178- const result : FullJsonLine = JSON . parse ( line ) ;
179- if ( ! newSpecs . has ( result . packageSpec ) ) {
180- appendFileSync ( cleanedFileName , ` ${ JSON . stringify ( result , ( key , value ) => ( key === "trace" ? [ ] : value ) ) } \n` ) ;
181- fullModified = true ;
183+ await outFh . close ( ) ;
184+
185+ const fullFh = await open ( fullJsonFileName , "r" ) ;
186+ for await ( const line of fullFh . readLines ( ) ) {
187+ const result : FullJsonLine = JSON . parse ( line ) ;
188+ if ( ! newSpecs . has ( result . packageSpec ) ) {
189+ appendFileSync ( cleanedFileName , ` ${ JSON . stringify ( result , ( key , value ) => ( key === "trace" ? [ ] : value ) ) } \n` ) ;
190+ fullModified = true ;
191+ }
182192 }
183- }
184193
185- await fullFh . close ( ) ;
186- await unlink ( fullJsonFileName ) ;
187- await rename ( cleanedFileName , fullJsonFileName ) ;
188- await new Promise ( ( resolve , reject ) => {
189- createReadStream ( fullJsonFileName )
190- . pipe ( createGzip ( { level : 9 } ) )
191- . pipe ( createWriteStream ( `${ fullJsonFileName . pathname } .gz` ) )
192- . on ( "error" , reject )
193- . on ( "close" , resolve ) ;
194- } ) ;
194+ await fullFh . close ( ) ;
195+ await unlink ( fullJsonFileName ) ;
196+ await rename ( cleanedFileName , fullJsonFileName ) ;
197+ await new Promise ( ( resolve , reject ) => {
198+ createReadStream ( fullJsonFileName )
199+ . pipe ( createGzip ( { level : 9 } ) )
200+ . pipe ( createWriteStream ( `${ fullJsonFileName . pathname } .gz` ) )
201+ . on ( "error" , reject )
202+ . on ( "close" , resolve ) ;
203+ } ) ;
195204
196- if ( datesModified || fullModified ) {
197- await uploadData ( ) ;
205+ if ( datesModified || fullModified ) {
206+ await uploadData ( ) ;
207+ }
198208}
199209
200210function nAtATime < T > ( n : number , items : T [ ] , fn : ( item : T ) => Promise < void > ) {
0 commit comments