Skip to content

Commit

Permalink
fix(utils): [toBareSpecifier] remove @types/ prefix
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Mar 3, 2023
1 parent b3ae5a9 commit 29120fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/utils/__tests__/to-bare-specifier.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('unit:utils/toBareSpecifier', () => {
['esbuild/lib/main.js', 'esbuild'],
['fs', 'node:fs'],
['node:fs', 'node:fs'],
['node_modules/@types/chai', '@types/chai'],
['node_modules/@types/chai', 'chai'],
[pathToFileURL('dist/index.mjs'), '@flex-development/mlly'],
[pathe.resolve('dist/index.mjs'), '@flex-development/mlly'],
['__fixtures__/node_modules/exports-map-2/dist/index', 'exports-map-2'],
Expand Down
13 changes: 10 additions & 3 deletions src/utils/to-bare-specifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,16 @@ const toBareSpecifier = (

// exit early if subpath does not need to be validated
if (isNIL(exports)) {
return [main, types].some(ep => ep === id.path || ep === id.path.slice(2))
? id.pkg
: specifier
// set specifier to package name if specifier is main or types entry point
if ([main, types].some(ep => ep === id.path || ep === id.path.slice(2))) {
specifier = id.pkg
}

// remove '@types/' prefix to avoid 'Cannot import type declaration files.
// Consider importing "*" instead of "@types/*"' (TS6137) error
specifier = specifier.replace(/^@types\//, '')

return specifier
}

// check if specifier contains valid subpath export
Expand Down

0 comments on commit 29120fa

Please sign in to comment.