@@ -10,9 +10,12 @@ namespace ts.tscWatch {
1010 import checkArray = TestFSWithWatch . checkArray ;
1111 import libFile = TestFSWithWatch . libFile ;
1212 import checkWatchedFiles = TestFSWithWatch . checkWatchedFiles ;
13+ import checkWatchedFilesDetailed = TestFSWithWatch . checkWatchedFilesDetailed ;
1314 import checkWatchedDirectories = TestFSWithWatch . checkWatchedDirectories ;
15+ import checkWatchedDirectoriesDetailed = TestFSWithWatch . checkWatchedDirectoriesDetailed ;
1416 import checkOutputContains = TestFSWithWatch . checkOutputContains ;
1517 import checkOutputDoesNotContain = TestFSWithWatch . checkOutputDoesNotContain ;
18+ import Tsc_WatchDirectory = TestFSWithWatch . Tsc_WatchDirectory ;
1619
1720 export function checkProgramActualFiles ( program : Program , expectedFiles : string [ ] ) {
1821 checkArray ( `Program actual files` , program . getSourceFiles ( ) . map ( file => file . fileName ) , expectedFiles ) ;
@@ -2379,7 +2382,7 @@ declare module "fs" {
23792382 } ) ;
23802383
23812384 describe ( "tsc-watch when watchDirectories implementation" , ( ) => {
2382- function verifyRenamingFileInSubFolder ( tscWatchDirectory : TestFSWithWatch . Tsc_WatchDirectory ) {
2385+ function verifyRenamingFileInSubFolder ( tscWatchDirectory : Tsc_WatchDirectory ) {
23832386 const projectFolder = "/a/username/project" ;
23842387 const projectSrcFolder = `${ projectFolder } /src` ;
23852388 const configFile : File = {
@@ -2399,8 +2402,8 @@ declare module "fs" {
23992402 const projectFolders = [ projectFolder , projectSrcFolder , `${ projectFolder } /node_modules/@types` ] ;
24002403 // Watching files config file, file, lib file
24012404 const expectedWatchedFiles = files . map ( f => f . path ) ;
2402- const expectedWatchedDirectories = tscWatchDirectory === TestFSWithWatch . Tsc_WatchDirectory . NonRecursiveWatchDirectory ? projectFolders : emptyArray ;
2403- if ( tscWatchDirectory === TestFSWithWatch . Tsc_WatchDirectory . WatchFile ) {
2405+ const expectedWatchedDirectories = tscWatchDirectory === Tsc_WatchDirectory . NonRecursiveWatchDirectory ? projectFolders : emptyArray ;
2406+ if ( tscWatchDirectory === Tsc_WatchDirectory . WatchFile ) {
24042407 expectedWatchedFiles . push ( ...projectFolders ) ;
24052408 }
24062409
@@ -2410,7 +2413,7 @@ declare module "fs" {
24102413 file . path = file . path . replace ( "file1.ts" , "file2.ts" ) ;
24112414 expectedWatchedFiles [ 0 ] = file . path ;
24122415 host . reloadFS ( files ) ;
2413- if ( tscWatchDirectory === TestFSWithWatch . Tsc_WatchDirectory . DynamicPolling ) {
2416+ if ( tscWatchDirectory === Tsc_WatchDirectory . DynamicPolling ) {
24142417 // With dynamic polling the fs change would be detected only by running timeouts
24152418 host . runQueuedTimeoutCallbacks ( ) ;
24162419 }
@@ -2429,21 +2432,21 @@ declare module "fs" {
24292432 checkWatchedDirectories ( host , emptyArray , /*recursive*/ true ) ;
24302433
24312434 // Watching config file, file, lib file and directories
2432- TestFSWithWatch . checkMultiMapEachKeyWithCount ( "watchedFiles" , host . watchedFiles , expectedWatchedFiles , 1 ) ;
2433- TestFSWithWatch . checkMultiMapEachKeyWithCount ( "watchedDirectories" , host . watchedDirectories , expectedWatchedDirectories , 1 ) ;
2435+ checkWatchedFilesDetailed ( host , expectedWatchedFiles , 1 ) ;
2436+ checkWatchedDirectoriesDetailed ( host , expectedWatchedDirectories , 1 , /*recursive*/ false ) ;
24342437 }
24352438 }
24362439
24372440 it ( "uses watchFile when renaming file in subfolder" , ( ) => {
2438- verifyRenamingFileInSubFolder ( TestFSWithWatch . Tsc_WatchDirectory . WatchFile ) ;
2441+ verifyRenamingFileInSubFolder ( Tsc_WatchDirectory . WatchFile ) ;
24392442 } ) ;
24402443
24412444 it ( "uses non recursive watchDirectory when renaming file in subfolder" , ( ) => {
2442- verifyRenamingFileInSubFolder ( TestFSWithWatch . Tsc_WatchDirectory . NonRecursiveWatchDirectory ) ;
2445+ verifyRenamingFileInSubFolder ( Tsc_WatchDirectory . NonRecursiveWatchDirectory ) ;
24432446 } ) ;
24442447
24452448 it ( "uses non recursive dynamic polling when renaming file in subfolder" , ( ) => {
2446- verifyRenamingFileInSubFolder ( TestFSWithWatch . Tsc_WatchDirectory . DynamicPolling ) ;
2449+ verifyRenamingFileInSubFolder ( Tsc_WatchDirectory . DynamicPolling ) ;
24472450 } ) ;
24482451
24492452 it ( "when there are symlinks to folders in recursive folders" , ( ) => {
@@ -2482,7 +2485,7 @@ declare module "fs" {
24822485 } ;
24832486 const files = [ file1 , tsconfig , realA , realB , symLinkA , symLinkB , symLinkBInA , symLinkAInB ] ;
24842487 const environmentVariables = createMap < string > ( ) ;
2485- environmentVariables . set ( "TSC_WATCHDIRECTORY" , TestFSWithWatch . Tsc_WatchDirectory . NonRecursiveWatchDirectory ) ;
2488+ environmentVariables . set ( "TSC_WATCHDIRECTORY" , Tsc_WatchDirectory . NonRecursiveWatchDirectory ) ;
24862489 const host = createWatchedSystem ( files , { environmentVariables, currentDirectory : cwd } ) ;
24872490 createWatchOfConfigFile ( "tsconfig.json" , host ) ;
24882491 checkWatchedDirectories ( host , emptyArray , /*recursive*/ true ) ;
@@ -2491,4 +2494,46 @@ declare module "fs" {
24912494 } ) ;
24922495 } ) ;
24932496 } ) ;
2497+
2498+ describe ( "tsc-watch with modules linked to sibling folder" , ( ) => {
2499+ const projectRoot = "/user/username/projects/project" ;
2500+ const mainPackageRoot = `${ projectRoot } /main` ;
2501+ const linkedPackageRoot = `${ projectRoot } /linked-package` ;
2502+ const mainFile : File = {
2503+ path : `${ mainPackageRoot } /index.ts` ,
2504+ content : "import { Foo } from '@scoped/linked-package'"
2505+ } ;
2506+ const config : File = {
2507+ path : `${ mainPackageRoot } /tsconfig.json` ,
2508+ content : JSON . stringify ( {
2509+ compilerOptions : { module : "commonjs" , moduleResolution : "node" , baseUrl : "." , rootDir : "." } ,
2510+ files : [ "index.ts" ]
2511+ } )
2512+ } ;
2513+ const linkedPackageInMain : SymLink = {
2514+ path : `${ mainPackageRoot } /node_modules/@scoped/linked-package` ,
2515+ symLink : `${ linkedPackageRoot } `
2516+ } ;
2517+ const linkedPackageJson : File = {
2518+ path : `${ linkedPackageRoot } /package.json` ,
2519+ content : JSON . stringify ( { name : "@scoped/linked-package" , version : "0.0.1" , types : "dist/index.d.ts" , main : "dist/index.js" } )
2520+ } ;
2521+ const linkedPackageIndex : File = {
2522+ path : `${ linkedPackageRoot } /dist/index.d.ts` ,
2523+ content : "export * from './other';"
2524+ } ;
2525+ const linkedPackageOther : File = {
2526+ path : `${ linkedPackageRoot } /dist/other.d.ts` ,
2527+ content : 'export declare const Foo = "BAR";'
2528+ } ;
2529+
2530+ it ( "verify watched directories" , ( ) => {
2531+ const files = [ libFile , mainFile , config , linkedPackageInMain , linkedPackageJson , linkedPackageIndex , linkedPackageOther ] ;
2532+ const host = createWatchedSystem ( files , { currentDirectory : mainPackageRoot } ) ;
2533+ createWatchOfConfigFile ( "tsconfig.json" , host ) ;
2534+ checkWatchedFilesDetailed ( host , [ libFile . path , mainFile . path , config . path , linkedPackageIndex . path , linkedPackageOther . path ] , 1 ) ;
2535+ checkWatchedDirectories ( host , emptyArray , /*recursive*/ false ) ;
2536+ checkWatchedDirectoriesDetailed ( host , [ mainPackageRoot , linkedPackageRoot , `${ mainPackageRoot } /node_modules/@types` , `${ projectRoot } /node_modules/@types` ] , 1 , /*recursive*/ true ) ;
2537+ } ) ;
2538+ } ) ;
24942539}
0 commit comments