Skip to content

Commit 1790c15

Browse files
committed
feat: add support for substituting configDir magic variable in tsconfig file
1 parent 63a2967 commit 1790c15

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ export function parseConfig(
7575
return
7676
}
7777

78+
if (parsedConfig!.raw.include) {
79+
parsedConfig!.raw.include = parsedConfig!.raw.include.map((includePath: string) => {
80+
return includePath.replace('${configDir}/', '')
81+
})
82+
}
83+
if (parsedConfig!.raw.exclude) {
84+
parsedConfig!.raw.exclude = parsedConfig!.raw.exclude.map((excludePath: string) => {
85+
return excludePath.replace('${configDir}/', '')
86+
})
87+
}
88+
7889
return parsedConfig
7990
}
8091

tests/utils/parse_config.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,18 @@ test.group('Helpers | Parse config', () => {
3737
const result = parseConfig(fs.baseUrl, ts)
3838
assert.deepEqual(result?.fileNames, [string.toUnixSlash(join(fs.basePath, 'foo.ts'))])
3939
})
40+
41+
test('parse tsconfig file using ${configDir} variable to point to the root dir', async ({
42+
assert,
43+
fs,
44+
}) => {
45+
await fs.createJson('tsconfig.json', {
46+
include: ['${configDir}/**/*', '${configDir}/.adonisjs/server/**/*'],
47+
})
48+
await fs.create('foo.ts', '')
49+
50+
const result = parseConfig(fs.baseUrl, ts)
51+
assert.deepEqual(result?.fileNames, [string.toUnixSlash(join(fs.basePath, 'foo.ts'))])
52+
assert.deepEqual(result?.raw.include, ['**/*', '.adonisjs/server/**/*'])
53+
})
4054
})

0 commit comments

Comments
 (0)