-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathnormalize-builder-schema.ts
73 lines (64 loc) · 2.46 KB
/
normalize-builder-schema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Path, virtualFs } from '@angular-devkit/core';
import { BuildOptions } from '../angular-cli-files/models/build-options';
import {
AssetPatternClass,
OptimizationClass,
Schema as BrowserBuilderSchema,
SourceMapClass,
} from '../browser/schema';
import { normalizeAssetPatterns } from './normalize-asset-patterns';
import {
NormalizedFileReplacement,
normalizeFileReplacements,
} from './normalize-file-replacements';
import { normalizeOptimization } from './normalize-optimization';
import { normalizeSourceMaps } from './normalize-source-maps';
/**
* A normalized browser builder schema.
*/
export type NormalizedBrowserBuilderSchema = BrowserBuilderSchema & BuildOptions & {
sourceMap: SourceMapClass;
assets: AssetPatternClass[];
fileReplacements: NormalizedFileReplacement[];
optimization: OptimizationClass;
};
export function normalizeBrowserSchema(
host: virtualFs.Host<{}>,
root: Path,
projectRoot: Path,
sourceRoot: Path | undefined,
options: BrowserBuilderSchema,
): NormalizedBrowserBuilderSchema {
const syncHost = new virtualFs.SyncDelegateHost(host);
const normalizedSourceMapOptions = normalizeSourceMaps(options.sourceMap || false);
normalizedSourceMapOptions.vendor = normalizedSourceMapOptions.vendor || options.vendorSourceMap;
return {
...options,
assets: normalizeAssetPatterns(options.assets || [], syncHost, root, projectRoot, sourceRoot),
fileReplacements: normalizeFileReplacements(options.fileReplacements || [], syncHost, root),
optimization: normalizeOptimization(options.optimization),
sourceMap: normalizedSourceMapOptions,
statsJson: options.statsJson || false,
forkTypeChecker: options.forkTypeChecker || false,
budgets: options.budgets || [],
scripts: options.scripts || [],
styles: options.styles || [],
stylePreprocessorOptions: {
includePaths: options.stylePreprocessorOptions
&& options.stylePreprocessorOptions.includePaths
|| [],
},
lazyModules: options.lazyModules || [],
// Using just `--poll` will result in a value of 0 which is very likely not the intention
// A value of 0 is falsy and will disable polling rather then enable
// 500 ms is a sensible default in this case
poll: options.poll === 0 ? 500 : options.poll,
};
}