@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
|
@@ -18,16 +18,16 @@ class MissingAssetSourceRootException extends core_1.BaseException {
|
|
|
18
18
|
exports.MissingAssetSourceRootException = MissingAssetSourceRootException;
|
|
19
19
|
function normalizeAssetPatterns(assetPatterns, root, projectRoot, maybeSourceRoot) {
|
|
20
20
|
// When sourceRoot is not available, we default to ${projectRoot}/src.
|
|
21
|
-
const sourceRoot = maybeSourceRoot || core_1.join(projectRoot, 'src');
|
|
22
|
-
const resolvedSourceRoot = core_1.resolve(root, sourceRoot);
|
|
21
|
+
const sourceRoot = maybeSourceRoot || (0, core_1.join)(projectRoot, 'src');
|
|
22
|
+
const resolvedSourceRoot = (0, core_1.resolve)(root, sourceRoot);
|
|
23
23
|
if (assetPatterns.length === 0) {
|
|
24
24
|
return [];
|
|
25
25
|
}
|
|
26
26
|
return assetPatterns.map((assetPattern) => {
|
|
27
27
|
// Normalize string asset patterns to objects.
|
|
28
28
|
if (typeof assetPattern === 'string') {
|
|
29
|
-
const assetPath = core_1.normalize(assetPattern);
|
|
30
|
-
const resolvedAssetPath = core_1.resolve(root, assetPath);
|
|
29
|
+
const assetPath = (0, core_1.normalize)(assetPattern);
|
|
30
|
+
const resolvedAssetPath = (0, core_1.resolve)(root, assetPath);
|
|
31
31
|
// Check if the string asset is within sourceRoot.
|
|
32
32
|
if (!resolvedAssetPath.startsWith(resolvedSourceRoot)) {
|
|
33
33
|
throw new MissingAssetSourceRootException(assetPattern);
|
|
@@ -35,7 +35,7 @@ function normalizeAssetPatterns(assetPatterns, root, projectRoot, maybeSourceRoo
|
|
|
35
35
|
let glob, input;
|
|
36
36
|
let isDirectory = false;
|
|
37
37
|
try {
|
|
38
|
-
isDirectory = fs_1.statSync(core_1.getSystemPath(resolvedAssetPath)).isDirectory();
|
|
38
|
+
isDirectory = (0, fs_1.statSync)((0, core_1.getSystemPath)(resolvedAssetPath)).isDirectory();
|
|
39
39
|
}
|
|
40
40
|
catch {
|
|
41
41
|
isDirectory = true;
|
|
@@ -48,12 +48,12 @@ function normalizeAssetPatterns(assetPatterns, root, projectRoot, maybeSourceRoo
|
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
50
|
// Files are their own glob.
|
|
51
|
-
glob = core_1.basename(assetPath);
|
|
51
|
+
glob = (0, core_1.basename)(assetPath);
|
|
52
52
|
// Input directory is their original dirname.
|
|
53
|
-
input = core_1.dirname(assetPath);
|
|
53
|
+
input = (0, core_1.dirname)(assetPath);
|
|
54
54
|
}
|
|
55
55
|
// Output directory for both is the relative path from source root to input.
|
|
56
|
-
const output = core_1.relative(resolvedSourceRoot, core_1.resolve(root, input));
|
|
56
|
+
const output = (0, core_1.relative)(resolvedSourceRoot, (0, core_1.resolve)(root, input));
|
|
57
57
|
// Return the asset pattern in object format.
|
|
58
58
|
return { glob, input, output };
|
|
59
59
|
}
|
|
@@ -13,12 +13,12 @@ const normalize_file_replacements_1 = require("./normalize-file-replacements");
|
|
|
13
13
|
const normalize_optimization_1 = require("./normalize-optimization");
|
|
14
14
|
const normalize_source_maps_1 = require("./normalize-source-maps");
|
|
15
15
|
function normalizeBrowserSchema(root, projectRoot, sourceRoot, options) {
|
|
16
|
-
const normalizedSourceMapOptions = normalize_source_maps_1.normalizeSourceMaps(options.sourceMap || false);
|
|
16
|
+
const normalizedSourceMapOptions = (0, normalize_source_maps_1.normalizeSourceMaps)(options.sourceMap || false);
|
|
17
17
|
return {
|
|
18
18
|
...options,
|
|
19
|
-
assets: normalize_asset_patterns_1.normalizeAssetPatterns(options.assets || [], root, projectRoot, sourceRoot),
|
|
20
|
-
fileReplacements: normalize_file_replacements_1.normalizeFileReplacements(options.fileReplacements || [], root),
|
|
21
|
-
optimization: normalize_optimization_1.normalizeOptimization(options.optimization),
|
|
19
|
+
assets: (0, normalize_asset_patterns_1.normalizeAssetPatterns)(options.assets || [], root, projectRoot, sourceRoot),
|
|
20
|
+
fileReplacements: (0, normalize_file_replacements_1.normalizeFileReplacements)(options.fileReplacements || [], root),
|
|
21
|
+
optimization: (0, normalize_optimization_1.normalizeOptimization)(options.optimization),
|
|
22
22
|
sourceMap: normalizedSourceMapOptions,
|
|
23
23
|
preserveSymlinks: options.preserveSymlinks === undefined
|
|
24
24
|
? process.execArgv.includes('--preserve-symlinks')
|
|
@@ -22,11 +22,11 @@ function normalizeFileReplacements(fileReplacements, root) {
|
|
|
22
22
|
}
|
|
23
23
|
const normalizedReplacement = fileReplacements.map((replacement) => normalizeFileReplacement(replacement, root));
|
|
24
24
|
for (const { replace, with: replacementWith } of normalizedReplacement) {
|
|
25
|
-
if (!fs_1.existsSync(core_1.getSystemPath(replacementWith))) {
|
|
26
|
-
throw new MissingFileReplacementException(core_1.getSystemPath(replacementWith));
|
|
25
|
+
if (!(0, fs_1.existsSync)((0, core_1.getSystemPath)(replacementWith))) {
|
|
26
|
+
throw new MissingFileReplacementException((0, core_1.getSystemPath)(replacementWith));
|
|
27
27
|
}
|
|
28
|
-
if (!fs_1.existsSync(core_1.getSystemPath(replace))) {
|
|
29
|
-
throw new MissingFileReplacementException(core_1.getSystemPath(replace));
|
|
28
|
+
if (!(0, fs_1.existsSync)((0, core_1.getSystemPath)(replace))) {
|
|
29
|
+
throw new MissingFileReplacementException((0, core_1.getSystemPath)(replace));
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
return normalizedReplacement;
|
|
@@ -36,22 +36,22 @@ function normalizeFileReplacement(fileReplacement, root) {
|
|
|
36
36
|
let replacePath;
|
|
37
37
|
let withPath;
|
|
38
38
|
if (fileReplacement.src && fileReplacement.replaceWith) {
|
|
39
|
-
replacePath = core_1.normalize(fileReplacement.src);
|
|
40
|
-
withPath = core_1.normalize(fileReplacement.replaceWith);
|
|
39
|
+
replacePath = (0, core_1.normalize)(fileReplacement.src);
|
|
40
|
+
withPath = (0, core_1.normalize)(fileReplacement.replaceWith);
|
|
41
41
|
}
|
|
42
42
|
else if (fileReplacement.replace && fileReplacement.with) {
|
|
43
|
-
replacePath = core_1.normalize(fileReplacement.replace);
|
|
44
|
-
withPath = core_1.normalize(fileReplacement.with);
|
|
43
|
+
replacePath = (0, core_1.normalize)(fileReplacement.replace);
|
|
44
|
+
withPath = (0, core_1.normalize)(fileReplacement.with);
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
47
|
throw new Error(`Invalid file replacement: ${JSON.stringify(fileReplacement)}`);
|
|
48
48
|
}
|
|
49
49
|
// TODO: For 7.x should this only happen if not absolute?
|
|
50
50
|
if (root) {
|
|
51
|
-
replacePath = core_1.join(root, replacePath);
|
|
51
|
+
replacePath = (0, core_1.join)(root, replacePath);
|
|
52
52
|
}
|
|
53
53
|
if (root) {
|
|
54
|
-
withPath = core_1.join(root, withPath);
|
|
54
|
+
withPath = (0, core_1.join)(root, withPath);
|
|
55
55
|
}
|
|
56
56
|
return { replace: replacePath, with: withPath };
|
|
57
57
|
}
|
|
@@ -14,12 +14,12 @@ function ensureOutputPaths(baseOutputPath, i18n) {
|
|
|
14
14
|
const outputPaths = i18n.shouldInline
|
|
15
15
|
? [...i18n.inlineLocales].map((l) => [
|
|
16
16
|
l,
|
|
17
|
-
i18n.flatOutput ? baseOutputPath : path_1.join(baseOutputPath, l),
|
|
17
|
+
i18n.flatOutput ? baseOutputPath : (0, path_1.join)(baseOutputPath, l),
|
|
18
18
|
])
|
|
19
19
|
: [['', baseOutputPath]];
|
|
20
20
|
for (const [, outputPath] of outputPaths) {
|
|
21
|
-
if (!fs_1.existsSync(outputPath)) {
|
|
22
|
-
fs_1.mkdirSync(outputPath, { recursive: true });
|
|
21
|
+
if (!(0, fs_1.existsSync)(outputPath)) {
|
|
22
|
+
(0, fs_1.mkdirSync)(outputPath, { recursive: true });
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
return new Map(outputPaths);
|
|
@@ -12,7 +12,7 @@ const helpers_1 = require("../webpack/utils/helpers");
|
|
|
12
12
|
function generateEntryPoints(options) {
|
|
13
13
|
// Add all styles/scripts, except lazy-loaded ones.
|
|
14
14
|
const extraEntryPoints = (extraEntryPoints, defaultBundleName) => {
|
|
15
|
-
const entryPoints = helpers_1.normalizeExtraEntryPoints(extraEntryPoints, defaultBundleName)
|
|
15
|
+
const entryPoints = (0, helpers_1.normalizeExtraEntryPoints)(extraEntryPoints, defaultBundleName)
|
|
16
16
|
.filter((entry) => entry.inject)
|
|
17
17
|
.map((entry) => entry.bundleName);
|
|
18
18
|
// remove duplicates
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
|
-
/// <reference types="packages/angular_devkit/build_angular/src/babel-bazel" />
|
|
9
8
|
export declare function createI18nPlugins(locale: string, translation: unknown | undefined, missingTranslation: 'error' | 'warning' | 'ignore', shouldInline: boolean, localeDataContent?: string): Promise<{
|
|
10
9
|
diagnostics: import("@angular/localize/src/tools/src/diagnostics").Diagnostics;
|
|
11
10
|
plugins: import("@babel/core").PluginObj<import("@babel/core").PluginPass>[];
|
|
@@ -37,30 +37,61 @@ const fs = __importStar(require("fs"));
|
|
|
37
37
|
const path = __importStar(require("path"));
|
|
38
38
|
const worker_threads_1 = require("worker_threads");
|
|
39
39
|
const environment_options_1 = require("./environment-options");
|
|
40
|
+
const load_esm_1 = require("./load-esm");
|
|
40
41
|
// Lazy loaded webpack-sources object
|
|
41
42
|
// Webpack is only imported if needed during the processing
|
|
42
43
|
let webpackSources;
|
|
43
44
|
const { i18n } = (worker_threads_1.workerData || {});
|
|
45
|
+
/**
|
|
46
|
+
* Internal flag to enable the direct usage of the `@angular/localize` translation plugins.
|
|
47
|
+
* Their usage is currently several times slower than the string manipulation method.
|
|
48
|
+
* Future work to optimize the plugins should enable plugin usage as the default.
|
|
49
|
+
*/
|
|
44
50
|
const USE_LOCALIZE_PLUGINS = false;
|
|
51
|
+
/**
|
|
52
|
+
* Cached instance of the `@angular/localize/tools` module.
|
|
53
|
+
* This is used to remove the need to repeatedly import the module per file translation.
|
|
54
|
+
*/
|
|
55
|
+
let localizeToolsModule;
|
|
56
|
+
/**
|
|
57
|
+
* Attempts to load the `@angular/localize/tools` module containing the functionality to
|
|
58
|
+
* perform the file translations.
|
|
59
|
+
* This module must be dynamically loaded as it is an ESM module and this file is CommonJS.
|
|
60
|
+
*/
|
|
61
|
+
async function loadLocalizeTools() {
|
|
62
|
+
if (localizeToolsModule !== undefined) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
// All the localize usages are setup to first try the ESM entry point then fallback to the deep imports.
|
|
66
|
+
// This provides interim compatibility while the framework is transitioned to bundled ESM packages.
|
|
67
|
+
// TODO_ESM: Remove all deep imports once `@angular/localize` is published with the `tools` entry point
|
|
68
|
+
try {
|
|
69
|
+
// Load ESM `@angular/localize/tools` using the TypeScript dynamic import workaround.
|
|
70
|
+
// Once TypeScript provides support for keeping the dynamic import this workaround can be
|
|
71
|
+
// changed to a direct dynamic import.
|
|
72
|
+
localizeToolsModule = await (0, load_esm_1.loadEsmModule)('@angular/localize/tools');
|
|
73
|
+
}
|
|
74
|
+
catch { }
|
|
75
|
+
}
|
|
45
76
|
async function createI18nPlugins(locale, translation, missingTranslation, shouldInline, localeDataContent) {
|
|
46
77
|
const plugins = [];
|
|
47
|
-
const localizeDiag = await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/diagnostics')));
|
|
78
|
+
const localizeDiag = localizeToolsModule !== null && localizeToolsModule !== void 0 ? localizeToolsModule : (await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/diagnostics'))));
|
|
48
79
|
const diagnostics = new localizeDiag.Diagnostics();
|
|
49
80
|
if (shouldInline) {
|
|
50
|
-
const es2015 = await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/translate/source_files/es2015_translate_plugin')));
|
|
81
|
+
const es2015 = localizeToolsModule !== null && localizeToolsModule !== void 0 ? localizeToolsModule : (await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/translate/source_files/es2015_translate_plugin'))));
|
|
51
82
|
plugins.push(
|
|
52
83
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
84
|
es2015.makeEs2015TranslatePlugin(diagnostics, (translation || {}), {
|
|
54
85
|
missingTranslation: translation === undefined ? 'ignore' : missingTranslation,
|
|
55
86
|
}));
|
|
56
|
-
const es5 = await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/translate/source_files/es5_translate_plugin')));
|
|
87
|
+
const es5 = localizeToolsModule !== null && localizeToolsModule !== void 0 ? localizeToolsModule : (await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/translate/source_files/es5_translate_plugin'))));
|
|
57
88
|
plugins.push(
|
|
58
89
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
90
|
es5.makeEs5TranslatePlugin(diagnostics, (translation || {}), {
|
|
60
91
|
missingTranslation: translation === undefined ? 'ignore' : missingTranslation,
|
|
61
92
|
}));
|
|
62
93
|
}
|
|
63
|
-
const inlineLocale = await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/translate/source_files/locale_plugin')));
|
|
94
|
+
const inlineLocale = localizeToolsModule !== null && localizeToolsModule !== void 0 ? localizeToolsModule : (await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/translate/source_files/locale_plugin'))));
|
|
64
95
|
plugins.push(inlineLocale.makeLocalePlugin(locale));
|
|
65
96
|
if (localeDataContent) {
|
|
66
97
|
plugins.push({
|
|
@@ -87,9 +118,10 @@ async function inlineLocales(options) {
|
|
|
87
118
|
if (!hasLocalizeName && !options.setLocale) {
|
|
88
119
|
return inlineCopyOnly(options);
|
|
89
120
|
}
|
|
121
|
+
await loadLocalizeTools();
|
|
90
122
|
let ast;
|
|
91
123
|
try {
|
|
92
|
-
ast = core_1.parseSync(options.code, {
|
|
124
|
+
ast = (0, core_1.parseSync)(options.code, {
|
|
93
125
|
babelrc: false,
|
|
94
126
|
configFile: false,
|
|
95
127
|
sourceType: 'script',
|
|
@@ -126,7 +158,7 @@ async function inlineLocales(options) {
|
|
|
126
158
|
}
|
|
127
159
|
}
|
|
128
160
|
const { diagnostics: localeDiagnostics, plugins } = await createI18nPlugins(locale, translations, isSourceLocale ? 'ignore' : options.missingTranslation || 'warning', true, localeDataContent);
|
|
129
|
-
const transformResult = await core_1.transformFromAstSync(ast, options.code, {
|
|
161
|
+
const transformResult = await (0, core_1.transformFromAstSync)(ast, options.code, {
|
|
130
162
|
filename: options.filename,
|
|
131
163
|
// using false ensures that babel will NOT search and process sourcemap comments (large memory usage)
|
|
132
164
|
// The types do not include the false option even though it is valid
|
|
@@ -145,7 +177,7 @@ async function inlineLocales(options) {
|
|
|
145
177
|
const outputPath = path.join(options.outputPath, i18n.flatOutput ? '' : locale, options.filename);
|
|
146
178
|
fs.writeFileSync(outputPath, transformResult.code);
|
|
147
179
|
if (options.map && transformResult.map) {
|
|
148
|
-
const outputMap = remapping_1.default([transformResult.map, options.map], () => null);
|
|
180
|
+
const outputMap = (0, remapping_1.default)([transformResult.map, options.map], () => null);
|
|
149
181
|
fs.writeFileSync(outputPath + '.map', JSON.stringify(outputMap));
|
|
150
182
|
}
|
|
151
183
|
}
|
|
@@ -157,8 +189,8 @@ async function inlineLocalesDirect(ast, options) {
|
|
|
157
189
|
return { file: options.filename, diagnostics: [], count: 0 };
|
|
158
190
|
}
|
|
159
191
|
const { default: generate } = await Promise.resolve().then(() => __importStar(require('@babel/generator')));
|
|
160
|
-
const utils = await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/source_file_utils')));
|
|
161
|
-
const localizeDiag = await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/diagnostics')));
|
|
192
|
+
const utils = localizeToolsModule !== null && localizeToolsModule !== void 0 ? localizeToolsModule : (await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/source_file_utils'))));
|
|
193
|
+
const localizeDiag = localizeToolsModule !== null && localizeToolsModule !== void 0 ? localizeToolsModule : (await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/diagnostics'))));
|
|
162
194
|
const diagnostics = new localizeDiag.Diagnostics();
|
|
163
195
|
const positions = findLocalizePositions(ast, options, utils);
|
|
164
196
|
if (positions.length === 0 && !options.setLocale) {
|
|
@@ -235,7 +267,7 @@ function findLocalizePositions(ast, options, utils) {
|
|
|
235
267
|
const { File } = require('@babel/core');
|
|
236
268
|
const file = new File({}, { code: options.code, ast });
|
|
237
269
|
if (options.es5) {
|
|
238
|
-
core_1.traverse(file.ast, {
|
|
270
|
+
(0, core_1.traverse)(file.ast, {
|
|
239
271
|
CallExpression(path) {
|
|
240
272
|
const callee = path.get('callee');
|
|
241
273
|
if (callee.isIdentifier() &&
|
|
@@ -255,7 +287,7 @@ function findLocalizePositions(ast, options, utils) {
|
|
|
255
287
|
});
|
|
256
288
|
}
|
|
257
289
|
else {
|
|
258
|
-
core_1.traverse(file.ast, {
|
|
290
|
+
(0, core_1.traverse)(file.ast, {
|
|
259
291
|
TaggedTemplateExpression(path) {
|
|
260
292
|
if (core_1.types.isIdentifier(path.node.tag) && path.node.tag.name === localizeName) {
|
|
261
293
|
const [messageParts, expressions] = unwrapTemplateLiteral(path, utils);
|
|
@@ -287,7 +319,7 @@ async function loadLocaleData(path, optimize, es5) {
|
|
|
287
319
|
// The path is validated during option processing before the build starts
|
|
288
320
|
const content = fs.readFileSync(path, 'utf8');
|
|
289
321
|
// Downlevel and optimize the data
|
|
290
|
-
const transformResult = await core_1.transformAsync(content, {
|
|
322
|
+
const transformResult = await (0, core_1.transformAsync)(content, {
|
|
291
323
|
filename: path,
|
|
292
324
|
// The types do not include the false option even though it is valid
|
|
293
325
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
|
-
import { ParsedConfiguration } from '@angular/compiler-cli';
|
|
8
|
+
import type { ParsedConfiguration } from '@angular/compiler-cli';
|
|
9
9
|
/**
|
|
10
10
|
* Reads and parses a given TsConfig file.
|
|
11
11
|
*
|
|
@@ -13,4 +13,4 @@ import { ParsedConfiguration } from '@angular/compiler-cli';
|
|
|
13
13
|
* @param workspaceRoot - workspaceRoot root location when provided
|
|
14
14
|
* it will resolve 'tsconfigPath' from this path.
|
|
15
15
|
*/
|
|
16
|
-
export declare function readTsconfig(tsconfigPath: string, workspaceRoot?: string): ParsedConfiguration
|
|
16
|
+
export declare function readTsconfig(tsconfigPath: string, workspaceRoot?: string): Promise<ParsedConfiguration>;
|
|
@@ -28,6 +28,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.readTsconfig = void 0;
|
|
30
30
|
const path = __importStar(require("path"));
|
|
31
|
+
const load_esm_1 = require("./load-esm");
|
|
31
32
|
/**
|
|
32
33
|
* Reads and parses a given TsConfig file.
|
|
33
34
|
*
|
|
@@ -35,14 +36,18 @@ const path = __importStar(require("path"));
|
|
|
35
36
|
* @param workspaceRoot - workspaceRoot root location when provided
|
|
36
37
|
* it will resolve 'tsconfigPath' from this path.
|
|
37
38
|
*/
|
|
38
|
-
function readTsconfig(tsconfigPath, workspaceRoot) {
|
|
39
|
+
async function readTsconfig(tsconfigPath, workspaceRoot) {
|
|
39
40
|
const tsConfigFullPath = workspaceRoot ? path.resolve(workspaceRoot, tsconfigPath) : tsconfigPath;
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
const
|
|
41
|
+
// Load ESM `@angular/compiler-cli` using the TypeScript dynamic import workaround.
|
|
42
|
+
// Once TypeScript provides support for keeping the dynamic import this workaround can be
|
|
43
|
+
// changed to a direct dynamic import.
|
|
44
|
+
const compilerCliModule = await (0, load_esm_1.loadEsmModule)('@angular/compiler-cli');
|
|
45
|
+
// If it is not ESM then the functions needed will be stored in the `default` property.
|
|
46
|
+
// TODO_ESM: This can be removed once `@angular/compiler-cli` is ESM only.
|
|
47
|
+
const { formatDiagnostics, readConfiguration } = (compilerCliModule.readConfiguration ? compilerCliModule : compilerCliModule.default);
|
|
48
|
+
const configResult = readConfiguration(tsConfigFullPath);
|
|
44
49
|
if (configResult.errors && configResult.errors.length) {
|
|
45
|
-
throw new Error(
|
|
50
|
+
throw new Error(formatDiagnostics(configResult.errors));
|
|
46
51
|
}
|
|
47
52
|
return configResult;
|
|
48
53
|
}
|
|
@@ -16,7 +16,7 @@ function runModuleAsObservableFork(cwd, modulePath, exportName,
|
|
|
16
16
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
17
|
args) {
|
|
18
18
|
return new rxjs_1.Observable((obs) => {
|
|
19
|
-
const workerPath = path_1.resolve(__dirname, './run-module-worker.js');
|
|
19
|
+
const workerPath = (0, path_1.resolve)(__dirname, './run-module-worker.js');
|
|
20
20
|
const debugArgRegex = /--inspect(?:-brk|-port)?|--debug(?:-brk|-port)/;
|
|
21
21
|
const execArgv = process.execArgv.filter((arg) => {
|
|
22
22
|
// Remove debug args.
|
|
@@ -35,7 +35,7 @@ args) {
|
|
|
35
35
|
// logger.error, // make it a stream
|
|
36
36
|
// ];
|
|
37
37
|
// }
|
|
38
|
-
const forkedProcess = child_process_1.fork(workerPath, undefined, forkOptions);
|
|
38
|
+
const forkedProcess = (0, child_process_1.fork)(workerPath, undefined, forkOptions);
|
|
39
39
|
// Cleanup.
|
|
40
40
|
const killForkedProcess = () => {
|
|
41
41
|
if (forkedProcess && forkedProcess.pid) {
|
|
@@ -32,6 +32,8 @@ const crypto = __importStar(require("crypto"));
|
|
|
32
32
|
const fs_1 = require("fs");
|
|
33
33
|
const path = __importStar(require("path"));
|
|
34
34
|
const stream_1 = require("stream");
|
|
35
|
+
const url_1 = require("url");
|
|
36
|
+
const load_esm_1 = require("./load-esm");
|
|
35
37
|
class CliFilesystem {
|
|
36
38
|
constructor(base) {
|
|
37
39
|
this.base = base;
|
|
@@ -45,7 +47,7 @@ class CliFilesystem {
|
|
|
45
47
|
hash(file) {
|
|
46
48
|
return new Promise((resolve, reject) => {
|
|
47
49
|
const hash = crypto.createHash('sha1').setEncoding('hex');
|
|
48
|
-
stream_1.pipeline(fs_1.createReadStream(this._resolve(file)), hash, (error) => error ? reject(error) : resolve(hash.read()));
|
|
50
|
+
(0, stream_1.pipeline)((0, fs_1.createReadStream)(this._resolve(file)), hash, (error) => error ? reject(error) : resolve(hash.read()));
|
|
49
51
|
});
|
|
50
52
|
}
|
|
51
53
|
write(file, content) {
|
|
@@ -72,22 +74,24 @@ class CliFilesystem {
|
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
async function augmentAppWithServiceWorker(projectRoot, appRoot, outputPath, baseHref, ngswConfigPath) {
|
|
75
|
-
const distPath = core_1.getSystemPath(core_1.normalize(outputPath));
|
|
76
|
-
const systemProjectRoot = core_1.getSystemPath(projectRoot);
|
|
77
|
+
const distPath = (0, core_1.getSystemPath)((0, core_1.normalize)(outputPath));
|
|
78
|
+
const systemProjectRoot = (0, core_1.getSystemPath)(projectRoot);
|
|
77
79
|
// Find the service worker package
|
|
78
80
|
const workerPath = require.resolve('@angular/service-worker/ngsw-worker.js', {
|
|
79
81
|
paths: [systemProjectRoot],
|
|
80
82
|
});
|
|
81
|
-
|
|
83
|
+
// Absolute paths on Windows must be `file://` URLs when using ESM. Otherwise,
|
|
84
|
+
// `c:` would be interpreted as a protocol instead of a drive letter.
|
|
85
|
+
const swConfigPath = (0, url_1.pathToFileURL)(require.resolve('@angular/service-worker/config', {
|
|
82
86
|
paths: [systemProjectRoot],
|
|
83
|
-
});
|
|
87
|
+
}));
|
|
84
88
|
// Determine the configuration file path
|
|
85
89
|
let configPath;
|
|
86
90
|
if (ngswConfigPath) {
|
|
87
|
-
configPath = core_1.getSystemPath(core_1.normalize(ngswConfigPath));
|
|
91
|
+
configPath = (0, core_1.getSystemPath)((0, core_1.normalize)(ngswConfigPath));
|
|
88
92
|
}
|
|
89
93
|
else {
|
|
90
|
-
configPath = path.join(core_1.getSystemPath(appRoot), 'ngsw-config.json');
|
|
94
|
+
configPath = path.join((0, core_1.getSystemPath)(appRoot), 'ngsw-config.json');
|
|
91
95
|
}
|
|
92
96
|
// Read the configuration file
|
|
93
97
|
let config;
|
|
@@ -98,15 +102,18 @@ async function augmentAppWithServiceWorker(projectRoot, appRoot, outputPath, bas
|
|
|
98
102
|
catch (error) {
|
|
99
103
|
if (error.code === 'ENOENT') {
|
|
100
104
|
throw new Error('Error: Expected to find an ngsw-config.json configuration file' +
|
|
101
|
-
` in the ${core_1.getSystemPath(appRoot)} folder. Either provide one or` +
|
|
105
|
+
` in the ${(0, core_1.getSystemPath)(appRoot)} folder. Either provide one or` +
|
|
102
106
|
' disable Service Worker in the angular.json configuration file.');
|
|
103
107
|
}
|
|
104
108
|
else {
|
|
105
109
|
throw error;
|
|
106
110
|
}
|
|
107
111
|
}
|
|
112
|
+
// Load ESM `@angular/service-worker/config` using the TypeScript dynamic import workaround.
|
|
113
|
+
// Once TypeScript provides support for keeping the dynamic import this workaround can be
|
|
114
|
+
// changed to a direct dynamic import.
|
|
115
|
+
const GeneratorConstructor = (await (0, load_esm_1.loadEsmModule)(swConfigPath)).Generator;
|
|
108
116
|
// Generate the manifest
|
|
109
|
-
const GeneratorConstructor = require(swConfigPath).Generator;
|
|
110
117
|
const generator = new GeneratorConstructor(new CliFilesystem(distPath), baseHref);
|
|
111
118
|
const output = await generator.process(config);
|
|
112
119
|
// Write the manifest
|
package/src/utils/spinner.js
CHANGED
|
@@ -24,8 +24,8 @@ class Spinner {
|
|
|
24
24
|
constructor(text) {
|
|
25
25
|
/** When false, only fail messages will be displayed. */
|
|
26
26
|
this.enabled = true;
|
|
27
|
-
_Spinner_isTTY.set(this, tty_1.isTTY());
|
|
28
|
-
this.spinner = ora_1.default({
|
|
27
|
+
_Spinner_isTTY.set(this, (0, tty_1.isTTY)());
|
|
28
|
+
this.spinner = (0, ora_1.default)({
|
|
29
29
|
text,
|
|
30
30
|
// The below 2 options are needed because otherwise CTRL+C will be delayed
|
|
31
31
|
// when the underlying process is sync.
|
package/src/utils/version.js
CHANGED
|
@@ -51,7 +51,7 @@ function assertCompatibleAngularVersion(projectRoot) {
|
|
|
51
51
|
}
|
|
52
52
|
const supportedAngularSemver = require('../../package.json')['peerDependencies']['@angular/compiler-cli'];
|
|
53
53
|
const angularVersion = new semver_1.SemVer(angularPkgJson['version']);
|
|
54
|
-
if (!semver_1.satisfies(angularVersion, supportedAngularSemver, { includePrerelease: true })) {
|
|
54
|
+
if (!(0, semver_1.satisfies)(angularVersion, supportedAngularSemver, { includePrerelease: true })) {
|
|
55
55
|
console.error(core_1.tags.stripIndents `
|
|
56
56
|
This version of CLI is only compatible with Angular versions ${supportedAngularSemver},
|
|
57
57
|
but Angular version ${angularVersion} was found instead.
|
|
@@ -14,15 +14,16 @@ import { NormalizedBrowserBuilderSchema } from '../utils';
|
|
|
14
14
|
import { WebpackConfigOptions } from '../utils/build-options';
|
|
15
15
|
import { I18nOptions } from './i18n-options';
|
|
16
16
|
export declare type BrowserWebpackConfigOptions = WebpackConfigOptions<NormalizedBrowserBuilderSchema>;
|
|
17
|
-
export declare
|
|
18
|
-
export declare function
|
|
17
|
+
export declare type WebpackPartialGenerator = (configurationOptions: BrowserWebpackConfigOptions) => (Promise<Configuration> | Configuration)[];
|
|
18
|
+
export declare function generateWebpackConfig(workspaceRoot: string, projectRoot: string, sourceRoot: string | undefined, options: NormalizedBrowserBuilderSchema, webpackPartialGenerator: WebpackPartialGenerator, logger: logging.LoggerApi, extraBuildOptions: Partial<NormalizedBrowserBuilderSchema>): Promise<Configuration>;
|
|
19
|
+
export declare function generateI18nBrowserWebpackConfigFromContext(options: BrowserBuilderSchema, context: BuilderContext, webpackPartialGenerator: WebpackPartialGenerator, extraBuildOptions?: Partial<NormalizedBrowserBuilderSchema>): Promise<{
|
|
19
20
|
config: Configuration;
|
|
20
21
|
projectRoot: string;
|
|
21
22
|
projectSourceRoot?: string;
|
|
22
23
|
i18n: I18nOptions;
|
|
23
24
|
target: ScriptTarget;
|
|
24
25
|
}>;
|
|
25
|
-
export declare function generateBrowserWebpackConfigFromContext(options: BrowserBuilderSchema, context: BuilderContext, webpackPartialGenerator:
|
|
26
|
+
export declare function generateBrowserWebpackConfigFromContext(options: BrowserBuilderSchema, context: BuilderContext, webpackPartialGenerator: WebpackPartialGenerator, extraBuildOptions?: Partial<NormalizedBrowserBuilderSchema>): Promise<{
|
|
26
27
|
config: Configuration;
|
|
27
28
|
projectRoot: string;
|
|
28
29
|
projectSourceRoot?: string;
|
|
@@ -42,7 +42,7 @@ async function generateWebpackConfig(workspaceRoot, projectRoot, sourceRoot, opt
|
|
|
42
42
|
throw new Error(`The 'buildOptimizer' option cannot be used without 'aot'.`);
|
|
43
43
|
}
|
|
44
44
|
const tsConfigPath = path.resolve(workspaceRoot, options.tsConfig);
|
|
45
|
-
const tsConfig = read_tsconfig_1.readTsconfig(tsConfigPath);
|
|
45
|
+
const tsConfig = await (0, read_tsconfig_1.readTsconfig)(tsConfigPath);
|
|
46
46
|
const ts = await Promise.resolve().then(() => __importStar(require('typescript')));
|
|
47
47
|
const scriptTarget = tsConfig.options.target || ts.ScriptTarget.ES5;
|
|
48
48
|
const buildOptions = { ...options, ...extraBuildOptions };
|
|
@@ -56,14 +56,15 @@ async function generateWebpackConfig(workspaceRoot, projectRoot, sourceRoot, opt
|
|
|
56
56
|
tsConfigPath,
|
|
57
57
|
scriptTarget,
|
|
58
58
|
};
|
|
59
|
-
wco.buildOptions.progress = utils_1.defaultProgress(wco.buildOptions.progress);
|
|
60
|
-
const
|
|
59
|
+
wco.buildOptions.progress = (0, utils_1.defaultProgress)(wco.buildOptions.progress);
|
|
60
|
+
const partials = await Promise.all(webpackPartialGenerator(wco));
|
|
61
|
+
const webpackConfig = (0, webpack_merge_1.merge)(partials);
|
|
61
62
|
return webpackConfig;
|
|
62
63
|
}
|
|
63
64
|
exports.generateWebpackConfig = generateWebpackConfig;
|
|
64
65
|
async function generateI18nBrowserWebpackConfigFromContext(options, context, webpackPartialGenerator, extraBuildOptions = {}) {
|
|
65
66
|
var _a;
|
|
66
|
-
const { buildOptions, i18n } = await i18n_options_1.configureI18nBuild(context, options);
|
|
67
|
+
const { buildOptions, i18n } = await (0, i18n_options_1.configureI18nBuild)(context, options);
|
|
67
68
|
let target = typescript_1.ScriptTarget.ES5;
|
|
68
69
|
const result = await generateBrowserWebpackConfigFromContext(buildOptions, context, (wco) => {
|
|
69
70
|
target = wco.scriptTarget;
|
|
@@ -110,15 +111,15 @@ async function generateBrowserWebpackConfigFromContext(options, context, webpack
|
|
|
110
111
|
if (!projectName) {
|
|
111
112
|
throw new Error('The builder requires a target.');
|
|
112
113
|
}
|
|
113
|
-
const workspaceRoot = core_1.normalize(context.workspaceRoot);
|
|
114
|
+
const workspaceRoot = (0, core_1.normalize)(context.workspaceRoot);
|
|
114
115
|
const projectMetadata = await context.getProjectMetadata(projectName);
|
|
115
|
-
const projectRoot = core_1.resolve(workspaceRoot, core_1.normalize(projectMetadata.root || ''));
|
|
116
|
+
const projectRoot = (0, core_1.resolve)(workspaceRoot, (0, core_1.normalize)(projectMetadata.root || ''));
|
|
116
117
|
const projectSourceRoot = projectMetadata.sourceRoot;
|
|
117
118
|
const sourceRoot = projectSourceRoot
|
|
118
|
-
? core_1.resolve(workspaceRoot, core_1.normalize(projectSourceRoot))
|
|
119
|
+
? (0, core_1.resolve)(workspaceRoot, (0, core_1.normalize)(projectSourceRoot))
|
|
119
120
|
: undefined;
|
|
120
|
-
const normalizedOptions = utils_1.normalizeBrowserSchema(workspaceRoot, projectRoot, sourceRoot, options);
|
|
121
|
-
const config = await generateWebpackConfig(core_1.getSystemPath(workspaceRoot), core_1.getSystemPath(projectRoot), sourceRoot && core_1.getSystemPath(sourceRoot), normalizedOptions, webpackPartialGenerator, context.logger, extraBuildOptions);
|
|
121
|
+
const normalizedOptions = (0, utils_1.normalizeBrowserSchema)(workspaceRoot, projectRoot, sourceRoot, options);
|
|
122
|
+
const config = await generateWebpackConfig((0, core_1.getSystemPath)(workspaceRoot), (0, core_1.getSystemPath)(projectRoot), sourceRoot && (0, core_1.getSystemPath)(sourceRoot), normalizedOptions, webpackPartialGenerator, context.logger, extraBuildOptions);
|
|
122
123
|
// If builder watch support is present in the context, add watch plugin
|
|
123
124
|
// This is internal only and currently only used for testing
|
|
124
125
|
const watcherFactory = context.watcherFactory;
|
|
@@ -130,8 +131,8 @@ async function generateBrowserWebpackConfigFromContext(options, context, webpack
|
|
|
130
131
|
}
|
|
131
132
|
return {
|
|
132
133
|
config,
|
|
133
|
-
projectRoot: core_1.getSystemPath(projectRoot),
|
|
134
|
-
projectSourceRoot: sourceRoot && core_1.getSystemPath(sourceRoot),
|
|
134
|
+
projectRoot: (0, core_1.getSystemPath)(projectRoot),
|
|
135
|
+
projectSourceRoot: sourceRoot && (0, core_1.getSystemPath)(sourceRoot),
|
|
135
136
|
};
|
|
136
137
|
}
|
|
137
138
|
exports.generateBrowserWebpackConfigFromContext = generateBrowserWebpackConfigFromContext;
|
|
@@ -22,7 +22,7 @@ function getBrowserConfig(wco) {
|
|
|
22
22
|
}));
|
|
23
23
|
}
|
|
24
24
|
if (scriptsSourceMap || stylesSourceMap) {
|
|
25
|
-
extraPlugins.push(helpers_1.getSourceMapDevTool(scriptsSourceMap, stylesSourceMap, hiddenSourceMap, false));
|
|
25
|
+
extraPlugins.push((0, helpers_1.getSourceMapDevTool)(scriptsSourceMap, stylesSourceMap, hiddenSourceMap, false));
|
|
26
26
|
}
|
|
27
27
|
let crossOriginLoading = false;
|
|
28
28
|
if (subresourceIntegrity && crossOrigin === 'none') {
|
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { Configuration } from 'webpack';
|
|
9
9
|
import { WebpackConfigOptions } from '../../utils/build-options';
|
|
10
|
-
export declare function getCommonConfig(wco: WebpackConfigOptions): Configuration
|
|
10
|
+
export declare function getCommonConfig(wco: WebpackConfigOptions): Promise<Configuration>;
|