Skip to content

Commit

Permalink
feat(resolve): [resolveModule] @types detection
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Oct 21, 2022
1 parent 6991fae commit bcd1de7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ export const RESOLVE_EXTENSIONS: readonly Ext[] = Object.freeze([
'.node',
'.ts',
'.tsx',
'.wasm'
'.wasm',
'.d.ts',
'.d.mts',
'.d.cts'
])
7 changes: 6 additions & 1 deletion src/lib/resolve-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import toRelativeSpecifier from './to-relative-specifier'
* Adds support for:
*
* - Resolving without file extensions and explicit `/index` usage
* - Resolving `@types/*` with **and** without explicit `@types/*` usage
* - Converting resolved modules into bare and relative specifiers
* - Removing and replacing file extensions
*
Expand Down Expand Up @@ -71,7 +72,11 @@ const resolveModule = async (
const tries: string[] =
isBuiltin(specifier) || /^(?:data|https?):/.test(specifier)
? []
: extensions.flatMap(ext => [specifier + ext, specifier + '/index' + ext])
: extensions.flatMap(ext => {
return [specifier + ext, specifier + '/index' + ext].flatMap($try => {
return [$try, '@types/' + $try]
})
})

// ensure attempt to resolve original specifier is first
tries.unshift(specifier)
Expand Down

0 comments on commit bcd1de7

Please sign in to comment.