@angular-devkit/build-angular 0.803.21 → 0.803.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +14 -14
- package/src/angular-cli-files/models/build-options.d.ts +2 -1
- package/src/angular-cli-files/models/es5-polyfills.js +8 -1
- package/src/angular-cli-files/models/webpack-configs/browser.js +17 -9
- package/src/angular-cli-files/models/webpack-configs/test.js +2 -3
- package/src/angular-cli-files/utilities/stats.js +9 -1
- package/src/browser/action-cache.d.ts +1 -1
- package/src/browser/action-cache.js +12 -8
- package/src/browser/index.js +2 -6
- package/src/tslint/index.js +4 -1
- package/src/utils/build-browser-features.d.ts +1 -1
- package/src/utils/build-browser-features.js +3 -3
- package/src/utils/process-bundle.d.ts +2 -1
- package/src/utils/process-bundle.js +60 -80
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-devkit/build-angular",
|
|
3
|
-
"version": "0.803.
|
|
3
|
+
"version": "0.803.25",
|
|
4
4
|
"description": "Angular Webpack Build Facade",
|
|
5
5
|
"experimental": true,
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"typings": "src/index.d.ts",
|
|
8
8
|
"builders": "builders.json",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@angular-devkit/architect": "0.803.
|
|
11
|
-
"@angular-devkit/build-optimizer": "0.803.
|
|
12
|
-
"@angular-devkit/build-webpack": "0.803.
|
|
13
|
-
"@angular-devkit/core": "8.3.
|
|
14
|
-
"@babel/core": "7.
|
|
15
|
-
"@babel/preset-env": "7.
|
|
16
|
-
"@ngtools/webpack": "8.3.
|
|
10
|
+
"@angular-devkit/architect": "0.803.25",
|
|
11
|
+
"@angular-devkit/build-optimizer": "0.803.25",
|
|
12
|
+
"@angular-devkit/build-webpack": "0.803.25",
|
|
13
|
+
"@angular-devkit/core": "8.3.25",
|
|
14
|
+
"@babel/core": "7.8.3",
|
|
15
|
+
"@babel/preset-env": "7.8.3",
|
|
16
|
+
"@ngtools/webpack": "8.3.25",
|
|
17
17
|
"ajv": "6.10.2",
|
|
18
18
|
"autoprefixer": "9.6.1",
|
|
19
|
-
"browserslist": "4.
|
|
19
|
+
"browserslist": "4.8.6",
|
|
20
20
|
"cacache": "12.0.2",
|
|
21
|
-
"caniuse-lite": "1.0.
|
|
21
|
+
"caniuse-lite": "1.0.30001024",
|
|
22
22
|
"circular-dependency-plugin": "5.2.0",
|
|
23
23
|
"clean-css": "4.2.1",
|
|
24
|
+
"coverage-istanbul-loader": "2.0.3",
|
|
24
25
|
"copy-webpack-plugin": "5.1.1",
|
|
25
|
-
"core-js": "3.
|
|
26
|
+
"core-js": "3.6.4",
|
|
26
27
|
"file-loader": "4.2.0",
|
|
27
28
|
"find-cache-dir": "3.0.0",
|
|
28
29
|
"glob": "7.1.4",
|
|
29
|
-
"istanbul-instrumenter-loader": "3.0.1",
|
|
30
30
|
"jest-worker": "24.9.0",
|
|
31
31
|
"karma-source-map-support": "1.4.0",
|
|
32
32
|
"less": "3.9.0",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"style-loader": "1.0.0",
|
|
54
54
|
"stylus": "0.54.5",
|
|
55
55
|
"stylus-loader": "3.0.2",
|
|
56
|
-
"tree-kill": "1.2.
|
|
57
|
-
"terser": "4.3
|
|
56
|
+
"tree-kill": "1.2.2",
|
|
57
|
+
"terser": "4.6.3",
|
|
58
58
|
"terser-webpack-plugin": "1.4.3",
|
|
59
59
|
"webpack": "4.39.2",
|
|
60
60
|
"webpack-dev-middleware": "3.7.2",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { logging } from '@angular-devkit/core';
|
|
9
9
|
import { ParsedConfiguration } from '@angular/compiler-cli';
|
|
10
10
|
import { ScriptTarget } from 'typescript';
|
|
11
|
-
import { AssetPatternClass, Budget, ExtraEntryPoint, OptimizationClass, SourceMapClass } from '../../browser/schema';
|
|
11
|
+
import { AssetPatternClass, Budget, CrossOrigin, ExtraEntryPoint, OptimizationClass, SourceMapClass } from '../../browser/schema';
|
|
12
12
|
import { NormalizedFileReplacement } from '../../utils/normalize-file-replacements';
|
|
13
13
|
export interface BuildOptions {
|
|
14
14
|
optimization: OptimizationClass;
|
|
@@ -43,6 +43,7 @@ export interface BuildOptions {
|
|
|
43
43
|
showCircularDependencies?: boolean;
|
|
44
44
|
buildOptimizer?: boolean;
|
|
45
45
|
namedChunks?: boolean;
|
|
46
|
+
crossOrigin?: CrossOrigin;
|
|
46
47
|
subresourceIntegrity?: boolean;
|
|
47
48
|
serviceWorker?: boolean;
|
|
48
49
|
webWorkerTsConfig?: string;
|
|
@@ -91,7 +91,14 @@ import 'core-js/modules/es.parse-float';
|
|
|
91
91
|
import 'core-js/es/number';
|
|
92
92
|
import 'core-js/es/math';
|
|
93
93
|
import 'core-js/es/date';
|
|
94
|
-
|
|
94
|
+
|
|
95
|
+
import 'core-js/modules/es.regexp.constructor';
|
|
96
|
+
import 'core-js/modules/es.regexp.to-string';
|
|
97
|
+
import 'core-js/modules/es.regexp.flags';
|
|
98
|
+
import 'core-js/modules/es.string.match';
|
|
99
|
+
import 'core-js/modules/es.string.replace';
|
|
100
|
+
import 'core-js/modules/es.string.search';
|
|
101
|
+
import 'core-js/modules/es.string.split';
|
|
95
102
|
|
|
96
103
|
import 'core-js/modules/es.map';
|
|
97
104
|
import 'core-js/modules/es.weak-map';
|
|
@@ -12,38 +12,46 @@ const utils_1 = require("./utils");
|
|
|
12
12
|
const SubresourceIntegrityPlugin = require('webpack-subresource-integrity');
|
|
13
13
|
function getBrowserConfig(wco) {
|
|
14
14
|
const { buildOptions } = wco;
|
|
15
|
+
const { crossOrigin = 'none', subresourceIntegrity, evalSourceMap, extractLicenses, vendorChunk, commonChunk, styles, } = buildOptions;
|
|
15
16
|
const extraPlugins = [];
|
|
16
17
|
let isEval = false;
|
|
17
18
|
const { styles: stylesOptimization, scripts: scriptsOptimization } = buildOptions.optimization;
|
|
18
19
|
const { styles: stylesSourceMap, scripts: scriptsSourceMap, hidden: hiddenSourceMap, } = buildOptions.sourceMap;
|
|
19
20
|
// See https://webpack.js.org/configuration/devtool/ for sourcemap types.
|
|
20
21
|
if ((stylesSourceMap || scriptsSourceMap) &&
|
|
21
|
-
|
|
22
|
+
evalSourceMap &&
|
|
22
23
|
!stylesOptimization &&
|
|
23
24
|
!scriptsOptimization) {
|
|
24
25
|
// Produce eval sourcemaps for development with serve, which are faster.
|
|
25
26
|
isEval = true;
|
|
26
27
|
}
|
|
27
|
-
if (
|
|
28
|
+
if (subresourceIntegrity) {
|
|
28
29
|
extraPlugins.push(new SubresourceIntegrityPlugin({
|
|
29
30
|
hashFuncNames: ['sha384'],
|
|
30
31
|
}));
|
|
31
32
|
}
|
|
32
|
-
if (
|
|
33
|
+
if (extractLicenses) {
|
|
33
34
|
extraPlugins.push(new license_webpack_plugin_1.LicenseWebpackPlugin({
|
|
34
35
|
stats: {
|
|
35
36
|
warnings: false,
|
|
36
37
|
errors: false,
|
|
37
38
|
},
|
|
38
39
|
perChunkOutput: false,
|
|
39
|
-
outputFilename:
|
|
40
|
+
outputFilename: '3rdpartylicenses.txt',
|
|
40
41
|
}));
|
|
41
42
|
}
|
|
42
43
|
if (!isEval && (scriptsSourceMap || stylesSourceMap)) {
|
|
43
44
|
extraPlugins.push(utils_1.getSourceMapDevTool(!!scriptsSourceMap, !!stylesSourceMap, wco.differentialLoadingMode ? true : hiddenSourceMap));
|
|
44
45
|
}
|
|
45
|
-
const globalStylesBundleNames = utils_1.normalizeExtraEntryPoints(
|
|
46
|
+
const globalStylesBundleNames = utils_1.normalizeExtraEntryPoints(styles, 'styles')
|
|
46
47
|
.map(style => style.bundleName);
|
|
48
|
+
let crossOriginLoading = false;
|
|
49
|
+
if (subresourceIntegrity && crossOrigin === 'none') {
|
|
50
|
+
crossOriginLoading = 'anonymous';
|
|
51
|
+
}
|
|
52
|
+
else if (crossOrigin !== 'none') {
|
|
53
|
+
crossOriginLoading = crossOrigin;
|
|
54
|
+
}
|
|
47
55
|
return {
|
|
48
56
|
devtool: isEval ? 'eval' : false,
|
|
49
57
|
resolve: {
|
|
@@ -53,19 +61,19 @@ function getBrowserConfig(wco) {
|
|
|
53
61
|
],
|
|
54
62
|
},
|
|
55
63
|
output: {
|
|
56
|
-
crossOriginLoading
|
|
64
|
+
crossOriginLoading,
|
|
57
65
|
},
|
|
58
66
|
optimization: {
|
|
59
67
|
runtimeChunk: 'single',
|
|
60
68
|
splitChunks: {
|
|
61
69
|
maxAsyncRequests: Infinity,
|
|
62
70
|
cacheGroups: {
|
|
63
|
-
default: !!
|
|
71
|
+
default: !!commonChunk && {
|
|
64
72
|
chunks: 'async',
|
|
65
73
|
minChunks: 2,
|
|
66
74
|
priority: 10,
|
|
67
75
|
},
|
|
68
|
-
common: !!
|
|
76
|
+
common: !!commonChunk && {
|
|
69
77
|
name: 'common',
|
|
70
78
|
chunks: 'async',
|
|
71
79
|
minChunks: 2,
|
|
@@ -73,7 +81,7 @@ function getBrowserConfig(wco) {
|
|
|
73
81
|
priority: 5,
|
|
74
82
|
},
|
|
75
83
|
vendors: false,
|
|
76
|
-
vendor: !!
|
|
84
|
+
vendor: !!vendorChunk && {
|
|
77
85
|
name: 'vendor',
|
|
78
86
|
chunks: 'initial',
|
|
79
87
|
enforce: true,
|
|
@@ -21,7 +21,6 @@ function getTestConfig(wco) {
|
|
|
21
21
|
const { root, buildOptions, sourceRoot: include } = wco;
|
|
22
22
|
const extraRules = [];
|
|
23
23
|
const extraPlugins = [];
|
|
24
|
-
// if (buildOptions.codeCoverage && CliConfig.fromProject()) {
|
|
25
24
|
if (buildOptions.codeCoverage) {
|
|
26
25
|
const codeCoverageExclude = buildOptions.codeCoverageExclude;
|
|
27
26
|
const exclude = [
|
|
@@ -37,8 +36,8 @@ function getTestConfig(wco) {
|
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
38
|
extraRules.push({
|
|
40
|
-
test: /\.(
|
|
41
|
-
loader: 'istanbul-
|
|
39
|
+
test: /\.(jsx?|tsx?)$/,
|
|
40
|
+
loader: require.resolve('coverage-istanbul-loader'),
|
|
42
41
|
options: { esModules: true },
|
|
43
42
|
enforce: 'post',
|
|
44
43
|
exclude,
|
|
@@ -66,11 +66,19 @@ function statsToString(json, statsConfig) {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
exports.statsToString = statsToString;
|
|
69
|
+
// TODO(#16193): Don't emit this warning in the first place rather than just suppressing it.
|
|
70
|
+
const ERRONEOUS_WARNINGS = [
|
|
71
|
+
/multiple assets emit different content.*3rdpartylicenses\.txt/i,
|
|
72
|
+
];
|
|
69
73
|
function statsWarningsToString(json, statsConfig) {
|
|
70
74
|
const colors = statsConfig.colors;
|
|
71
75
|
const rs = (x) => colors ? reset(x) : x;
|
|
72
76
|
const y = (x) => colors ? bold(yellow(x)) : x;
|
|
73
|
-
return rs('\n' + json.warnings
|
|
77
|
+
return rs('\n' + json.warnings
|
|
78
|
+
.map((warning) => `${warning}`)
|
|
79
|
+
.filter((warning) => !ERRONEOUS_WARNINGS.some((erroneous) => erroneous.test(warning)))
|
|
80
|
+
.map((warning) => y(`WARNING in ${warning}`))
|
|
81
|
+
.join('\n\n'));
|
|
74
82
|
}
|
|
75
83
|
exports.statsWarningsToString = statsWarningsToString;
|
|
76
84
|
function statsErrorsToString(json, statsConfig) {
|
|
@@ -12,6 +12,6 @@ export declare class BundleActionCache {
|
|
|
12
12
|
static copyEntryContent(entry: CacheEntry | string, dest: fs.PathLike): void;
|
|
13
13
|
generateBaseCacheKey(content: string): string;
|
|
14
14
|
generateCacheKeys(action: ProcessBundleOptions): string[];
|
|
15
|
-
getCacheEntries(cacheKeys: (string |
|
|
15
|
+
getCacheEntries(cacheKeys: (string | undefined)[]): Promise<(CacheEntry | null)[] | false>;
|
|
16
16
|
getCachedBundleResult(action: ProcessBundleOptions): Promise<ProcessBundleResult | null>;
|
|
17
17
|
}
|
|
@@ -56,26 +56,30 @@ class BundleActionCache {
|
|
|
56
56
|
return baseCacheKey;
|
|
57
57
|
}
|
|
58
58
|
generateCacheKeys(action) {
|
|
59
|
-
|
|
60
|
-
// Postfix added to sourcemap cache keys when vendor sourcemaps are present
|
|
59
|
+
// Postfix added to sourcemap cache keys when vendor, hidden sourcemaps are present
|
|
61
60
|
// Allows non-destructive caching of both variants
|
|
62
|
-
const
|
|
61
|
+
const sourceMapVendorPostfix = action.sourceMaps && action.vendorSourceMaps ? '|vendor' : '';
|
|
62
|
+
// sourceMappingURL is added at the very end which causes the code to be the same when sourcemaps are enabled/disabled
|
|
63
|
+
// When using hiddenSourceMaps we can omit the postfix since sourceMappingURL will not be added.
|
|
64
|
+
// When having sourcemaps a hashed file and non hashed file can have the same content. But the sourceMappingURL will differ.
|
|
65
|
+
const sourceMapPostFix = action.sourceMaps && !action.hiddenSourceMaps ? `|sourcemap|${action.filename}` : '';
|
|
66
|
+
const baseCacheKey = this.generateBaseCacheKey(action.code);
|
|
63
67
|
// Determine cache entries required based on build settings
|
|
64
68
|
const cacheKeys = [];
|
|
65
69
|
// If optimizing and the original is not ignored, add original as required
|
|
66
|
-
if (
|
|
67
|
-
cacheKeys[0 /* OriginalCode */] = baseCacheKey + '|orig';
|
|
70
|
+
if (!action.ignoreOriginal) {
|
|
71
|
+
cacheKeys[0 /* OriginalCode */] = baseCacheKey + sourceMapPostFix + '|orig';
|
|
68
72
|
// If sourcemaps are enabled, add original sourcemap as required
|
|
69
73
|
if (action.sourceMaps) {
|
|
70
|
-
cacheKeys[1 /* OriginalMap */] = baseCacheKey +
|
|
74
|
+
cacheKeys[1 /* OriginalMap */] = baseCacheKey + sourceMapVendorPostfix + '|orig-map';
|
|
71
75
|
}
|
|
72
76
|
}
|
|
73
77
|
// If not only optimizing, add downlevel as required
|
|
74
78
|
if (!action.optimizeOnly) {
|
|
75
|
-
cacheKeys[2 /* DownlevelCode */] = baseCacheKey + '|dl';
|
|
79
|
+
cacheKeys[2 /* DownlevelCode */] = baseCacheKey + sourceMapPostFix + '|dl';
|
|
76
80
|
// If sourcemaps are enabled, add downlevel sourcemap as required
|
|
77
81
|
if (action.sourceMaps) {
|
|
78
|
-
cacheKeys[3 /* DownlevelMap */] = baseCacheKey +
|
|
82
|
+
cacheKeys[3 /* DownlevelMap */] = baseCacheKey + sourceMapVendorPostfix + '|dl-map';
|
|
79
83
|
}
|
|
80
84
|
}
|
|
81
85
|
return cacheKeys;
|
package/src/browser/index.js
CHANGED
|
@@ -212,12 +212,6 @@ function buildWebpackBrowser(options, context, transforms = {}) {
|
|
|
212
212
|
if (!es5Polyfills) {
|
|
213
213
|
moduleFiles.push(file);
|
|
214
214
|
}
|
|
215
|
-
// If not optimizing then ES2015 polyfills do not need processing
|
|
216
|
-
// Unlike other module scripts, it is never downleveled
|
|
217
|
-
const es2015Polyfills = file.file.startsWith('polyfills-es20');
|
|
218
|
-
if (!actionOptions.optimize && es2015Polyfills) {
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
215
|
// Retrieve the content/map for the file
|
|
222
216
|
// NOTE: Additional future optimizations will read directly from memory
|
|
223
217
|
let filename = path.resolve(core_1.getSystemPath(root), options.outputPath, file.file);
|
|
@@ -236,6 +230,7 @@ function buildWebpackBrowser(options, context, transforms = {}) {
|
|
|
236
230
|
fs.unlinkSync(filename);
|
|
237
231
|
filename = filename.replace(/\-es20\d{2}/, '');
|
|
238
232
|
}
|
|
233
|
+
const es2015Polyfills = file.file.startsWith('polyfills-es20');
|
|
239
234
|
// Record the bundle processing action
|
|
240
235
|
// The runtime chunk gets special processing for lazy loaded files
|
|
241
236
|
actions.push({
|
|
@@ -289,6 +284,7 @@ function buildWebpackBrowser(options, context, transforms = {}) {
|
|
|
289
284
|
const runtimeOptions = {
|
|
290
285
|
...processRuntimeAction,
|
|
291
286
|
runtimeData: processResults,
|
|
287
|
+
supportedBrowsers: buildBrowserFeatures.supportedBrowsers,
|
|
292
288
|
};
|
|
293
289
|
processResults.push(await Promise.resolve().then(() => require('../utils/process-bundle')).then(m => m.process(runtimeOptions)));
|
|
294
290
|
}
|
package/src/tslint/index.js
CHANGED
|
@@ -22,7 +22,10 @@ async function _loadTslint() {
|
|
|
22
22
|
throw new Error('Unable to find TSLint. Ensure TSLint is installed.');
|
|
23
23
|
}
|
|
24
24
|
const version = tslint.Linter.VERSION && tslint.Linter.VERSION.split('.');
|
|
25
|
-
if (!version || version.length < 2
|
|
25
|
+
if (!version || version.length < 2
|
|
26
|
+
|| (Number(version[0]) === 5 && Number(version[1]) < 5) // 5.5+
|
|
27
|
+
|| Number(version[0]) < 5 // 6.0+
|
|
28
|
+
) {
|
|
26
29
|
throw new Error('TSLint must be version 5.5 or higher.');
|
|
27
30
|
}
|
|
28
31
|
return tslint;
|
|
@@ -10,8 +10,8 @@ export declare const fullDifferential: boolean;
|
|
|
10
10
|
export declare class BuildBrowserFeatures {
|
|
11
11
|
private projectRoot;
|
|
12
12
|
private scriptTarget;
|
|
13
|
-
private readonly _supportedBrowsers;
|
|
14
13
|
private readonly _es6TargetOrLater;
|
|
14
|
+
readonly supportedBrowsers: string[];
|
|
15
15
|
constructor(projectRoot: string, scriptTarget: ts.ScriptTarget);
|
|
16
16
|
/**
|
|
17
17
|
* True, when one or more browsers requires ES5
|
|
@@ -18,7 +18,7 @@ class BuildBrowserFeatures {
|
|
|
18
18
|
constructor(projectRoot, scriptTarget) {
|
|
19
19
|
this.projectRoot = projectRoot;
|
|
20
20
|
this.scriptTarget = scriptTarget;
|
|
21
|
-
this.
|
|
21
|
+
this.supportedBrowsers = browserslist(undefined, { path: this.projectRoot });
|
|
22
22
|
this._es6TargetOrLater = this.scriptTarget > ts.ScriptTarget.ES5;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
@@ -48,7 +48,7 @@ class BuildBrowserFeatures {
|
|
|
48
48
|
'safari 10.1',
|
|
49
49
|
'ios_saf 10.3',
|
|
50
50
|
];
|
|
51
|
-
return this.
|
|
51
|
+
return this.supportedBrowsers.some(browser => safariBrowsers.includes(browser));
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* True, when a browser feature is supported partially or fully.
|
|
@@ -63,7 +63,7 @@ class BuildBrowserFeatures {
|
|
|
63
63
|
'a',
|
|
64
64
|
];
|
|
65
65
|
const data = caniuse_lite_1.feature(caniuse_lite_1.features[featureId]);
|
|
66
|
-
return !this.
|
|
66
|
+
return !this.supportedBrowsers
|
|
67
67
|
.some(browser => {
|
|
68
68
|
const [agentId, version] = browser.split(' ');
|
|
69
69
|
const browserData = data.stats[agentId];
|
|
@@ -10,9 +10,10 @@ export interface ProcessBundleOptions {
|
|
|
10
10
|
optimize?: boolean;
|
|
11
11
|
optimizeOnly?: boolean;
|
|
12
12
|
ignoreOriginal?: boolean;
|
|
13
|
-
cacheKeys?: (string |
|
|
13
|
+
cacheKeys?: (string | undefined)[];
|
|
14
14
|
integrityAlgorithm?: 'sha256' | 'sha384' | 'sha512';
|
|
15
15
|
runtimeData?: ProcessBundleResult[];
|
|
16
|
+
supportedBrowsers?: string[] | Record<string, string>;
|
|
16
17
|
}
|
|
17
18
|
export interface ProcessBundleResult {
|
|
18
19
|
name: string;
|
|
@@ -22,7 +22,7 @@ function setup(options) {
|
|
|
22
22
|
exports.setup = setup;
|
|
23
23
|
async function cachePut(content, key, integrity) {
|
|
24
24
|
if (cachePath && key) {
|
|
25
|
-
await cacache.put(cachePath, key, content, {
|
|
25
|
+
await cacache.put(cachePath, key || null, content, {
|
|
26
26
|
metadata: { integrity },
|
|
27
27
|
});
|
|
28
28
|
}
|
|
@@ -47,21 +47,24 @@ async function process(options) {
|
|
|
47
47
|
// if code size is larger than 1 MB, manually handle sourcemaps with newer source-map package.
|
|
48
48
|
const codeSize = Buffer.byteLength(options.code);
|
|
49
49
|
const mapSize = options.map ? Buffer.byteLength(options.map) : 0;
|
|
50
|
-
const manualSourceMaps = codeSize >=
|
|
50
|
+
const manualSourceMaps = codeSize >= 500 * 1024 || mapSize >= 500 * 1024;
|
|
51
51
|
const sourceCode = options.code;
|
|
52
|
-
const sourceMap = options.map ? JSON.parse(options.map) :
|
|
52
|
+
const sourceMap = options.map ? JSON.parse(options.map) : false;
|
|
53
53
|
let downlevelCode;
|
|
54
54
|
let downlevelMap;
|
|
55
55
|
if (downlevel) {
|
|
56
56
|
// Downlevel the bundle
|
|
57
57
|
const transformResult = await core_1.transformAsync(sourceCode, {
|
|
58
58
|
filename: options.filename,
|
|
59
|
-
|
|
59
|
+
// using false ensures that babel will NOT search and process sourcemap comments (large memory usage)
|
|
60
|
+
inputSourceMap: manualSourceMaps ? false : sourceMap,
|
|
60
61
|
babelrc: false,
|
|
61
62
|
presets: [
|
|
62
63
|
[
|
|
63
64
|
require.resolve('@babel/preset-env'),
|
|
64
65
|
{
|
|
66
|
+
// browserslist-compatible query or object of minimum environment versions to support
|
|
67
|
+
targets: options.supportedBrowsers,
|
|
65
68
|
// modules aren't needed since the bundles use webpack's custom module loading
|
|
66
69
|
modules: false,
|
|
67
70
|
// 'transform-typeof-symbol' generates slower code
|
|
@@ -86,38 +89,20 @@ async function process(options) {
|
|
|
86
89
|
downlevelMap = transformResult.map || undefined;
|
|
87
90
|
}
|
|
88
91
|
}
|
|
89
|
-
if (options.optimize) {
|
|
90
|
-
if (downlevelCode) {
|
|
91
|
-
const minifyResult = terserMangle(downlevelCode, {
|
|
92
|
-
filename: downlevelFilename,
|
|
93
|
-
map: downlevelMap,
|
|
94
|
-
compress: true,
|
|
95
|
-
});
|
|
96
|
-
downlevelCode = minifyResult.code;
|
|
97
|
-
downlevelMap = minifyResult.map;
|
|
98
|
-
}
|
|
99
|
-
if (!options.ignoreOriginal) {
|
|
100
|
-
result.original = await mangleOriginal(options);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
92
|
if (downlevelCode) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
await cachePut(mapContent, options.cacheKeys[3 /* DownlevelMap */]);
|
|
112
|
-
fs.writeFileSync(downlevelPath + '.map', mapContent);
|
|
113
|
-
}
|
|
114
|
-
result.downlevel = createFileEntry(downlevelFilename, downlevelCode, mapContent, options.integrityAlgorithm);
|
|
115
|
-
await cachePut(downlevelCode, options.cacheKeys[2 /* DownlevelCode */], result.downlevel.integrity);
|
|
116
|
-
fs.writeFileSync(downlevelPath, downlevelCode);
|
|
93
|
+
result.downlevel = await processBundle({
|
|
94
|
+
...options,
|
|
95
|
+
code: downlevelCode,
|
|
96
|
+
map: downlevelMap,
|
|
97
|
+
filename: path.join(basePath, downlevelFilename),
|
|
98
|
+
isOriginal: false,
|
|
99
|
+
});
|
|
117
100
|
}
|
|
118
|
-
// If original was not processed, add info
|
|
119
101
|
if (!result.original && !options.ignoreOriginal) {
|
|
120
|
-
result.original =
|
|
102
|
+
result.original = await processBundle({
|
|
103
|
+
...options,
|
|
104
|
+
isOriginal: true,
|
|
105
|
+
});
|
|
121
106
|
}
|
|
122
107
|
return result;
|
|
123
108
|
}
|
|
@@ -166,24 +151,40 @@ async function mergeSourcemaps(first, second) {
|
|
|
166
151
|
}
|
|
167
152
|
return map;
|
|
168
153
|
}
|
|
169
|
-
async function
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
154
|
+
async function processBundle(options) {
|
|
155
|
+
const { optimize, isOriginal, code, map, filename: filepath, hiddenSourceMaps, cacheKeys = [], integrityAlgorithm, } = options;
|
|
156
|
+
const rawMap = typeof map === 'string' ? JSON.parse(map) : map;
|
|
157
|
+
const filename = path.basename(filepath);
|
|
158
|
+
let result;
|
|
159
|
+
if (optimize) {
|
|
160
|
+
result = terserMangle(code, {
|
|
161
|
+
filename,
|
|
162
|
+
map: rawMap,
|
|
163
|
+
compress: !isOriginal,
|
|
164
|
+
ecma: isOriginal ? 6 : 5,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
if (rawMap) {
|
|
169
|
+
rawMap.file = filename;
|
|
170
|
+
}
|
|
171
|
+
result = {
|
|
172
|
+
map: rawMap,
|
|
173
|
+
code,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
175
176
|
let mapContent;
|
|
176
177
|
if (result.map) {
|
|
177
|
-
if (!
|
|
178
|
-
result.code += `\n//# sourceMappingURL=${
|
|
178
|
+
if (!hiddenSourceMaps) {
|
|
179
|
+
result.code += `\n//# sourceMappingURL=${filename}.map`;
|
|
179
180
|
}
|
|
180
181
|
mapContent = JSON.stringify(result.map);
|
|
181
|
-
await cachePut(mapContent,
|
|
182
|
-
fs.writeFileSync(
|
|
182
|
+
await cachePut(mapContent, cacheKeys[isOriginal ? 1 /* OriginalMap */ : 3 /* DownlevelMap */]);
|
|
183
|
+
fs.writeFileSync(filepath + '.map', mapContent);
|
|
183
184
|
}
|
|
184
|
-
const fileResult = createFileEntry(
|
|
185
|
-
await cachePut(result.code,
|
|
186
|
-
fs.writeFileSync(
|
|
185
|
+
const fileResult = createFileEntry(filepath, result.code, mapContent, integrityAlgorithm);
|
|
186
|
+
await cachePut(result.code, cacheKeys[isOriginal ? 0 /* OriginalCode */ : 2 /* DownlevelCode */], fileResult.integrity);
|
|
187
|
+
fs.writeFileSync(filepath, result.code);
|
|
187
188
|
return fileResult;
|
|
188
189
|
}
|
|
189
190
|
function terserMangle(code, options = {}) {
|
|
@@ -257,38 +258,17 @@ async function processRuntime(options) {
|
|
|
257
258
|
// Adjust lazy loaded scripts to point to the proper variant
|
|
258
259
|
// Extra spacing is intentional to align source line positions
|
|
259
260
|
downlevelCode = downlevelCode.replace(/"\-es20\d{2}\./, ' "-es5.');
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
if (options.map) {
|
|
277
|
-
const rawMap = JSON.parse(options.map);
|
|
278
|
-
rawMap.file = path.basename(downlevelFilePath);
|
|
279
|
-
downlevelMap = JSON.stringify(rawMap);
|
|
280
|
-
}
|
|
281
|
-
result = {
|
|
282
|
-
original: createFileEntry(options.filename, originalCode, options.map, options.integrityAlgorithm),
|
|
283
|
-
downlevel: createFileEntry(downlevelFilePath, downlevelCode, downlevelMap, options.integrityAlgorithm),
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
if (downlevelMap) {
|
|
287
|
-
await cachePut(downlevelMap, (options.cacheKeys && options.cacheKeys[3 /* DownlevelMap */]) || null);
|
|
288
|
-
fs.writeFileSync(downlevelFilePath + '.map', downlevelMap);
|
|
289
|
-
downlevelCode += `\n//# sourceMappingURL=${path.basename(downlevelFilePath)}.map`;
|
|
290
|
-
}
|
|
291
|
-
await cachePut(downlevelCode, (options.cacheKeys && options.cacheKeys[2 /* DownlevelCode */]) || null);
|
|
292
|
-
fs.writeFileSync(downlevelFilePath, downlevelCode);
|
|
293
|
-
return result;
|
|
261
|
+
return {
|
|
262
|
+
original: await processBundle({
|
|
263
|
+
...options,
|
|
264
|
+
code: originalCode,
|
|
265
|
+
isOriginal: true,
|
|
266
|
+
}),
|
|
267
|
+
downlevel: await processBundle({
|
|
268
|
+
...options,
|
|
269
|
+
code: downlevelCode,
|
|
270
|
+
filename: options.filename.replace(/\-es20\d{2}/, '-es5'),
|
|
271
|
+
isOriginal: false,
|
|
272
|
+
}),
|
|
273
|
+
};
|
|
294
274
|
}
|