6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
import { RawSourceMap } from 'source-map' ;
9
- import * as webpack from 'webpack' ; // tslint:disable-line:no-implicit-dependencies
10
9
import { SourceMapSource } from 'webpack-sources' ;
11
10
const loaderUtils = require ( 'loader-utils' ) ;
12
11
@@ -27,26 +26,25 @@ const alwaysProcess = (path: string) =>
27
26
path . endsWith ( '.ngstyle.js' ) ;
28
27
29
28
export default function buildOptimizerLoader (
30
- this : webpack . loader . LoaderContext ,
29
+ // Webpack 5 does not provide a LoaderContext type
30
+ this : {
31
+ resourcePath : string ;
32
+ _module : { factoryMeta : { skipBuildOptimizer ?: boolean ; sideEffectFree ?: boolean } } ;
33
+ cacheable ( ) : void ;
34
+ callback ( error ?: Error | null , content ?: string , sourceMap ?: unknown ) : void ;
35
+ } ,
31
36
content : string ,
32
37
previousSourceMap : RawSourceMap ,
33
38
) {
34
39
this . cacheable ( ) ;
35
- const callback = this . async ( ) ;
36
- if ( ! callback ) {
37
- throw new Error ( 'Async loader support is required.' ) ;
38
- }
39
40
40
41
const skipBuildOptimizer =
41
42
this . _module && this . _module . factoryMeta && this . _module . factoryMeta . skipBuildOptimizer ;
42
43
43
44
if ( ! alwaysProcess ( this . resourcePath ) && skipBuildOptimizer ) {
44
45
// Skip loading processing this file with Build Optimizer if we determined in
45
46
// BuildOptimizerWebpackPlugin that we shouldn't.
46
-
47
- // Webpack typings for previousSourceMap are wrong, they are JSON objects and not strings.
48
- // tslint:disable-next-line:no-any
49
- this . callback ( null , content , previousSourceMap as any ) ;
47
+ this . callback ( null , content , previousSourceMap ) ;
50
48
51
49
return ;
52
50
}
@@ -64,8 +62,7 @@ export default function buildOptimizerLoader(
64
62
} ) ;
65
63
66
64
if ( boOutput . emitSkipped || boOutput . content === null ) {
67
- // tslint:disable-next-line:no-any
68
- this . callback ( null , content , previousSourceMap as any ) ;
65
+ this . callback ( null , content , previousSourceMap ) ;
69
66
70
67
return ;
71
68
}
@@ -81,10 +78,7 @@ export default function buildOptimizerLoader(
81
78
82
79
if ( previousSourceMap ) {
83
80
// Use http://sokra.github.io/source-map-visualization/ to validate sourcemaps make sense.
84
-
85
- // The last argument is not yet in the typings
86
- // tslint:disable-next-line: no-any
87
- newSourceMap = new ( SourceMapSource as any ) (
81
+ newSourceMap = new SourceMapSource (
88
82
newContent ,
89
83
this . resourcePath ,
90
84
intermediateSourceMap ,
@@ -98,7 +92,5 @@ export default function buildOptimizerLoader(
98
92
}
99
93
}
100
94
101
- // Webpack typings for previousSourceMap are wrong, they are JSON objects and not strings.
102
- // tslint:disable-next-line:no-any
103
- callback ( null , newContent , newSourceMap as any ) ;
95
+ this . callback ( null , newContent , newSourceMap ) ;
104
96
}
0 commit comments