@@ -304,35 +304,35 @@ namespace ts.projectSystem {
304
304
// 1. react typings are installed for .jsx
305
305
// 2. loose files names are matched against safe list for typings if
306
306
// this is a JS project (only js, jsx, d.ts files are present)
307
- const file1 = {
307
+ const lodashJs = {
308
308
path : "/a/b/lodash.js" ,
309
309
content : ""
310
310
} ;
311
- const file2 = {
311
+ const file2Jsx = {
312
312
path : "/a/b/file2.jsx" ,
313
313
content : ""
314
314
} ;
315
- const file3 = {
315
+ const file3dts = {
316
316
path : "/a/b/file3.d.ts" ,
317
317
content : ""
318
318
} ;
319
- const react = {
319
+ const reactDts = {
320
320
path : "/a/data/node_modules/@types/react/index.d.ts" ,
321
321
content : "declare const react: { x: number }"
322
322
} ;
323
- const lodash = {
323
+ const lodashDts = {
324
324
path : "/a/data/node_modules/@types/lodash/index.d.ts" ,
325
325
content : "declare const lodash: { x: number }"
326
326
} ;
327
327
328
- const host = createServerHost ( [ file1 , file2 , file3 , customTypesMap ] ) ;
328
+ const host = createServerHost ( [ lodashJs , file2Jsx , file3dts , customTypesMap ] ) ;
329
329
const installer = new ( class extends Installer {
330
330
constructor ( ) {
331
331
super ( host , { typesRegistry : createTypesRegistry ( "lodash" , "react" ) } ) ;
332
332
}
333
333
installWorker ( _requestId : number , _args : string [ ] , _cwd : string , cb : TI . RequestCompletedAction ) : void {
334
334
const installedTypings = [ "@types/lodash" , "@types/react" ] ;
335
- const typingFiles = [ lodash , react ] ;
335
+ const typingFiles = [ lodashDts , reactDts ] ;
336
336
executeCommand ( this , host , installedTypings , typingFiles , cb ) ;
337
337
}
338
338
} ) ( ) ;
@@ -342,35 +342,74 @@ namespace ts.projectSystem {
342
342
projectService . openExternalProject ( {
343
343
projectFileName,
344
344
options : { allowJS : true , moduleResolution : ModuleResolutionKind . NodeJs } ,
345
- rootFiles : [ toExternalFile ( file1 . path ) , toExternalFile ( file2 . path ) , toExternalFile ( file3 . path ) ] ,
346
- typeAcquisition : { }
345
+ rootFiles : [ toExternalFile ( lodashJs . path ) , toExternalFile ( file2Jsx . path ) , toExternalFile ( file3dts . path ) ] ,
346
+ typeAcquisition : { }
347
347
} ) ;
348
348
349
349
const p = projectService . externalProjects [ 0 ] ;
350
350
projectService . checkNumberOfProjects ( { externalProjects : 1 } ) ;
351
- checkProjectActualFiles ( p , [ file1 . path , file2 . path , file3 . path ] ) ;
351
+ checkProjectActualFiles ( p , [ file2Jsx . path , file3dts . path ] ) ;
352
352
353
353
installer . installAll ( /*expectedCount*/ 1 ) ;
354
354
355
355
checkNumberOfProjects ( projectService , { externalProjects : 1 } ) ;
356
356
host . checkTimeoutQueueLengthAndRun ( 2 ) ;
357
357
checkNumberOfProjects ( projectService , { externalProjects : 1 } ) ;
358
- checkProjectActualFiles ( p , [ file1 . path , file2 . path , file3 . path , lodash . path , react . path ] ) ;
358
+ checkProjectActualFiles ( p , [ file2Jsx . path , file3dts . path , lodashDts . path , reactDts . path ] ) ;
359
359
} ) ;
360
360
361
+ it ( "external project - type acquisition with enable: false" , ( ) => {
362
+ // Tests:
363
+ // Exclude
364
+ const jqueryJs = {
365
+ path : "/a/b/jquery.js" ,
366
+ content : ""
367
+ } ;
368
+
369
+ const host = createServerHost ( [ jqueryJs ] ) ;
370
+ const installer = new ( class extends Installer {
371
+ constructor ( ) {
372
+ super ( host , { typesRegistry : createTypesRegistry ( "jquery" ) } ) ;
373
+ }
374
+ enqueueInstallTypingsRequest ( project : server . Project , typeAcquisition : TypeAcquisition , unresolvedImports : server . SortedReadonlyArray < string > ) {
375
+ super . enqueueInstallTypingsRequest ( project , typeAcquisition , unresolvedImports ) ;
376
+ }
377
+ installWorker ( _requestId : number , _args : string [ ] , _cwd : string , cb : TI . RequestCompletedAction ) : void {
378
+ const installedTypings : string [ ] = [ ] ;
379
+ const typingFiles : FileOrFolder [ ] = [ ] ;
380
+ executeCommand ( this , host , installedTypings , typingFiles , cb ) ;
381
+ }
382
+ } ) ( ) ;
383
+
384
+ const projectFileName = "/a/app/test.csproj" ;
385
+ const projectService = createProjectService ( host , { typingsInstaller : installer } ) ;
386
+ projectService . openExternalProject ( {
387
+ projectFileName,
388
+ options : { allowJS : true , moduleResolution : ModuleResolutionKind . NodeJs } ,
389
+ rootFiles : [ toExternalFile ( jqueryJs . path ) ] ,
390
+ typeAcquisition : { enable : false }
391
+ } ) ;
392
+
393
+ const p = projectService . externalProjects [ 0 ] ;
394
+ projectService . checkNumberOfProjects ( { externalProjects : 1 } ) ;
395
+
396
+ checkProjectActualFiles ( p , [ jqueryJs . path ] ) ;
397
+
398
+ installer . checkPendingCommands ( /*expectedCount*/ 0 ) ;
399
+ } ) ;
361
400
it ( "external project - no type acquisition, with js & ts files" , ( ) => {
362
401
// Tests:
363
402
// 1. No typings are included for JS projects when the project contains ts files
364
- const file1 = {
403
+ const jqueryJs = {
365
404
path : "/a/b/jquery.js" ,
366
405
content : ""
367
406
} ;
368
- const file2 = {
407
+ const file2Ts = {
369
408
path : "/a/b/file2.ts" ,
370
409
content : ""
371
410
} ;
372
411
373
- const host = createServerHost ( [ file1 , file2 ] ) ;
412
+ const host = createServerHost ( [ jqueryJs , file2Ts ] ) ;
374
413
const installer = new ( class extends Installer {
375
414
constructor ( ) {
376
415
super ( host , { typesRegistry : createTypesRegistry ( "jquery" ) } ) ;
@@ -390,34 +429,35 @@ namespace ts.projectSystem {
390
429
projectService . openExternalProject ( {
391
430
projectFileName,
392
431
options : { allowJS : true , moduleResolution : ModuleResolutionKind . NodeJs } ,
393
- rootFiles : [ toExternalFile ( file1 . path ) , toExternalFile ( file2 . path ) ] ,
432
+ rootFiles : [ toExternalFile ( jqueryJs . path ) , toExternalFile ( file2Ts . path ) ] ,
394
433
typeAcquisition : { }
395
434
} ) ;
396
435
397
436
const p = projectService . externalProjects [ 0 ] ;
398
437
projectService . checkNumberOfProjects ( { externalProjects : 1 } ) ;
399
- checkProjectActualFiles ( p , [ file2 . path ] ) ;
438
+
439
+ checkProjectActualFiles ( p , [ jqueryJs . path , file2Ts . path ] ) ;
400
440
401
441
installer . checkPendingCommands ( /*expectedCount*/ 0 ) ;
402
442
403
443
checkNumberOfProjects ( projectService , { externalProjects : 1 } ) ;
404
- checkProjectActualFiles ( p , [ file2 . path ] ) ;
444
+ checkProjectActualFiles ( p , [ jqueryJs . path , file2Ts . path ] ) ;
405
445
} ) ;
406
446
407
447
it ( "external project - with type acquisition, with only js, d.ts files" , ( ) => {
408
448
// Tests:
409
449
// 1. Safelist matching, type acquisition includes/excludes and package.json typings are all acquired
410
450
// 2. Types for safelist matches are not included when they also appear in the type acquisition exclude list
411
451
// 3. Multiple includes and excludes are respected in type acquisition
412
- const file1 = {
452
+ const lodashJs = {
413
453
path : "/a/b/lodash.js" ,
414
454
content : ""
415
455
} ;
416
- const file2 = {
456
+ const commanderJs = {
417
457
path : "/a/b/commander.js" ,
418
458
content : ""
419
459
} ;
420
- const file3 = {
460
+ const file3dts = {
421
461
path : "/a/b/file3.d.ts" ,
422
462
content : ""
423
463
} ;
@@ -448,7 +488,7 @@ namespace ts.projectSystem {
448
488
content : "declare const moment: { x: number }"
449
489
} ;
450
490
451
- const host = createServerHost ( [ file1 , file2 , file3 , packageJson , customTypesMap ] ) ;
491
+ const host = createServerHost ( [ lodashJs , commanderJs , file3dts , packageJson , customTypesMap ] ) ;
452
492
const installer = new ( class extends Installer {
453
493
constructor ( ) {
454
494
super ( host , { typesRegistry : createTypesRegistry ( "jquery" , "commander" , "moment" , "express" ) } ) ;
@@ -465,20 +505,25 @@ namespace ts.projectSystem {
465
505
projectService . openExternalProject ( {
466
506
projectFileName,
467
507
options : { allowJS : true , moduleResolution : ModuleResolutionKind . NodeJs } ,
468
- rootFiles : [ toExternalFile ( file1 . path ) , toExternalFile ( file2 . path ) , toExternalFile ( file3 . path ) ] ,
469
- typeAcquisition : { include : [ "jquery" , "moment" ] , exclude : [ "lodash" ] }
508
+ rootFiles : [ toExternalFile ( lodashJs . path ) , toExternalFile ( commanderJs . path ) , toExternalFile ( file3dts . path ) ] ,
509
+ typeAcquisition : { enable : true , include : [ "jquery" , "moment" ] , exclude : [ "lodash" ] }
470
510
} ) ;
471
511
472
512
const p = projectService . externalProjects [ 0 ] ;
473
513
projectService . checkNumberOfProjects ( { externalProjects : 1 } ) ;
474
- checkProjectActualFiles ( p , [ file1 . path , file2 . path , file3 . path ] ) ;
514
+ checkProjectActualFiles ( p , [ file3dts . path ] ) ;
475
515
476
516
installer . installAll ( /*expectedCount*/ 1 ) ;
477
517
478
518
checkNumberOfProjects ( projectService , { externalProjects : 1 } ) ;
479
519
host . checkTimeoutQueueLengthAndRun ( 2 ) ;
480
520
checkNumberOfProjects ( projectService , { externalProjects : 1 } ) ;
481
- checkProjectActualFiles ( p , [ file1 . path , file2 . path , file3 . path , commander . path , express . path , jquery . path , moment . path ] ) ;
521
+ // Commander: Existed as a JS file
522
+ // JQuery: Specified in 'include'
523
+ // Moment: Specified in 'include'
524
+ // Express: Specified in package.json
525
+ // lodash: Excluded (not present)
526
+ checkProjectActualFiles ( p , [ file3dts . path , commander . path , express . path , jquery . path , moment . path ] ) ;
482
527
} ) ;
483
528
484
529
it ( "Throttle - delayed typings to install" , ( ) => {
@@ -548,7 +593,7 @@ namespace ts.projectSystem {
548
593
549
594
const p = projectService . externalProjects [ 0 ] ;
550
595
projectService . checkNumberOfProjects ( { externalProjects : 1 } ) ;
551
- checkProjectActualFiles ( p , [ lodashJs . path , commanderJs . path , file3 . path ] ) ;
596
+ checkProjectActualFiles ( p , [ file3 . path ] ) ;
552
597
installer . checkPendingCommands ( /*expectedCount*/ 1 ) ;
553
598
installer . executePendingCommands ( ) ;
554
599
// expected all typings file to exist
@@ -557,7 +602,7 @@ namespace ts.projectSystem {
557
602
}
558
603
host . checkTimeoutQueueLengthAndRun ( 2 ) ;
559
604
checkNumberOfProjects ( projectService , { externalProjects : 1 } ) ;
560
- checkProjectActualFiles ( p , [ lodashJs . path , commanderJs . path , file3 . path , commander . path , express . path , jquery . path , moment . path , lodash . path ] ) ;
605
+ checkProjectActualFiles ( p , [ file3 . path , commander . path , express . path , jquery . path , moment . path , lodash . path ] ) ;
561
606
} ) ;
562
607
563
608
it ( "Throttle - delayed run install requests" , ( ) => {
@@ -648,7 +693,7 @@ namespace ts.projectSystem {
648
693
const p1 = projectService . externalProjects [ 0 ] ;
649
694
const p2 = projectService . externalProjects [ 1 ] ;
650
695
projectService . checkNumberOfProjects ( { externalProjects : 2 } ) ;
651
- checkProjectActualFiles ( p1 , [ lodashJs . path , commanderJs . path , file3 . path ] ) ;
696
+ checkProjectActualFiles ( p1 , [ file3 . path ] ) ;
652
697
checkProjectActualFiles ( p2 , [ file3 . path ] ) ;
653
698
654
699
installer . executePendingCommands ( ) ;
@@ -659,7 +704,7 @@ namespace ts.projectSystem {
659
704
660
705
installer . executePendingCommands ( ) ;
661
706
host . checkTimeoutQueueLengthAndRun ( 3 ) ; // for 2 projects and 1 refreshing inferred project
662
- checkProjectActualFiles ( p1 , [ lodashJs . path , commanderJs . path , file3 . path , commander . path , jquery . path , lodash . path , cordova . path ] ) ;
707
+ checkProjectActualFiles ( p1 , [ file3 . path , commander . path , jquery . path , lodash . path , cordova . path ] ) ;
663
708
checkProjectActualFiles ( p2 , [ file3 . path , grunt . path , gulp . path ] ) ;
664
709
} ) ;
665
710
@@ -973,7 +1018,7 @@ namespace ts.projectSystem {
973
1018
}
974
1019
} ;
975
1020
session . executeCommand ( changeRequest ) ;
976
- host . checkTimeoutQueueLengthAndRun ( 2 ) ; // This enqueues the updategraph and refresh inferred projects
1021
+ host . checkTimeoutQueueLengthAndRun ( 0 ) ; // This enqueues the updategraph and refresh inferred projects
977
1022
const version2 = proj . getCachedUnresolvedImportsPerFile_TestOnly ( ) . getVersion ( ) ;
978
1023
assert . equal ( version1 , version2 , "set of unresolved imports should not change" ) ;
979
1024
} ) ;
@@ -1057,11 +1102,12 @@ namespace ts.projectSystem {
1057
1102
const host = createServerHost ( [ app , jquery , chroma ] ) ;
1058
1103
const logger = trackingLogger ( ) ;
1059
1104
const result = JsTyping . discoverTypings ( host , logger . log , [ app . path , jquery . path , chroma . path ] , getDirectoryPath ( < Path > app . path ) , safeList , emptyMap , { enable : true } , emptyArray ) ;
1060
- assert . deepEqual ( logger . finish ( ) , [
1105
+ const finish = logger . finish ( ) ;
1106
+ assert . deepEqual ( finish , [
1061
1107
'Inferred typings from file names: ["jquery","chroma-js"]' ,
1062
1108
"Inferred typings from unresolved imports: []" ,
1063
1109
'Result: {"cachedTypingPaths":[],"newTypingNames":["jquery","chroma-js"],"filesToWatch":["/a/b/bower_components","/a/b/node_modules"]}' ,
1064
- ] ) ;
1110
+ ] , finish . join ( "\r\n" ) ) ;
1065
1111
assert . deepEqual ( result . newTypingNames , [ "jquery" , "chroma-js" ] ) ;
1066
1112
} ) ;
1067
1113
0 commit comments