@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,75 @@
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 { BuildOptions, Message, Metafile, OutputFile } from 'esbuild';
9
+ import { LoadResultCache } from './load-result-cache';
10
+ export type BundleContextResult = {
11
+ errors: Message[];
12
+ warnings: Message[];
13
+ } | {
14
+ errors: undefined;
15
+ warnings: Message[];
16
+ metafile: Metafile;
17
+ outputFiles: BuildOutputFile[];
18
+ initialFiles: Map<string, InitialFileRecord>;
19
+ externalImports: {
20
+ server?: Set<string>;
21
+ browser?: Set<string>;
22
+ };
23
+ externalConfiguration?: string[];
24
+ };
25
+ export interface InitialFileRecord {
26
+ entrypoint: boolean;
27
+ name?: string;
28
+ type: 'script' | 'style';
29
+ external?: boolean;
30
+ serverFile: boolean;
31
+ }
32
+ export declare enum BuildOutputFileType {
33
+ Browser = 1,
34
+ Media = 2,
35
+ Server = 3,
36
+ Root = 4
37
+ }
38
+ export interface BuildOutputFile extends OutputFile {
39
+ type: BuildOutputFileType;
40
+ clone: () => BuildOutputFile;
41
+ }
42
+ export type BundlerOptionsFactory<T extends BuildOptions = BuildOptions> = (loadCache: LoadResultCache | undefined) => T;
43
+ export declare class BundlerContext {
44
+ #private;
45
+ private workspaceRoot;
46
+ private incremental;
47
+ private initialFilter?;
48
+ readonly watchFiles: Set<string>;
49
+ constructor(workspaceRoot: string, incremental: boolean, options: BuildOptions | BundlerOptionsFactory, initialFilter?: ((initial: Readonly<InitialFileRecord>) => boolean) | undefined);
50
+ static bundleAll(contexts: Iterable<BundlerContext>, changedFiles?: Iterable<string>): Promise<BundleContextResult>;
51
+ /**
52
+ * Executes the esbuild build function and normalizes the build result in the event of a
53
+ * build failure that results in no output being generated.
54
+ * All builds use the `write` option with a value of `false` to allow for the output files
55
+ * build result array to be populated.
56
+ *
57
+ * @returns If output files are generated, the full esbuild BuildResult; if not, the
58
+ * warnings and errors for the attempted build.
59
+ */
60
+ bundle(): Promise<BundleContextResult>;
61
+ /**
62
+ * Invalidate a stored bundler result based on the previous watch files
63
+ * and a list of changed files.
64
+ * The context must be created with incremental mode enabled for results
65
+ * to be stored.
66
+ * @returns True, if the result was invalidated; False, otherwise.
67
+ */
68
+ invalidate(files: Iterable<string>): boolean;
69
+ /**
70
+ * Disposes incremental build resources present in the context.
71
+ *
72
+ * @returns A promise that resolves when disposal is complete.
73
+ */
74
+ dispose(): Promise<void>;
75
+ }
@@ -0,0 +1,366 @@
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.BundlerContext = exports.BuildOutputFileType = void 0;
14
+ const esbuild_1 = require("esbuild");
15
+ const node_assert_1 = __importDefault(require("node:assert"));
16
+ const node_path_1 = require("node:path");
17
+ const load_result_cache_1 = require("./load-result-cache");
18
+ const utils_1 = require("./utils");
19
+ var BuildOutputFileType;
20
+ (function (BuildOutputFileType) {
21
+ BuildOutputFileType[BuildOutputFileType["Browser"] = 1] = "Browser";
22
+ BuildOutputFileType[BuildOutputFileType["Media"] = 2] = "Media";
23
+ BuildOutputFileType[BuildOutputFileType["Server"] = 3] = "Server";
24
+ BuildOutputFileType[BuildOutputFileType["Root"] = 4] = "Root";
25
+ })(BuildOutputFileType || (exports.BuildOutputFileType = BuildOutputFileType = {}));
26
+ /**
27
+ * Determines if an unknown value is an esbuild BuildFailure error object thrown by esbuild.
28
+ * @param value A potential esbuild BuildFailure error object.
29
+ * @returns `true` if the object is determined to be a BuildFailure object; otherwise, `false`.
30
+ */
31
+ function isEsBuildFailure(value) {
32
+ return !!value && typeof value === 'object' && 'errors' in value && 'warnings' in value;
33
+ }
34
+ class BundlerContext {
35
+ workspaceRoot;
36
+ incremental;
37
+ initialFilter;
38
+ #esbuildContext;
39
+ #esbuildOptions;
40
+ #esbuildResult;
41
+ #optionsFactory;
42
+ #shouldCacheResult;
43
+ #loadCache;
44
+ watchFiles = new Set();
45
+ constructor(workspaceRoot, incremental, options, initialFilter) {
46
+ this.workspaceRoot = workspaceRoot;
47
+ this.incremental = incremental;
48
+ this.initialFilter = initialFilter;
49
+ // To cache the results an option factory is needed to capture the full set of dependencies
50
+ this.#shouldCacheResult = incremental && typeof options === 'function';
51
+ this.#optionsFactory = (...args) => {
52
+ const baseOptions = typeof options === 'function' ? options(...args) : options;
53
+ return {
54
+ ...baseOptions,
55
+ metafile: true,
56
+ write: false,
57
+ };
58
+ };
59
+ }
60
+ static async bundleAll(contexts, changedFiles) {
61
+ const individualResults = await Promise.all([...contexts].map((context) => {
62
+ if (changedFiles) {
63
+ context.invalidate(changedFiles);
64
+ }
65
+ return context.bundle();
66
+ }));
67
+ // Return directly if only one result
68
+ if (individualResults.length === 1) {
69
+ return individualResults[0];
70
+ }
71
+ let errors;
72
+ const warnings = [];
73
+ const metafile = { inputs: {}, outputs: {} };
74
+ const initialFiles = new Map();
75
+ const externalImportsBrowser = new Set();
76
+ const externalImportsServer = new Set();
77
+ const outputFiles = [];
78
+ let externalConfiguration;
79
+ for (const result of individualResults) {
80
+ warnings.push(...result.warnings);
81
+ if (result.errors) {
82
+ errors ??= [];
83
+ errors.push(...result.errors);
84
+ continue;
85
+ }
86
+ // Combine metafiles used for the stats option as well as bundle budgets and console output
87
+ if (result.metafile) {
88
+ Object.assign(metafile.inputs, result.metafile.inputs);
89
+ Object.assign(metafile.outputs, result.metafile.outputs);
90
+ }
91
+ result.initialFiles.forEach((value, key) => initialFiles.set(key, value));
92
+ outputFiles.push(...result.outputFiles);
93
+ result.externalImports.browser?.forEach((value) => externalImportsBrowser.add(value));
94
+ result.externalImports.server?.forEach((value) => externalImportsServer.add(value));
95
+ if (result.externalConfiguration) {
96
+ externalConfiguration ??= new Set();
97
+ for (const value of result.externalConfiguration) {
98
+ externalConfiguration.add(value);
99
+ }
100
+ }
101
+ }
102
+ if (errors !== undefined) {
103
+ return { errors, warnings };
104
+ }
105
+ return {
106
+ errors,
107
+ warnings,
108
+ metafile,
109
+ initialFiles,
110
+ outputFiles,
111
+ externalImports: {
112
+ browser: externalImportsBrowser,
113
+ server: externalImportsServer,
114
+ },
115
+ externalConfiguration: externalConfiguration ? [...externalConfiguration] : undefined,
116
+ };
117
+ }
118
+ /**
119
+ * Executes the esbuild build function and normalizes the build result in the event of a
120
+ * build failure that results in no output being generated.
121
+ * All builds use the `write` option with a value of `false` to allow for the output files
122
+ * build result array to be populated.
123
+ *
124
+ * @returns If output files are generated, the full esbuild BuildResult; if not, the
125
+ * warnings and errors for the attempted build.
126
+ */
127
+ async bundle() {
128
+ // Return existing result if present
129
+ if (this.#esbuildResult) {
130
+ return this.#esbuildResult;
131
+ }
132
+ const result = await this.#performBundle();
133
+ if (this.#shouldCacheResult) {
134
+ this.#esbuildResult = result;
135
+ }
136
+ return result;
137
+ }
138
+ async #performBundle() {
139
+ // Create esbuild options if not present
140
+ if (this.#esbuildOptions === undefined) {
141
+ if (this.incremental) {
142
+ this.#loadCache = new load_result_cache_1.MemoryLoadResultCache();
143
+ }
144
+ this.#esbuildOptions = this.#optionsFactory(this.#loadCache);
145
+ }
146
+ if (this.incremental) {
147
+ this.watchFiles.clear();
148
+ }
149
+ let result;
150
+ try {
151
+ if (this.#esbuildContext) {
152
+ // Rebuild using the existing incremental build context
153
+ result = await this.#esbuildContext.rebuild();
154
+ }
155
+ else if (this.incremental) {
156
+ // Create an incremental build context and perform the first build.
157
+ // Context creation does not perform a build.
158
+ this.#esbuildContext = await (0, esbuild_1.context)(this.#esbuildOptions);
159
+ result = await this.#esbuildContext.rebuild();
160
+ }
161
+ else {
162
+ // For non-incremental builds, perform a single build
163
+ result = await (0, esbuild_1.build)(this.#esbuildOptions);
164
+ }
165
+ if (this.#platformIsServer) {
166
+ for (const entry of Object.values(result.metafile.outputs)) {
167
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
168
+ entry['ng-platform-server'] = true;
169
+ }
170
+ }
171
+ }
172
+ catch (failure) {
173
+ // Build failures will throw an exception which contains errors/warnings
174
+ if (isEsBuildFailure(failure)) {
175
+ this.#addErrorsToWatch(failure);
176
+ return failure;
177
+ }
178
+ else {
179
+ throw failure;
180
+ }
181
+ }
182
+ finally {
183
+ if (this.incremental) {
184
+ // When incremental always add any files from the load result cache
185
+ if (this.#loadCache) {
186
+ for (const file of this.#loadCache.watchFiles) {
187
+ if (!isInternalAngularFile(file)) {
188
+ // watch files are fully resolved paths
189
+ this.watchFiles.add(file);
190
+ }
191
+ }
192
+ }
193
+ }
194
+ }
195
+ // Update files that should be watched.
196
+ // While this should technically not be linked to incremental mode, incremental is only
197
+ // currently enabled with watch mode where watch files are needed.
198
+ if (this.incremental) {
199
+ // Add input files except virtual angular files which do not exist on disk
200
+ for (const input of Object.keys(result.metafile.inputs)) {
201
+ if (!isInternalAngularFile(input)) {
202
+ // input file paths are always relative to the workspace root
203
+ this.watchFiles.add((0, node_path_1.join)(this.workspaceRoot, input));
204
+ }
205
+ }
206
+ }
207
+ // Return if the build encountered any errors
208
+ if (result.errors.length) {
209
+ this.#addErrorsToWatch(result);
210
+ return {
211
+ errors: result.errors,
212
+ warnings: result.warnings,
213
+ };
214
+ }
215
+ // Find all initial files
216
+ const initialFiles = new Map();
217
+ for (const outputFile of result.outputFiles) {
218
+ // Entries in the metafile are relative to the `absWorkingDir` option which is set to the workspaceRoot
219
+ const relativeFilePath = (0, node_path_1.relative)(this.workspaceRoot, outputFile.path);
220
+ const entryPoint = result.metafile.outputs[relativeFilePath]?.entryPoint;
221
+ outputFile.path = relativeFilePath;
222
+ if (entryPoint) {
223
+ // The first part of the filename is the name of file (e.g., "polyfills" for "polyfills-7S5G3MDY.js")
224
+ const name = (0, node_path_1.basename)(relativeFilePath).replace(/(?:-[\dA-Z]{8})?\.[a-z]{2,3}$/, '');
225
+ // Entry points are only styles or scripts
226
+ const type = (0, node_path_1.extname)(relativeFilePath) === '.css' ? 'style' : 'script';
227
+ // Only entrypoints with an entry in the options are initial files.
228
+ // Dynamic imports also have an entryPoint value in the meta file.
229
+ if (this.#esbuildOptions.entryPoints?.[name]) {
230
+ // An entryPoint value indicates an initial file
231
+ const record = {
232
+ name,
233
+ type,
234
+ entrypoint: true,
235
+ serverFile: this.#platformIsServer,
236
+ };
237
+ if (!this.initialFilter || this.initialFilter(record)) {
238
+ initialFiles.set(relativeFilePath, record);
239
+ }
240
+ }
241
+ }
242
+ }
243
+ // Analyze for transitive initial files
244
+ const files = [...initialFiles.keys()];
245
+ for (const file of files) {
246
+ for (const initialImport of result.metafile.outputs[file].imports) {
247
+ if (initialFiles.has(initialImport.path)) {
248
+ continue;
249
+ }
250
+ if (initialImport.kind === 'import-statement' || initialImport.kind === 'import-rule') {
251
+ const record = {
252
+ type: initialImport.kind === 'import-rule' ? 'style' : 'script',
253
+ entrypoint: false,
254
+ external: initialImport.external,
255
+ serverFile: this.#platformIsServer,
256
+ };
257
+ if (!this.initialFilter || this.initialFilter(record)) {
258
+ initialFiles.set(initialImport.path, record);
259
+ }
260
+ if (!initialImport.external) {
261
+ files.push(initialImport.path);
262
+ }
263
+ }
264
+ }
265
+ }
266
+ // Collect all external package names
267
+ const externalImports = new Set();
268
+ for (const { imports } of Object.values(result.metafile.outputs)) {
269
+ for (const importData of imports) {
270
+ if (!importData.external ||
271
+ (importData.kind !== 'import-statement' &&
272
+ importData.kind !== 'dynamic-import' &&
273
+ importData.kind !== 'require-call')) {
274
+ continue;
275
+ }
276
+ externalImports.add(importData.path);
277
+ }
278
+ }
279
+ (0, node_assert_1.default)(this.#esbuildOptions, 'esbuild options cannot be undefined.');
280
+ const outputFiles = result.outputFiles.map((file) => {
281
+ let fileType;
282
+ // All files that are not JS, CSS, WASM, or sourcemaps for them are considered media
283
+ if (!/\.([cm]?js|css|wasm)(\.map)?$/i.test(file.path)) {
284
+ fileType = BuildOutputFileType.Media;
285
+ }
286
+ else {
287
+ fileType = this.#platformIsServer
288
+ ? BuildOutputFileType.Server
289
+ : BuildOutputFileType.Browser;
290
+ }
291
+ return (0, utils_1.convertOutputFile)(file, fileType);
292
+ });
293
+ // Return the successful build results
294
+ return {
295
+ ...result,
296
+ outputFiles,
297
+ initialFiles,
298
+ externalImports: {
299
+ [this.#platformIsServer ? 'server' : 'browser']: externalImports,
300
+ },
301
+ externalConfiguration: this.#esbuildOptions.external,
302
+ errors: undefined,
303
+ };
304
+ }
305
+ #addErrorsToWatch(result) {
306
+ for (const error of result.errors) {
307
+ let file = error.location?.file;
308
+ if (file && !isInternalAngularFile(file)) {
309
+ this.watchFiles.add((0, node_path_1.join)(this.workspaceRoot, file));
310
+ }
311
+ for (const note of error.notes) {
312
+ file = note.location?.file;
313
+ if (file && !isInternalAngularFile(file)) {
314
+ this.watchFiles.add((0, node_path_1.join)(this.workspaceRoot, file));
315
+ }
316
+ }
317
+ }
318
+ }
319
+ get #platformIsServer() {
320
+ return this.#esbuildOptions?.platform === 'node';
321
+ }
322
+ /**
323
+ * Invalidate a stored bundler result based on the previous watch files
324
+ * and a list of changed files.
325
+ * The context must be created with incremental mode enabled for results
326
+ * to be stored.
327
+ * @returns True, if the result was invalidated; False, otherwise.
328
+ */
329
+ invalidate(files) {
330
+ if (!this.incremental) {
331
+ return false;
332
+ }
333
+ let invalid = false;
334
+ for (const file of files) {
335
+ if (this.#loadCache?.invalidate(file)) {
336
+ invalid = true;
337
+ continue;
338
+ }
339
+ invalid ||= this.watchFiles.has(file);
340
+ }
341
+ if (invalid) {
342
+ this.#esbuildResult = undefined;
343
+ }
344
+ return invalid;
345
+ }
346
+ /**
347
+ * Disposes incremental build resources present in the context.
348
+ *
349
+ * @returns A promise that resolves when disposal is complete.
350
+ */
351
+ async dispose() {
352
+ try {
353
+ this.#esbuildOptions = undefined;
354
+ this.#esbuildResult = undefined;
355
+ this.#loadCache = undefined;
356
+ await this.#esbuildContext?.dispose();
357
+ }
358
+ finally {
359
+ this.#esbuildContext = undefined;
360
+ }
361
+ }
362
+ }
363
+ exports.BundlerContext = BundlerContext;
364
+ function isInternalAngularFile(file) {
365
+ return file.startsWith('angular:');
366
+ }
@@ -0,0 +1,71 @@
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 { Message, PartialMessage } from 'esbuild';
9
+ import type { ChangedFiles } from '../../tools/esbuild/watcher';
10
+ import type { SourceFileCache } from './angular/source-file-cache';
11
+ import type { BuildOutputFile, BuildOutputFileType, BundlerContext } from './bundler-context';
12
+ export interface BuildOutputAsset {
13
+ source: string;
14
+ destination: string;
15
+ }
16
+ export interface RebuildState {
17
+ rebuildContexts: BundlerContext[];
18
+ codeBundleCache?: SourceFileCache;
19
+ fileChanges: ChangedFiles;
20
+ previousOutputHashes: Map<string, string>;
21
+ }
22
+ export interface ExternalResultMetadata {
23
+ implicitBrowser: string[];
24
+ implicitServer: string[];
25
+ explicit: string[];
26
+ }
27
+ /**
28
+ * Represents the result of a single builder execute call.
29
+ */
30
+ export declare class ExecutionResult {
31
+ private rebuildContexts;
32
+ private codeBundleCache?;
33
+ outputFiles: BuildOutputFile[];
34
+ assetFiles: BuildOutputAsset[];
35
+ errors: (Message | PartialMessage)[];
36
+ prerenderedRoutes: string[];
37
+ warnings: (Message | PartialMessage)[];
38
+ logs: string[];
39
+ externalMetadata?: ExternalResultMetadata;
40
+ constructor(rebuildContexts: BundlerContext[], codeBundleCache?: SourceFileCache | undefined);
41
+ addOutputFile(path: string, content: string, type: BuildOutputFileType): void;
42
+ addAssets(assets: BuildOutputAsset[]): void;
43
+ addLog(value: string): void;
44
+ addError(error: PartialMessage | string): void;
45
+ addErrors(errors: (PartialMessage | string)[]): void;
46
+ addPrerenderedRoutes(routes: string[]): void;
47
+ addWarning(error: PartialMessage | string): void;
48
+ addWarnings(errors: (PartialMessage | string)[]): void;
49
+ /**
50
+ * Add external JavaScript import metadata to the result. This is currently used
51
+ * by the development server to optimize the prebundling process.
52
+ * @param implicitBrowser External dependencies for the browser bundles due to the external packages option.
53
+ * @param implicitServer External dependencies for the server bundles due to the external packages option.
54
+ * @param explicit External dependencies due to explicit project configuration.
55
+ */
56
+ setExternalMetadata(implicitBrowser: string[], implicitServer: string[], explicit: string[] | undefined): void;
57
+ get output(): {
58
+ success: boolean;
59
+ };
60
+ get outputWithFiles(): {
61
+ success: boolean;
62
+ outputFiles: BuildOutputFile[];
63
+ assetFiles: BuildOutputAsset[];
64
+ errors: (Message | PartialMessage)[];
65
+ externalMetadata: ExternalResultMetadata | undefined;
66
+ };
67
+ get watchFiles(): string[];
68
+ createRebuildState(fileChanges: ChangedFiles): RebuildState;
69
+ findChangedFiles(previousOutputHashes: Map<string, string>): Set<string>;
70
+ dispose(): Promise<void>;
71
+ }
@@ -0,0 +1,131 @@
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.ExecutionResult = void 0;
11
+ const node_path_1 = require("node:path");
12
+ const utils_1 = require("./utils");
13
+ /**
14
+ * Represents the result of a single builder execute call.
15
+ */
16
+ class ExecutionResult {
17
+ rebuildContexts;
18
+ codeBundleCache;
19
+ outputFiles = [];
20
+ assetFiles = [];
21
+ errors = [];
22
+ prerenderedRoutes = [];
23
+ warnings = [];
24
+ logs = [];
25
+ externalMetadata;
26
+ constructor(rebuildContexts, codeBundleCache) {
27
+ this.rebuildContexts = rebuildContexts;
28
+ this.codeBundleCache = codeBundleCache;
29
+ }
30
+ addOutputFile(path, content, type) {
31
+ this.outputFiles.push((0, utils_1.createOutputFileFromText)(path, content, type));
32
+ }
33
+ addAssets(assets) {
34
+ this.assetFiles.push(...assets);
35
+ }
36
+ addLog(value) {
37
+ this.logs.push(value);
38
+ }
39
+ addError(error) {
40
+ if (typeof error === 'string') {
41
+ this.errors.push({ text: error, location: null });
42
+ }
43
+ else {
44
+ this.errors.push(error);
45
+ }
46
+ }
47
+ addErrors(errors) {
48
+ for (const error of errors) {
49
+ this.addError(error);
50
+ }
51
+ }
52
+ addPrerenderedRoutes(routes) {
53
+ this.prerenderedRoutes.push(...routes);
54
+ // Sort the prerendered routes.
55
+ this.prerenderedRoutes.sort((a, b) => a.localeCompare(b));
56
+ }
57
+ addWarning(error) {
58
+ if (typeof error === 'string') {
59
+ this.warnings.push({ text: error, location: null });
60
+ }
61
+ else {
62
+ this.warnings.push(error);
63
+ }
64
+ }
65
+ addWarnings(errors) {
66
+ for (const error of errors) {
67
+ this.addWarning(error);
68
+ }
69
+ }
70
+ /**
71
+ * Add external JavaScript import metadata to the result. This is currently used
72
+ * by the development server to optimize the prebundling process.
73
+ * @param implicitBrowser External dependencies for the browser bundles due to the external packages option.
74
+ * @param implicitServer External dependencies for the server bundles due to the external packages option.
75
+ * @param explicit External dependencies due to explicit project configuration.
76
+ */
77
+ setExternalMetadata(implicitBrowser, implicitServer, explicit) {
78
+ this.externalMetadata = { implicitBrowser, implicitServer, explicit: explicit ?? [] };
79
+ }
80
+ get output() {
81
+ return {
82
+ success: this.errors.length === 0,
83
+ };
84
+ }
85
+ get outputWithFiles() {
86
+ return {
87
+ success: this.errors.length === 0,
88
+ outputFiles: this.outputFiles,
89
+ assetFiles: this.assetFiles,
90
+ errors: this.errors,
91
+ externalMetadata: this.externalMetadata,
92
+ };
93
+ }
94
+ get watchFiles() {
95
+ // Bundler contexts internally normalize file dependencies
96
+ const files = this.rebuildContexts.flatMap((context) => [...context.watchFiles]);
97
+ if (this.codeBundleCache?.referencedFiles) {
98
+ // These files originate from TS/NG and can have POSIX path separators even on Windows.
99
+ // To ensure path comparisons are valid, all these paths must be normalized.
100
+ files.push(...this.codeBundleCache.referencedFiles.map(node_path_1.normalize));
101
+ }
102
+ if (this.codeBundleCache?.loadResultCache) {
103
+ // Load result caches internally normalize file dependencies
104
+ files.push(...this.codeBundleCache.loadResultCache.watchFiles);
105
+ }
106
+ return files;
107
+ }
108
+ createRebuildState(fileChanges) {
109
+ this.codeBundleCache?.invalidate([...fileChanges.modified, ...fileChanges.removed]);
110
+ return {
111
+ rebuildContexts: this.rebuildContexts,
112
+ codeBundleCache: this.codeBundleCache,
113
+ fileChanges,
114
+ previousOutputHashes: new Map(this.outputFiles.map((file) => [file.path, file.hash])),
115
+ };
116
+ }
117
+ findChangedFiles(previousOutputHashes) {
118
+ const changed = new Set();
119
+ for (const file of this.outputFiles) {
120
+ const previousHash = previousOutputHashes.get(file.path);
121
+ if (previousHash === undefined || previousHash !== file.hash) {
122
+ changed.add(file.path);
123
+ }
124
+ }
125
+ return changed;
126
+ }
127
+ async dispose() {
128
+ await Promise.allSettled(this.rebuildContexts.map((context) => context.dispose()));
129
+ }
130
+ }
131
+ exports.ExecutionResult = ExecutionResult;