@angular-devkit/build-angular 18.0.0-next.2 → 18.0.0-next.3

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.
Files changed (50) hide show
  1. package/package.json +18 -18
  2. package/src/builders/application/execute-build.js +2 -4
  3. package/src/builders/application/execute-post-bundle.js +9 -12
  4. package/src/builders/application/options.js +42 -25
  5. package/src/builders/browser/index.js +1 -1
  6. package/src/builders/dev-server/vite-server.js +3 -3
  7. package/src/builders/dev-server/webpack-server.js +2 -2
  8. package/src/builders/ssr-dev-server/index.js +28 -28
  9. package/src/tools/esbuild/angular/compiler-plugin.js +12 -4
  10. package/src/tools/esbuild/index-html-generator.d.ts +2 -2
  11. package/src/tools/esbuild/index-html-generator.js +5 -53
  12. package/src/tools/esbuild/javascript-transformer.js +5 -1
  13. package/src/tools/esbuild/stylesheets/css-resource-plugin.js +15 -8
  14. package/src/tools/esbuild/utils.js +2 -2
  15. package/src/tools/sass/rebasing-importer.js +3 -6
  16. package/src/tools/sass/sass-service.d.ts +24 -1
  17. package/src/tools/sass/worker.js +32 -4
  18. package/src/tools/webpack/plugins/any-component-style-budget-checker.d.ts +2 -2
  19. package/src/tools/webpack/plugins/any-component-style-budget-checker.js +13 -16
  20. package/src/tools/webpack/plugins/index-html-webpack-plugin.js +1 -1
  21. package/src/tools/webpack/utils/stats.d.ts +0 -13
  22. package/src/tools/webpack/utils/stats.js +3 -207
  23. package/src/utils/action-executor.d.ts +1 -1
  24. package/src/utils/bundle-calculator.d.ts +5 -5
  25. package/src/utils/bundle-calculator.js +8 -7
  26. package/src/utils/format-bytes.d.ts +8 -0
  27. package/src/utils/format-bytes.js +22 -0
  28. package/src/utils/i18n-inlining.d.ts +1 -1
  29. package/src/utils/i18n-options.d.ts +2 -9
  30. package/src/utils/i18n-options.js +4 -97
  31. package/src/utils/i18n-webpack.d.ts +16 -0
  32. package/src/utils/i18n-webpack.js +108 -0
  33. package/src/utils/index-file/add-event-dispatch-contract.d.ts +8 -0
  34. package/src/utils/index-file/add-event-dispatch-contract.js +28 -0
  35. package/src/utils/index-file/augment-index-html.js +1 -0
  36. package/src/utils/index-file/index-html-generator.d.ts +12 -2
  37. package/src/utils/index-file/index-html-generator.js +38 -22
  38. package/src/utils/index-file/inline-fonts.js +1 -1
  39. package/src/utils/index-file/{style-nonce.d.ts → nonce.d.ts} +2 -2
  40. package/src/utils/index-file/{style-nonce.js → nonce.js} +7 -5
  41. package/src/utils/load-proxy-config.d.ts +1 -1
  42. package/src/utils/load-proxy-config.js +2 -5
  43. package/src/utils/normalize-cache.js +1 -1
  44. package/src/utils/output-paths.d.ts +1 -1
  45. package/src/utils/resolve-assets.d.ts +18 -0
  46. package/src/utils/resolve-assets.js +35 -0
  47. package/src/utils/stats-table.d.ts +20 -0
  48. package/src/utils/stats-table.js +205 -0
  49. package/src/utils/webpack-browser-config.d.ts +1 -1
  50. package/src/utils/webpack-browser-config.js +2 -2
@@ -0,0 +1,205 @@
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.generateBuildStatsTable = exports.generateEsbuildBuildStatsTable = void 0;
11
+ const node_util_1 = require("node:util");
12
+ const color_1 = require("./color");
13
+ const format_bytes_1 = require("./format-bytes");
14
+ function generateEsbuildBuildStatsTable([browserStats, serverStats], colors, showTotalSize, showEstimatedTransferSize, budgetFailures, verbose) {
15
+ const bundleInfo = generateBuildStatsData(browserStats, colors, showTotalSize, showEstimatedTransferSize, budgetFailures, verbose);
16
+ if (serverStats.length) {
17
+ const m = (x) => (colors ? color_1.colors.magenta(x) : x);
18
+ if (browserStats.length) {
19
+ bundleInfo.unshift([m('Browser bundles')]);
20
+ // Add seperators between browser and server logs
21
+ bundleInfo.push([], []);
22
+ }
23
+ bundleInfo.push([m('Server bundles')], ...generateBuildStatsData(serverStats, colors, false, false, undefined, verbose));
24
+ }
25
+ return generateTableText(bundleInfo, colors);
26
+ }
27
+ exports.generateEsbuildBuildStatsTable = generateEsbuildBuildStatsTable;
28
+ function generateBuildStatsTable(data, colors, showTotalSize, showEstimatedTransferSize, budgetFailures) {
29
+ const bundleInfo = generateBuildStatsData(data, colors, showTotalSize, showEstimatedTransferSize, budgetFailures, true);
30
+ return generateTableText(bundleInfo, colors);
31
+ }
32
+ exports.generateBuildStatsTable = generateBuildStatsTable;
33
+ function generateBuildStatsData(data, colors, showTotalSize, showEstimatedTransferSize, budgetFailures, verbose) {
34
+ if (data.length === 0) {
35
+ return [];
36
+ }
37
+ const g = (x) => (colors ? color_1.colors.green(x) : x);
38
+ const c = (x) => (colors ? color_1.colors.cyan(x) : x);
39
+ const r = (x) => (colors ? color_1.colors.redBright(x) : x);
40
+ const y = (x) => (colors ? color_1.colors.yellowBright(x) : x);
41
+ const bold = (x) => (colors ? color_1.colors.bold(x) : x);
42
+ const dim = (x) => (colors ? color_1.colors.dim(x) : x);
43
+ const getSizeColor = (name, file, defaultColor = c) => {
44
+ const severity = budgets.get(name) || (file && budgets.get(file));
45
+ switch (severity) {
46
+ case 'warning':
47
+ return y;
48
+ case 'error':
49
+ return r;
50
+ default:
51
+ return defaultColor;
52
+ }
53
+ };
54
+ const changedEntryChunksStats = [];
55
+ const changedLazyChunksStats = [];
56
+ let initialTotalRawSize = 0;
57
+ let changedLazyChunksCount = 0;
58
+ let initialTotalEstimatedTransferSize;
59
+ const maxLazyChunksWithoutBudgetFailures = 15;
60
+ const budgets = new Map();
61
+ if (budgetFailures) {
62
+ for (const { label, severity } of budgetFailures) {
63
+ // In some cases a file can have multiple budget failures.
64
+ // Favor error.
65
+ if (label && (!budgets.has(label) || budgets.get(label) === 'warning')) {
66
+ budgets.set(label, severity);
67
+ }
68
+ }
69
+ }
70
+ // Sort descending by raw size
71
+ data.sort((a, b) => {
72
+ if (a.stats[2] > b.stats[2]) {
73
+ return -1;
74
+ }
75
+ if (a.stats[2] < b.stats[2]) {
76
+ return 1;
77
+ }
78
+ return 0;
79
+ });
80
+ for (const { initial, stats } of data) {
81
+ const [files, names, rawSize, estimatedTransferSize] = stats;
82
+ if (!initial &&
83
+ !verbose &&
84
+ changedLazyChunksStats.length >= maxLazyChunksWithoutBudgetFailures &&
85
+ !budgets.has(names) &&
86
+ !budgets.has(files)) {
87
+ // Limit the number of lazy chunks displayed in the stats table when there is no budget failure and not in verbose mode.
88
+ changedLazyChunksCount++;
89
+ continue;
90
+ }
91
+ const getRawSizeColor = getSizeColor(names, files);
92
+ let data;
93
+ if (showEstimatedTransferSize) {
94
+ data = [
95
+ g(files),
96
+ dim(names),
97
+ getRawSizeColor(typeof rawSize === 'number' ? (0, format_bytes_1.formatSize)(rawSize) : rawSize),
98
+ c(typeof estimatedTransferSize === 'number'
99
+ ? (0, format_bytes_1.formatSize)(estimatedTransferSize)
100
+ : estimatedTransferSize),
101
+ ];
102
+ }
103
+ else {
104
+ data = [
105
+ g(files),
106
+ dim(names),
107
+ getRawSizeColor(typeof rawSize === 'number' ? (0, format_bytes_1.formatSize)(rawSize) : rawSize),
108
+ '',
109
+ ];
110
+ }
111
+ if (initial) {
112
+ changedEntryChunksStats.push(data);
113
+ if (typeof rawSize === 'number') {
114
+ initialTotalRawSize += rawSize;
115
+ }
116
+ if (showEstimatedTransferSize && typeof estimatedTransferSize === 'number') {
117
+ if (initialTotalEstimatedTransferSize === undefined) {
118
+ initialTotalEstimatedTransferSize = 0;
119
+ }
120
+ initialTotalEstimatedTransferSize += estimatedTransferSize;
121
+ }
122
+ }
123
+ else {
124
+ changedLazyChunksStats.push(data);
125
+ changedLazyChunksCount++;
126
+ }
127
+ }
128
+ const bundleInfo = [];
129
+ const baseTitles = ['Names', 'Raw size'];
130
+ if (showEstimatedTransferSize) {
131
+ baseTitles.push('Estimated transfer size');
132
+ }
133
+ // Entry chunks
134
+ if (changedEntryChunksStats.length) {
135
+ bundleInfo.push(['Initial chunk files', ...baseTitles].map(bold), ...changedEntryChunksStats);
136
+ if (showTotalSize) {
137
+ const initialSizeTotalColor = getSizeColor('bundle initial', undefined, (x) => x);
138
+ const totalSizeElements = [
139
+ ' ',
140
+ 'Initial total',
141
+ initialSizeTotalColor((0, format_bytes_1.formatSize)(initialTotalRawSize)),
142
+ ];
143
+ if (showEstimatedTransferSize) {
144
+ totalSizeElements.push(typeof initialTotalEstimatedTransferSize === 'number'
145
+ ? (0, format_bytes_1.formatSize)(initialTotalEstimatedTransferSize)
146
+ : '-');
147
+ }
148
+ bundleInfo.push([], totalSizeElements.map(bold));
149
+ }
150
+ }
151
+ // Seperator
152
+ if (changedEntryChunksStats.length && changedLazyChunksStats.length) {
153
+ bundleInfo.push([]);
154
+ }
155
+ // Lazy chunks
156
+ if (changedLazyChunksStats.length) {
157
+ bundleInfo.push(['Lazy chunk files', ...baseTitles].map(bold), ...changedLazyChunksStats);
158
+ if (changedLazyChunksCount > changedLazyChunksStats.length) {
159
+ bundleInfo.push([
160
+ dim(`...and ${changedLazyChunksCount - changedLazyChunksStats.length} more lazy chunks files. ` +
161
+ 'Use "--verbose" to show all the files.'),
162
+ ]);
163
+ }
164
+ }
165
+ return bundleInfo;
166
+ }
167
+ function generateTableText(bundleInfo, colors) {
168
+ const skipText = (value) => value.includes('...and ');
169
+ const longest = [];
170
+ for (const item of bundleInfo) {
171
+ for (let i = 0; i < item.length; i++) {
172
+ if (item[i] === undefined) {
173
+ continue;
174
+ }
175
+ const currentItem = item[i].toString();
176
+ if (skipText(currentItem)) {
177
+ continue;
178
+ }
179
+ const currentLongest = (longest[i] ??= 0);
180
+ const currentItemLength = (0, node_util_1.stripVTControlCharacters)(currentItem).length;
181
+ if (currentLongest < currentItemLength) {
182
+ longest[i] = currentItemLength;
183
+ }
184
+ }
185
+ }
186
+ const seperator = colors ? color_1.colors.dim(' | ') : ' | ';
187
+ const outputTable = [];
188
+ for (const item of bundleInfo) {
189
+ for (let i = 0; i < longest.length; i++) {
190
+ if (item[i] === undefined) {
191
+ continue;
192
+ }
193
+ const currentItem = item[i].toString();
194
+ if (skipText(currentItem)) {
195
+ continue;
196
+ }
197
+ const currentItemLength = (0, node_util_1.stripVTControlCharacters)(currentItem).length;
198
+ const stringPad = ' '.repeat(longest[i] - currentItemLength);
199
+ // Values in columns at index 2 and 3 (Raw and Estimated sizes) are always right aligned.
200
+ item[i] = i >= 2 ? stringPad + currentItem : currentItem + stringPad;
201
+ }
202
+ outputTable.push(item.join(seperator));
203
+ }
204
+ return outputTable.join('\n');
205
+ }
@@ -10,7 +10,7 @@ import { Configuration } from 'webpack';
10
10
  import { Schema as BrowserBuilderSchema } from '../builders/browser/schema';
11
11
  import { NormalizedBrowserBuilderSchema } from '../utils';
12
12
  import { WebpackConfigOptions } from '../utils/build-options';
13
- import { I18nOptions } from './i18n-options';
13
+ import { I18nOptions } from './i18n-webpack';
14
14
  export type BrowserWebpackConfigOptions = WebpackConfigOptions<NormalizedBrowserBuilderSchema>;
15
15
  export type WebpackPartialGenerator = (configurationOptions: BrowserWebpackConfigOptions) => (Promise<Configuration> | Configuration)[];
16
16
  export declare function generateWebpackConfig(workspaceRoot: string, projectRoot: string, sourceRoot: string | undefined, projectName: string, options: NormalizedBrowserBuilderSchema, webpackPartialGenerator: WebpackPartialGenerator, logger: BuilderContext['logger'], extraBuildOptions: Partial<NormalizedBrowserBuilderSchema>): Promise<Configuration>;
@@ -37,7 +37,7 @@ const webpack_merge_1 = require("webpack-merge");
37
37
  const builder_watch_plugin_1 = require("../tools/webpack/plugins/builder-watch-plugin");
38
38
  const utils_1 = require("../utils");
39
39
  const read_tsconfig_1 = require("../utils/read-tsconfig");
40
- const i18n_options_1 = require("./i18n-options");
40
+ const i18n_webpack_1 = require("./i18n-webpack");
41
41
  async function generateWebpackConfig(workspaceRoot, projectRoot, sourceRoot, projectName, options, webpackPartialGenerator, logger, extraBuildOptions) {
42
42
  // Ensure Build Optimizer is only used with AOT.
43
43
  if (options.buildOptimizer && !options.aot) {
@@ -63,7 +63,7 @@ async function generateWebpackConfig(workspaceRoot, projectRoot, sourceRoot, pro
63
63
  }
64
64
  exports.generateWebpackConfig = generateWebpackConfig;
65
65
  async function generateI18nBrowserWebpackConfigFromContext(options, context, webpackPartialGenerator, extraBuildOptions = {}) {
66
- const { buildOptions, i18n } = await (0, i18n_options_1.configureI18nBuild)(context, options);
66
+ const { buildOptions, i18n } = await (0, i18n_webpack_1.configureI18nBuild)(context, options);
67
67
  const result = await generateBrowserWebpackConfigFromContext(buildOptions, context, (wco) => {
68
68
  return webpackPartialGenerator(wco);
69
69
  }, extraBuildOptions);