File tree 2 files changed +22
-24
lines changed
2 files changed +22
-24
lines changed Original file line number Diff line number Diff line change @@ -262,7 +262,6 @@ export function resolvePlugin(baseOptions: InternalResolveOptions): Plugin {
262
262
// bare package imports, perform node resolve
263
263
if ( bareImportRE . test ( id ) ) {
264
264
const external = options . shouldExternalize ?.( id )
265
-
266
265
if (
267
266
! external &&
268
267
asSrc &&
@@ -636,8 +635,17 @@ export function tryNodeResolve(
636
635
return resolved
637
636
}
638
637
const resolvedExt = path . extname ( resolved . id )
639
- const resolvedId =
640
- isDeepImport && path . extname ( id ) !== resolvedExt ? id + resolvedExt : id
638
+ let resolvedId = id
639
+ if ( isDeepImport ) {
640
+ // check ext before externalizing - only externalize
641
+ // extension-less imports and explicit .js imports
642
+ if ( resolvedExt && ! resolved . id . match ( / ( .j s | .m j s | .c j s ) $ / ) ) {
643
+ return
644
+ }
645
+ if ( ! pkg ?. data . exports && path . extname ( id ) !== resolvedExt ) {
646
+ resolvedId += resolvedExt
647
+ }
648
+ }
641
649
return { ...resolved , id : resolvedId , external : true }
642
650
}
643
651
Original file line number Diff line number Diff line change @@ -139,29 +139,19 @@ function createIsSsrExternal(
139
139
isBuild : true
140
140
}
141
141
142
- const isPackageEntry = ( id : string ) => {
142
+ const isValidPackageEntry = ( id : string ) => {
143
143
if ( ! bareImportRE . test ( id ) || id . includes ( '\0' ) ) {
144
144
return false
145
145
}
146
- if (
147
- tryNodeResolve (
148
- id ,
149
- undefined ,
150
- resolveOptions ,
151
- ssr ?. target === 'webworker' ,
152
- undefined ,
153
- true
154
- )
155
- ) {
156
- return true
157
- }
158
- try {
159
- // no main entry, but deep imports may be allowed
160
- if ( resolveFrom ( `${ id } /package.json` , root ) ) {
161
- return true
162
- }
163
- } catch { }
164
- return false
146
+ return ! ! tryNodeResolve (
147
+ id ,
148
+ undefined ,
149
+ resolveOptions ,
150
+ ssr ?. target === 'webworker' ,
151
+ undefined ,
152
+ true ,
153
+ true // try to externalize, will return undefined if not possible
154
+ )
165
155
}
166
156
167
157
return ( id : string ) => {
@@ -171,7 +161,7 @@ function createIsSsrExternal(
171
161
const external =
172
162
! id . startsWith ( '.' ) &&
173
163
! path . isAbsolute ( id ) &&
174
- ( isBuiltin ( id ) || ( isConfiguredAsExternal ( id ) && isPackageEntry ( id ) ) )
164
+ ( isBuiltin ( id ) || ( isConfiguredAsExternal ( id ) && isValidPackageEntry ( id ) ) )
175
165
processedIds . set ( id , external )
176
166
return external
177
167
}
You can’t perform that action at this time.
0 commit comments