@@ -2532,4 +2532,43 @@ declare module "fs" {
25322532 checkWatchedDirectoriesDetailed ( host , [ mainPackageRoot , linkedPackageRoot , `${ mainPackageRoot } /node_modules/@types` , `${ projectRoot } /node_modules/@types` ] , 1 , /*recursive*/ true ) ;
25332533 } ) ;
25342534 } ) ;
2535+
2536+ describe ( "tsc-watch with custom module resolution" , ( ) => {
2537+ const projectRoot = "/user/username/projects/project" ;
2538+ const configFileJson : any = {
2539+ compilerOptions : { module : "commonjs" , resolveJsonModule : true } ,
2540+ files : [ "index.ts" ]
2541+ } ;
2542+ const mainFile : File = {
2543+ path : `${ projectRoot } /index.ts` ,
2544+ content : "import settings from './settings.json';"
2545+ } ;
2546+ const config : File = {
2547+ path : `${ projectRoot } /tsconfig.json` ,
2548+ content : JSON . stringify ( configFileJson )
2549+ } ;
2550+ const settingsJson : File = {
2551+ path : `${ projectRoot } /settings.json` ,
2552+ content : JSON . stringify ( { content : "Print this" } )
2553+ } ;
2554+
2555+ it ( "verify that module resolution with json extension works when returned without extension" , ( ) => {
2556+ const files = [ libFile , mainFile , config , settingsJson ] ;
2557+ const host = createWatchedSystem ( files , { currentDirectory : projectRoot } ) ;
2558+ const compilerHost = createWatchCompilerHostOfConfigFile ( config . path , { } , host ) ;
2559+ const parsedCommandResult = parseJsonConfigFileContent ( configFileJson , host , config . path ) ;
2560+ compilerHost . resolveModuleNames = ( moduleNames , containingFile ) => moduleNames . map ( m => {
2561+ const result = resolveModuleName ( m , containingFile , parsedCommandResult . options , compilerHost ) ;
2562+ const resolvedModule = result . resolvedModule ! ;
2563+ return {
2564+ resolvedFileName : resolvedModule . resolvedFileName ,
2565+ isExternalLibraryImport : resolvedModule . isExternalLibraryImport ,
2566+ originalFileName : resolvedModule . originalPath ,
2567+ } ;
2568+ } ) ;
2569+ const watch = createWatchProgram ( compilerHost ) ;
2570+ const program = watch . getCurrentProgram ( ) . getProgram ( ) ;
2571+ checkProgramActualFiles ( program , [ mainFile . path , libFile . path , settingsJson . path ] ) ;
2572+ } ) ;
2573+ } ) ;
25352574}
0 commit comments