1
1
#!/usr/bin/env node
2
2
3
3
import path from "node:path" ;
4
+ import os from "node:os" ;
4
5
5
6
import { execa } from "execa" ;
6
7
import { detect , getCommand } from "@antfu/ni" ;
7
8
import PackageJson from "@npmcli/package-json" ;
8
9
import fse from "fs-extra" ;
10
+ import PQueue from "p-queue" ;
9
11
10
- const TO_IGNORE = [ ".github" , "__scripts" , "yarn.lock" , "package.json" ] ;
12
+ console . log ( { concurrency : os . cpus ( ) . length } ) ;
13
+
14
+ const queue = new PQueue ( { concurrency : os . cpus ( ) . length } ) ;
15
+
16
+ const TO_IGNORE = [ ".git" , ".github" , "__scripts" , "yarn.lock" , "package.json" ] ;
11
17
12
18
let examples = [ ] ;
13
19
@@ -32,15 +38,19 @@ if (process.env.CI) {
32
38
const entries = await fse . readdir ( process . cwd ( ) , { withFileTypes : true } ) ;
33
39
examples = entries
34
40
. filter ( ( entry ) => entry . isDirectory ( ) )
35
- . filter ( ( d ) => ! TO_IGNORE . includes ( d ) ) ;
41
+ . filter ( ( entry ) => ! TO_IGNORE . includes ( entry . name ) )
42
+ . map ( ( entry ) => entry . name )
43
+ . filter ( ( entry ) => {
44
+ return fse . existsSync ( path . join ( entry , "package.json" ) ) ;
45
+ } ) ;
36
46
}
37
47
38
48
const list = new Intl . ListFormat ( "en" , { style : "long" , type : "conjunction" } ) ;
39
49
40
50
console . log ( `Testing changed examples: ${ list . format ( examples ) } ` ) ;
41
51
42
- const settled = await Promise . allSettled (
43
- examples . map ( async ( example ) => {
52
+ for ( const example of examples ) {
53
+ queue . add ( async ( ) => {
44
54
const pkgJson = await PackageJson . load ( example ) ;
45
55
46
56
const remixDeps = Object . keys ( pkgJson . content . dependencies ) . filter ( ( d ) => {
@@ -139,9 +149,16 @@ const settled = await Promise.allSettled(
139
149
} ) ;
140
150
141
151
await pkgJson . save ( ) ;
142
- } )
143
- ) ;
152
+ } ) ;
153
+ }
154
+
155
+ try {
156
+ queue . start ( ) ;
157
+ } catch ( error ) {
158
+ console . error ( error ) ;
159
+ process . exit ( 1 ) ;
160
+ }
144
161
145
- const rejected = settled . filter ( ( s ) => s . status === "rejected" ) ;
146
- rejected . forEach ( ( s ) => console . error ( s . reason ) ) ;
147
- process . exit ( rejected . length > 0 ? 1 : 0 ) ;
162
+ // const rejected = promises .filter((s) => s.status === "rejected");
163
+ // rejected.forEach((s) => console.error(s.reason));
164
+ // process.exit(rejected.length > 0 ? 1 : 0);
0 commit comments