@@ -154,14 +154,21 @@ export function resolveWithPaths(
154
154
155
155
// If TypeScript gives us a `.d.ts`, it is probably a node module
156
156
if ( moduleFilePath . endsWith ( '.d.ts' ) ) {
157
- // If in a package, let webpack resolve the package
158
- const packageRootPath = path . join ( path . dirname ( moduleFilePath ) , 'package.json' ) ;
159
- if ( ! host . fileExists ( packageRootPath ) ) {
160
- // Otherwise, if there is a file with a .js extension use that
161
- const jsFilePath = moduleFilePath . slice ( 0 , - 5 ) + '.js' ;
162
- if ( host . fileExists ( jsFilePath ) ) {
157
+ const pathNoExtension = moduleFilePath . slice ( 0 , - 5 ) ;
158
+ const pathDirName = path . dirname ( moduleFilePath ) ;
159
+ const packageRootPath = path . join ( pathDirName , 'package.json' ) ;
160
+ const jsFilePath = `${ pathNoExtension } .js` ;
161
+
162
+ if ( host . fileExists ( pathNoExtension ) ) {
163
+ // This is mainly for secondary entry points
164
+ // ex: 'node_modules/@angular/core/testing.d.ts' -> 'node_modules/@angular/core/testing'
165
+ request . request = pathNoExtension ;
166
+ } else if ( host . fileExists ( packageRootPath ) ) {
167
+ // Let webpack resolve the correct module format
168
+ request . request = pathDirName ;
169
+ } else if ( host . fileExists ( jsFilePath ) ) {
170
+ // Otherwise, if there is a file with a .js extension use that
163
171
request . request = jsFilePath ;
164
- }
165
172
}
166
173
167
174
callback ( null , request ) ;
0 commit comments