Skip to content

Commit 44d0ab9

Browse files
refactor: use isWebpack5 in after-compile module mapping
Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/6940b64c-bb0d-431f-b8cf-7e83f58ff811 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com>
1 parent 8fa971e commit 44d0ab9

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/after-compile.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,24 @@ function provideCompilerOptionDiagnosticErrorsToWebpack(
120120
*/
121121
function determineModules(
122122
compilation: webpack.Compilation,
123-
{ filePathKeyMapper }: TSInstance
123+
{ filePathKeyMapper, isWebpack5 }: TSInstance
124124
) {
125125
const modules: Map<FilePathKey, webpack.Module[]> = new Map();
126126

127127
compilation.modules.forEach(module => {
128-
const normalModule = module as webpack.Module & { resource?: string };
129-
if (typeof normalModule.resource === 'string') {
130-
const modulePath = filePathKeyMapper(normalModule.resource);
128+
const resource = isWebpack5
129+
? (module as webpack.NormalModule).resource
130+
: (module as webpack.Module & { resource?: string }).resource;
131+
132+
if (typeof resource === 'string') {
133+
const modulePath = filePathKeyMapper(resource);
131134
const existingModules = modules.get(modulePath);
132135
if (existingModules !== undefined) {
133-
if (!existingModules.includes(normalModule)) {
134-
existingModules.push(normalModule);
136+
if (!existingModules.includes(module)) {
137+
existingModules.push(module);
135138
}
136139
} else {
137-
modules.set(modulePath, [normalModule]);
140+
modules.set(modulePath, [module]);
138141
}
139142
}
140143
});

0 commit comments

Comments
 (0)