Skip to content

Commit da40062

Browse files
committed
feat(utils): [resolvePaths] allow compilerOptions.baseUrl override
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent 53fea0b commit da40062

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/interfaces/__tests__/options-resolve-paths.spec-d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ describe('unit-d:interfaces/ResolvePathsOptions', () => {
1818
>()
1919
})
2020

21+
it('should match [baseUrl?: mlly.ResolveAliasOptions["cwd"]]', () => {
22+
expectTypeOf<TestSubject>()
23+
.toHaveProperty('baseUrl')
24+
.toEqualTypeOf<mlly.ResolveAliasOptions['cwd']>()
25+
})
26+
2127
it('should match [parent: mlly.ModuleId]', () => {
2228
expectTypeOf<TestSubject>()
2329
.toHaveProperty('parent')

src/interfaces/options-resolve-paths.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ interface ResolvePathsOptions
3232
*/
3333
absolute?: boolean | undefined
3434

35+
/**
36+
* Base directory to resolve non-absolute modules from.
37+
*
38+
* Overrides `compilerOptions.baseUrl` if set in {@linkcode tsconfig} file.
39+
*/
40+
baseUrl?: mlly.ResolveAliasOptions['cwd']
41+
3542
/**
3643
* Id of module to resolve from.
3744
*/

src/utils/resolve-paths.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const resolvePaths = async (
2525
): Promise<string> => {
2626
const {
2727
absolute = false,
28+
baseUrl,
2829
condition,
2930
conditions,
3031
ext,
@@ -51,7 +52,7 @@ const resolvePaths = async (
5152
aliases: compilerOptions.paths,
5253
condition,
5354
conditions,
54-
cwd: compilerOptions.baseUrl,
55+
cwd: baseUrl ?? compilerOptions.baseUrl,
5556
ext,
5657
extensions,
5758
parent,

0 commit comments

Comments
 (0)