@@ -10,9 +10,12 @@ namespace ts.tscWatch {
10
10
import checkArray = TestFSWithWatch . checkArray ;
11
11
import libFile = TestFSWithWatch . libFile ;
12
12
import checkWatchedFiles = TestFSWithWatch . checkWatchedFiles ;
13
+ import checkWatchedFilesDetailed = TestFSWithWatch . checkWatchedFilesDetailed ;
13
14
import checkWatchedDirectories = TestFSWithWatch . checkWatchedDirectories ;
15
+ import checkWatchedDirectoriesDetailed = TestFSWithWatch . checkWatchedDirectoriesDetailed ;
14
16
import checkOutputContains = TestFSWithWatch . checkOutputContains ;
15
17
import checkOutputDoesNotContain = TestFSWithWatch . checkOutputDoesNotContain ;
18
+ import Tsc_WatchDirectory = TestFSWithWatch . Tsc_WatchDirectory ;
16
19
17
20
export function checkProgramActualFiles ( program : Program , expectedFiles : string [ ] ) {
18
21
checkArray ( `Program actual files` , program . getSourceFiles ( ) . map ( file => file . fileName ) , expectedFiles ) ;
@@ -2379,7 +2382,7 @@ declare module "fs" {
2379
2382
} ) ;
2380
2383
2381
2384
describe ( "tsc-watch when watchDirectories implementation" , ( ) => {
2382
- function verifyRenamingFileInSubFolder ( tscWatchDirectory : TestFSWithWatch . Tsc_WatchDirectory ) {
2385
+ function verifyRenamingFileInSubFolder ( tscWatchDirectory : Tsc_WatchDirectory ) {
2383
2386
const projectFolder = "/a/username/project" ;
2384
2387
const projectSrcFolder = `${ projectFolder } /src` ;
2385
2388
const configFile : File = {
@@ -2399,8 +2402,8 @@ declare module "fs" {
2399
2402
const projectFolders = [ projectFolder , projectSrcFolder , `${ projectFolder } /node_modules/@types` ] ;
2400
2403
// Watching files config file, file, lib file
2401
2404
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 ) {
2404
2407
expectedWatchedFiles . push ( ...projectFolders ) ;
2405
2408
}
2406
2409
@@ -2410,7 +2413,7 @@ declare module "fs" {
2410
2413
file . path = file . path . replace ( "file1.ts" , "file2.ts" ) ;
2411
2414
expectedWatchedFiles [ 0 ] = file . path ;
2412
2415
host . reloadFS ( files ) ;
2413
- if ( tscWatchDirectory === TestFSWithWatch . Tsc_WatchDirectory . DynamicPolling ) {
2416
+ if ( tscWatchDirectory === Tsc_WatchDirectory . DynamicPolling ) {
2414
2417
// With dynamic polling the fs change would be detected only by running timeouts
2415
2418
host . runQueuedTimeoutCallbacks ( ) ;
2416
2419
}
@@ -2429,21 +2432,21 @@ declare module "fs" {
2429
2432
checkWatchedDirectories ( host , emptyArray , /*recursive*/ true ) ;
2430
2433
2431
2434
// 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 ) ;
2434
2437
}
2435
2438
}
2436
2439
2437
2440
it ( "uses watchFile when renaming file in subfolder" , ( ) => {
2438
- verifyRenamingFileInSubFolder ( TestFSWithWatch . Tsc_WatchDirectory . WatchFile ) ;
2441
+ verifyRenamingFileInSubFolder ( Tsc_WatchDirectory . WatchFile ) ;
2439
2442
} ) ;
2440
2443
2441
2444
it ( "uses non recursive watchDirectory when renaming file in subfolder" , ( ) => {
2442
- verifyRenamingFileInSubFolder ( TestFSWithWatch . Tsc_WatchDirectory . NonRecursiveWatchDirectory ) ;
2445
+ verifyRenamingFileInSubFolder ( Tsc_WatchDirectory . NonRecursiveWatchDirectory ) ;
2443
2446
} ) ;
2444
2447
2445
2448
it ( "uses non recursive dynamic polling when renaming file in subfolder" , ( ) => {
2446
- verifyRenamingFileInSubFolder ( TestFSWithWatch . Tsc_WatchDirectory . DynamicPolling ) ;
2449
+ verifyRenamingFileInSubFolder ( Tsc_WatchDirectory . DynamicPolling ) ;
2447
2450
} ) ;
2448
2451
2449
2452
it ( "when there are symlinks to folders in recursive folders" , ( ) => {
@@ -2482,7 +2485,7 @@ declare module "fs" {
2482
2485
} ;
2483
2486
const files = [ file1 , tsconfig , realA , realB , symLinkA , symLinkB , symLinkBInA , symLinkAInB ] ;
2484
2487
const environmentVariables = createMap < string > ( ) ;
2485
- environmentVariables . set ( "TSC_WATCHDIRECTORY" , TestFSWithWatch . Tsc_WatchDirectory . NonRecursiveWatchDirectory ) ;
2488
+ environmentVariables . set ( "TSC_WATCHDIRECTORY" , Tsc_WatchDirectory . NonRecursiveWatchDirectory ) ;
2486
2489
const host = createWatchedSystem ( files , { environmentVariables, currentDirectory : cwd } ) ;
2487
2490
createWatchOfConfigFile ( "tsconfig.json" , host ) ;
2488
2491
checkWatchedDirectories ( host , emptyArray , /*recursive*/ true ) ;
@@ -2491,4 +2494,46 @@ declare module "fs" {
2491
2494
} ) ;
2492
2495
} ) ;
2493
2496
} ) ;
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
+ } ) ;
2494
2539
}
0 commit comments