1
1
import { versions } from "@arethetypeswrong/core/versions" ;
2
2
import cliProgress from "cli-progress" ;
3
3
import { 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" ;
5
5
import { createRequire } from "module" ;
6
6
import fetch from "node-fetch" ;
7
7
import { npmHighImpact } from "npm-high-impact" ;
@@ -26,6 +26,8 @@ const excludePackages = [
26
26
27
27
const excludedSpecs = [
28
28
"[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
29
31
] ;
30
32
31
33
// 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)) {
161
163
}
162
164
}
163
165
}
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
+ }
172
182
}
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
+ }
182
192
}
183
- }
184
193
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
+ } ) ;
195
204
196
- if ( datesModified || fullModified ) {
197
- await uploadData ( ) ;
205
+ if ( datesModified || fullModified ) {
206
+ await uploadData ( ) ;
207
+ }
198
208
}
199
209
200
210
function nAtATime < T > ( n : number , items : T [ ] , fn : ( item : T ) => Promise < void > ) {
0 commit comments