@angular-devkit/build-angular 13.0.0-next.3 → 13.0.0-next.7
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/esbuild-check.js +16 -0
- package/package.json +32 -29
- package/src/babel/plugins/adjust-static-class-members.js +2 -2
- package/src/babel/plugins/adjust-typescript-enums.js +8 -2
- package/src/babel/plugins/pure-toplevel-functions.js +2 -2
- package/src/babel/presets/application.d.ts +14 -0
- package/src/babel/presets/application.js +42 -36
- package/src/babel/webpack-loader.js +50 -5
- package/src/builders/app-shell/index.js +9 -9
- package/src/builders/browser/index.js +42 -52
- package/src/builders/dev-server/index.js +23 -23
- package/src/builders/extract-i18n/index.js +33 -21
- package/src/builders/extract-i18n/ivy-extract-loader.js +34 -8
- package/src/builders/karma/find-tests.js +5 -5
- package/src/builders/karma/index.js +14 -14
- package/src/builders/ng-packagr/index.js +4 -4
- package/src/builders/protractor/index.js +4 -4
- package/src/builders/server/index.js +16 -16
- package/src/sass/worker.js +2 -2
- package/src/utils/build-browser-features.js +2 -2
- package/src/utils/build-options.d.ts +1 -1
- package/src/utils/bundle-calculator.js +4 -4
- package/src/utils/cache-path.js +2 -2
- package/src/utils/check-port.js +1 -1
- package/src/utils/color.js +25 -2
- package/src/utils/copy-assets.js +1 -1
- package/src/utils/delete-output-dir.js +1 -1
- package/src/utils/i18n-inlining.js +1 -1
- package/src/utils/i18n-options.js +26 -50
- package/src/utils/index-file/augment-index-html.js +2 -2
- package/src/utils/index-file/index-html-generator.js +3 -3
- package/src/utils/index-file/inline-fonts.js +4 -4
- package/src/utils/load-esm.d.ts +22 -0
- package/src/utils/load-esm.js +37 -0
- package/src/utils/load-translations.js +21 -8
- package/src/utils/normalize-asset-patterns.js +8 -8
- package/src/utils/normalize-builder-schema.js +4 -4
- package/src/utils/normalize-file-replacements.js +10 -10
- package/src/utils/output-paths.js +3 -3
- package/src/utils/package-chunk-sort.js +1 -1
- package/src/utils/process-bundle.d.ts +0 -1
- package/src/utils/process-bundle.js +44 -12
- package/src/utils/read-tsconfig.d.ts +2 -2
- package/src/utils/read-tsconfig.js +11 -6
- package/src/utils/run-module-as-observable-fork.js +2 -2
- package/src/utils/service-worker.js +16 -9
- package/src/utils/spinner.js +2 -2
- package/src/utils/version.js +1 -1
- package/src/utils/webpack-browser-config.d.ts +4 -3
- package/src/utils/webpack-browser-config.js +12 -11
- package/src/webpack/configs/browser.js +1 -1
- package/src/webpack/configs/common.d.ts +1 -1
- package/src/webpack/configs/common.js +24 -16
- package/src/webpack/configs/dev-server.d.ts +1 -1
- package/src/webpack/configs/dev-server.js +22 -10
- package/src/webpack/configs/server.js +2 -2
- package/src/webpack/configs/styles.js +4 -4
- package/src/webpack/configs/test.js +2 -2
- package/src/webpack/configs/typescript.js +1 -1
- package/src/webpack/configs/worker.js +1 -1
- package/src/webpack/plugins/any-component-style-budget-checker.js +4 -4
- package/src/webpack/plugins/common-js-usage-warn-plugin.js +2 -2
- package/src/webpack/plugins/css-optimizer-plugin.d.ts +12 -0
- package/src/webpack/plugins/css-optimizer-plugin.js +43 -17
- package/src/webpack/plugins/dedupe-module-resolve-plugin.js +1 -1
- package/src/webpack/plugins/esbuild-executor.d.ts +46 -0
- package/src/webpack/plugins/esbuild-executor.js +126 -0
- package/src/webpack/plugins/hmr/hmr-accept.js +3 -3
- package/src/webpack/plugins/hmr/hmr-loader.js +1 -1
- package/src/webpack/plugins/index-html-webpack-plugin.js +6 -6
- package/src/webpack/plugins/javascript-optimizer-plugin.js +5 -0
- package/src/webpack/plugins/javascript-optimizer-worker.d.ts +42 -0
- package/src/webpack/plugins/javascript-optimizer-worker.js +63 -27
- package/src/webpack/plugins/karma/karma.js +4 -4
- package/src/webpack/plugins/postcss-cli-resources.js +1 -1
- package/src/webpack/plugins/scripts-webpack-plugin.js +1 -1
- package/src/webpack/plugins/single-test-transform.js +1 -1
- package/src/webpack/utils/stats.js +6 -6
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.EsbuildExecutor = void 0;
|
|
30
|
+
const child_process_1 = require("child_process");
|
|
31
|
+
const path = __importStar(require("path"));
|
|
32
|
+
/**
|
|
33
|
+
* Provides the ability to execute esbuild regardless of the current platform's support
|
|
34
|
+
* for using the native variant of esbuild. The native variant will be preferred (assuming
|
|
35
|
+
* the `alwaysUseWasm` constructor option is `false) due to its inherent performance advantages.
|
|
36
|
+
* At first use of esbuild, a supportability test will be automatically performed and the
|
|
37
|
+
* WASM-variant will be used if needed by the platform.
|
|
38
|
+
*/
|
|
39
|
+
class EsbuildExecutor {
|
|
40
|
+
/**
|
|
41
|
+
* Constructs an instance of the `EsbuildExecutor` class.
|
|
42
|
+
*
|
|
43
|
+
* @param alwaysUseWasm If true, the WASM-variant will be preferred and no support test will be
|
|
44
|
+
* performed; if false (default), the native variant will be preferred.
|
|
45
|
+
*/
|
|
46
|
+
constructor(alwaysUseWasm = false) {
|
|
47
|
+
this.alwaysUseWasm = alwaysUseWasm;
|
|
48
|
+
this.initialized = false;
|
|
49
|
+
this.esbuildTransform = this.esbuildFormatMessages = () => {
|
|
50
|
+
throw new Error('esbuild implementation missing');
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Determines whether the native variant of esbuild can be used on the current platform.
|
|
55
|
+
*
|
|
56
|
+
* @returns True, if the native variant of esbuild is support; False, if the WASM variant is required.
|
|
57
|
+
*/
|
|
58
|
+
static hasNativeSupport() {
|
|
59
|
+
// Try to use native variant to ensure it is functional for the platform.
|
|
60
|
+
// Spawning a separate esbuild check process is used to determine if the native
|
|
61
|
+
// variant is viable. If check fails, the WASM variant is initialized instead.
|
|
62
|
+
// Attempting to call one of the native esbuild functions is not a viable test
|
|
63
|
+
// currently since esbuild spawn errors are currently not propagated through the
|
|
64
|
+
// call stack for the esbuild function. If this limitation is removed in the future
|
|
65
|
+
// then the separate process spawn check can be removed in favor of a direct function
|
|
66
|
+
// call check.
|
|
67
|
+
try {
|
|
68
|
+
const { status, error } = (0, child_process_1.spawnSync)(process.execPath, [
|
|
69
|
+
path.join(__dirname, '../../../esbuild-check.js'),
|
|
70
|
+
]);
|
|
71
|
+
return status === 0 && error === undefined;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Initializes the esbuild transform and format messages functions.
|
|
79
|
+
*
|
|
80
|
+
* @returns A promise that fulfills when esbuild has been loaded and available for use.
|
|
81
|
+
*/
|
|
82
|
+
async ensureEsbuild() {
|
|
83
|
+
if (this.initialized) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
// If the WASM variant was preferred at class construction or native is not supported, use WASM
|
|
87
|
+
if (this.alwaysUseWasm || !EsbuildExecutor.hasNativeSupport()) {
|
|
88
|
+
await this.useWasm();
|
|
89
|
+
this.initialized = true;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
// Use the faster native variant if available.
|
|
94
|
+
const { transform, formatMessages } = await Promise.resolve().then(() => __importStar(require('esbuild')));
|
|
95
|
+
this.esbuildTransform = transform;
|
|
96
|
+
this.esbuildFormatMessages = formatMessages;
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// If the native variant is not installed then use the WASM-based variant
|
|
100
|
+
await this.useWasm();
|
|
101
|
+
}
|
|
102
|
+
this.initialized = true;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Transitions an executor instance to use the WASM-variant of esbuild.
|
|
106
|
+
*/
|
|
107
|
+
async useWasm() {
|
|
108
|
+
const { transform, formatMessages } = await Promise.resolve().then(() => __importStar(require('esbuild-wasm')));
|
|
109
|
+
this.esbuildTransform = transform;
|
|
110
|
+
this.esbuildFormatMessages = formatMessages;
|
|
111
|
+
// The ESBUILD_BINARY_PATH environment variable cannot exist when attempting to use the
|
|
112
|
+
// WASM variant. If it is then the binary located at the specified path will be used instead
|
|
113
|
+
// of the WASM variant.
|
|
114
|
+
delete process.env.ESBUILD_BINARY_PATH;
|
|
115
|
+
this.alwaysUseWasm = true;
|
|
116
|
+
}
|
|
117
|
+
async transform(input, options) {
|
|
118
|
+
await this.ensureEsbuild();
|
|
119
|
+
return this.esbuildTransform(input, options);
|
|
120
|
+
}
|
|
121
|
+
async formatMessages(messages, options) {
|
|
122
|
+
await this.ensureEsbuild();
|
|
123
|
+
return this.esbuildFormatMessages(messages, options);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.EsbuildExecutor = EsbuildExecutor;
|
|
@@ -14,7 +14,7 @@ function default_1(mod) {
|
|
|
14
14
|
if (!mod['hot']) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
|
-
if (!core_1.isDevMode()) {
|
|
17
|
+
if (!(0, core_1.isDevMode)()) {
|
|
18
18
|
console.error(`[NG HMR] Cannot use HMR when Angular is running in production mode. To prevent production mode, do not call 'enableProdMode()'.`);
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
@@ -29,7 +29,7 @@ function default_1(mod) {
|
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
// Reset JIT compiled components cache
|
|
32
|
-
core_1.ɵresetCompiledComponents();
|
|
32
|
+
(0, core_1.ɵresetCompiledComponents)();
|
|
33
33
|
const appRoot = getAppRoot();
|
|
34
34
|
if (!appRoot) {
|
|
35
35
|
return;
|
|
@@ -72,7 +72,7 @@ function default_1(mod) {
|
|
|
72
72
|
}
|
|
73
73
|
// Wait until the application isStable to restore the form values
|
|
74
74
|
newAppRef.isStable
|
|
75
|
-
.pipe(operators_1.filter((isStable) => !!isStable), operators_1.take(1))
|
|
75
|
+
.pipe((0, operators_1.filter)((isStable) => !!isStable), (0, operators_1.take)(1))
|
|
76
76
|
.subscribe(() => restoreFormValues(oldInputs, oldOptions));
|
|
77
77
|
}).observe(bodyElement, {
|
|
78
78
|
attributes: true,
|
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.HmrLoader = void 0;
|
|
11
11
|
const path_1 = require("path");
|
|
12
12
|
exports.HmrLoader = __filename;
|
|
13
|
-
const hmrAcceptPath = path_1.join(__dirname, './hmr-accept.js').replace(/\\/g, '/');
|
|
13
|
+
const hmrAcceptPath = (0, path_1.join)(__dirname, './hmr-accept.js').replace(/\\/g, '/');
|
|
14
14
|
function default_1(content,
|
|
15
15
|
// Source map types are broken in the webpack type definitions
|
|
16
16
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -43,27 +43,27 @@ class IndexHtmlWebpackPlugin extends index_html_generator_1.IndexHtmlGenerator {
|
|
|
43
43
|
files.push({
|
|
44
44
|
name: chunk.name,
|
|
45
45
|
file,
|
|
46
|
-
extension: path_1.extname(file),
|
|
46
|
+
extension: (0, path_1.extname)(file),
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
const { content, warnings, errors } = await this.process({
|
|
51
51
|
files,
|
|
52
|
-
outputPath: path_1.dirname(this.options.outputPath),
|
|
52
|
+
outputPath: (0, path_1.dirname)(this.options.outputPath),
|
|
53
53
|
baseHref: this.options.baseHref,
|
|
54
54
|
lang: this.options.lang,
|
|
55
55
|
});
|
|
56
56
|
assets[this.options.outputPath] = new webpack_1.sources.RawSource(content);
|
|
57
|
-
warnings.forEach((msg) => webpack_diagnostics_1.addWarning(this.compilation, msg));
|
|
58
|
-
errors.forEach((msg) => webpack_diagnostics_1.addError(this.compilation, msg));
|
|
57
|
+
warnings.forEach((msg) => (0, webpack_diagnostics_1.addWarning)(this.compilation, msg));
|
|
58
|
+
errors.forEach((msg) => (0, webpack_diagnostics_1.addError)(this.compilation, msg));
|
|
59
59
|
}
|
|
60
60
|
catch (error) {
|
|
61
|
-
webpack_diagnostics_1.addError(this.compilation, error.message);
|
|
61
|
+
(0, webpack_diagnostics_1.addError)(this.compilation, error.message);
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
async readAsset(path) {
|
|
66
|
-
const data = this.compilation.assets[path_1.basename(path)].source();
|
|
66
|
+
const data = this.compilation.assets[(0, path_1.basename)(path)].source();
|
|
67
67
|
return typeof data === 'string' ? data : data.toString();
|
|
68
68
|
}
|
|
69
69
|
async readIndex(path) {
|
|
@@ -14,6 +14,7 @@ exports.JavaScriptOptimizerPlugin = void 0;
|
|
|
14
14
|
const piscina_1 = __importDefault(require("piscina"));
|
|
15
15
|
const typescript_1 = require("typescript");
|
|
16
16
|
const environment_options_1 = require("../../utils/environment-options");
|
|
17
|
+
const esbuild_executor_1 = require("./esbuild-executor");
|
|
17
18
|
/**
|
|
18
19
|
* The maximum number of Workers that will be created to execute optimize tasks.
|
|
19
20
|
*/
|
|
@@ -105,6 +106,10 @@ class JavaScriptOptimizerPlugin {
|
|
|
105
106
|
target,
|
|
106
107
|
removeLicenses: this.options.removeLicenses,
|
|
107
108
|
advanced: this.options.advanced,
|
|
109
|
+
// Perform a single native esbuild support check.
|
|
110
|
+
// This removes the need for each worker to perform the check which would
|
|
111
|
+
// otherwise require spawning a separate process per worker.
|
|
112
|
+
alwaysUseWasm: !esbuild_executor_1.EsbuildExecutor.hasNativeSupport(),
|
|
108
113
|
};
|
|
109
114
|
// Sort scripts so larger scripts start first - worker pool uses a FIFO queue
|
|
110
115
|
scriptsToOptimize.sort((a, b) => a.code.length - b.code.length);
|
|
@@ -13,22 +13,64 @@ interface OptimizeRequest {
|
|
|
13
13
|
* The options to use when optimizing.
|
|
14
14
|
*/
|
|
15
15
|
options: {
|
|
16
|
+
/**
|
|
17
|
+
* Controls advanced optimizations.
|
|
18
|
+
* Currently these are only terser related:
|
|
19
|
+
* * terser compress passes are set to 2
|
|
20
|
+
* * terser pure_getters option is enabled
|
|
21
|
+
*/
|
|
16
22
|
advanced: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Specifies the string tokens that should be replaced with a defined value.
|
|
25
|
+
*/
|
|
17
26
|
define?: Record<string, string>;
|
|
27
|
+
/**
|
|
28
|
+
* Controls whether class, function, and variable names should be left intact
|
|
29
|
+
* throughout the output code.
|
|
30
|
+
*/
|
|
18
31
|
keepNames: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Controls whether license text is removed from the output code.
|
|
34
|
+
* Within the CLI, this option is linked to the license extraction functionality.
|
|
35
|
+
*/
|
|
19
36
|
removeLicenses: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Controls whether source maps should be generated.
|
|
39
|
+
*/
|
|
20
40
|
sourcemap: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Specifies the target ECMAScript version for the output code.
|
|
43
|
+
*/
|
|
21
44
|
target: 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020;
|
|
45
|
+
/**
|
|
46
|
+
* Controls whether esbuild should only use the WASM-variant instead of trying to
|
|
47
|
+
* use the native variant. Some platforms may not support the native-variant and
|
|
48
|
+
* this option allows one support test to be conducted prior to all the workers starting.
|
|
49
|
+
*/
|
|
50
|
+
alwaysUseWasm: boolean;
|
|
22
51
|
};
|
|
23
52
|
/**
|
|
24
53
|
* The JavaScript asset to optimize.
|
|
25
54
|
*/
|
|
26
55
|
asset: {
|
|
56
|
+
/**
|
|
57
|
+
* The name of the JavaScript asset (typically the filename).
|
|
58
|
+
*/
|
|
27
59
|
name: string;
|
|
60
|
+
/**
|
|
61
|
+
* The source content of the JavaScript asset.
|
|
62
|
+
*/
|
|
28
63
|
code: string;
|
|
64
|
+
/**
|
|
65
|
+
* The source map of the JavaScript asset, if available.
|
|
66
|
+
* This map is merged with all intermediate source maps during optimization.
|
|
67
|
+
*/
|
|
29
68
|
map: object;
|
|
30
69
|
};
|
|
31
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Handles optimization requests sent from the main thread via the `JavaScriptOptimizerPlugin`.
|
|
73
|
+
*/
|
|
32
74
|
export default function ({ asset, options }: OptimizeRequest): Promise<{
|
|
33
75
|
name: string;
|
|
34
76
|
code: string;
|
|
@@ -11,21 +11,63 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
const remapping_1 = __importDefault(require("@ampproject/remapping"));
|
|
14
|
-
const esbuild_1 = require("esbuild");
|
|
15
14
|
const terser_1 = require("terser");
|
|
15
|
+
const esbuild_executor_1 = require("./esbuild-executor");
|
|
16
|
+
/**
|
|
17
|
+
* The cached esbuild executor.
|
|
18
|
+
* This will automatically use the native or WASM version based on platform and availability
|
|
19
|
+
* with the native version given priority due to its superior performance.
|
|
20
|
+
*/
|
|
21
|
+
let esbuild;
|
|
22
|
+
/**
|
|
23
|
+
* Handles optimization requests sent from the main thread via the `JavaScriptOptimizerPlugin`.
|
|
24
|
+
*/
|
|
16
25
|
async function default_1({ asset, options }) {
|
|
17
|
-
var _a;
|
|
18
26
|
// esbuild is used as a first pass
|
|
19
|
-
|
|
27
|
+
const esbuildResult = await optimizeWithEsbuild(asset.code, asset.name, options);
|
|
28
|
+
// terser is used as a second pass
|
|
29
|
+
const terserResult = await optimizeWithTerser(asset.name, esbuildResult.code, options.sourcemap, options.target, options.advanced);
|
|
30
|
+
// Merge intermediate sourcemaps with input sourcemap if enabled
|
|
31
|
+
let fullSourcemap;
|
|
32
|
+
if (options.sourcemap) {
|
|
33
|
+
const partialSourcemaps = [];
|
|
34
|
+
if (esbuildResult.map) {
|
|
35
|
+
partialSourcemaps.unshift(JSON.parse(esbuildResult.map));
|
|
36
|
+
}
|
|
37
|
+
if (terserResult.map) {
|
|
38
|
+
partialSourcemaps.unshift(terserResult.map);
|
|
39
|
+
}
|
|
40
|
+
if (asset.map) {
|
|
41
|
+
partialSourcemaps.push(asset.map);
|
|
42
|
+
}
|
|
43
|
+
fullSourcemap = (0, remapping_1.default)(partialSourcemaps, () => null);
|
|
44
|
+
}
|
|
45
|
+
return { name: asset.name, code: terserResult.code, map: fullSourcemap };
|
|
46
|
+
}
|
|
47
|
+
exports.default = default_1;
|
|
48
|
+
/**
|
|
49
|
+
* Optimizes a JavaScript asset using esbuild.
|
|
50
|
+
*
|
|
51
|
+
* @param content The JavaScript asset source content to optimize.
|
|
52
|
+
* @param name The name of the JavaScript asset. Used to generate source maps.
|
|
53
|
+
* @param options The optimization request options to apply to the content.
|
|
54
|
+
* @returns A promise that resolves with the optimized code, source map, and any warnings.
|
|
55
|
+
*/
|
|
56
|
+
async function optimizeWithEsbuild(content, name, options) {
|
|
57
|
+
var _a;
|
|
58
|
+
if (!esbuild) {
|
|
59
|
+
esbuild = new esbuild_executor_1.EsbuildExecutor(options.alwaysUseWasm);
|
|
60
|
+
}
|
|
61
|
+
let result;
|
|
20
62
|
try {
|
|
21
|
-
|
|
63
|
+
result = await esbuild.transform(content, {
|
|
22
64
|
minifyIdentifiers: !options.keepNames,
|
|
23
65
|
minifySyntax: true,
|
|
24
66
|
// NOTE: Disabling whitespace ensures unused pure annotations are kept
|
|
25
67
|
minifyWhitespace: false,
|
|
26
68
|
pure: ['forwardRef'],
|
|
27
69
|
legalComments: options.removeLicenses ? 'none' : 'inline',
|
|
28
|
-
sourcefile:
|
|
70
|
+
sourcefile: name,
|
|
29
71
|
sourcemap: options.sourcemap && 'external',
|
|
30
72
|
define: options.define,
|
|
31
73
|
keepNames: options.keepNames,
|
|
@@ -40,36 +82,30 @@ async function default_1({ asset, options }) {
|
|
|
40
82
|
// this is and has been considered a configuration issue. Global scripts must be compatible with
|
|
41
83
|
// the target environment.
|
|
42
84
|
if ((_a = failure.errors) === null || _a === void 0 ? void 0 : _a.every((error) => error.text.includes('to the configured target environment ("es5") is not supported yet'))) {
|
|
43
|
-
|
|
44
|
-
code:
|
|
85
|
+
result = {
|
|
86
|
+
code: content,
|
|
87
|
+
map: '',
|
|
88
|
+
warnings: [],
|
|
45
89
|
};
|
|
46
90
|
}
|
|
47
91
|
else {
|
|
48
92
|
throw error;
|
|
49
93
|
}
|
|
50
94
|
}
|
|
51
|
-
|
|
52
|
-
const terserResult = await optimizeWithTerser(asset.name, esbuildResult.code, options.sourcemap, options.target, options.advanced);
|
|
53
|
-
// Merge intermediate sourcemaps with input sourcemap if enabled
|
|
54
|
-
let fullSourcemap;
|
|
55
|
-
if (options.sourcemap) {
|
|
56
|
-
const partialSourcemaps = [];
|
|
57
|
-
if (esbuildResult.map) {
|
|
58
|
-
partialSourcemaps.unshift(JSON.parse(esbuildResult.map));
|
|
59
|
-
}
|
|
60
|
-
if (terserResult.map) {
|
|
61
|
-
partialSourcemaps.unshift(terserResult.map);
|
|
62
|
-
}
|
|
63
|
-
if (asset.map) {
|
|
64
|
-
partialSourcemaps.push(asset.map);
|
|
65
|
-
}
|
|
66
|
-
fullSourcemap = remapping_1.default(partialSourcemaps, () => null);
|
|
67
|
-
}
|
|
68
|
-
return { name: asset.name, code: terserResult.code, map: fullSourcemap };
|
|
95
|
+
return result;
|
|
69
96
|
}
|
|
70
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Optimizes a JavaScript asset using terser.
|
|
99
|
+
*
|
|
100
|
+
* @param name The name of the JavaScript asset. Used to generate source maps.
|
|
101
|
+
* @param code The JavaScript asset source content to optimize.
|
|
102
|
+
* @param sourcemaps If true, generate an output source map for the optimized code.
|
|
103
|
+
* @param target Specifies the target ECMAScript version for the output code.
|
|
104
|
+
* @param advanced Controls advanced optimizations.
|
|
105
|
+
* @returns A promise that resolves with the optimized code and source map.
|
|
106
|
+
*/
|
|
71
107
|
async function optimizeWithTerser(name, code, sourcemaps, target, advanced) {
|
|
72
|
-
const result = await terser_1.minify({ [name]: code }, {
|
|
108
|
+
const result = await (0, terser_1.minify)({ [name]: code }, {
|
|
73
109
|
compress: {
|
|
74
110
|
passes: advanced ? 2 : 1,
|
|
75
111
|
pure_getters: advanced,
|
|
@@ -69,11 +69,11 @@ const init = (config, emitter) => {
|
|
|
69
69
|
` be used from within Angular CLI and will not work correctly outside of it.`);
|
|
70
70
|
}
|
|
71
71
|
const options = config.buildWebpack.options;
|
|
72
|
-
const logger = config.buildWebpack.logger || node_1.createConsoleLogger();
|
|
72
|
+
const logger = config.buildWebpack.logger || (0, node_1.createConsoleLogger)();
|
|
73
73
|
successCb = config.buildWebpack.successCb;
|
|
74
74
|
failureCb = config.buildWebpack.failureCb;
|
|
75
75
|
// Add a reporter that fixes sourcemap urls.
|
|
76
|
-
if (index_1.normalizeSourceMaps(options.sourceMap).scripts) {
|
|
76
|
+
if ((0, index_1.normalizeSourceMaps)(options.sourceMap).scripts) {
|
|
77
77
|
config.reporters.unshift('@angular-devkit/build-angular--sourcemap-reporter');
|
|
78
78
|
// Code taken from https://github.com/tschaub/karma-source-map-support.
|
|
79
79
|
// We can't use it directly because we need to add it conditionally in this file, and karma
|
|
@@ -124,7 +124,7 @@ const init = (config, emitter) => {
|
|
|
124
124
|
// Files need to be served from a custom path for Karma.
|
|
125
125
|
webpackConfig.output.path = `/${KARMA_APPLICATION_PATH}/`;
|
|
126
126
|
webpackConfig.output.publicPath = `/${KARMA_APPLICATION_PATH}/`;
|
|
127
|
-
const compiler = webpack_1.default(webpackConfig, (error, stats) => {
|
|
127
|
+
const compiler = (0, webpack_1.default)(webpackConfig, (error, stats) => {
|
|
128
128
|
var _a;
|
|
129
129
|
if (error) {
|
|
130
130
|
throw error;
|
|
@@ -137,7 +137,7 @@ const init = (config, emitter) => {
|
|
|
137
137
|
errors: true,
|
|
138
138
|
warnings: true,
|
|
139
139
|
});
|
|
140
|
-
logger.error(stats_1.statsErrorsToString(statsJson, { colors: true }));
|
|
140
|
+
logger.error((0, stats_1.statsErrorsToString)(statsJson, { colors: true }));
|
|
141
141
|
// Notify potential listeners of the compile error.
|
|
142
142
|
emitter.emit('compile_error', {
|
|
143
143
|
errors: (_a = statsJson.errors) === null || _a === void 0 ? void 0 : _a.map((e) => e.message),
|
|
@@ -93,7 +93,7 @@ function default_1(options) {
|
|
|
93
93
|
reject(err);
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
|
-
let outputPath = loader_utils_1.interpolateName({ resourcePath: result }, filename(result), {
|
|
96
|
+
let outputPath = (0, loader_utils_1.interpolateName)({ resourcePath: result }, filename(result), {
|
|
97
97
|
content,
|
|
98
98
|
context: loader.context || loader.rootContext,
|
|
99
99
|
}).replace(/\\|\//g, '-');
|
|
@@ -125,7 +125,7 @@ class ScriptsWebpackPlugin {
|
|
|
125
125
|
concatSource.add('\n;');
|
|
126
126
|
});
|
|
127
127
|
const combinedSource = new webpack_1.sources.CachedSource(concatSource);
|
|
128
|
-
const filename = loader_utils_1.interpolateName({ resourcePath: 'scripts.js' }, this.options.filename, {
|
|
128
|
+
const filename = (0, loader_utils_1.interpolateName)({ resourcePath: 'scripts.js' }, this.options.filename, {
|
|
129
129
|
content: combinedSource.source(),
|
|
130
130
|
});
|
|
131
131
|
const output = { filename, source: combinedSource };
|
|
@@ -35,7 +35,7 @@ function loader(source) {
|
|
|
35
35
|
return source;
|
|
36
36
|
}
|
|
37
37
|
const targettedImports = files
|
|
38
|
-
.map((path) => `require('./${path.replace('.' + path_1.extname(path), '')}');`)
|
|
38
|
+
.map((path) => `require('./${path.replace('.' + (0, path_1.extname)(path), '')}');`)
|
|
39
39
|
.join('\n');
|
|
40
40
|
const mockedRequireContext = 'Object.assign(() => { }, { keys: () => [], resolve: () => undefined });\n';
|
|
41
41
|
source = source.replace(/require\.context\(.*/, mockedRequireContext + targettedImports);
|
|
@@ -103,9 +103,9 @@ function generateBuildStatsTable(data, colors, showTotalSize) {
|
|
|
103
103
|
if (changedLazyChunksStats.length) {
|
|
104
104
|
bundleInfo.push(['Lazy Chunk Files', 'Names', 'Size'].map(bold), ...changedLazyChunksStats);
|
|
105
105
|
}
|
|
106
|
-
return text_table_1.default(bundleInfo, {
|
|
106
|
+
return (0, text_table_1.default)(bundleInfo, {
|
|
107
107
|
hsep: dim(' | '),
|
|
108
|
-
stringLength: (s) => color_1.removeColor(s).length,
|
|
108
|
+
stringLength: (s) => (0, color_1.removeColor)(s).length,
|
|
109
109
|
align: ['l', 'l', 'r'],
|
|
110
110
|
});
|
|
111
111
|
}
|
|
@@ -259,17 +259,17 @@ exports.statsHasWarnings = statsHasWarnings;
|
|
|
259
259
|
function createWebpackLoggingCallback(options, logger) {
|
|
260
260
|
const { verbose = false, scripts = [], styles = [] } = options;
|
|
261
261
|
const extraEntryPoints = [
|
|
262
|
-
...helpers_1.normalizeExtraEntryPoints(styles, 'styles'),
|
|
263
|
-
...helpers_1.normalizeExtraEntryPoints(scripts, 'scripts'),
|
|
262
|
+
...(0, helpers_1.normalizeExtraEntryPoints)(styles, 'styles'),
|
|
263
|
+
...(0, helpers_1.normalizeExtraEntryPoints)(scripts, 'scripts'),
|
|
264
264
|
];
|
|
265
265
|
return (stats, config) => {
|
|
266
266
|
if (verbose) {
|
|
267
267
|
logger.info(stats.toString(config.stats));
|
|
268
268
|
}
|
|
269
|
-
const rawStats = stats.toJson(stats_1.getWebpackStatsConfig(false));
|
|
269
|
+
const rawStats = stats.toJson((0, stats_1.getWebpackStatsConfig)(false));
|
|
270
270
|
const webpackStats = {
|
|
271
271
|
...rawStats,
|
|
272
|
-
chunks: async_chunks_1.markAsyncChunksNonInitial(rawStats, extraEntryPoints),
|
|
272
|
+
chunks: (0, async_chunks_1.markAsyncChunksNonInitial)(rawStats, extraEntryPoints),
|
|
273
273
|
};
|
|
274
274
|
webpackStatsLogger(logger, webpackStats, config);
|
|
275
275
|
};
|