@angular/build 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 (253) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/builders.json +14 -0
  4. package/package.json +87 -0
  5. package/src/builders/application/build-action.d.ts +33 -0
  6. package/src/builders/application/build-action.js +183 -0
  7. package/src/builders/application/execute-build.d.ts +11 -0
  8. package/src/builders/application/execute-build.js +125 -0
  9. package/src/builders/application/execute-post-bundle.d.ts +25 -0
  10. package/src/builders/application/execute-post-bundle.js +93 -0
  11. package/src/builders/application/i18n.d.ts +29 -0
  12. package/src/builders/application/i18n.js +128 -0
  13. package/src/builders/application/index.d.ts +57 -0
  14. package/src/builders/application/index.js +121 -0
  15. package/src/builders/application/options.d.ts +149 -0
  16. package/src/builders/application/options.js +369 -0
  17. package/src/builders/application/schema.d.ts +512 -0
  18. package/src/builders/application/schema.js +58 -0
  19. package/src/builders/application/schema.json +635 -0
  20. package/src/builders/application/setup-bundling.d.ts +19 -0
  21. package/src/builders/application/setup-bundling.js +71 -0
  22. package/src/builders/dev-server/builder.d.ts +32 -0
  23. package/src/builders/dev-server/builder.js +70 -0
  24. package/src/builders/dev-server/index.d.ts +14 -0
  25. package/src/builders/dev-server/index.js +15 -0
  26. package/src/builders/dev-server/internal.d.ts +19 -0
  27. package/src/builders/dev-server/internal.js +29 -0
  28. package/src/builders/dev-server/options.d.ts +47 -0
  29. package/src/builders/dev-server/options.js +65 -0
  30. package/src/builders/dev-server/output.d.ts +16 -0
  31. package/src/builders/dev-server/output.js +9 -0
  32. package/src/builders/dev-server/schema.d.ts +118 -0
  33. package/src/builders/dev-server/schema.js +4 -0
  34. package/src/builders/dev-server/schema.json +131 -0
  35. package/src/builders/dev-server/vite-server.d.ts +31 -0
  36. package/src/builders/dev-server/vite-server.js +504 -0
  37. package/src/index.d.ts +11 -0
  38. package/src/index.js +16 -0
  39. package/src/private.d.ts +35 -0
  40. package/src/private.js +70 -0
  41. package/src/tools/babel/plugins/adjust-static-class-members.d.ts +26 -0
  42. package/src/tools/babel/plugins/adjust-static-class-members.js +351 -0
  43. package/src/tools/babel/plugins/adjust-typescript-enums.d.ts +22 -0
  44. package/src/tools/babel/plugins/adjust-typescript-enums.js +113 -0
  45. package/src/tools/babel/plugins/elide-angular-metadata.d.ts +22 -0
  46. package/src/tools/babel/plugins/elide-angular-metadata.js +110 -0
  47. package/src/tools/babel/plugins/index.d.ts +11 -0
  48. package/src/tools/babel/plugins/index.js +21 -0
  49. package/src/tools/babel/plugins/pure-toplevel-functions.d.ts +15 -0
  50. package/src/tools/babel/plugins/pure-toplevel-functions.js +90 -0
  51. package/src/tools/babel/typings.d.ts +21 -0
  52. package/src/tools/esbuild/angular/angular-host.d.ts +26 -0
  53. package/src/tools/esbuild/angular/angular-host.js +134 -0
  54. package/src/tools/esbuild/angular/compilation/angular-compilation.d.ts +42 -0
  55. package/src/tools/esbuild/angular/compilation/angular-compilation.js +94 -0
  56. package/src/tools/esbuild/angular/compilation/aot-compilation.d.ts +21 -0
  57. package/src/tools/esbuild/angular/compilation/aot-compilation.js +224 -0
  58. package/src/tools/esbuild/angular/compilation/factory.d.ts +16 -0
  59. package/src/tools/esbuild/angular/compilation/factory.js +56 -0
  60. package/src/tools/esbuild/angular/compilation/index.d.ts +10 -0
  61. package/src/tools/esbuild/angular/compilation/index.js +17 -0
  62. package/src/tools/esbuild/angular/compilation/jit-bootstrap-transformer.d.ts +10 -0
  63. package/src/tools/esbuild/angular/compilation/jit-bootstrap-transformer.js +182 -0
  64. package/src/tools/esbuild/angular/compilation/jit-compilation.d.ts +21 -0
  65. package/src/tools/esbuild/angular/compilation/jit-compilation.js +106 -0
  66. package/src/tools/esbuild/angular/compilation/noop-compilation.d.ts +20 -0
  67. package/src/tools/esbuild/angular/compilation/noop-compilation.js +26 -0
  68. package/src/tools/esbuild/angular/compilation/parallel-compilation.d.ts +42 -0
  69. package/src/tools/esbuild/angular/compilation/parallel-compilation.js +123 -0
  70. package/src/tools/esbuild/angular/compilation/parallel-worker.d.ts +33 -0
  71. package/src/tools/esbuild/angular/compilation/parallel-worker.js +90 -0
  72. package/src/tools/esbuild/angular/compilation-state.d.ts +15 -0
  73. package/src/tools/esbuild/angular/compilation-state.js +44 -0
  74. package/src/tools/esbuild/angular/compiler-plugin.d.ts +27 -0
  75. package/src/tools/esbuild/angular/compiler-plugin.js +441 -0
  76. package/src/tools/esbuild/angular/component-stylesheets.d.ts +44 -0
  77. package/src/tools/esbuild/angular/component-stylesheets.js +150 -0
  78. package/src/tools/esbuild/angular/diagnostics.d.ts +15 -0
  79. package/src/tools/esbuild/angular/diagnostics.js +69 -0
  80. package/src/tools/esbuild/angular/file-reference-tracker.d.ts +17 -0
  81. package/src/tools/esbuild/angular/file-reference-tracker.js +57 -0
  82. package/src/tools/esbuild/angular/jit-plugin-callbacks.d.ts +23 -0
  83. package/src/tools/esbuild/angular/jit-plugin-callbacks.js +117 -0
  84. package/src/tools/esbuild/angular/jit-resource-transformer.d.ts +17 -0
  85. package/src/tools/esbuild/angular/jit-resource-transformer.js +186 -0
  86. package/src/tools/esbuild/angular/source-file-cache.d.ts +18 -0
  87. package/src/tools/esbuild/angular/source-file-cache.js +65 -0
  88. package/src/tools/esbuild/angular/uri.d.ts +54 -0
  89. package/src/tools/esbuild/angular/uri.js +74 -0
  90. package/src/tools/esbuild/angular/web-worker-transformer.d.ts +17 -0
  91. package/src/tools/esbuild/angular/web-worker-transformer.js +94 -0
  92. package/src/tools/esbuild/application-code-bundle.d.ts +20 -0
  93. package/src/tools/esbuild/application-code-bundle.js +368 -0
  94. package/src/tools/esbuild/budget-stats.d.ts +19 -0
  95. package/src/tools/esbuild/budget-stats.js +59 -0
  96. package/src/tools/esbuild/bundler-context.d.ts +75 -0
  97. package/src/tools/esbuild/bundler-context.js +366 -0
  98. package/src/tools/esbuild/bundler-execution-result.d.ts +71 -0
  99. package/src/tools/esbuild/bundler-execution-result.js +131 -0
  100. package/src/tools/esbuild/cache.d.ts +88 -0
  101. package/src/tools/esbuild/cache.js +92 -0
  102. package/src/tools/esbuild/commonjs-checker.d.ts +28 -0
  103. package/src/tools/esbuild/commonjs-checker.js +151 -0
  104. package/src/tools/esbuild/compiler-plugin-options.d.ts +16 -0
  105. package/src/tools/esbuild/compiler-plugin-options.js +49 -0
  106. package/src/tools/esbuild/external-packages-plugin.d.ts +18 -0
  107. package/src/tools/esbuild/external-packages-plugin.js +70 -0
  108. package/src/tools/esbuild/global-scripts.d.ts +16 -0
  109. package/src/tools/esbuild/global-scripts.js +142 -0
  110. package/src/tools/esbuild/global-styles.d.ts +10 -0
  111. package/src/tools/esbuild/global-styles.js +74 -0
  112. package/src/tools/esbuild/i18n-inliner-worker.d.ts +42 -0
  113. package/src/tools/esbuild/i18n-inliner-worker.js +136 -0
  114. package/src/tools/esbuild/i18n-inliner.d.ts +44 -0
  115. package/src/tools/esbuild/i18n-inliner.js +150 -0
  116. package/src/tools/esbuild/i18n-locale-plugin.d.ts +22 -0
  117. package/src/tools/esbuild/i18n-locale-plugin.js +120 -0
  118. package/src/tools/esbuild/index-html-generator.d.ts +15 -0
  119. package/src/tools/esbuild/index-html-generator.js +81 -0
  120. package/src/tools/esbuild/javascript-transformer-worker.d.ts +19 -0
  121. package/src/tools/esbuild/javascript-transformer-worker.js +154 -0
  122. package/src/tools/esbuild/javascript-transformer.d.ts +54 -0
  123. package/src/tools/esbuild/javascript-transformer.js +147 -0
  124. package/src/tools/esbuild/license-extractor.d.ts +25 -0
  125. package/src/tools/esbuild/license-extractor.js +158 -0
  126. package/src/tools/esbuild/load-result-cache.d.ts +21 -0
  127. package/src/tools/esbuild/load-result-cache.js +75 -0
  128. package/src/tools/esbuild/profiling.d.ts +11 -0
  129. package/src/tools/esbuild/profiling.js +78 -0
  130. package/src/tools/esbuild/rxjs-esm-resolution-plugin.d.ts +18 -0
  131. package/src/tools/esbuild/rxjs-esm-resolution-plugin.js +44 -0
  132. package/src/tools/esbuild/sourcemap-ignorelist-plugin.d.ts +17 -0
  133. package/src/tools/esbuild/sourcemap-ignorelist-plugin.js +73 -0
  134. package/src/tools/esbuild/stylesheets/bundle-options.d.ts +35 -0
  135. package/src/tools/esbuild/stylesheets/bundle-options.js +64 -0
  136. package/src/tools/esbuild/stylesheets/css-inline-fonts-plugin.d.ts +25 -0
  137. package/src/tools/esbuild/stylesheets/css-inline-fonts-plugin.js +57 -0
  138. package/src/tools/esbuild/stylesheets/css-language.d.ts +9 -0
  139. package/src/tools/esbuild/stylesheets/css-language.js +15 -0
  140. package/src/tools/esbuild/stylesheets/css-resource-plugin.d.ts +18 -0
  141. package/src/tools/esbuild/stylesheets/css-resource-plugin.js +114 -0
  142. package/src/tools/esbuild/stylesheets/less-language.d.ts +9 -0
  143. package/src/tools/esbuild/stylesheets/less-language.js +155 -0
  144. package/src/tools/esbuild/stylesheets/sass-language.d.ts +10 -0
  145. package/src/tools/esbuild/stylesheets/sass-language.js +185 -0
  146. package/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.d.ts +58 -0
  147. package/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.js +282 -0
  148. package/src/tools/esbuild/utils.d.ts +49 -0
  149. package/src/tools/esbuild/utils.js +392 -0
  150. package/src/tools/esbuild/virtual-module-plugin.d.ts +33 -0
  151. package/src/tools/esbuild/virtual-module-plugin.js +43 -0
  152. package/src/tools/esbuild/watcher.d.ts +25 -0
  153. package/src/tools/esbuild/watcher.js +118 -0
  154. package/src/tools/sass/lexer.d.ts +18 -0
  155. package/src/tools/sass/lexer.js +161 -0
  156. package/src/tools/sass/rebasing-importer.d.ts +101 -0
  157. package/src/tools/sass/rebasing-importer.js +334 -0
  158. package/src/tools/sass/sass-service.d.ts +72 -0
  159. package/src/tools/sass/sass-service.js +213 -0
  160. package/src/tools/sass/worker.d.ts +8 -0
  161. package/src/tools/sass/worker.js +192 -0
  162. package/src/tools/vite/angular-memory-plugin.d.ts +24 -0
  163. package/src/tools/vite/angular-memory-plugin.js +268 -0
  164. package/src/tools/vite/i18n-locale-plugin.d.ts +18 -0
  165. package/src/tools/vite/i18n-locale-plugin.js +55 -0
  166. package/src/utils/bundle-calculator.d.ts +44 -0
  167. package/src/utils/bundle-calculator.js +303 -0
  168. package/src/utils/check-port.d.ts +8 -0
  169. package/src/utils/check-port.js +58 -0
  170. package/src/utils/color.d.ts +10 -0
  171. package/src/utils/color.js +63 -0
  172. package/src/utils/delete-output-dir.d.ts +11 -0
  173. package/src/utils/delete-output-dir.js +46 -0
  174. package/src/utils/environment-options.d.ts +16 -0
  175. package/src/utils/environment-options.js +79 -0
  176. package/src/utils/error.d.ts +10 -0
  177. package/src/utils/error.js +21 -0
  178. package/src/utils/format-bytes.d.ts +8 -0
  179. package/src/utils/format-bytes.js +22 -0
  180. package/src/utils/i18n-options.d.ts +33 -0
  181. package/src/utils/i18n-options.js +161 -0
  182. package/src/utils/index-file/add-event-dispatch-contract.d.ts +8 -0
  183. package/src/utils/index-file/add-event-dispatch-contract.js +28 -0
  184. package/src/utils/index-file/augment-index-html.d.ts +40 -0
  185. package/src/utils/index-file/augment-index-html.js +239 -0
  186. package/src/utils/index-file/html-rewriting-stream.d.ts +11 -0
  187. package/src/utils/index-file/html-rewriting-stream.js +28 -0
  188. package/src/utils/index-file/index-html-generator.d.ts +57 -0
  189. package/src/utils/index-file/index-html-generator.js +135 -0
  190. package/src/utils/index-file/inline-critical-css.d.ts +24 -0
  191. package/src/utils/index-file/inline-critical-css.js +179 -0
  192. package/src/utils/index-file/inline-fonts.d.ts +23 -0
  193. package/src/utils/index-file/inline-fonts.js +267 -0
  194. package/src/utils/index-file/nonce.d.ts +12 -0
  195. package/src/utils/index-file/nonce.js +55 -0
  196. package/src/utils/index-file/style-nonce.d.ts +12 -0
  197. package/src/utils/index-file/style-nonce.js +55 -0
  198. package/src/utils/index.d.ts +11 -0
  199. package/src/utils/index.js +27 -0
  200. package/src/utils/load-esm.d.ts +20 -0
  201. package/src/utils/load-esm.js +31 -0
  202. package/src/utils/load-proxy-config.d.ts +8 -0
  203. package/src/utils/load-proxy-config.js +189 -0
  204. package/src/utils/load-translations.d.ts +16 -0
  205. package/src/utils/load-translations.js +84 -0
  206. package/src/utils/normalize-asset-patterns.d.ts +14 -0
  207. package/src/utils/normalize-asset-patterns.js +96 -0
  208. package/src/utils/normalize-cache.d.ts +16 -0
  209. package/src/utils/normalize-cache.js +44 -0
  210. package/src/utils/normalize-optimization.d.ts +13 -0
  211. package/src/utils/normalize-optimization.js +42 -0
  212. package/src/utils/normalize-source-maps.d.ts +9 -0
  213. package/src/utils/normalize-source-maps.js +23 -0
  214. package/src/utils/postcss-configuration.d.ts +17 -0
  215. package/src/utils/postcss-configuration.js +86 -0
  216. package/src/utils/purge-cache.d.ts +10 -0
  217. package/src/utils/purge-cache.js +40 -0
  218. package/src/utils/resolve-assets.d.ts +18 -0
  219. package/src/utils/resolve-assets.js +35 -0
  220. package/src/utils/routes-extractor/extractor.d.ts +15 -0
  221. package/src/utils/routes-extractor/extractor.js +97 -0
  222. package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.d.ts +18 -0
  223. package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.js +129 -0
  224. package/src/utils/server-rendering/esm-in-memory-loader/register-hooks.d.ts +8 -0
  225. package/src/utils/server-rendering/esm-in-memory-loader/register-hooks.js +13 -0
  226. package/src/utils/server-rendering/fetch-patch.d.ts +8 -0
  227. package/src/utils/server-rendering/fetch-patch.js +66 -0
  228. package/src/utils/server-rendering/load-esm-from-memory.d.ts +10 -0
  229. package/src/utils/server-rendering/load-esm-from-memory.js +26 -0
  230. package/src/utils/server-rendering/main-bundle-exports.d.ts +27 -0
  231. package/src/utils/server-rendering/main-bundle-exports.js +9 -0
  232. package/src/utils/server-rendering/prerender.d.ts +23 -0
  233. package/src/utils/server-rendering/prerender.js +192 -0
  234. package/src/utils/server-rendering/render-page.d.ts +26 -0
  235. package/src/utils/server-rendering/render-page.js +110 -0
  236. package/src/utils/server-rendering/render-worker.d.ts +22 -0
  237. package/src/utils/server-rendering/render-worker.js +30 -0
  238. package/src/utils/server-rendering/routes-extractor-worker.d.ts +21 -0
  239. package/src/utils/server-rendering/routes-extractor-worker.js +53 -0
  240. package/src/utils/service-worker.d.ts +25 -0
  241. package/src/utils/service-worker.js +211 -0
  242. package/src/utils/spinner.d.ts +20 -0
  243. package/src/utils/spinner.js +55 -0
  244. package/src/utils/stats-table.d.ts +20 -0
  245. package/src/utils/stats-table.js +205 -0
  246. package/src/utils/supported-browsers.d.ts +10 -0
  247. package/src/utils/supported-browsers.js +42 -0
  248. package/src/utils/tty.d.ts +8 -0
  249. package/src/utils/tty.js +23 -0
  250. package/src/utils/url.d.ts +8 -0
  251. package/src/utils/url.js +18 -0
  252. package/src/utils/version.d.ts +8 -0
  253. package/src/utils/version.js +59 -0
@@ -0,0 +1,392 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.isZonelessApp = exports.logMessages = exports.createJsonBuildManifest = exports.getSupportedNodeTargets = exports.transformSupportedBrowsersToTargets = exports.convertOutputFile = exports.createOutputFileFromData = exports.createOutputFileFromText = exports.emitFilesToDisk = exports.writeResultFiles = exports.getFeatureSupport = exports.withNoProgress = exports.withSpinner = exports.calculateEstimatedTransferSizes = exports.logBuildStats = void 0;
14
+ const esbuild_1 = require("esbuild");
15
+ const node_crypto_1 = require("node:crypto");
16
+ const node_fs_1 = require("node:fs");
17
+ const promises_1 = __importDefault(require("node:fs/promises"));
18
+ const node_path_1 = require("node:path");
19
+ const node_url_1 = require("node:url");
20
+ const node_zlib_1 = require("node:zlib");
21
+ const semver_1 = require("semver");
22
+ const spinner_1 = require("../../utils/spinner");
23
+ const stats_table_1 = require("../../utils/stats-table");
24
+ const bundler_context_1 = require("./bundler-context");
25
+ function logBuildStats(metafile, initial, budgetFailures, colors, changedFiles, estimatedTransferSizes, ssrOutputEnabled, verbose) {
26
+ const browserStats = [];
27
+ const serverStats = [];
28
+ let unchangedCount = 0;
29
+ for (const [file, output] of Object.entries(metafile.outputs)) {
30
+ // Only display JavaScript and CSS files
31
+ if (!/\.(?:css|m?js)$/.test(file)) {
32
+ continue;
33
+ }
34
+ // Skip internal component resources
35
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
+ if (output['ng-component']) {
37
+ continue;
38
+ }
39
+ // Show only changed files if a changed list is provided
40
+ if (changedFiles && !changedFiles.has(file)) {
41
+ ++unchangedCount;
42
+ continue;
43
+ }
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
+ const isPlatformServer = output['ng-platform-server'];
46
+ if (isPlatformServer && !ssrOutputEnabled) {
47
+ // Only log server build stats when SSR is enabled.
48
+ continue;
49
+ }
50
+ let name = initial.get(file)?.name;
51
+ if (name === undefined && output.entryPoint) {
52
+ name = (0, node_path_1.basename)(output.entryPoint)
53
+ .replace(/\.[cm]?[jt]s$/, '')
54
+ .replace(/[\\/.]/g, '-');
55
+ }
56
+ const stat = {
57
+ initial: initial.has(file),
58
+ stats: [file, name ?? '-', output.bytes, estimatedTransferSizes?.get(file) ?? '-'],
59
+ };
60
+ if (isPlatformServer) {
61
+ serverStats.push(stat);
62
+ }
63
+ else {
64
+ browserStats.push(stat);
65
+ }
66
+ }
67
+ if (browserStats.length > 0 || serverStats.length > 0) {
68
+ const tableText = (0, stats_table_1.generateEsbuildBuildStatsTable)([browserStats, serverStats], colors, unchangedCount === 0, !!estimatedTransferSizes, budgetFailures, verbose);
69
+ return tableText + '\n';
70
+ }
71
+ else if (changedFiles !== undefined) {
72
+ return '\nNo output file changes.\n';
73
+ }
74
+ if (unchangedCount > 0) {
75
+ return `Unchanged output files: ${unchangedCount}`;
76
+ }
77
+ return '';
78
+ }
79
+ exports.logBuildStats = logBuildStats;
80
+ async function calculateEstimatedTransferSizes(outputFiles) {
81
+ const sizes = new Map();
82
+ if (outputFiles.length <= 0) {
83
+ return sizes;
84
+ }
85
+ return new Promise((resolve, reject) => {
86
+ let completeCount = 0;
87
+ for (const outputFile of outputFiles) {
88
+ // Only calculate JavaScript and CSS files
89
+ if (!outputFile.path.endsWith('.js') && !outputFile.path.endsWith('.css')) {
90
+ ++completeCount;
91
+ continue;
92
+ }
93
+ // Skip compressing small files which may end being larger once compressed and will most likely not be
94
+ // compressed in actual transit.
95
+ if (outputFile.contents.byteLength < 1024) {
96
+ sizes.set(outputFile.path, outputFile.contents.byteLength);
97
+ ++completeCount;
98
+ continue;
99
+ }
100
+ // Directly use the async callback function to minimize the number of Promises that need to be created.
101
+ (0, node_zlib_1.brotliCompress)(outputFile.contents, (error, result) => {
102
+ if (error) {
103
+ reject(error);
104
+ return;
105
+ }
106
+ sizes.set(outputFile.path, result.byteLength);
107
+ if (++completeCount >= outputFiles.length) {
108
+ resolve(sizes);
109
+ }
110
+ });
111
+ }
112
+ // Covers the case where no files need to be compressed
113
+ if (completeCount >= outputFiles.length) {
114
+ resolve(sizes);
115
+ }
116
+ });
117
+ }
118
+ exports.calculateEstimatedTransferSizes = calculateEstimatedTransferSizes;
119
+ async function withSpinner(text, action) {
120
+ const spinner = new spinner_1.Spinner(text);
121
+ spinner.start();
122
+ try {
123
+ return await action();
124
+ }
125
+ finally {
126
+ spinner.stop();
127
+ }
128
+ }
129
+ exports.withSpinner = withSpinner;
130
+ async function withNoProgress(text, action) {
131
+ return action();
132
+ }
133
+ exports.withNoProgress = withNoProgress;
134
+ /**
135
+ * Generates a syntax feature object map for Angular applications based on a list of targets.
136
+ * A full set of feature names can be found here: https://esbuild.github.io/api/#supported
137
+ * @param target An array of browser/engine targets in the format accepted by the esbuild `target` option.
138
+ * @param nativeAsyncAwait Indicate whether to support native async/await.
139
+ * @returns An object that can be used with the esbuild build `supported` option.
140
+ */
141
+ function getFeatureSupport(target, nativeAsyncAwait) {
142
+ const supported = {
143
+ // Native async/await is not supported with Zone.js. Disabling support here will cause
144
+ // esbuild to downlevel async/await, async generators, and for await...of to a Zone.js supported form.
145
+ 'async-await': nativeAsyncAwait,
146
+ // V8 currently has a performance defect involving object spread operations that can cause signficant
147
+ // degradation in runtime performance. By not supporting the language feature here, a downlevel form
148
+ // will be used instead which provides a workaround for the performance issue.
149
+ // For more details: https://bugs.chromium.org/p/v8/issues/detail?id=11536
150
+ 'object-rest-spread': false,
151
+ // Using top-level-await is not guaranteed to be safe with some code optimizations.
152
+ 'top-level-await': false,
153
+ };
154
+ // Detect Safari browser versions that have a class field behavior bug
155
+ // See: https://github.com/angular/angular-cli/issues/24355#issuecomment-1333477033
156
+ // See: https://github.com/WebKit/WebKit/commit/e8788a34b3d5f5b4edd7ff6450b80936bff396f2
157
+ let safariClassFieldScopeBug = false;
158
+ for (const browser of target) {
159
+ let majorVersion;
160
+ if (browser.startsWith('ios')) {
161
+ majorVersion = Number(browser.slice(3, 5));
162
+ }
163
+ else if (browser.startsWith('safari')) {
164
+ majorVersion = Number(browser.slice(6, 8));
165
+ }
166
+ else {
167
+ continue;
168
+ }
169
+ // Technically, 14.0 is not broken but rather does not have support. However, the behavior
170
+ // is identical since it would be set to false by esbuild if present as a target.
171
+ if (majorVersion === 14 || majorVersion === 15) {
172
+ safariClassFieldScopeBug = true;
173
+ break;
174
+ }
175
+ }
176
+ // If class field support cannot be used set to false; otherwise leave undefined to allow
177
+ // esbuild to use `target` to determine support.
178
+ if (safariClassFieldScopeBug) {
179
+ supported['class-field'] = false;
180
+ supported['class-static-field'] = false;
181
+ }
182
+ return supported;
183
+ }
184
+ exports.getFeatureSupport = getFeatureSupport;
185
+ async function writeResultFiles(outputFiles, assetFiles, { base, browser, server }) {
186
+ const directoryExists = new Set();
187
+ const ensureDirectoryExists = async (destPath) => {
188
+ const basePath = (0, node_path_1.dirname)(destPath);
189
+ if (!directoryExists.has(basePath)) {
190
+ await promises_1.default.mkdir((0, node_path_1.join)(base, basePath), { recursive: true });
191
+ directoryExists.add(basePath);
192
+ }
193
+ };
194
+ // Writes the output file to disk and ensures the containing directories are present
195
+ await emitFilesToDisk(outputFiles, async (file) => {
196
+ let outputDir;
197
+ switch (file.type) {
198
+ case bundler_context_1.BuildOutputFileType.Browser:
199
+ case bundler_context_1.BuildOutputFileType.Media:
200
+ outputDir = browser;
201
+ break;
202
+ case bundler_context_1.BuildOutputFileType.Server:
203
+ outputDir = server;
204
+ break;
205
+ case bundler_context_1.BuildOutputFileType.Root:
206
+ outputDir = '';
207
+ break;
208
+ default:
209
+ throw new Error(`Unhandled write for file "${file.path}" with type "${bundler_context_1.BuildOutputFileType[file.type]}".`);
210
+ }
211
+ const destPath = (0, node_path_1.join)(outputDir, file.path);
212
+ // Ensure output subdirectories exist
213
+ await ensureDirectoryExists(destPath);
214
+ // Write file contents
215
+ await promises_1.default.writeFile((0, node_path_1.join)(base, destPath), file.contents);
216
+ });
217
+ if (assetFiles?.length) {
218
+ await emitFilesToDisk(assetFiles, async ({ source, destination }) => {
219
+ const destPath = (0, node_path_1.join)(browser, destination);
220
+ // Ensure output subdirectories exist
221
+ await ensureDirectoryExists(destPath);
222
+ // Copy file contents
223
+ await promises_1.default.copyFile(source, (0, node_path_1.join)(base, destPath), node_fs_1.constants.COPYFILE_FICLONE);
224
+ });
225
+ }
226
+ }
227
+ exports.writeResultFiles = writeResultFiles;
228
+ const MAX_CONCURRENT_WRITES = 64;
229
+ async function emitFilesToDisk(files, writeFileCallback) {
230
+ // Write files in groups of MAX_CONCURRENT_WRITES to avoid too many open files
231
+ for (let fileIndex = 0; fileIndex < files.length;) {
232
+ const groupMax = Math.min(fileIndex + MAX_CONCURRENT_WRITES, files.length);
233
+ const actions = [];
234
+ while (fileIndex < groupMax) {
235
+ actions.push(writeFileCallback(files[fileIndex++]));
236
+ }
237
+ await Promise.all(actions);
238
+ }
239
+ }
240
+ exports.emitFilesToDisk = emitFilesToDisk;
241
+ function createOutputFileFromText(path, text, type) {
242
+ return {
243
+ path,
244
+ text,
245
+ type,
246
+ get hash() {
247
+ return (0, node_crypto_1.createHash)('sha256').update(this.text).digest('hex');
248
+ },
249
+ get contents() {
250
+ return Buffer.from(this.text, 'utf-8');
251
+ },
252
+ clone() {
253
+ return createOutputFileFromText(this.path, this.text, this.type);
254
+ },
255
+ };
256
+ }
257
+ exports.createOutputFileFromText = createOutputFileFromText;
258
+ function createOutputFileFromData(path, data, type) {
259
+ return {
260
+ path,
261
+ type,
262
+ get text() {
263
+ return Buffer.from(data.buffer, data.byteOffset, data.byteLength).toString('utf-8');
264
+ },
265
+ get hash() {
266
+ return (0, node_crypto_1.createHash)('sha256').update(this.text).digest('hex');
267
+ },
268
+ get contents() {
269
+ return data;
270
+ },
271
+ clone() {
272
+ return createOutputFileFromData(this.path, this.contents, this.type);
273
+ },
274
+ };
275
+ }
276
+ exports.createOutputFileFromData = createOutputFileFromData;
277
+ function convertOutputFile(file, type) {
278
+ const { path, contents, hash } = file;
279
+ return {
280
+ contents,
281
+ hash,
282
+ path,
283
+ type,
284
+ get text() {
285
+ return Buffer.from(this.contents.buffer, this.contents.byteOffset, this.contents.byteLength).toString('utf-8');
286
+ },
287
+ clone() {
288
+ return convertOutputFile(this, this.type);
289
+ },
290
+ };
291
+ }
292
+ exports.convertOutputFile = convertOutputFile;
293
+ /**
294
+ * Transform browserlists result to esbuild target.
295
+ * @see https://esbuild.github.io/api/#target
296
+ */
297
+ function transformSupportedBrowsersToTargets(supportedBrowsers) {
298
+ const transformed = [];
299
+ // https://esbuild.github.io/api/#target
300
+ const esBuildSupportedBrowsers = new Set([
301
+ 'chrome',
302
+ 'edge',
303
+ 'firefox',
304
+ 'ie',
305
+ 'ios',
306
+ 'node',
307
+ 'opera',
308
+ 'safari',
309
+ ]);
310
+ for (const browser of supportedBrowsers) {
311
+ let [browserName, version] = browser.toLowerCase().split(' ');
312
+ // browserslist uses the name `ios_saf` for iOS Safari whereas esbuild uses `ios`
313
+ if (browserName === 'ios_saf') {
314
+ browserName = 'ios';
315
+ }
316
+ // browserslist uses ranges `15.2-15.3` versions but only the lowest is required
317
+ // to perform minimum supported feature checks. esbuild also expects a single version.
318
+ [version] = version.split('-');
319
+ if (esBuildSupportedBrowsers.has(browserName)) {
320
+ if (browserName === 'safari' && version === 'tp') {
321
+ // esbuild only supports numeric versions so `TP` is converted to a high number (999) since
322
+ // a Technology Preview (TP) of Safari is assumed to support all currently known features.
323
+ version = '999';
324
+ }
325
+ else if (!version.includes('.')) {
326
+ // A lone major version is considered by esbuild to include all minor versions. However,
327
+ // browserslist does not and is also inconsistent in its `.0` version naming. For example,
328
+ // Safari 15.0 is named `safari 15` but Safari 16.0 is named `safari 16.0`.
329
+ version += '.0';
330
+ }
331
+ transformed.push(browserName + version);
332
+ }
333
+ }
334
+ return transformed;
335
+ }
336
+ exports.transformSupportedBrowsersToTargets = transformSupportedBrowsersToTargets;
337
+ const SUPPORTED_NODE_VERSIONS = '^18.19.1 || >=20.11.1';
338
+ /**
339
+ * Transform supported Node.js versions to esbuild target.
340
+ * @see https://esbuild.github.io/api/#target
341
+ */
342
+ function getSupportedNodeTargets() {
343
+ if (SUPPORTED_NODE_VERSIONS.charAt(0) === '0') {
344
+ // Unlike `pkg_npm`, `ts_library` which is used to run unit tests does not support substitutions.
345
+ return [];
346
+ }
347
+ return SUPPORTED_NODE_VERSIONS.split('||').map((v) => 'node' + (0, semver_1.coerce)(v)?.version);
348
+ }
349
+ exports.getSupportedNodeTargets = getSupportedNodeTargets;
350
+ async function createJsonBuildManifest(result, normalizedOptions) {
351
+ const { colors: color, outputOptions: { base, server, browser }, ssrOptions, } = normalizedOptions;
352
+ const { warnings, errors, prerenderedRoutes } = result;
353
+ const manifest = {
354
+ errors: errors.length ? await (0, esbuild_1.formatMessages)(errors, { kind: 'error', color }) : [],
355
+ warnings: warnings.length ? await (0, esbuild_1.formatMessages)(warnings, { kind: 'warning', color }) : [],
356
+ outputPaths: {
357
+ root: (0, node_url_1.pathToFileURL)(base),
358
+ browser: (0, node_url_1.pathToFileURL)((0, node_path_1.join)(base, browser)),
359
+ server: ssrOptions ? (0, node_url_1.pathToFileURL)((0, node_path_1.join)(base, server)) : undefined,
360
+ },
361
+ prerenderedRoutes,
362
+ };
363
+ return JSON.stringify(manifest, undefined, 2);
364
+ }
365
+ exports.createJsonBuildManifest = createJsonBuildManifest;
366
+ async function logMessages(logger, executionResult, color, jsonLogs) {
367
+ const { warnings, errors, logs } = executionResult;
368
+ if (logs.length) {
369
+ logger.info(logs.join('\n'));
370
+ }
371
+ if (jsonLogs) {
372
+ return;
373
+ }
374
+ if (warnings.length) {
375
+ logger.warn((await (0, esbuild_1.formatMessages)(warnings, { kind: 'warning', color })).join('\n'));
376
+ }
377
+ if (errors.length) {
378
+ logger.error((await (0, esbuild_1.formatMessages)(errors, { kind: 'error', color })).join('\n'));
379
+ }
380
+ }
381
+ exports.logMessages = logMessages;
382
+ /**
383
+ * Ascertain whether the application operates without `zone.js`, we currently rely on the polyfills setting to determine its status.
384
+ * If a file with an extension is provided or if `zone.js` is included in the polyfills, the application is deemed as not zoneless.
385
+ * @param polyfills An array of polyfills
386
+ * @returns true, when the application is considered as zoneless.
387
+ */
388
+ function isZonelessApp(polyfills) {
389
+ // TODO: Instead, we should rely on the presence of zone.js in the polyfills build metadata.
390
+ return !polyfills?.some((p) => p === 'zone.js' || /\.[mc]?[jt]s$/.test(p));
391
+ }
392
+ exports.isZonelessApp = isZonelessApp;
@@ -0,0 +1,33 @@
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
+ import type { OnLoadArgs, Plugin, PluginBuild } from 'esbuild';
9
+ import { LoadResultCache } from './load-result-cache';
10
+ /**
11
+ * Options for the createVirtualModulePlugin
12
+ * @see createVirtualModulePlugin
13
+ */
14
+ export interface VirtualModulePluginOptions {
15
+ /** Namespace. Example: `angular:polyfills`. */
16
+ namespace: string;
17
+ /** If the generated module should be marked as external. */
18
+ external?: boolean;
19
+ /** Method to transform the onResolve path. */
20
+ transformPath?: (path: string) => string;
21
+ /** Method to provide the module content. */
22
+ loadContent: (args: OnLoadArgs, build: PluginBuild) => ReturnType<Parameters<PluginBuild['onLoad']>[1]>;
23
+ /** Restrict to only entry points. Defaults to `true`. */
24
+ entryPointOnly?: boolean;
25
+ /** Load results cache. */
26
+ cache?: LoadResultCache;
27
+ }
28
+ /**
29
+ * Creates an esbuild plugin that generated virtual modules.
30
+ *
31
+ * @returns An esbuild plugin.
32
+ */
33
+ export declare function createVirtualModulePlugin(options: VirtualModulePluginOptions): Plugin;
@@ -0,0 +1,43 @@
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.createVirtualModulePlugin = void 0;
11
+ const load_result_cache_1 = require("./load-result-cache");
12
+ /**
13
+ * Creates an esbuild plugin that generated virtual modules.
14
+ *
15
+ * @returns An esbuild plugin.
16
+ */
17
+ function createVirtualModulePlugin(options) {
18
+ const { namespace, external, transformPath: pathTransformer, loadContent, cache, entryPointOnly = true, } = options;
19
+ return {
20
+ name: namespace.replace(/[/:]/g, '-'),
21
+ setup(build) {
22
+ build.onResolve({ filter: new RegExp('^' + namespace) }, ({ kind, path }) => {
23
+ if (entryPointOnly && kind !== 'entry-point') {
24
+ return null;
25
+ }
26
+ return {
27
+ path: pathTransformer?.(path) ?? path,
28
+ namespace,
29
+ };
30
+ });
31
+ if (external) {
32
+ build.onResolve({ filter: /./, namespace }, ({ path }) => {
33
+ return {
34
+ path,
35
+ external: true,
36
+ };
37
+ });
38
+ }
39
+ build.onLoad({ filter: /./, namespace }, (0, load_result_cache_1.createCachedLoad)(cache, (args) => loadContent(args, build)));
40
+ },
41
+ };
42
+ }
43
+ exports.createVirtualModulePlugin = createVirtualModulePlugin;
@@ -0,0 +1,25 @@
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
+ export declare class ChangedFiles {
9
+ readonly added: Set<string>;
10
+ readonly modified: Set<string>;
11
+ readonly removed: Set<string>;
12
+ get all(): string[];
13
+ toDebugString(): string;
14
+ }
15
+ export interface BuildWatcher extends AsyncIterableIterator<ChangedFiles> {
16
+ add(paths: string | readonly string[]): void;
17
+ remove(paths: string | readonly string[]): void;
18
+ close(): Promise<void>;
19
+ }
20
+ export declare function createWatcher(options?: {
21
+ polling?: boolean;
22
+ interval?: number;
23
+ ignored?: string[];
24
+ followSymlinks?: boolean;
25
+ }): BuildWatcher;
@@ -0,0 +1,118 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.createWatcher = exports.ChangedFiles = void 0;
14
+ const watchpack_1 = __importDefault(require("watchpack"));
15
+ class ChangedFiles {
16
+ added = new Set();
17
+ modified = new Set();
18
+ removed = new Set();
19
+ get all() {
20
+ return [...this.added, ...this.modified, ...this.removed];
21
+ }
22
+ toDebugString() {
23
+ const content = {
24
+ added: Array.from(this.added),
25
+ modified: Array.from(this.modified),
26
+ removed: Array.from(this.removed),
27
+ };
28
+ return JSON.stringify(content, null, 2);
29
+ }
30
+ }
31
+ exports.ChangedFiles = ChangedFiles;
32
+ function createWatcher(options) {
33
+ const watcher = new watchpack_1.default({
34
+ poll: options?.polling ? options?.interval ?? true : false,
35
+ ignored: options?.ignored,
36
+ followSymlinks: options?.followSymlinks,
37
+ aggregateTimeout: 250,
38
+ });
39
+ const watchedFiles = new Set();
40
+ const nextQueue = [];
41
+ let currentChangedFiles;
42
+ watcher.on('aggregated', (changes, removals) => {
43
+ const changedFiles = currentChangedFiles ?? new ChangedFiles();
44
+ for (const file of changes) {
45
+ changedFiles.modified.add(file);
46
+ }
47
+ for (const file of removals) {
48
+ changedFiles.removed.add(file);
49
+ }
50
+ const next = nextQueue.shift();
51
+ if (next) {
52
+ currentChangedFiles = undefined;
53
+ next(changedFiles);
54
+ }
55
+ else {
56
+ currentChangedFiles = changedFiles;
57
+ }
58
+ });
59
+ return {
60
+ [Symbol.asyncIterator]() {
61
+ return this;
62
+ },
63
+ async next() {
64
+ if (currentChangedFiles && nextQueue.length === 0) {
65
+ const result = { value: currentChangedFiles };
66
+ currentChangedFiles = undefined;
67
+ return result;
68
+ }
69
+ return new Promise((resolve) => {
70
+ nextQueue.push((value) => resolve(value ? { value } : { done: true, value }));
71
+ });
72
+ },
73
+ add(paths) {
74
+ const previousSize = watchedFiles.size;
75
+ if (typeof paths === 'string') {
76
+ watchedFiles.add(paths);
77
+ }
78
+ else {
79
+ for (const file of paths) {
80
+ watchedFiles.add(file);
81
+ }
82
+ }
83
+ if (previousSize !== watchedFiles.size) {
84
+ watcher.watch({
85
+ files: watchedFiles,
86
+ });
87
+ }
88
+ },
89
+ remove(paths) {
90
+ const previousSize = watchedFiles.size;
91
+ if (typeof paths === 'string') {
92
+ watchedFiles.delete(paths);
93
+ }
94
+ else {
95
+ for (const file of paths) {
96
+ watchedFiles.delete(file);
97
+ }
98
+ }
99
+ if (previousSize !== watchedFiles.size) {
100
+ watcher.watch({
101
+ files: watchedFiles,
102
+ });
103
+ }
104
+ },
105
+ async close() {
106
+ try {
107
+ watcher.close();
108
+ }
109
+ finally {
110
+ let next;
111
+ while ((next = nextQueue.shift()) !== undefined) {
112
+ next();
113
+ }
114
+ }
115
+ },
116
+ };
117
+ }
118
+ exports.createWatcher = createWatcher;
@@ -0,0 +1,18 @@
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
+ * Scans a CSS or Sass file and locates all valid url function values as defined by the
10
+ * syntax specification.
11
+ * @param contents A string containing a CSS or Sass file to scan.
12
+ * @returns An iterable that yields each CSS url function value found.
13
+ */
14
+ export declare function findUrls(contents: string): Iterable<{
15
+ start: number;
16
+ end: number;
17
+ value: string;
18
+ }>;