Skip to content

Commit 29120fa

Browse files
committed
fix(utils): [toBareSpecifier] remove @types/ prefix
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent b3ae5a9 commit 29120fa

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/utils/__tests__/to-bare-specifier.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('unit:utils/toBareSpecifier', () => {
3232
['esbuild/lib/main.js', 'esbuild'],
3333
['fs', 'node:fs'],
3434
['node:fs', 'node:fs'],
35-
['node_modules/@types/chai', '@types/chai'],
35+
['node_modules/@types/chai', 'chai'],
3636
[pathToFileURL('dist/index.mjs'), '@flex-development/mlly'],
3737
[pathe.resolve('dist/index.mjs'), '@flex-development/mlly'],
3838
['__fixtures__/node_modules/exports-map-2/dist/index', 'exports-map-2'],

src/utils/to-bare-specifier.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,16 @@ const toBareSpecifier = (
136136

137137
// exit early if subpath does not need to be validated
138138
if (isNIL(exports)) {
139-
return [main, types].some(ep => ep === id.path || ep === id.path.slice(2))
140-
? id.pkg
141-
: specifier
139+
// set specifier to package name if specifier is main or types entry point
140+
if ([main, types].some(ep => ep === id.path || ep === id.path.slice(2))) {
141+
specifier = id.pkg
142+
}
143+
144+
// remove '@types/' prefix to avoid 'Cannot import type declaration files.
145+
// Consider importing "*" instead of "@types/*"' (TS6137) error
146+
specifier = specifier.replace(/^@types\//, '')
147+
148+
return specifier
142149
}
143150

144151
// check if specifier contains valid subpath export

0 commit comments

Comments
 (0)