1
1
import * as path from 'path' ;
2
+ import * as webpack from 'webpack' ;
2
3
3
4
import * as constants from './constants' ;
4
5
import { getEmitOutput } from './instances' ;
5
6
import {
6
7
TSFile ,
7
8
TSFiles ,
8
9
TSInstance ,
9
- WebpackCompilation ,
10
10
WebpackError ,
11
11
WebpackModule
12
12
} from './interfaces' ;
@@ -23,7 +23,10 @@ export function makeAfterCompile(
23
23
let getCompilerOptionDiagnostics = true ;
24
24
let checkAllFilesForErrors = true ;
25
25
26
- return ( compilation : WebpackCompilation , callback : ( ) => void ) => {
26
+ return (
27
+ compilation : webpack . compilation . Compilation ,
28
+ callback : ( ) => void
29
+ ) => {
27
30
// Don't add errors for child compilations
28
31
if ( compilation . compiler . isChild ( ) ) {
29
32
callback ( ) ;
@@ -76,7 +79,7 @@ export function makeAfterCompile(
76
79
*/
77
80
function provideCompilerOptionDiagnosticErrorsToWebpack (
78
81
getCompilerOptionDiagnostics : boolean ,
79
- compilation : WebpackCompilation ,
82
+ compilation : webpack . compilation . Compilation ,
80
83
instance : TSInstance ,
81
84
configFilePath : string | undefined
82
85
) {
@@ -103,23 +106,25 @@ function provideCompilerOptionDiagnosticErrorsToWebpack(
103
106
* this is used for quick-lookup when trying to find modules
104
107
* based on filepath
105
108
*/
106
- function determineModules ( compilation : WebpackCompilation ) {
107
- // TODO: Convert to reduce
108
- const modules = new Map < string , WebpackModule [ ] > ( ) ;
109
- compilation . modules . forEach ( module => {
110
- if ( module . resource ) {
111
- const modulePath = path . normalize ( module . resource ) ;
112
- const existingModules = modules . get ( modulePath ) ;
113
- if ( existingModules !== undefined ) {
114
- if ( existingModules . indexOf ( module ) === - 1 ) {
115
- existingModules . push ( module ) ;
109
+ function determineModules ( compilation : webpack . compilation . Compilation ) {
110
+ return compilation . modules . reduce < Map < string , WebpackModule [ ] > > (
111
+ ( modules , module ) => {
112
+ if ( module . resource ) {
113
+ const modulePath = path . normalize ( module . resource ) ;
114
+ const existingModules = modules . get ( modulePath ) ;
115
+ if ( existingModules !== undefined ) {
116
+ if ( existingModules . indexOf ( module ) === - 1 ) {
117
+ existingModules . push ( module ) ;
118
+ }
119
+ } else {
120
+ modules . set ( modulePath , [ module ] ) ;
116
121
}
117
- } else {
118
- modules . set ( modulePath , [ module ] ) ;
119
122
}
120
- }
121
- } ) ;
122
- return modules ;
123
+
124
+ return modules ;
125
+ } ,
126
+ new Map < string , WebpackModule [ ] > ( )
127
+ ) ;
123
128
}
124
129
125
130
function determineFilesToCheckForErrors (
@@ -163,7 +168,7 @@ function determineFilesToCheckForErrors(
163
168
function provideErrorsToWebpack (
164
169
filesToCheckForErrors : TSFiles ,
165
170
filesWithErrors : TSFiles ,
166
- compilation : WebpackCompilation ,
171
+ compilation : webpack . compilation . Compilation ,
167
172
modules : Map < string , WebpackModule [ ] > ,
168
173
instance : TSInstance
169
174
) {
@@ -255,7 +260,7 @@ function provideErrorsToWebpack(
255
260
function provideDeclarationFilesToWebpack (
256
261
filesToCheckForErrors : TSFiles ,
257
262
instance : TSInstance ,
258
- compilation : WebpackCompilation
263
+ compilation : webpack . compilation . Compilation
259
264
) {
260
265
for ( const filePath of filesToCheckForErrors . keys ( ) ) {
261
266
if ( filePath . match ( constants . tsTsxRegex ) === null ) {
0 commit comments