Skip to content

Commit

Permalink
feat(utils): [resolvePaths] allow compilerOptions.baseUrl override
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Feb 8, 2023
1 parent 53fea0b commit da40062
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/interfaces/__tests__/options-resolve-paths.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ describe('unit-d:interfaces/ResolvePathsOptions', () => {
>()
})

it('should match [baseUrl?: mlly.ResolveAliasOptions["cwd"]]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('baseUrl')
.toEqualTypeOf<mlly.ResolveAliasOptions['cwd']>()
})

it('should match [parent: mlly.ModuleId]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('parent')
Expand Down
7 changes: 7 additions & 0 deletions src/interfaces/options-resolve-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ interface ResolvePathsOptions
*/
absolute?: boolean | undefined

/**
* Base directory to resolve non-absolute modules from.
*
* Overrides `compilerOptions.baseUrl` if set in {@linkcode tsconfig} file.
*/
baseUrl?: mlly.ResolveAliasOptions['cwd']

/**
* Id of module to resolve from.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/utils/resolve-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const resolvePaths = async (
): Promise<string> => {
const {
absolute = false,
baseUrl,
condition,
conditions,
ext,
Expand All @@ -51,7 +52,7 @@ const resolvePaths = async (
aliases: compilerOptions.paths,
condition,
conditions,
cwd: compilerOptions.baseUrl,
cwd: baseUrl ?? compilerOptions.baseUrl,
ext,
extensions,
parent,
Expand Down

0 comments on commit da40062

Please sign in to comment.