@@ -13,6 +13,12 @@ import * as c from "./constants";
13
13
* TODO CMT stuff
14
14
* - Compile resi
15
15
* - Wait a certain threshold for compilation before using the old cmt
16
+ * - Monorepos? Namespaces
17
+ * Questions:
18
+ * - We trigger no incremental compilation for other files. This might be problematic if we want to go across files. Track dependencies? What's supposed to be used when and where?
19
+ * Improvements:
20
+ * - Ask build system for complete build command for file X, instead of piecing together from build.ninja. Rewatch?
21
+ * - Have build system communicate what was actually rebuilt after compilation finishes.
16
22
*/
17
23
18
24
let debug = true ;
@@ -22,6 +28,8 @@ let savedIncrementalFiles: Set<string> = new Set();
22
28
let compileContentsCache : Map < string , { timeout : any ; triggerToken : number } > =
23
29
new Map ( ) ;
24
30
let compileContentsListeners : Map < string , Array < ( ) => void > > = new Map ( ) ;
31
+ const incrementalFolderName = "___incremental" ;
32
+ const incrementalFileFolderLocation = `lib/bs/${ incrementalFolderName } ` ;
25
33
26
34
export function cleanupIncrementalFilesAfterCompilation ( changedPath : string ) {
27
35
const projectRootPath = utils . findProjectRootOfFile ( changedPath ) ;
@@ -40,7 +48,7 @@ export function removeIncrementalFileFolder(
40
48
onAfterRemove ?: ( ) => void
41
49
) {
42
50
fs . rm (
43
- path . resolve ( projectRootPath , "lib/bs/___incremental" ) ,
51
+ path . resolve ( projectRootPath , incrementalFileFolderLocation ) ,
44
52
{ force : true , recursive : true } ,
45
53
( _ ) => {
46
54
onAfterRemove ?.( ) ;
@@ -50,7 +58,10 @@ export function removeIncrementalFileFolder(
50
58
51
59
export function recreateIncrementalFileFolder ( projectRootPath : string ) {
52
60
removeIncrementalFileFolder ( projectRootPath , ( ) => {
53
- fs . mkdir ( path . resolve ( projectRootPath , "lib/bs/___incremental" ) , ( _ ) => { } ) ;
61
+ fs . mkdir (
62
+ path . resolve ( projectRootPath , incrementalFileFolderLocation ) ,
63
+ ( _ ) => { }
64
+ ) ;
54
65
} ) ;
55
66
}
56
67
@@ -59,7 +70,11 @@ export function fileIsIncrementallyCompiled(filePath: string): boolean {
59
70
let fileName = path . basename ( filePath , ".res" ) ;
60
71
if ( projectRootPath != null ) {
61
72
return fs . existsSync (
62
- path . resolve ( projectRootPath , "lib/bs/___incremental" , fileName + ".cmt" )
73
+ path . resolve (
74
+ projectRootPath ,
75
+ incrementalFileFolderLocation ,
76
+ fileName + ".cmt"
77
+ )
63
78
) ;
64
79
}
65
80
return false ;
@@ -77,7 +92,7 @@ export function cleanUpIncrementalFiles(
77
92
path . basename ( filePath ) ,
78
93
] . forEach ( ( file ) => {
79
94
fs . unlink (
80
- path . resolve ( projectRootPath , "lib/bs/___incremental" , file ) ,
95
+ path . resolve ( projectRootPath , incrementalFileFolderLocation , file ) ,
81
96
( _ ) => { }
82
97
) ;
83
98
} ) ;
@@ -149,19 +164,24 @@ function argsFromCommandString(cmdString: string): Array<Array<string>> {
149
164
150
165
for ( let i = 0 ; i <= s . length - 1 ; i ++ ) {
151
166
let item = s [ i ] ;
152
- let nextItem = s [ i + 1 ] ?? "" ;
167
+ let nextIndex = i + 1 ;
168
+ let nextItem = s [ nextIndex ] ?? "" ;
153
169
if ( item . startsWith ( "-" ) && nextItem . startsWith ( "-" ) ) {
154
170
// Single entry arg
155
171
args . push ( [ item ] ) ;
156
- } else if ( item . startsWith ( "-" ) && s [ i + 1 ] ?. startsWith ( "'" ) ) {
157
- let nextIndex = i + 1 ;
172
+ } else if ( item . startsWith ( "-" ) && nextItem . startsWith ( "'" ) ) {
158
173
// Quoted arg, take until ending '
159
- let arg = [ s [ nextIndex ] ] ;
174
+ let arg = [ nextItem . slice ( 1 ) ] ;
160
175
for ( let x = nextIndex + 1 ; x <= s . length - 1 ; x ++ ) {
161
- let nextItem = s [ x ] ;
162
- arg . push ( nextItem ) ;
163
- if ( nextItem . endsWith ( "'" ) ) {
164
- i = x + 1 ;
176
+ let subItem = s [ x ] ;
177
+ let break_ = false ;
178
+ if ( subItem . endsWith ( "'" ) ) {
179
+ subItem = subItem . slice ( 0 , subItem . length - 1 ) ;
180
+ i = x ;
181
+ break_ = true ;
182
+ }
183
+ arg . push ( subItem ) ;
184
+ if ( break_ ) {
165
185
break ;
166
186
}
167
187
}
@@ -224,11 +244,15 @@ async function compileContents(
224
244
if ( debug ) console . log ( "Did not find bsc." ) ;
225
245
return ;
226
246
}
227
- let incrementalFilePath = path . resolve (
247
+ let incrementalFolderPath = path . resolve (
228
248
projectRootPath ,
229
- "lib/bs/___incremental" ,
230
- fileName
249
+ incrementalFileFolderLocation
231
250
) ;
251
+ let incrementalFilePath = path . resolve ( incrementalFolderPath , fileName ) ;
252
+
253
+ if ( ! fs . existsSync ( incrementalFolderPath ) ) {
254
+ fs . mkdirSync ( incrementalFolderPath ) ;
255
+ }
232
256
233
257
fs . writeFileSync ( incrementalFilePath , fileContent ) ;
234
258
@@ -240,7 +264,7 @@ async function compileContents(
240
264
241
265
let callArgs : Array < string > = [
242
266
"-I" ,
243
- path . resolve ( projectRootPath , "lib/bs/___incremental" ) ,
267
+ path . resolve ( projectRootPath , incrementalFileFolderLocation ) ,
244
268
] ;
245
269
246
270
buildArgs . forEach ( ( [ key , value ] : Array < string > ) => {
@@ -298,7 +322,7 @@ async function compileContents(
298
322
. filter (
299
323
( d ) =>
300
324
! d . message . startsWith ( "Uninterpreted extension 'rescript." ) &&
301
- ! d . message . includes ( `/___incremental /${ fileName } ` )
325
+ ! d . message . includes ( `/${ incrementalFolderName } /${ fileName } ` )
302
326
) ;
303
327
304
328
let notification : p . NotificationMessage = {
0 commit comments