1
1
// @ts -check
2
2
import { existsSync } from "node:fs" ;
3
3
import { symlink } from "node:fs/promises" ;
4
- import { dirname , join , resolve } from "node:path" ;
4
+ import { dirname , resolve } from "node:path" ;
5
5
import { fileURLToPath } from "node:url" ;
6
6
import { patch } from "ts-patch" ;
7
7
import { patch as patch1 } from "tsp1" ;
@@ -20,27 +20,17 @@ async function symlinkTsNode() {
20
20
}
21
21
22
22
function patchTsModules ( ) {
23
- /* ****************************************************************************************************************** *
24
- * Config
25
- * ****************************************************************************************************************** */
26
23
const rootDir = __dirname ;
27
- const tsDirs = [ "typescript-three" , "typescript-four-seven" , "typescript" ] ;
28
- /* ****************************************************************************************************************** *
29
- * Patch TS Modules
30
- * ****************************************************************************************************************** */
31
24
32
- const baseDirs = new Map ( ) ;
33
-
34
- for ( const tsDirName of tsDirs ) {
35
- const mainDir = resolve ( rootDir , "node_modules" , tsDirName ) ;
36
- if ( ! existsSync ( join ( mainDir , "lib-backup" ) ) ) baseDirs . set ( tsDirName , mainDir ) ;
25
+ /** @param {string } moduleName */
26
+ function patchTypescript ( moduleName , tspatch ) {
27
+ const basedir = resolve ( rootDir , "node_modules" , moduleName ) ;
28
+ tspatch ( [ "tsc.js" , "typescript.js" ] , { basedir, dir : basedir } ) ;
37
29
}
38
30
39
- // Patch discovered modules
40
- for ( const [ dirName , dir ] of baseDirs )
41
- if ( dirName === "typescript-three" ) patch1 ( [ "tsc.js" , "typescript.js" ] , { basedir : dir } ) ;
42
- else if ( dirName === "typescript-four-seven" ) patch2 ( [ "tsc.js" , "typescript.js" ] , { dir } ) ;
43
- else patch ( [ "tsc.js" , "typescript.js" ] , { dir } ) ;
31
+ patchTypescript ( "typescript-three" , patch1 ) ;
32
+ patchTypescript ( "typescript-four-seven" , patch2 ) ;
33
+ patchTypescript ( "typescript" , patch ) ;
44
34
}
45
35
46
36
patchTsModules ( ) ;
0 commit comments