File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -378,4 +378,24 @@ describe('readConfigFile', () => {
378378 ] ) ;
379379 } ) ;
380380 } ) ;
381+ describe ( 'configDir template variable' , ( ) => {
382+ test ( 'correctly resolves configDir' , async ( ) => {
383+ const iff = await createIFF ( {
384+ 'apps/app/tsconfig.json' : dedent `
385+ {
386+ "extends": ["../../tsconfig.a.json"]
387+ }
388+ ` ,
389+ 'tsconfig.a.json' : dedent `
390+ {
391+ "include": ["./types", "\${configDir}/src"],
392+ "exclude": ["./dist", "\${configDir}/dist"]
393+ }
394+ ` ,
395+ } ) ;
396+ const result = readConfigFile ( iff . join ( 'apps/app' ) ) ;
397+ expect ( result . includes ) . toEqual ( [ iff . join ( 'types' ) , iff . join ( 'apps/app/src' ) ] ) ;
398+ expect ( result . excludes ) . toEqual ( [ iff . join ( 'dist' ) , iff . join ( 'apps/app/dist' ) ] ) ;
399+ } ) ;
400+ } ) ;
381401} ) ;
Original file line number Diff line number Diff line change @@ -256,11 +256,17 @@ export function readConfigFile(project: string): CMKConfig {
256256 }
257257
258258 const basePath = dirname ( configFileName ) ;
259+
260+ // https://github.com/microsoft/TypeScript/blob/55423abe4d029017f19b6e4c32097591994836b4/src/compiler/commandLineParser.ts#L3299-L3328
261+ function resolvePath ( path : string ) {
262+ return join ( basePath , path . replace ( / ^ \$ \{ c o n f i g D i r } / i, './' ) ) ;
263+ }
264+
259265 return {
260266 // If `include` is not specified, fallback to the default include spec。
261267 // ref: https://github.com/microsoft/TypeScript/blob/caf1aee269d1660b4d2a8b555c2d602c97cb28d7/src/compiler/commandLineParser.ts#L3102
262- includes : ( parsedTsConfig . config . includes ?? [ DEFAULT_INCLUDE_SPEC ] ) . map ( ( i ) => join ( basePath , i ) ) ,
263- excludes : ( parsedTsConfig . config . excludes ?? [ ] ) . map ( ( e ) => join ( basePath , e ) ) ,
268+ includes : ( parsedTsConfig . config . includes ?? [ DEFAULT_INCLUDE_SPEC ] ) . map ( resolvePath ) ,
269+ excludes : ( parsedTsConfig . config . excludes ?? [ ] ) . map ( resolvePath ) ,
264270 dtsOutDir : join ( basePath , parsedTsConfig . config . dtsOutDir ?? 'generated' ) ,
265271 arbitraryExtensions : parsedTsConfig . config . arbitraryExtensions ?? false ,
266272 namedExports : parsedTsConfig . config . namedExports ?? false ,
You can’t perform that action at this time.
0 commit comments