@@ -38,78 +38,42 @@ import {
38
38
NormalizedOptimization ,
39
39
NormalizedSourceMaps ,
40
40
defaultProgress ,
41
- normalizeAssetPatterns ,
42
- normalizeFileReplacements ,
43
- normalizeOptimization ,
44
- normalizeSourceMaps ,
41
+ normalizeBuilderSchema ,
45
42
} from '../utils' ;
46
43
import {
47
44
AssetPatternObject ,
48
45
BrowserBuilderSchema ,
49
46
CurrentFileReplacement ,
47
+ NormalizedBrowserBuilderSchema ,
50
48
} from './schema' ;
51
49
const SpeedMeasurePlugin = require ( 'speed-measure-webpack-plugin' ) ;
52
50
const webpackMerge = require ( 'webpack-merge' ) ;
53
51
54
-
55
- // TODO: figure out a better way to normalize assets, extra entry points, file replacements,
56
- // and whatever else needs to be normalized, while keeping type safety.
57
- // Right now this normalization has to be done in all other builders that make use of the
58
- // BrowserBuildSchema and BrowserBuilder.buildWebpackConfig.
59
- // It would really help if it happens during architect.validateBuilderOptions, or similar.
60
- export interface NormalizedBrowserBuilderSchema extends
61
- Pick <
62
- BrowserBuilderSchema ,
63
- Exclude < keyof BrowserBuilderSchema , 'sourceMap' | 'vendorSourceMap' | 'optimization' >
64
- > ,
65
- NormalizedSourceMaps {
66
- assets : AssetPatternObject [ ] ;
67
- fileReplacements : CurrentFileReplacement [ ] ;
68
- optimization : NormalizedOptimization ;
69
- }
70
-
71
52
export class BrowserBuilder implements Builder < BrowserBuilderSchema > {
72
53
73
54
constructor ( public context : BuilderContext ) { }
74
55
75
56
run ( builderConfig : BuilderConfiguration < BrowserBuilderSchema > ) : Observable < BuildEvent > {
76
- let options = builderConfig . options ;
57
+ let options : NormalizedBrowserBuilderSchema ;
77
58
const root = this . context . workspace . root ;
78
59
const projectRoot = resolve ( root , builderConfig . root ) ;
79
60
const host = new virtualFs . AliasHost ( this . context . host as virtualFs . Host < fs . Stats > ) ;
80
61
const webpackBuilder = new WebpackBuilder ( { ...this . context , host } ) ;
81
62
82
63
return of ( null ) . pipe (
64
+ concatMap ( ( ) => normalizeBuilderSchema (
65
+ host ,
66
+ root ,
67
+ builderConfig ,
68
+ ) ) ,
69
+ tap ( normalizedOptions => options = normalizedOptions ) ,
83
70
concatMap ( ( ) => options . deleteOutputPath
84
71
? this . _deleteOutputDir ( root , normalize ( options . outputPath ) , this . context . host )
85
72
: of ( null ) ) ,
86
- concatMap ( ( ) => normalizeFileReplacements ( options . fileReplacements , host , root ) ) ,
87
- tap ( fileReplacements => options . fileReplacements = fileReplacements ) ,
88
- concatMap ( ( ) => normalizeAssetPatterns (
89
- options . assets , host , root , projectRoot , builderConfig . sourceRoot ) ) ,
90
- // Replace the assets in options with the normalized version.
91
- tap ( ( assetPatternObjects => options . assets = assetPatternObjects ) ) ,
92
- tap ( ( ) => {
93
- const normalizedOptions = normalizeSourceMaps ( options . sourceMap ) ;
94
- // todo: remove when removing the deprecations
95
- normalizedOptions . vendorSourceMap
96
- = normalizedOptions . vendorSourceMap || ! ! options . vendorSourceMap ;
97
-
98
- options = {
99
- ...options ,
100
- ...normalizedOptions ,
101
- // tslint:disable-next-line:no-any
102
- optimization : normalizeOptimization ( options . optimization ) as any ,
103
- } ;
104
- } ) ,
105
73
concatMap ( ( ) => {
106
74
let webpackConfig ;
107
75
try {
108
- webpackConfig = this . buildWebpackConfig ( root , projectRoot , host ,
109
- // todo replace with unknown
110
- // we need to find a clear way to create this options
111
- // tslint:disable-next-line:no-any
112
- options as any as NormalizedBrowserBuilderSchema ) ;
76
+ webpackConfig = this . buildWebpackConfig ( root , projectRoot , host , options ) ;
113
77
} catch ( e ) {
114
78
return throwError ( e ) ;
115
79
}
0 commit comments