11#!/usr/bin/env node
22
33import path from "node:path" ;
4+ import os from "node:os" ;
45
56import { execa } from "execa" ;
67import { detect , getCommand } from "@antfu/ni" ;
78import PackageJson from "@npmcli/package-json" ;
89import fse from "fs-extra" ;
10+ import PQueue from "p-queue" ;
911
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" ] ;
1117
1218let examples = [ ] ;
1319
@@ -32,15 +38,19 @@ if (process.env.CI) {
3238 const entries = await fse . readdir ( process . cwd ( ) , { withFileTypes : true } ) ;
3339 examples = entries
3440 . 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+ } ) ;
3646}
3747
3848const list = new Intl . ListFormat ( "en" , { style : "long" , type : "conjunction" } ) ;
3949
4050console . log ( `Testing changed examples: ${ list . format ( examples ) } ` ) ;
4151
42- const settled = await Promise . allSettled (
43- examples . map ( async ( example ) => {
52+ for ( const example of examples ) {
53+ queue . add ( async ( ) => {
4454 const pkgJson = await PackageJson . load ( example ) ;
4555
4656 const remixDeps = Object . keys ( pkgJson . content . dependencies ) . filter ( ( d ) => {
@@ -139,9 +149,16 @@ const settled = await Promise.allSettled(
139149 } ) ;
140150
141151 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+ }
144161
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