@angular-devkit/build-angular 15.0.0-next.0 → 15.0.0-next.2
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 +13 -15
- package/src/babel/presets/application.d.ts +1 -2
- package/src/babel/presets/application.js +1 -4
- package/src/babel/webpack-loader.js +8 -22
- package/src/builders/browser/index.d.ts +1 -1
- package/src/builders/browser/index.js +4 -16
- package/src/builders/browser/schema.json +2 -2
- package/src/builders/browser-esbuild/compiler-plugin.d.ts +1 -0
- package/src/builders/browser-esbuild/compiler-plugin.js +20 -17
- package/src/builders/browser-esbuild/experimental-warnings.js +0 -1
- package/src/builders/browser-esbuild/index.js +18 -5
- package/src/builders/browser-esbuild/schema.d.ts +2 -4
- package/src/builders/browser-esbuild/schema.json +13 -32
- package/src/builders/browser-esbuild/stylesheets.d.ts +1 -0
- package/src/builders/browser-esbuild/stylesheets.js +1 -0
- package/src/builders/extract-i18n/index.js +1 -1
- package/src/builders/karma/schema.json +2 -2
- package/src/builders/server/index.d.ts +1 -1
- package/src/builders/server/index.js +42 -28
- package/src/builders/server/platform-server-exports-loader.d.ts +13 -0
- package/src/builders/server/platform-server-exports-loader.js +24 -0
- package/src/builders/server/schema.d.ts +1 -10
- package/src/builders/server/schema.js +1 -6
- package/src/builders/server/schema.json +1 -9
- package/src/utils/build-options.d.ts +1 -2
- package/src/utils/esbuild-targets.d.ts +12 -0
- package/src/utils/esbuild-targets.js +39 -0
- package/src/utils/i18n-inlining.d.ts +1 -1
- package/src/utils/i18n-inlining.js +3 -4
- package/src/utils/normalize-builder-schema.d.ts +2 -2
- package/src/utils/normalize-builder-schema.js +2 -2
- package/src/utils/process-bundle.d.ts +0 -1
- package/src/utils/process-bundle.js +29 -57
- package/src/utils/supported-browsers.d.ts +2 -1
- package/src/utils/supported-browsers.js +18 -2
- package/src/utils/webpack-browser-config.d.ts +0 -2
- package/src/utils/webpack-browser-config.js +2 -8
- package/src/webpack/configs/common.js +19 -12
- package/src/webpack/configs/dev-server.js +1 -1
- package/src/webpack/configs/styles.js +6 -28
- package/src/webpack/plugins/any-component-style-budget-checker.js +1 -1
- package/src/webpack/plugins/css-optimizer-plugin.d.ts +0 -1
- package/src/webpack/plugins/css-optimizer-plugin.js +3 -26
- package/src/webpack/plugins/hmr/hmr-loader.d.ts +1 -1
- package/src/webpack/plugins/hmr/hmr-loader.js +2 -5
- package/src/webpack/plugins/javascript-optimizer-plugin.d.ts +4 -6
- package/src/webpack/plugins/javascript-optimizer-plugin.js +5 -14
- package/src/webpack/plugins/javascript-optimizer-worker.d.ts +3 -2
- package/src/webpack/plugins/javascript-optimizer-worker.js +21 -46
- package/src/webpack/plugins/typescript.js +14 -25
- package/src/webpack/utils/helpers.d.ts +0 -2
- package/src/webpack/utils/helpers.js +1 -17
- package/src/webpack/utils/stats.js +1 -1
|
@@ -33,11 +33,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
33
33
|
exports.execute = void 0;
|
|
34
34
|
const architect_1 = require("@angular-devkit/architect");
|
|
35
35
|
const build_webpack_1 = require("@angular-devkit/build-webpack");
|
|
36
|
-
const core_1 = require("@angular-devkit/core");
|
|
37
36
|
const path = __importStar(require("path"));
|
|
38
37
|
const rxjs_1 = require("rxjs");
|
|
39
38
|
const operators_1 = require("rxjs/operators");
|
|
40
|
-
const typescript_1 = require("typescript");
|
|
41
39
|
const utils_1 = require("../../utils");
|
|
42
40
|
const i18n_inlining_1 = require("../../utils/i18n-inlining");
|
|
43
41
|
const output_paths_1 = require("../../utils/output-paths");
|
|
@@ -55,24 +53,7 @@ function execute(options, context, transforms = {}) {
|
|
|
55
53
|
(0, version_1.assertCompatibleAngularVersion)(root);
|
|
56
54
|
const baseOutputPath = path.resolve(root, options.outputPath);
|
|
57
55
|
let outputPaths;
|
|
58
|
-
|
|
59
|
-
options.bundleDependencies = options.bundleDependencies === 'all';
|
|
60
|
-
context.logger.warn(`Option 'bundleDependencies' string value is deprecated since version 9. Use a boolean value instead.`);
|
|
61
|
-
}
|
|
62
|
-
if (!options.bundleDependencies) {
|
|
63
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
64
|
-
const { __processed_by_ivy_ngcc__, main = '' } = require('@angular/core/package.json');
|
|
65
|
-
if (!__processed_by_ivy_ngcc__ ||
|
|
66
|
-
!__processed_by_ivy_ngcc__.main ||
|
|
67
|
-
main.includes('__ivy_ngcc__')) {
|
|
68
|
-
context.logger.warn(core_1.tags.stripIndent `
|
|
69
|
-
Warning: Turning off 'bundleDependencies' with Ivy may result in undefined behaviour
|
|
70
|
-
unless 'node_modules' are transformed using the standalone Angular compatibility compiler (NGCC).
|
|
71
|
-
See: https://angular.io/guide/ivy#ivy-and-universal-app-shell
|
|
72
|
-
`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return (0, rxjs_1.from)(initialize(options, context, transforms.webpackConfiguration)).pipe((0, operators_1.concatMap)(({ config, i18n, target }) => {
|
|
56
|
+
return (0, rxjs_1.from)(initialize(options, context, transforms.webpackConfiguration)).pipe((0, operators_1.concatMap)(({ config, i18n }) => {
|
|
76
57
|
return (0, build_webpack_1.runWebpack)(config, context, {
|
|
77
58
|
webpackFactory: require('webpack'),
|
|
78
59
|
logging: (stats, config) => {
|
|
@@ -88,7 +69,7 @@ function execute(options, context, transforms = {}) {
|
|
|
88
69
|
let success = output.success;
|
|
89
70
|
if (success && i18n.shouldInline) {
|
|
90
71
|
outputPaths = (0, output_paths_1.ensureOutputPaths)(baseOutputPath, i18n);
|
|
91
|
-
success = await (0, i18n_inlining_1.i18nInlineEmittedFiles)(context, emittedFiles, i18n, baseOutputPath, Array.from(outputPaths.values()), [], outputPath,
|
|
72
|
+
success = await (0, i18n_inlining_1.i18nInlineEmittedFiles)(context, emittedFiles, i18n, baseOutputPath, Array.from(outputPaths.values()), [], outputPath, options.i18nMissingTranslation);
|
|
92
73
|
}
|
|
93
74
|
(0, stats_1.webpackStatsLogger)(context.logger, webpackStats, config);
|
|
94
75
|
return { ...output, success };
|
|
@@ -115,21 +96,54 @@ function execute(options, context, transforms = {}) {
|
|
|
115
96
|
exports.execute = execute;
|
|
116
97
|
exports.default = (0, architect_1.createBuilder)(execute);
|
|
117
98
|
async function initialize(options, context, webpackConfigurationTransform) {
|
|
99
|
+
var _a;
|
|
118
100
|
// Purge old build disk cache.
|
|
119
101
|
await (0, purge_cache_1.purgeStaleBuildCache)(context);
|
|
102
|
+
const browserslist = (await Promise.resolve().then(() => __importStar(require('browserslist')))).default;
|
|
120
103
|
const originalOutputPath = options.outputPath;
|
|
121
|
-
const { config, i18n
|
|
104
|
+
const { config, i18n } = await (0, webpack_browser_config_1.generateI18nBrowserWebpackConfigFromContext)({
|
|
122
105
|
...options,
|
|
123
106
|
buildOptimizer: false,
|
|
124
107
|
aot: true,
|
|
125
108
|
platform: 'server',
|
|
126
|
-
}, context, (wco) =>
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
109
|
+
}, context, (wco) => {
|
|
110
|
+
var _a;
|
|
111
|
+
var _b;
|
|
112
|
+
// We use the platform to determine the JavaScript syntax output.
|
|
113
|
+
(_a = (_b = wco.buildOptions).supportedBrowsers) !== null && _a !== void 0 ? _a : (_b.supportedBrowsers = []);
|
|
114
|
+
wco.buildOptions.supportedBrowsers.push(...browserslist('maintained node versions'));
|
|
115
|
+
return [getPlatformServerExportsConfig(wco), (0, configs_1.getCommonConfig)(wco), (0, configs_1.getStylesConfig)(wco)];
|
|
116
|
+
});
|
|
131
117
|
if (options.deleteOutputPath) {
|
|
132
118
|
(0, utils_1.deleteOutputDir)(context.workspaceRoot, originalOutputPath);
|
|
133
119
|
}
|
|
134
|
-
|
|
120
|
+
const transformedConfig = (_a = (await (webpackConfigurationTransform === null || webpackConfigurationTransform === void 0 ? void 0 : webpackConfigurationTransform(config)))) !== null && _a !== void 0 ? _a : config;
|
|
121
|
+
return { config: transformedConfig, i18n };
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Add `@angular/platform-server` exports.
|
|
125
|
+
* This is needed so that DI tokens can be referenced and set at runtime outside of the bundle.
|
|
126
|
+
*/
|
|
127
|
+
function getPlatformServerExportsConfig(wco) {
|
|
128
|
+
// Add `@angular/platform-server` exports.
|
|
129
|
+
// This is needed so that DI tokens can be referenced and set at runtime outside of the bundle.
|
|
130
|
+
try {
|
|
131
|
+
// Only add `@angular/platform-server` exports when it is installed.
|
|
132
|
+
// In some cases this builder is used when `@angular/platform-server` is not installed.
|
|
133
|
+
// Example: when using `@nguniversal/common/clover` which does not need `@angular/platform-server`.
|
|
134
|
+
require.resolve('@angular/platform-server', { paths: [wco.root] });
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return {};
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
module: {
|
|
141
|
+
rules: [
|
|
142
|
+
{
|
|
143
|
+
loader: require.resolve('./platform-server-exports-loader'),
|
|
144
|
+
include: [path.resolve(wco.root, wco.buildOptions.main)],
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
};
|
|
135
149
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* This loader is needed to add additional exports and is a workaround for a Webpack bug that doesn't
|
|
10
|
+
* allow exports from multiple files in the same entry.
|
|
11
|
+
* @see https://github.com/webpack/webpack/issues/15936.
|
|
12
|
+
*/
|
|
13
|
+
export default function (this: import('webpack').LoaderContext<{}>, content: string, map: Parameters<import('webpack').LoaderDefinitionFunction>[1]): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
/**
|
|
11
|
+
* This loader is needed to add additional exports and is a workaround for a Webpack bug that doesn't
|
|
12
|
+
* allow exports from multiple files in the same entry.
|
|
13
|
+
* @see https://github.com/webpack/webpack/issues/15936.
|
|
14
|
+
*/
|
|
15
|
+
function default_1(content, map) {
|
|
16
|
+
const source = `${content}
|
|
17
|
+
|
|
18
|
+
// EXPORTS added by @angular-devkit/build-angular
|
|
19
|
+
export { renderModule, ɵSERVER_CONTEXT } from '@angular/platform-server';
|
|
20
|
+
`;
|
|
21
|
+
this.callback(null, source, map);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
exports.default = default_1;
|
|
@@ -3,7 +3,7 @@ export interface Schema {
|
|
|
3
3
|
* Which external dependencies to bundle into the bundle. By default, all of node_modules
|
|
4
4
|
* will be bundled.
|
|
5
5
|
*/
|
|
6
|
-
bundleDependencies?:
|
|
6
|
+
bundleDependencies?: boolean;
|
|
7
7
|
/**
|
|
8
8
|
* Delete the output path before building.
|
|
9
9
|
*/
|
|
@@ -110,15 +110,6 @@ export interface Schema {
|
|
|
110
110
|
*/
|
|
111
111
|
watch?: boolean;
|
|
112
112
|
}
|
|
113
|
-
/**
|
|
114
|
-
* Which external dependencies to bundle into the bundle. By default, all of node_modules
|
|
115
|
-
* will be bundled.
|
|
116
|
-
*/
|
|
117
|
-
export declare type BundleDependenciesUnion = boolean | BundleDependenciesEnum;
|
|
118
|
-
export declare enum BundleDependenciesEnum {
|
|
119
|
-
All = "all",
|
|
120
|
-
None = "none"
|
|
121
|
-
}
|
|
122
113
|
export interface FileReplacement {
|
|
123
114
|
replace?: string;
|
|
124
115
|
replaceWith?: string;
|
|
@@ -2,12 +2,7 @@
|
|
|
2
2
|
// THIS FILE IS AUTOMATICALLY GENERATED. TO UPDATE THIS FILE YOU NEED TO CHANGE THE
|
|
3
3
|
// CORRESPONDING JSON SCHEMA FILE, THEN RUN devkit-admin build (or bazel build ...).
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.OutputHashing = exports.InlineStyleLanguage = exports.I18NTranslation =
|
|
6
|
-
var BundleDependenciesEnum;
|
|
7
|
-
(function (BundleDependenciesEnum) {
|
|
8
|
-
BundleDependenciesEnum["All"] = "all";
|
|
9
|
-
BundleDependenciesEnum["None"] = "none";
|
|
10
|
-
})(BundleDependenciesEnum = exports.BundleDependenciesEnum || (exports.BundleDependenciesEnum = {}));
|
|
5
|
+
exports.OutputHashing = exports.InlineStyleLanguage = exports.I18NTranslation = void 0;
|
|
11
6
|
/**
|
|
12
7
|
* How to handle duplicate translations for i18n.
|
|
13
8
|
*
|
|
@@ -184,15 +184,7 @@
|
|
|
184
184
|
"bundleDependencies": {
|
|
185
185
|
"description": "Which external dependencies to bundle into the bundle. By default, all of node_modules will be bundled.",
|
|
186
186
|
"default": true,
|
|
187
|
-
"
|
|
188
|
-
{
|
|
189
|
-
"type": "boolean"
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
"type": "string",
|
|
193
|
-
"enum": ["none", "all"]
|
|
194
|
-
}
|
|
195
|
-
]
|
|
187
|
+
"type": "boolean"
|
|
196
188
|
},
|
|
197
189
|
"externalDependencies": {
|
|
198
190
|
"description": "Exclude the listed external dependencies from being bundled into the bundle. Instead, the created bundle relies on these dependencies to be available during runtime.",
|
|
@@ -60,7 +60,7 @@ export interface BuildOptions {
|
|
|
60
60
|
cache: NormalizedCachedOptions;
|
|
61
61
|
codeCoverage?: boolean;
|
|
62
62
|
codeCoverageExclude?: string[];
|
|
63
|
-
supportedBrowsers
|
|
63
|
+
supportedBrowsers?: string[];
|
|
64
64
|
}
|
|
65
65
|
export interface WebpackDevServerOptions extends BuildOptions, Omit<DevServerSchema, 'optimization' | 'sourceMap' | 'browserTarget'> {
|
|
66
66
|
}
|
|
@@ -72,6 +72,5 @@ export interface WebpackConfigOptions<T = BuildOptions> {
|
|
|
72
72
|
buildOptions: T;
|
|
73
73
|
tsConfig: ParsedConfiguration;
|
|
74
74
|
tsConfigPath: string;
|
|
75
|
-
scriptTarget: import('typescript').ScriptTarget;
|
|
76
75
|
projectName: string;
|
|
77
76
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Transform browserlists result to esbuild target.
|
|
10
|
+
* @see https://esbuild.github.io/api/#target
|
|
11
|
+
*/
|
|
12
|
+
export declare function transformSupportedBrowsersToTargets(supportedBrowsers: string[]): string[];
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.transformSupportedBrowsersToTargets = void 0;
|
|
11
|
+
/**
|
|
12
|
+
* Transform browserlists result to esbuild target.
|
|
13
|
+
* @see https://esbuild.github.io/api/#target
|
|
14
|
+
*/
|
|
15
|
+
function transformSupportedBrowsersToTargets(supportedBrowsers) {
|
|
16
|
+
const transformed = [];
|
|
17
|
+
// https://esbuild.github.io/api/#target
|
|
18
|
+
const esBuildSupportedBrowsers = new Set(['safari', 'firefox', 'edge', 'chrome', 'ios', 'node']);
|
|
19
|
+
for (const browser of supportedBrowsers) {
|
|
20
|
+
let [browserName, version] = browser.split(' ');
|
|
21
|
+
// browserslist uses the name `ios_saf` for iOS Safari whereas esbuild uses `ios`
|
|
22
|
+
if (browserName === 'ios_saf') {
|
|
23
|
+
browserName = 'ios';
|
|
24
|
+
}
|
|
25
|
+
// browserslist uses ranges `15.2-15.3` versions but only the lowest is required
|
|
26
|
+
// to perform minimum supported feature checks. esbuild also expects a single version.
|
|
27
|
+
[version] = version.split('-');
|
|
28
|
+
if (esBuildSupportedBrowsers.has(browserName)) {
|
|
29
|
+
if (browserName === 'safari' && version === 'TP') {
|
|
30
|
+
// esbuild only supports numeric versions so `TP` is converted to a high number (999) since
|
|
31
|
+
// a Technology Preview (TP) of Safari is assumed to support all currently known features.
|
|
32
|
+
version = '999';
|
|
33
|
+
}
|
|
34
|
+
transformed.push(browserName + version);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return transformed;
|
|
38
|
+
}
|
|
39
|
+
exports.transformSupportedBrowsersToTargets = transformSupportedBrowsersToTargets;
|
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
import { BuilderContext } from '@angular-devkit/architect';
|
|
9
9
|
import { EmittedFiles } from '@angular-devkit/build-webpack';
|
|
10
10
|
import { I18nOptions } from './i18n-options';
|
|
11
|
-
export declare function i18nInlineEmittedFiles(context: BuilderContext, emittedFiles: EmittedFiles[], i18n: I18nOptions, baseOutputPath: string, outputPaths: string[], scriptsEntryPointName: string[], emittedPath: string,
|
|
11
|
+
export declare function i18nInlineEmittedFiles(context: BuilderContext, emittedFiles: EmittedFiles[], i18n: I18nOptions, baseOutputPath: string, outputPaths: string[], scriptsEntryPointName: string[], emittedPath: string, missingTranslation: 'error' | 'warning' | 'ignore' | undefined): Promise<boolean>;
|
|
@@ -37,7 +37,7 @@ const action_executor_1 = require("./action-executor");
|
|
|
37
37
|
const copy_assets_1 = require("./copy-assets");
|
|
38
38
|
const error_1 = require("./error");
|
|
39
39
|
const spinner_1 = require("./spinner");
|
|
40
|
-
function emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emittedPath, outputPath,
|
|
40
|
+
function emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emittedPath, outputPath, missingTranslation, context) {
|
|
41
41
|
const options = [];
|
|
42
42
|
const originalFiles = [];
|
|
43
43
|
for (const emittedFile of emittedFiles) {
|
|
@@ -50,7 +50,6 @@ function emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emitte
|
|
|
50
50
|
const action = {
|
|
51
51
|
filename: emittedFile.file,
|
|
52
52
|
code: fs.readFileSync(originalPath, 'utf8'),
|
|
53
|
-
es5,
|
|
54
53
|
outputPath,
|
|
55
54
|
missingTranslation,
|
|
56
55
|
setLocale: emittedFile.name === 'main' || emittedFile.name === 'vendor',
|
|
@@ -72,13 +71,13 @@ function emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emitte
|
|
|
72
71
|
}
|
|
73
72
|
return { options, originalFiles };
|
|
74
73
|
}
|
|
75
|
-
async function i18nInlineEmittedFiles(context, emittedFiles, i18n, baseOutputPath, outputPaths, scriptsEntryPointName, emittedPath,
|
|
74
|
+
async function i18nInlineEmittedFiles(context, emittedFiles, i18n, baseOutputPath, outputPaths, scriptsEntryPointName, emittedPath, missingTranslation) {
|
|
76
75
|
const executor = new action_executor_1.BundleActionExecutor({ i18n });
|
|
77
76
|
let hasErrors = false;
|
|
78
77
|
const spinner = new spinner_1.Spinner();
|
|
79
78
|
spinner.start('Generating localized bundles...');
|
|
80
79
|
try {
|
|
81
|
-
const { options, originalFiles: processedFiles } = emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emittedPath, baseOutputPath,
|
|
80
|
+
const { options, originalFiles: processedFiles } = emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emittedPath, baseOutputPath, missingTranslation, context);
|
|
82
81
|
for await (const result of executor.inlineAll(options)) {
|
|
83
82
|
context.logger.debug(`i18n file processed: ${result.file}`);
|
|
84
83
|
for (const diagnostic of result.diagnostics) {
|
|
@@ -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 { json } from '@angular-devkit/core';
|
|
8
|
+
import { json, logging } from '@angular-devkit/core';
|
|
9
9
|
import { AssetPatternClass, Schema as BrowserBuilderSchema, SourceMapClass } from '../builders/browser/schema';
|
|
10
10
|
import { BuildOptions } from './build-options';
|
|
11
11
|
import { NormalizedFileReplacement } from './normalize-file-replacements';
|
|
@@ -19,4 +19,4 @@ export declare type NormalizedBrowserBuilderSchema = BrowserBuilderSchema & Buil
|
|
|
19
19
|
fileReplacements: NormalizedFileReplacement[];
|
|
20
20
|
optimization: NormalizedOptimizationOptions;
|
|
21
21
|
};
|
|
22
|
-
export declare function normalizeBrowserSchema(workspaceRoot: string, projectRoot: string, projectSourceRoot: string | undefined, options: BrowserBuilderSchema, metadata: json.JsonObject): NormalizedBrowserBuilderSchema;
|
|
22
|
+
export declare function normalizeBrowserSchema(workspaceRoot: string, projectRoot: string, projectSourceRoot: string | undefined, options: BrowserBuilderSchema, metadata: json.JsonObject, logger: logging.LoggerApi): NormalizedBrowserBuilderSchema;
|
|
@@ -14,7 +14,7 @@ const normalize_file_replacements_1 = require("./normalize-file-replacements");
|
|
|
14
14
|
const normalize_optimization_1 = require("./normalize-optimization");
|
|
15
15
|
const normalize_source_maps_1 = require("./normalize-source-maps");
|
|
16
16
|
const supported_browsers_1 = require("./supported-browsers");
|
|
17
|
-
function normalizeBrowserSchema(workspaceRoot, projectRoot, projectSourceRoot, options, metadata) {
|
|
17
|
+
function normalizeBrowserSchema(workspaceRoot, projectRoot, projectSourceRoot, options, metadata, logger) {
|
|
18
18
|
const normalizedSourceMapOptions = (0, normalize_source_maps_1.normalizeSourceMaps)(options.sourceMap || false);
|
|
19
19
|
return {
|
|
20
20
|
...options,
|
|
@@ -37,7 +37,7 @@ function normalizeBrowserSchema(workspaceRoot, projectRoot, projectSourceRoot, o
|
|
|
37
37
|
// A value of 0 is falsy and will disable polling rather then enable
|
|
38
38
|
// 500 ms is a sensible default in this case
|
|
39
39
|
poll: options.poll === 0 ? 500 : options.poll,
|
|
40
|
-
supportedBrowsers: (0, supported_browsers_1.getSupportedBrowsers)(projectRoot),
|
|
40
|
+
supportedBrowsers: (0, supported_browsers_1.getSupportedBrowsers)(projectRoot, logger),
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
exports.normalizeBrowserSchema = normalizeBrowserSchema;
|
|
@@ -37,7 +37,7 @@ exports.inlineLocales = exports.createI18nPlugins = void 0;
|
|
|
37
37
|
const remapping_1 = __importDefault(require("@ampproject/remapping"));
|
|
38
38
|
const core_1 = require("@babel/core");
|
|
39
39
|
const template_1 = __importDefault(require("@babel/template"));
|
|
40
|
-
const fs = __importStar(require("fs"));
|
|
40
|
+
const fs = __importStar(require("fs/promises"));
|
|
41
41
|
const path = __importStar(require("path"));
|
|
42
42
|
const worker_threads_1 = require("worker_threads");
|
|
43
43
|
const environment_options_1 = require("./environment-options");
|
|
@@ -73,7 +73,7 @@ async function loadLocalizeTools() {
|
|
|
73
73
|
return (0, load_esm_1.loadEsmModule)('@angular/localize/tools');
|
|
74
74
|
}
|
|
75
75
|
async function createI18nPlugins(locale, translation, missingTranslation, shouldInline, localeDataContent) {
|
|
76
|
-
const { Diagnostics, makeEs2015TranslatePlugin,
|
|
76
|
+
const { Diagnostics, makeEs2015TranslatePlugin, makeLocalePlugin } = await loadLocalizeTools();
|
|
77
77
|
const plugins = [];
|
|
78
78
|
const diagnostics = new Diagnostics();
|
|
79
79
|
if (shouldInline) {
|
|
@@ -82,11 +82,6 @@ async function createI18nPlugins(locale, translation, missingTranslation, should
|
|
|
82
82
|
makeEs2015TranslatePlugin(diagnostics, (translation || {}), {
|
|
83
83
|
missingTranslation: translation === undefined ? 'ignore' : missingTranslation,
|
|
84
84
|
}));
|
|
85
|
-
plugins.push(
|
|
86
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
|
-
makeEs5TranslatePlugin(diagnostics, (translation || {}), {
|
|
88
|
-
missingTranslation: translation === undefined ? 'ignore' : missingTranslation,
|
|
89
|
-
}));
|
|
90
85
|
}
|
|
91
86
|
plugins.push(makeLocalePlugin(locale));
|
|
92
87
|
if (localeDataContent) {
|
|
@@ -149,7 +144,7 @@ async function inlineLocales(options) {
|
|
|
149
144
|
// If locale data is provided, load it and prepend to file
|
|
150
145
|
const localeDataPath = (_a = i18n.locales[locale]) === null || _a === void 0 ? void 0 : _a.dataPath;
|
|
151
146
|
if (localeDataPath) {
|
|
152
|
-
localeDataContent = await loadLocaleData(localeDataPath, true
|
|
147
|
+
localeDataContent = await loadLocaleData(localeDataPath, true);
|
|
153
148
|
}
|
|
154
149
|
}
|
|
155
150
|
const { diagnostics: localeDiagnostics, plugins } = await createI18nPlugins(locale, translations, isSourceLocale ? 'ignore' : options.missingTranslation || 'warning', true, localeDataContent);
|
|
@@ -170,10 +165,10 @@ async function inlineLocales(options) {
|
|
|
170
165
|
throw new Error(`Unknown error occurred processing bundle for "${options.filename}".`);
|
|
171
166
|
}
|
|
172
167
|
const outputPath = path.join(options.outputPath, i18n.flatOutput ? '' : locale, options.filename);
|
|
173
|
-
fs.
|
|
168
|
+
await fs.writeFile(outputPath, transformResult.code);
|
|
174
169
|
if (options.map && transformResult.map) {
|
|
175
170
|
const outputMap = (0, remapping_1.default)([transformResult.map, options.map], () => null);
|
|
176
|
-
fs.
|
|
171
|
+
await fs.writeFile(outputPath + '.map', JSON.stringify(outputMap));
|
|
177
172
|
}
|
|
178
173
|
}
|
|
179
174
|
return { file: options.filename, diagnostics };
|
|
@@ -221,7 +216,7 @@ async function inlineLocalesDirect(ast, options) {
|
|
|
221
216
|
let localeDataSource;
|
|
222
217
|
const localeDataPath = i18n.locales[locale] && i18n.locales[locale].dataPath;
|
|
223
218
|
if (localeDataPath) {
|
|
224
|
-
const localeDataContent = await loadLocaleData(localeDataPath, true
|
|
219
|
+
const localeDataContent = await loadLocaleData(localeDataPath, true);
|
|
225
220
|
localeDataSource = new OriginalSource(localeDataContent, path.basename(localeDataPath));
|
|
226
221
|
}
|
|
227
222
|
outputSource = localeDataSource
|
|
@@ -231,26 +226,26 @@ async function inlineLocalesDirect(ast, options) {
|
|
|
231
226
|
}
|
|
232
227
|
const { source: outputCode, map: outputMap } = outputSource.sourceAndMap();
|
|
233
228
|
const outputPath = path.join(options.outputPath, i18n.flatOutput ? '' : locale, options.filename);
|
|
234
|
-
fs.
|
|
229
|
+
await fs.writeFile(outputPath, outputCode);
|
|
235
230
|
if (inputMap && outputMap) {
|
|
236
231
|
outputMap.file = options.filename;
|
|
237
232
|
if (mapSourceRoot) {
|
|
238
233
|
outputMap.sourceRoot = mapSourceRoot;
|
|
239
234
|
}
|
|
240
|
-
fs.
|
|
235
|
+
await fs.writeFile(outputPath + '.map', JSON.stringify(outputMap));
|
|
241
236
|
}
|
|
242
237
|
}
|
|
243
238
|
return { file: options.filename, diagnostics: diagnostics.messages, count: positions.length };
|
|
244
239
|
}
|
|
245
|
-
function inlineCopyOnly(options) {
|
|
240
|
+
async function inlineCopyOnly(options) {
|
|
246
241
|
if (!i18n) {
|
|
247
242
|
throw new Error('i18n options are missing');
|
|
248
243
|
}
|
|
249
244
|
for (const locale of i18n.inlineLocales) {
|
|
250
245
|
const outputPath = path.join(options.outputPath, i18n.flatOutput ? '' : locale, options.filename);
|
|
251
|
-
fs.
|
|
246
|
+
await fs.writeFile(outputPath, options.code);
|
|
252
247
|
if (options.map) {
|
|
253
|
-
fs.
|
|
248
|
+
await fs.writeFile(outputPath + '.map', options.map);
|
|
254
249
|
}
|
|
255
250
|
}
|
|
256
251
|
return { file: options.filename, diagnostics: [], count: 0 };
|
|
@@ -260,43 +255,21 @@ function findLocalizePositions(ast, options, utils) {
|
|
|
260
255
|
// Workaround to ensure a path hub is present for traversal
|
|
261
256
|
const { File } = require('@babel/core');
|
|
262
257
|
const file = new File({}, { code: options.code, ast });
|
|
263
|
-
|
|
264
|
-
(
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
},
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
(0, core_1.traverse)(file.ast, {
|
|
285
|
-
TaggedTemplateExpression(path) {
|
|
286
|
-
if (core_1.types.isIdentifier(path.node.tag) && path.node.tag.name === localizeName) {
|
|
287
|
-
const [messageParts, expressions] = unwrapTemplateLiteral(path, utils);
|
|
288
|
-
positions.push({
|
|
289
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
290
|
-
start: path.node.start,
|
|
291
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
292
|
-
end: path.node.end,
|
|
293
|
-
messageParts,
|
|
294
|
-
expressions,
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
},
|
|
298
|
-
});
|
|
299
|
-
}
|
|
258
|
+
(0, core_1.traverse)(file.ast, {
|
|
259
|
+
TaggedTemplateExpression(path) {
|
|
260
|
+
if (core_1.types.isIdentifier(path.node.tag) && path.node.tag.name === localizeName) {
|
|
261
|
+
const [messageParts, expressions] = unwrapTemplateLiteral(path, utils);
|
|
262
|
+
positions.push({
|
|
263
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
264
|
+
start: path.node.start,
|
|
265
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
266
|
+
end: path.node.end,
|
|
267
|
+
messageParts,
|
|
268
|
+
expressions,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
});
|
|
300
273
|
return positions;
|
|
301
274
|
}
|
|
302
275
|
function unwrapTemplateLiteral(path, utils) {
|
|
@@ -309,9 +282,9 @@ function unwrapLocalizeCall(path, utils) {
|
|
|
309
282
|
const [expressions] = utils.unwrapSubstitutionsFromLocalizeCall(path);
|
|
310
283
|
return [messageParts, expressions];
|
|
311
284
|
}
|
|
312
|
-
async function loadLocaleData(path, optimize
|
|
285
|
+
async function loadLocaleData(path, optimize) {
|
|
313
286
|
// The path is validated during option processing before the build starts
|
|
314
|
-
const content = fs.
|
|
287
|
+
const content = await fs.readFile(path, 'utf8');
|
|
315
288
|
// Downlevel and optimize the data
|
|
316
289
|
const transformResult = await (0, core_1.transformAsync)(content, {
|
|
317
290
|
filename: path,
|
|
@@ -325,8 +298,7 @@ async function loadLocaleData(path, optimize, es5) {
|
|
|
325
298
|
require.resolve('@babel/preset-env'),
|
|
326
299
|
{
|
|
327
300
|
bugfixes: true,
|
|
328
|
-
|
|
329
|
-
targets: es5 ? { ie: '11' } : { esmodules: true },
|
|
301
|
+
targets: { esmodules: true },
|
|
330
302
|
},
|
|
331
303
|
],
|
|
332
304
|
],
|
|
@@ -5,4 +5,5 @@
|
|
|
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
|
-
|
|
8
|
+
import { logging } from '@angular-devkit/core';
|
|
9
|
+
export declare function getSupportedBrowsers(projectRoot: string, logger: logging.LoggerApi): string[];
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.getSupportedBrowsers = void 0;
|
|
14
14
|
const browserslist_1 = __importDefault(require("browserslist"));
|
|
15
|
-
function getSupportedBrowsers(projectRoot) {
|
|
15
|
+
function getSupportedBrowsers(projectRoot, logger) {
|
|
16
16
|
browserslist_1.default.defaults = [
|
|
17
17
|
'last 1 Chrome version',
|
|
18
18
|
'last 1 Firefox version',
|
|
@@ -21,6 +21,22 @@ function getSupportedBrowsers(projectRoot) {
|
|
|
21
21
|
'last 2 iOS major versions',
|
|
22
22
|
'Firefox ESR',
|
|
23
23
|
];
|
|
24
|
-
|
|
24
|
+
// Get browsers from config or default.
|
|
25
|
+
const browsersFromConfigOrDefault = new Set((0, browserslist_1.default)(undefined, { path: projectRoot }));
|
|
26
|
+
// Get browsers that support ES6 modules.
|
|
27
|
+
const browsersThatSupportEs6 = new Set((0, browserslist_1.default)('supports es6-module'));
|
|
28
|
+
const unsupportedBrowsers = [];
|
|
29
|
+
for (const browser of browsersFromConfigOrDefault) {
|
|
30
|
+
if (!browsersThatSupportEs6.has(browser)) {
|
|
31
|
+
browsersFromConfigOrDefault.delete(browser);
|
|
32
|
+
unsupportedBrowsers.push(browser);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (unsupportedBrowsers.length) {
|
|
36
|
+
logger.warn(`One or more browsers which are configured in the project's Browserslist configuration ` +
|
|
37
|
+
'will be ignored as ES5 output is not supported by the Angular CLI.\n' +
|
|
38
|
+
`Ignored browsers: ${unsupportedBrowsers.join(', ')}`);
|
|
39
|
+
}
|
|
40
|
+
return Array.from(browsersFromConfigOrDefault);
|
|
25
41
|
}
|
|
26
42
|
exports.getSupportedBrowsers = getSupportedBrowsers;
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { BuilderContext } from '@angular-devkit/architect';
|
|
9
9
|
import { logging } from '@angular-devkit/core';
|
|
10
|
-
import { ScriptTarget } from 'typescript';
|
|
11
10
|
import { Configuration } from 'webpack';
|
|
12
11
|
import { Schema as BrowserBuilderSchema } from '../builders/browser/schema';
|
|
13
12
|
import { NormalizedBrowserBuilderSchema } from '../utils';
|
|
@@ -21,7 +20,6 @@ export declare function generateI18nBrowserWebpackConfigFromContext(options: Bro
|
|
|
21
20
|
projectRoot: string;
|
|
22
21
|
projectSourceRoot?: string;
|
|
23
22
|
i18n: I18nOptions;
|
|
24
|
-
target: ScriptTarget;
|
|
25
23
|
}>;
|
|
26
24
|
export declare function generateBrowserWebpackConfigFromContext(options: BrowserBuilderSchema, context: BuilderContext, webpackPartialGenerator: WebpackPartialGenerator, extraBuildOptions?: Partial<NormalizedBrowserBuilderSchema>): Promise<{
|
|
27
25
|
config: Configuration;
|
|
@@ -32,7 +32,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
32
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
33
|
exports.getIndexInputFile = exports.getIndexOutputFile = exports.generateBrowserWebpackConfigFromContext = exports.generateI18nBrowserWebpackConfigFromContext = exports.generateWebpackConfig = void 0;
|
|
34
34
|
const path = __importStar(require("path"));
|
|
35
|
-
const typescript_1 = require("typescript");
|
|
36
35
|
const webpack_1 = require("webpack");
|
|
37
36
|
const webpack_merge_1 = require("webpack-merge");
|
|
38
37
|
const utils_1 = require("../utils");
|
|
@@ -46,8 +45,6 @@ async function generateWebpackConfig(workspaceRoot, projectRoot, sourceRoot, pro
|
|
|
46
45
|
}
|
|
47
46
|
const tsConfigPath = path.resolve(workspaceRoot, options.tsConfig);
|
|
48
47
|
const tsConfig = await (0, read_tsconfig_1.readTsconfig)(tsConfigPath);
|
|
49
|
-
const ts = await Promise.resolve().then(() => __importStar(require('typescript')));
|
|
50
|
-
const scriptTarget = tsConfig.options.target || ts.ScriptTarget.ES5;
|
|
51
48
|
const buildOptions = { ...options, ...extraBuildOptions };
|
|
52
49
|
const wco = {
|
|
53
50
|
root: workspaceRoot,
|
|
@@ -58,7 +55,6 @@ async function generateWebpackConfig(workspaceRoot, projectRoot, sourceRoot, pro
|
|
|
58
55
|
tsConfig,
|
|
59
56
|
tsConfigPath,
|
|
60
57
|
projectName,
|
|
61
|
-
scriptTarget,
|
|
62
58
|
};
|
|
63
59
|
wco.buildOptions.progress = (0, utils_1.defaultProgress)(wco.buildOptions.progress);
|
|
64
60
|
const partials = await Promise.all(webpackPartialGenerator(wco));
|
|
@@ -69,9 +65,7 @@ exports.generateWebpackConfig = generateWebpackConfig;
|
|
|
69
65
|
async function generateI18nBrowserWebpackConfigFromContext(options, context, webpackPartialGenerator, extraBuildOptions = {}) {
|
|
70
66
|
var _a;
|
|
71
67
|
const { buildOptions, i18n } = await (0, i18n_options_1.configureI18nBuild)(context, options);
|
|
72
|
-
let target = typescript_1.ScriptTarget.ES5;
|
|
73
68
|
const result = await generateBrowserWebpackConfigFromContext(buildOptions, context, (wco) => {
|
|
74
|
-
target = wco.scriptTarget;
|
|
75
69
|
return webpackPartialGenerator(wco);
|
|
76
70
|
}, extraBuildOptions);
|
|
77
71
|
const config = result.config;
|
|
@@ -107,7 +101,7 @@ async function generateI18nBrowserWebpackConfigFromContext(options, context, web
|
|
|
107
101
|
},
|
|
108
102
|
});
|
|
109
103
|
}
|
|
110
|
-
return { ...result, i18n
|
|
104
|
+
return { ...result, i18n };
|
|
111
105
|
}
|
|
112
106
|
exports.generateI18nBrowserWebpackConfigFromContext = generateI18nBrowserWebpackConfigFromContext;
|
|
113
107
|
async function generateBrowserWebpackConfigFromContext(options, context, webpackPartialGenerator, extraBuildOptions = {}) {
|
|
@@ -121,7 +115,7 @@ async function generateBrowserWebpackConfigFromContext(options, context, webpack
|
|
|
121
115
|
const projectRoot = path.join(workspaceRoot, (_a = projectMetadata.root) !== null && _a !== void 0 ? _a : '');
|
|
122
116
|
const sourceRoot = projectMetadata.sourceRoot;
|
|
123
117
|
const projectSourceRoot = sourceRoot ? path.join(workspaceRoot, sourceRoot) : undefined;
|
|
124
|
-
const normalizedOptions = (0, utils_1.normalizeBrowserSchema)(workspaceRoot, projectRoot, projectSourceRoot, options, projectMetadata);
|
|
118
|
+
const normalizedOptions = (0, utils_1.normalizeBrowserSchema)(workspaceRoot, projectRoot, projectSourceRoot, options, projectMetadata, context.logger);
|
|
125
119
|
const config = await generateWebpackConfig(workspaceRoot, projectRoot, projectSourceRoot, projectName, normalizedOptions, webpackPartialGenerator, context.logger, extraBuildOptions);
|
|
126
120
|
// If builder watch support is present in the context, add watch plugin
|
|
127
121
|
// This is internal only and currently only used for testing
|