11import os from 'node:os' ;
2+ import { fs } from 'zx' ;
23
3- await $ `tsc` ;
4- await $ `tsc -p tsconfig.require.json` ;
4+ const { mkdir , writeJson } = fs ;
5+ const TMP_DIR = './tmp/' ;
56
67const targets = [
78 'esnext' ,
@@ -19,8 +20,10 @@ const envs = [
1920 null ,
2021 '@types/node@24' ,
2122 '@types/node@20' ,
22- // '@types/node@18',
23- '@types/bun@latest' ,
23+ '@types/node@18' ,
24+ '@types/node@16' ,
25+ // '@types/node@15', // fails
26+ // '@types/bun@latest', // fails
2427] ;
2528const types = [
2629 'global' ,
@@ -31,29 +34,40 @@ const libs = [
3134 'dom' ,
3235] ;
3336
37+ let tested = 0 ;
38+ let failed = 0 ;
39+
40+ const getEnvPath = function ( env ) {
41+ if ( ! env ) return null ;
42+ return path . join ( TMP_DIR , env . replaceAll ( '/' , '-' ) . replaceAll ( '@' , '' ) ) ;
43+ } ;
44+
3445const runTestsOnEnv = async function ( { typeScriptVersion, target, type, env, lib } ) {
3546 $ . verbose = false ;
36- const command = `npx -p typescript@${ typeScriptVersion } ${ env ? ` -p ${ env } ` : '' } tsc -p proposals/${ type } /tsconfig.json --target ${ target } ${ lib ? ` --lib ${ lib } ` : '' } ` ;
47+ const envLibName = env ? env . substring ( 0 , env . lastIndexOf ( '@' ) ) : '' ;
48+ const command = `npx -p typescript@${ typeScriptVersion } ${ env ? ` -p ${ env } ` : '' } `
49+ + `tsc -p proposals/${ type } /tsconfig.json --target ${ target } ${ lib ? ` --lib ${ target } ,${ lib } ` : '' } ${ env ? ` --types @core-js/types,${ envLibName } ` : '' } ` ;
3750 echo ( `$ ${ command } ` ) ;
3851 try {
3952 if ( env && lib ) {
40- await $ `npx -p typescript@${ typeScriptVersion } -p ${ env } tsc -p proposals/ ${ type } /tsconfig .json --target ${ target } --lib ${ target } ,${ lib } ` . quiet ( ) ;
53+ await $ ( { cwd : getEnvPath ( env ) } ) `npx -p typescript@${ typeScriptVersion } tsc -p ./tsconfig. ${ type } .json --target ${ target } --lib ${ target } ,${ lib } --types @core-js/types, ${ envLibName } ` . quiet ( ) ;
4154 } else if ( env ) {
42- await $ `npx -p typescript@${ typeScriptVersion } -p ${ env } tsc -p proposals/ ${ type } /tsconfig .json --target ${ target } ` . quiet ( ) ;
55+ await $ ( { cwd : getEnvPath ( env ) } ) `npx -p typescript@${ typeScriptVersion } tsc -p ./tsconfig. ${ type } .json --target ${ target } --types @core-js/types, ${ envLibName } ` . quiet ( ) ;
4356 } else if ( lib ) {
4457 await $ `npx -p typescript@${ typeScriptVersion } tsc -p proposals/${ type } /tsconfig.json --target ${ target } --lib ${ target } ,${ lib } ` . quiet ( ) ;
4558 } else {
4659 await $ `npx -p typescript@${ typeScriptVersion } tsc -p proposals/${ type } /tsconfig.json --target ${ target } ` . quiet ( ) ;
4760 }
4861 echo ( chalk . green ( `$ ${ command } ` ) ) ;
62+ tested ++ ;
4963 } catch ( error ) {
64+ tested ++ ;
65+ failed ++ ;
5066 echo ( `$ ${ chalk . red ( command ) } \n ${ error } ` ) ;
51- // eslint-disable-next-line node/no-process-exit -- it's needed here
52- process . exit ( 1 ) ;
5367 }
5468} ;
5569
56- async function runLimited ( configs , limit ) {
70+ const runLimited = async function ( configs , limit ) {
5771 let i = 0 ;
5872 async function worker ( ) {
5973 while ( i < configs . length ) {
@@ -62,7 +76,7 @@ async function runLimited(configs, limit) {
6276 }
6377 }
6478 await Promise . all ( Array . from ( { length : limit } , worker ) ) ;
65- }
79+ } ;
6680
6781const taskConfigs = [ ] ;
6882for ( const type of types ) {
@@ -77,8 +91,34 @@ for (const type of types) {
7791 }
7892}
7993
94+ const clearTmpDir = async function ( ) {
95+ await $ `rm -rf ${ TMP_DIR } ` ;
96+ } ;
97+
98+ const prepareEnvironment = async function ( environments , coreJsTypes ) {
99+ await clearTmpDir ( ) ;
100+ for ( const env of environments ) {
101+ if ( ! env ) continue ;
102+ const tmpEnvDir = getEnvPath ( env ) ;
103+ await mkdir ( tmpEnvDir , { recursive : true } ) ;
104+ await $ ( { cwd : tmpEnvDir } ) `npm init -y > /dev/null 2>&1` ;
105+ await $ ( { cwd : tmpEnvDir } ) `npm install ${ env } ` ;
106+ for ( const type of coreJsTypes ) {
107+ await writeJson ( path . join ( tmpEnvDir , `tsconfig.${ type } .json` ) , {
108+ extends : '../../tsconfig.json' ,
109+ include : [ `../../proposals/${ type } /*.ts` ] ,
110+ } ) ;
111+ }
112+ }
113+ } ;
114+
115+ await $ `npx -p typescript@5.9 tsc` ;
116+ await $ `npx -p typescript@5.9 -p @types/node@24 tsc -p tsconfig.require.json` ;
80117const numCPUs = os . cpus ( ) . length ;
118+ await prepareEnvironment ( envs , types ) ;
81119await runLimited ( taskConfigs , Math . max ( numCPUs - 1 , 1 ) ) ;
120+ await clearTmpDir ( ) ;
121+ echo ( `Tested: ${ chalk . green ( tested ) } , Failed: ${ chalk . red ( failed ) } ` ) ;
82122
83123// await $`tsc -p proposals/global/tsconfig.esnext.json`;
84124// await $`tsc -p proposals/global/tsconfig.es2023.json`;
0 commit comments