2
2
// See LICENSE in the project root for license information.
3
3
4
4
import * as path from 'path' ;
5
- import glob from 'glob' ;
6
- import { LegacyAdapters , ITerminalProvider , Terminal } from '@rushstack/node-core-library' ;
5
+ import { ITerminalProvider , Terminal , FileSystem } from '@rushstack/node-core-library' ;
7
6
8
7
import { TypeScriptBuilder , ITypeScriptBuilderConfiguration } from './TypeScriptBuilder' ;
9
8
import { HeftSession } from '../../pluginFramework/HeftSession' ;
@@ -30,7 +29,6 @@ interface IRunTypeScriptOptions {
30
29
31
30
/**
32
31
* Fired whenever the compiler emits an output. In watch mode, this event occurs after each recompile.
33
- * If there are multiple tsconfigs being processed in parallel, the event fires for each one.
34
32
*/
35
33
emitCallback : ( ) => void ;
36
34
@@ -224,18 +222,11 @@ export class TypeScriptPlugin implements IHeftPlugin {
224
222
225
223
const typescriptConfigurationJson : ITypeScriptConfigurationJson | undefined =
226
224
await this . _ensureConfigFileLoadedAsync ( logger . terminal , heftConfiguration ) ;
227
- const tsconfigPaths : string [ ] = await LegacyAdapters . convertCallbackToPromise (
228
- glob ,
229
- 'tsconfig?(-*).json' ,
230
- {
231
- cwd : heftConfiguration . buildFolder ,
232
- nocase : true
233
- }
234
- ) ;
235
225
236
- buildProperties . isTypeScriptProject = tsconfigPaths . length > 0 ;
226
+ const tsconfigPath : string = `${ heftConfiguration . buildFolder } /tsconfig.json` ;
227
+ buildProperties . isTypeScriptProject = await FileSystem . existsAsync ( tsconfigPath ) ;
237
228
if ( ! buildProperties . isTypeScriptProject ) {
238
- // If there are no TSConfigs , we have nothing to do
229
+ // If there are no TSConfig , we have nothing to do
239
230
return ;
240
231
}
241
232
@@ -275,15 +266,13 @@ export class TypeScriptPlugin implements IHeftPlugin {
275
266
throw new Error ( 'Unable to resolve a TypeScript compiler package' ) ;
276
267
}
277
268
278
- const builderOptions : Omit <
279
- IRunBuilderForTsconfigOptions ,
280
- | 'terminalProvider'
281
- | 'tsconfigFilePath'
282
- | 'additionalModuleKindsToEmit'
283
- | 'terminalPrefixLabel'
284
- | 'emitCallback'
285
- | 'firstEmitCallback'
286
- > = {
269
+ // Set some properties used by the Jest plugin
270
+ buildProperties . emitFolderNameForTests = typeScriptConfiguration . emitFolderNameForTests || 'lib' ;
271
+ buildProperties . emitExtensionForTests = typeScriptConfiguration . emitCjsExtensionForCommonJS
272
+ ? '.cjs'
273
+ : '.js' ;
274
+
275
+ await this . _runBuilderForTsconfigAsync ( logger , {
287
276
heftSession : heftSession ,
288
277
heftConfiguration,
289
278
toolPackageResolution,
@@ -292,71 +281,14 @@ export class TypeScriptPlugin implements IHeftPlugin {
292
281
lintingEnabled : ! ! typeScriptConfiguration . isLintingEnabled ,
293
282
copyFromCacheMode : typeScriptConfiguration . copyFromCacheMode ,
294
283
watchMode : watchMode ,
295
- maxWriteParallelism : typeScriptConfiguration . maxWriteParallelism
296
- } ;
297
-
298
- // Set some properties used by the Jest plugin
299
- buildProperties . emitFolderNameForTests = typeScriptConfiguration . emitFolderNameForTests || 'lib' ;
300
- buildProperties . emitExtensionForTests = typeScriptConfiguration . emitCjsExtensionForCommonJS
301
- ? '.cjs'
302
- : '.js' ;
303
-
304
- // Wrap the "firstEmitCallback" to fire only after all of the builder processes have completed.
305
- const callbacksForTsconfigs : Set < ( ) => void > = new Set < ( ) => void > ( ) ;
306
- function getFirstEmitCallbackForTsconfig ( ) : ( ) => void {
307
- let hasAlreadyReportedFirstEmit : boolean = false ;
308
-
309
- const callback : ( ) => void = ( ) => {
310
- if ( hasAlreadyReportedFirstEmit ) {
311
- return ;
312
- }
313
- hasAlreadyReportedFirstEmit = true ;
314
-
315
- callbacksForTsconfigs . delete ( callback ) ;
316
- if ( callbacksForTsconfigs . size === 0 ) {
317
- firstEmitCallback ( ) ;
318
- }
319
- } ;
320
-
321
- callbacksForTsconfigs . add ( callback ) ;
322
-
323
- return callback ;
324
- }
325
-
326
- if ( tsconfigPaths . length === 1 ) {
327
- await this . _runBuilderForTsconfigAsync ( logger , {
328
- ...builderOptions ,
329
- tsconfigFilePath : tsconfigPaths [ 0 ] ,
330
- terminalProvider : heftConfiguration . terminalProvider ,
331
- additionalModuleKindsToEmit : typeScriptConfiguration . additionalModuleKindsToEmit ,
332
- terminalPrefixLabel : undefined ,
333
- emitCallback : emitCallback ,
334
- firstEmitCallback : getFirstEmitCallbackForTsconfig ( )
335
- } ) ;
336
- } else {
337
- const builderProcesses : Promise < void > [ ] = [ ] ;
338
- for ( const tsconfigFilePath of tsconfigPaths ) {
339
- const tsconfigFilename : string = path . basename ( tsconfigFilePath , path . extname ( tsconfigFilePath ) ) ;
340
-
341
- // Only provide additionalModuleKindsToEmit to the default tsconfig.json
342
- const additionalModuleKindsToEmit : IEmitModuleKind [ ] | undefined =
343
- tsconfigFilename === 'tsconfig' ? typeScriptConfiguration . additionalModuleKindsToEmit : undefined ;
344
-
345
- builderProcesses . push (
346
- this . _runBuilderForTsconfigAsync ( logger , {
347
- ...builderOptions ,
348
- tsconfigFilePath,
349
- terminalProvider : heftConfiguration . terminalProvider ,
350
- additionalModuleKindsToEmit,
351
- terminalPrefixLabel : tsconfigFilename ,
352
- emitCallback : emitCallback ,
353
- firstEmitCallback : getFirstEmitCallbackForTsconfig ( )
354
- } )
355
- ) ;
356
- }
357
-
358
- await Promise . all ( builderProcesses ) ;
359
- }
284
+ maxWriteParallelism : typeScriptConfiguration . maxWriteParallelism ,
285
+ tsconfigFilePath : tsconfigPath ,
286
+ terminalProvider : heftConfiguration . terminalProvider ,
287
+ additionalModuleKindsToEmit : typeScriptConfiguration . additionalModuleKindsToEmit ,
288
+ terminalPrefixLabel : undefined ,
289
+ emitCallback : emitCallback ,
290
+ firstEmitCallback : firstEmitCallback
291
+ } ) ;
360
292
}
361
293
362
294
private async _runBuilderForTsconfigAsync (
@@ -383,12 +315,17 @@ export class TypeScriptPlugin implements IHeftPlugin {
383
315
loggerPrefixLabel : options . terminalPrefixLabel ,
384
316
maxWriteParallelism : options . maxWriteParallelism
385
317
} ;
318
+ let firstEmitAlreadyCalled : boolean = false ;
386
319
const typeScriptBuilder : TypeScriptBuilder = new TypeScriptBuilder (
387
320
options . terminalProvider ,
388
321
typeScriptBuilderConfiguration ,
389
322
heftSession ,
390
323
( ) => {
391
- options . firstEmitCallback ( ) ;
324
+ if ( firstEmitAlreadyCalled ) {
325
+ firstEmitAlreadyCalled = true ;
326
+ options . firstEmitCallback ( ) ;
327
+ }
328
+
392
329
options . emitCallback ( ) ;
393
330
}
394
331
) ;
0 commit comments