@@ -8011,10 +8011,10 @@ new C();`
8011
8011
checkCompleteEvent ( session , 2 , expectedSequenceId ) ;
8012
8012
}
8013
8013
8014
- function verifyWatchedFilesAndDirectories ( host : TestServerHost , files : string [ ] , directories : string [ ] ) {
8014
+ function verifyWatchedFilesAndDirectories ( host : TestServerHost , files : string [ ] , recursiveDirectories : string [ ] , nonRecursiveDirectories : string [ ] ) {
8015
8015
checkWatchedFilesDetailed ( host , files . filter ( f => f !== recognizersDateTimeSrcFile . path ) , 1 ) ;
8016
- checkWatchedDirectories ( host , emptyArray , /*recursive*/ false ) ;
8017
- checkWatchedDirectoriesDetailed ( host , directories , 1 , /*recursive*/ true ) ;
8016
+ checkWatchedDirectoriesDetailed ( host , nonRecursiveDirectories , 1 , /*recursive*/ false ) ;
8017
+ checkWatchedDirectoriesDetailed ( host , recursiveDirectories , 1 , /*recursive*/ true ) ;
8018
8018
}
8019
8019
8020
8020
function createSessionAndOpenFile ( host : TestServerHost ) {
@@ -8035,22 +8035,23 @@ new C();`
8035
8035
const filesWithNodeModulesSetup = [ ...filesWithSources , nodeModulesRecorgnizersText ] ;
8036
8036
const filesAfterCompilation = [ ...filesWithNodeModulesSetup , recongnizerTextDistTypingFile ] ;
8037
8037
8038
- const watchedDirectoriesWithResolvedModule = [ `${ recognizersDateTime } /src` , withPathMapping ? packages : recognizersDateTime , ...getTypeRootsFromLocation ( recognizersDateTime ) ] ;
8038
+ const watchedDirectoriesWithResolvedModule = [ `${ recognizersDateTime } /src` , ... ( withPathMapping ? emptyArray : [ recognizersDateTime ] ) , ...getTypeRootsFromLocation ( recognizersDateTime ) ] ;
8039
8039
const watchedDirectoriesWithUnresolvedModule = [ recognizersDateTime , ...( withPathMapping ? [ recognizersText ] : emptyArray ) , ...watchedDirectoriesWithResolvedModule , ...getNodeModuleDirectories ( packages ) ] ;
8040
+ const nonRecursiveWatchedDirectories = withPathMapping ? [ packages ] : emptyArray ;
8040
8041
8041
8042
function verifyProjectWithResolvedModule ( session : TestSession ) {
8042
8043
const projectService = session . getProjectService ( ) ;
8043
8044
const project = projectService . configuredProjects . get ( recognizerDateTimeTsconfigPath ) ! ;
8044
8045
checkProjectActualFiles ( project , filesInProjectWithResolvedModule ) ;
8045
- verifyWatchedFilesAndDirectories ( session . host , filesInProjectWithResolvedModule , watchedDirectoriesWithResolvedModule ) ;
8046
+ verifyWatchedFilesAndDirectories ( session . host , filesInProjectWithResolvedModule , watchedDirectoriesWithResolvedModule , nonRecursiveWatchedDirectories ) ;
8046
8047
verifyErrors ( session , [ ] ) ;
8047
8048
}
8048
8049
8049
8050
function verifyProjectWithUnresolvedModule ( session : TestSession ) {
8050
8051
const projectService = session . getProjectService ( ) ;
8051
8052
const project = projectService . configuredProjects . get ( recognizerDateTimeTsconfigPath ) ! ;
8052
8053
checkProjectActualFiles ( project , filesInProjectWithUnresolvedModule ) ;
8053
- verifyWatchedFilesAndDirectories ( session . host , filesInProjectWithUnresolvedModule , watchedDirectoriesWithUnresolvedModule ) ;
8054
+ verifyWatchedFilesAndDirectories ( session . host , filesInProjectWithUnresolvedModule , watchedDirectoriesWithUnresolvedModule , nonRecursiveWatchedDirectories ) ;
8054
8055
const startOffset = recognizersDateTimeSrcFile . content . indexOf ( '"' ) + 1 ;
8055
8056
verifyErrors ( session , [
8056
8057
createDiagnostic ( { line : 1 , offset : startOffset } , { line : 1 , offset : startOffset + moduleNameInFile . length } , Diagnostics . Cannot_find_module_0 , [ moduleName ] )
@@ -8506,6 +8507,65 @@ new C();`
8506
8507
}
8507
8508
} ) ;
8508
8509
} ) ;
8510
+
8511
+ it ( "when watching directories for failed lookup locations in amd resolution" , ( ) => {
8512
+ const projectRoot = "/user/username/projects/project" ;
8513
+ const nodeFile : File = {
8514
+ path : `${ projectRoot } /src/typings/node.d.ts` ,
8515
+ content : `
8516
+ declare module "fs" {
8517
+ export interface something {
8518
+ }
8519
+ }`
8520
+ } ;
8521
+ const electronFile : File = {
8522
+ path : `${ projectRoot } /src/typings/electron.d.ts` ,
8523
+ content : `
8524
+ declare module 'original-fs' {
8525
+ import * as fs from 'fs';
8526
+ export = fs;
8527
+ }`
8528
+ } ;
8529
+ const srcFile : File = {
8530
+ path : `${ projectRoot } /src/somefolder/srcfile.ts` ,
8531
+ content : `
8532
+ import { x } from "somefolder/module1";
8533
+ import { x } from "somefolder/module2";
8534
+ const y = x;`
8535
+ } ;
8536
+ const moduleFile : File = {
8537
+ path : `${ projectRoot } /src/somefolder/module1.ts` ,
8538
+ content : `
8539
+ export const x = 10;`
8540
+ } ;
8541
+ const configFile : File = {
8542
+ path : `${ projectRoot } /src/tsconfig.json` ,
8543
+ content : JSON . stringify ( {
8544
+ compilerOptions : {
8545
+ module : "amd" ,
8546
+ moduleResolution : "classic" ,
8547
+ target : "es5" ,
8548
+ outDir : "../out" ,
8549
+ baseUrl : "./" ,
8550
+ typeRoots : [ "typings" ]
8551
+
8552
+ }
8553
+ } )
8554
+ } ;
8555
+ const files = [ nodeFile , electronFile , srcFile , moduleFile , configFile , libFile ] ;
8556
+ const host = createServerHost ( files ) ;
8557
+ const service = createProjectService ( host ) ;
8558
+ service . openClientFile ( srcFile . path , srcFile . content , ScriptKind . TS , projectRoot ) ;
8559
+ checkProjectActualFiles ( service . configuredProjects . get ( configFile . path ) ! , files . map ( f => f . path ) ) ;
8560
+ checkWatchedFilesDetailed ( host , mapDefined ( files , f => f === srcFile ? undefined : f . path ) , 1 ) ;
8561
+ checkWatchedDirectoriesDetailed ( host , [ `${ projectRoot } ` ] , 1 , /*recursive*/ false ) ; // failed lookup for fs
8562
+ const expectedWatchedDirectories = createMap < number > ( ) ;
8563
+ expectedWatchedDirectories . set ( `${ projectRoot } /src` , 2 ) ; // Wild card and failed lookup
8564
+ expectedWatchedDirectories . set ( `${ projectRoot } /somefolder` , 1 ) ; // failed lookup for somefolder/module2
8565
+ expectedWatchedDirectories . set ( `${ projectRoot } /node_modules` , 1 ) ; // failed lookup for with node_modules/@types /fs
8566
+ expectedWatchedDirectories . set ( `${ projectRoot } /src/typings` , 1 ) ; // typeroot directory
8567
+ checkWatchedDirectoriesDetailed ( host , expectedWatchedDirectories , /*recursive*/ true ) ;
8568
+ } ) ;
8509
8569
} ) ;
8510
8570
8511
8571
describe ( "tsserverProjectSystem watchDirectories implementation" , ( ) => {
0 commit comments