2
2
3
3
//@ts -check
4
4
5
- "use strict" ;
6
-
7
5
// This script is supposed to be running in project root directory
8
6
// It matters since we need read .sourcedirs(location)
9
7
// and its content are file/directories with regard to project root
10
8
11
- const tty = require ( "node:tty" ) ;
12
- const { bsc_exe, rescript_exe } = require ( "./bin_path.js" ) ;
13
- const bsb = require ( "./rescript_bsb.js" ) ;
9
+ import * as tty from "node:tty" ;
10
+ import packageJson from "rescript/package.json" with { type : "json" } ;
11
+
12
+ import * as bsb from "./_bsb.js" ;
13
+ import { bsc_exe , rescript_exe } from "./_paths.js" ;
14
14
15
15
const cwd = process . cwd ( ) ;
16
16
process . env . BSB_PROJECT_ROOT = cwd ;
@@ -21,7 +21,10 @@ if (process.env.FORCE_COLOR === undefined) {
21
21
process . env . NINJA_ANSI_FORCED = "1" ;
22
22
}
23
23
} else {
24
- if ( process . env . FORCE_COLOR === "1" && process . env . NINJA_ANSI_FORCED === undefined ) {
24
+ if (
25
+ process . env . FORCE_COLOR === "1" &&
26
+ process . env . NINJA_ANSI_FORCED === undefined
27
+ ) {
25
28
process . env . NINJA_ANSI_FORCED = "1" ;
26
29
}
27
30
if ( process . argv . includes ( "-verbose" ) ) {
@@ -77,19 +80,20 @@ try {
77
80
78
81
const args = process . argv . slice ( 2 ) ;
79
82
const argPatterns = {
80
- help : [ ' help' , '-h' , ' -help' , ' --help' ] ,
81
- version : [ ' version' , '-v' , ' -version' , ' --version' ] ,
83
+ help : [ " help" , "-h" , " -help" , " --help" ] ,
84
+ version : [ " version" , "-v" , " -version" , " --version" ] ,
82
85
} ;
83
86
84
87
const helpArgIndex = args . findIndex ( arg => argPatterns . help . includes ( arg ) ) ;
85
88
const firstPositionalArgIndex = args . findIndex ( arg => ! arg . startsWith ( "-" ) ) ;
86
89
87
- if ( helpArgIndex !== - 1 && ( firstPositionalArgIndex === - 1 || helpArgIndex <= firstPositionalArgIndex ) ) {
90
+ if (
91
+ helpArgIndex !== - 1 &&
92
+ ( firstPositionalArgIndex === - 1 || helpArgIndex <= firstPositionalArgIndex )
93
+ ) {
88
94
console . log ( helpMessage ) ;
89
-
90
95
} else if ( argPatterns . version . includes ( args [ 0 ] ) ) {
91
- console . log ( require ( "../package.json" ) . version ) ;
92
-
96
+ console . log ( packageJson . version ) ;
93
97
} else if ( firstPositionalArgIndex !== - 1 ) {
94
98
const subcmd = args [ firstPositionalArgIndex ] ;
95
99
const subcmdArgs = args . slice ( firstPositionalArgIndex + 1 ) ;
@@ -108,25 +112,17 @@ if (helpArgIndex !== -1 && (firstPositionalArgIndex === -1 || helpArgIndex <= fi
108
112
break ;
109
113
}
110
114
case "format" : {
111
- require ( "./rescript_format.js" ) . main (
112
- subcmdArgs ,
113
- rescript_exe ,
114
- bsc_exe
115
- ) ;
115
+ const mod = await import ( "./rescript/rescript_format.js" ) ;
116
+ await mod . main ( subcmdArgs , rescript_exe , bsc_exe ) ;
116
117
break ;
117
118
}
118
119
case "dump" : {
119
- require ( "./rescript_dump.js" ) . main (
120
- subcmdArgs ,
121
- rescript_exe ,
122
- bsc_exe
123
- ) ;
120
+ const mod = await import ( "./rescript/rescript_dump.js" ) ;
121
+ mod . main ( subcmdArgs , rescript_exe , bsc_exe ) ;
124
122
break ;
125
123
}
126
124
default : {
127
- console . error (
128
- `Error: Unknown command "${ subcmd } ".\n${ helpMessage } `
129
- ) ;
125
+ console . error ( `Error: Unknown command "${ subcmd } ".\n${ helpMessage } ` ) ;
130
126
process . exit ( 2 ) ;
131
127
}
132
128
}
0 commit comments