@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,224 @@
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.AotCompilation = void 0;
14
+ const node_assert_1 = __importDefault(require("node:assert"));
15
+ const typescript_1 = __importDefault(require("typescript"));
16
+ const profiling_1 = require("../../profiling");
17
+ const angular_host_1 = require("../angular-host");
18
+ const web_worker_transformer_1 = require("../web-worker-transformer");
19
+ const angular_compilation_1 = require("./angular-compilation");
20
+ const jit_bootstrap_transformer_1 = require("./jit-bootstrap-transformer");
21
+ class AngularCompilationState {
22
+ angularProgram;
23
+ compilerHost;
24
+ typeScriptProgram;
25
+ affectedFiles;
26
+ templateDiagnosticsOptimization;
27
+ webWorkerTransform;
28
+ diagnosticCache;
29
+ constructor(angularProgram, compilerHost, typeScriptProgram, affectedFiles, templateDiagnosticsOptimization, webWorkerTransform, diagnosticCache = new WeakMap()) {
30
+ this.angularProgram = angularProgram;
31
+ this.compilerHost = compilerHost;
32
+ this.typeScriptProgram = typeScriptProgram;
33
+ this.affectedFiles = affectedFiles;
34
+ this.templateDiagnosticsOptimization = templateDiagnosticsOptimization;
35
+ this.webWorkerTransform = webWorkerTransform;
36
+ this.diagnosticCache = diagnosticCache;
37
+ }
38
+ get angularCompiler() {
39
+ return this.angularProgram.compiler;
40
+ }
41
+ }
42
+ class AotCompilation extends angular_compilation_1.AngularCompilation {
43
+ #state;
44
+ async initialize(tsconfig, hostOptions, compilerOptionsTransformer) {
45
+ // Dynamically load the Angular compiler CLI package
46
+ const { NgtscProgram, OptimizeFor } = await angular_compilation_1.AngularCompilation.loadCompilerCli();
47
+ // Load the compiler configuration and transform as needed
48
+ const { options: originalCompilerOptions, rootNames, errors: configurationDiagnostics, } = await this.loadConfiguration(tsconfig);
49
+ const compilerOptions = compilerOptionsTransformer?.(originalCompilerOptions) ?? originalCompilerOptions;
50
+ // Create Angular compiler host
51
+ const host = (0, angular_host_1.createAngularCompilerHost)(typescript_1.default, compilerOptions, hostOptions);
52
+ // Create the Angular specific program that contains the Angular compiler
53
+ const angularProgram = (0, profiling_1.profileSync)('NG_CREATE_PROGRAM', () => new NgtscProgram(rootNames, compilerOptions, host, this.#state?.angularProgram));
54
+ const angularCompiler = angularProgram.compiler;
55
+ const angularTypeScriptProgram = angularProgram.getTsProgram();
56
+ (0, angular_host_1.ensureSourceFileVersions)(angularTypeScriptProgram);
57
+ let oldProgram = this.#state?.typeScriptProgram;
58
+ let usingBuildInfo = false;
59
+ if (!oldProgram) {
60
+ oldProgram = typescript_1.default.readBuilderProgram(compilerOptions, host);
61
+ usingBuildInfo = !!oldProgram;
62
+ }
63
+ const typeScriptProgram = typescript_1.default.createEmitAndSemanticDiagnosticsBuilderProgram(angularTypeScriptProgram, host, oldProgram, configurationDiagnostics);
64
+ await (0, profiling_1.profileAsync)('NG_ANALYZE_PROGRAM', () => angularCompiler.analyzeAsync());
65
+ const affectedFiles = (0, profiling_1.profileSync)('NG_FIND_AFFECTED', () => findAffectedFiles(typeScriptProgram, angularCompiler, usingBuildInfo));
66
+ // Get all files referenced in the TypeScript/Angular program including component resources
67
+ const referencedFiles = typeScriptProgram
68
+ .getSourceFiles()
69
+ .filter((sourceFile) => !angularCompiler.ignoreForEmit.has(sourceFile))
70
+ .flatMap((sourceFile) => {
71
+ const resourceDependencies = angularCompiler.getResourceDependencies(sourceFile);
72
+ // Also invalidate Angular diagnostics for a source file if component resources are modified
73
+ if (this.#state && hostOptions.modifiedFiles?.size) {
74
+ for (const resourceDependency of resourceDependencies) {
75
+ if (hostOptions.modifiedFiles.has(resourceDependency)) {
76
+ this.#state.diagnosticCache.delete(sourceFile);
77
+ // Also mark as affected in case changed template affects diagnostics
78
+ affectedFiles.add(sourceFile);
79
+ }
80
+ }
81
+ }
82
+ return [sourceFile.fileName, ...resourceDependencies];
83
+ });
84
+ this.#state = new AngularCompilationState(angularProgram, host, typeScriptProgram, affectedFiles, affectedFiles.size === 1 ? OptimizeFor.SingleFile : OptimizeFor.WholeProgram, (0, web_worker_transformer_1.createWorkerTransformer)(hostOptions.processWebWorker.bind(hostOptions)), this.#state?.diagnosticCache);
85
+ return { affectedFiles, compilerOptions, referencedFiles };
86
+ }
87
+ *collectDiagnostics(modes) {
88
+ (0, node_assert_1.default)(this.#state, 'Angular compilation must be initialized prior to collecting diagnostics.');
89
+ const { affectedFiles, angularCompiler, diagnosticCache, templateDiagnosticsOptimization, typeScriptProgram, } = this.#state;
90
+ const syntactic = modes & angular_compilation_1.DiagnosticModes.Syntactic;
91
+ const semantic = modes & angular_compilation_1.DiagnosticModes.Semantic;
92
+ // Collect program level diagnostics
93
+ if (modes & angular_compilation_1.DiagnosticModes.Option) {
94
+ yield* typeScriptProgram.getConfigFileParsingDiagnostics();
95
+ yield* angularCompiler.getOptionDiagnostics();
96
+ yield* typeScriptProgram.getOptionsDiagnostics();
97
+ }
98
+ if (syntactic) {
99
+ yield* typeScriptProgram.getGlobalDiagnostics();
100
+ }
101
+ // Collect source file specific diagnostics
102
+ for (const sourceFile of typeScriptProgram.getSourceFiles()) {
103
+ if (angularCompiler.ignoreForDiagnostics.has(sourceFile)) {
104
+ continue;
105
+ }
106
+ if (syntactic) {
107
+ // TypeScript will use cached diagnostics for files that have not been
108
+ // changed or affected for this build when using incremental building.
109
+ yield* (0, profiling_1.profileSync)('NG_DIAGNOSTICS_SYNTACTIC', () => typeScriptProgram.getSyntacticDiagnostics(sourceFile), true);
110
+ }
111
+ if (!semantic) {
112
+ continue;
113
+ }
114
+ yield* (0, profiling_1.profileSync)('NG_DIAGNOSTICS_SEMANTIC', () => typeScriptProgram.getSemanticDiagnostics(sourceFile), true);
115
+ // Declaration files cannot have template diagnostics
116
+ if (sourceFile.isDeclarationFile) {
117
+ continue;
118
+ }
119
+ // Only request Angular template diagnostics for affected files to avoid
120
+ // overhead of template diagnostics for unchanged files.
121
+ if (affectedFiles.has(sourceFile)) {
122
+ const angularDiagnostics = (0, profiling_1.profileSync)('NG_DIAGNOSTICS_TEMPLATE', () => angularCompiler.getDiagnosticsForFile(sourceFile, templateDiagnosticsOptimization), true);
123
+ diagnosticCache.set(sourceFile, angularDiagnostics);
124
+ yield* angularDiagnostics;
125
+ }
126
+ else {
127
+ const angularDiagnostics = diagnosticCache.get(sourceFile);
128
+ if (angularDiagnostics) {
129
+ yield* angularDiagnostics;
130
+ }
131
+ }
132
+ }
133
+ }
134
+ emitAffectedFiles() {
135
+ (0, node_assert_1.default)(this.#state, 'Angular compilation must be initialized prior to emitting files.');
136
+ const { angularCompiler, compilerHost, typeScriptProgram, webWorkerTransform } = this.#state;
137
+ const buildInfoFilename = typeScriptProgram.getCompilerOptions().tsBuildInfoFile ?? '.tsbuildinfo';
138
+ const emittedFiles = new Map();
139
+ const writeFileCallback = (filename, contents, _a, _b, sourceFiles) => {
140
+ if (!sourceFiles?.length && filename.endsWith(buildInfoFilename)) {
141
+ // Save builder info contents to specified location
142
+ compilerHost.writeFile(filename, contents, false);
143
+ return;
144
+ }
145
+ (0, node_assert_1.default)(sourceFiles?.length === 1, 'Invalid TypeScript program emit for ' + filename);
146
+ const sourceFile = typescript_1.default.getOriginalNode(sourceFiles[0], typescript_1.default.isSourceFile);
147
+ if (angularCompiler.ignoreForEmit.has(sourceFile)) {
148
+ return;
149
+ }
150
+ angularCompiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);
151
+ emittedFiles.set(sourceFile, { filename: sourceFile.fileName, contents });
152
+ };
153
+ const transformers = angularCompiler.prepareEmit().transformers;
154
+ transformers.before ??= [];
155
+ transformers.before.push((0, jit_bootstrap_transformer_1.replaceBootstrap)(() => typeScriptProgram.getProgram().getTypeChecker()));
156
+ transformers.before.push(webWorkerTransform);
157
+ // TypeScript will loop until there are no more affected files in the program
158
+ while (typeScriptProgram.emitNextAffectedFile(writeFileCallback, undefined, undefined, transformers)) {
159
+ /* empty */
160
+ }
161
+ // Angular may have files that must be emitted but TypeScript does not consider affected
162
+ for (const sourceFile of typeScriptProgram.getSourceFiles()) {
163
+ if (emittedFiles.has(sourceFile) || angularCompiler.ignoreForEmit.has(sourceFile)) {
164
+ continue;
165
+ }
166
+ if (sourceFile.isDeclarationFile) {
167
+ continue;
168
+ }
169
+ if (angularCompiler.incrementalCompilation.safeToSkipEmit(sourceFile)) {
170
+ continue;
171
+ }
172
+ typeScriptProgram.emit(sourceFile, writeFileCallback, undefined, undefined, transformers);
173
+ }
174
+ return emittedFiles.values();
175
+ }
176
+ }
177
+ exports.AotCompilation = AotCompilation;
178
+ function findAffectedFiles(builder, { ignoreForDiagnostics }, includeTTC) {
179
+ const affectedFiles = new Set();
180
+ // eslint-disable-next-line no-constant-condition
181
+ while (true) {
182
+ const result = builder.getSemanticDiagnosticsOfNextAffectedFile(undefined, (sourceFile) => {
183
+ // If the affected file is a TTC shim, add the shim's original source file.
184
+ // This ensures that changes that affect TTC are typechecked even when the changes
185
+ // are otherwise unrelated from a TS perspective and do not result in Ivy codegen changes.
186
+ // For example, changing @Input property types of a directive used in another component's
187
+ // template.
188
+ // A TTC shim is a file that has been ignored for diagnostics and has a filename ending in `.ngtypecheck.ts`.
189
+ if (ignoreForDiagnostics.has(sourceFile) && sourceFile.fileName.endsWith('.ngtypecheck.ts')) {
190
+ // This file name conversion relies on internal compiler logic and should be converted
191
+ // to an official method when available. 15 is length of `.ngtypecheck.ts`
192
+ const originalFilename = sourceFile.fileName.slice(0, -15) + '.ts';
193
+ const originalSourceFile = builder.getSourceFile(originalFilename);
194
+ if (originalSourceFile) {
195
+ affectedFiles.add(originalSourceFile);
196
+ }
197
+ return true;
198
+ }
199
+ return false;
200
+ });
201
+ if (!result) {
202
+ break;
203
+ }
204
+ affectedFiles.add(result.affected);
205
+ }
206
+ // Add all files with associated template type checking files.
207
+ // Stored TS build info does not have knowledge of the AOT compiler or the typechecking state of the templates.
208
+ // To ensure that errors are reported correctly, all AOT component diagnostics need to be analyzed even if build
209
+ // info is present.
210
+ if (includeTTC) {
211
+ for (const sourceFile of builder.getSourceFiles()) {
212
+ if (ignoreForDiagnostics.has(sourceFile) && sourceFile.fileName.endsWith('.ngtypecheck.ts')) {
213
+ // This file name conversion relies on internal compiler logic and should be converted
214
+ // to an official method when available. 15 is length of `.ngtypecheck.ts`
215
+ const originalFilename = sourceFile.fileName.slice(0, -15) + '.ts';
216
+ const originalSourceFile = builder.getSourceFile(originalFilename);
217
+ if (originalSourceFile) {
218
+ affectedFiles.add(originalSourceFile);
219
+ }
220
+ }
221
+ }
222
+ }
223
+ return affectedFiles;
224
+ }
@@ -0,0 +1,16 @@
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 { AngularCompilation } from './angular-compilation';
9
+ /**
10
+ * Creates an Angular compilation object that can be used to perform Angular application
11
+ * compilation either for AOT or JIT mode. By default a parallel compilation is created
12
+ * that uses a Node.js worker thread.
13
+ * @param jit True, for Angular JIT compilation; False, for Angular AOT compilation.
14
+ * @returns An instance of an Angular compilation object.
15
+ */
16
+ export declare function createAngularCompilation(jit: boolean): Promise<AngularCompilation>;
@@ -0,0 +1,56 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.createAngularCompilation = void 0;
34
+ const environment_options_1 = require("../../../../utils/environment-options");
35
+ /**
36
+ * Creates an Angular compilation object that can be used to perform Angular application
37
+ * compilation either for AOT or JIT mode. By default a parallel compilation is created
38
+ * that uses a Node.js worker thread.
39
+ * @param jit True, for Angular JIT compilation; False, for Angular AOT compilation.
40
+ * @returns An instance of an Angular compilation object.
41
+ */
42
+ async function createAngularCompilation(jit) {
43
+ if (environment_options_1.useParallelTs) {
44
+ const { ParallelCompilation } = await Promise.resolve().then(() => __importStar(require('./parallel-compilation')));
45
+ return new ParallelCompilation(jit);
46
+ }
47
+ if (jit) {
48
+ const { JitCompilation } = await Promise.resolve().then(() => __importStar(require('./jit-compilation')));
49
+ return new JitCompilation();
50
+ }
51
+ else {
52
+ const { AotCompilation } = await Promise.resolve().then(() => __importStar(require('./aot-compilation')));
53
+ return new AotCompilation();
54
+ }
55
+ }
56
+ exports.createAngularCompilation = createAngularCompilation;
@@ -0,0 +1,10 @@
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 { AngularCompilation, DiagnosticModes } from './angular-compilation';
9
+ export { createAngularCompilation } from './factory';
10
+ export { NoopCompilation } from './noop-compilation';
@@ -0,0 +1,17 @@
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.NoopCompilation = exports.createAngularCompilation = exports.DiagnosticModes = exports.AngularCompilation = void 0;
11
+ var angular_compilation_1 = require("./angular-compilation");
12
+ Object.defineProperty(exports, "AngularCompilation", { enumerable: true, get: function () { return angular_compilation_1.AngularCompilation; } });
13
+ Object.defineProperty(exports, "DiagnosticModes", { enumerable: true, get: function () { return angular_compilation_1.DiagnosticModes; } });
14
+ var factory_1 = require("./factory");
15
+ Object.defineProperty(exports, "createAngularCompilation", { enumerable: true, get: function () { return factory_1.createAngularCompilation; } });
16
+ var noop_compilation_1 = require("./noop-compilation");
17
+ Object.defineProperty(exports, "NoopCompilation", { enumerable: true, get: function () { return noop_compilation_1.NoopCompilation; } });
@@ -0,0 +1,10 @@
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 ts from 'typescript';
9
+ export declare function replaceBootstrap(getTypeChecker: () => ts.TypeChecker): ts.TransformerFactory<ts.SourceFile>;
10
+ export declare function elideImports(sourceFile: ts.SourceFile, removedNodes: ts.Node[], getTypeChecker: () => ts.TypeChecker, compilerOptions: ts.CompilerOptions): Set<ts.Node>;
@@ -0,0 +1,182 @@
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.elideImports = exports.replaceBootstrap = void 0;
14
+ const typescript_1 = __importDefault(require("typescript"));
15
+ /**
16
+ * The name of the Angular platform that should be replaced within
17
+ * bootstrap call expressions to support AOT.
18
+ */
19
+ const PLATFORM_BROWSER_DYNAMIC_NAME = 'platformBrowserDynamic';
20
+ function replaceBootstrap(getTypeChecker) {
21
+ return (context) => {
22
+ let bootstrapImport;
23
+ let bootstrapNamespace;
24
+ const replacedNodes = [];
25
+ const nodeFactory = context.factory;
26
+ const visitNode = (node) => {
27
+ if (typescript_1.default.isCallExpression(node) && typescript_1.default.isIdentifier(node.expression)) {
28
+ const target = node.expression;
29
+ if (target.text === PLATFORM_BROWSER_DYNAMIC_NAME) {
30
+ if (!bootstrapNamespace) {
31
+ bootstrapNamespace = nodeFactory.createUniqueName('__NgCli_bootstrap_');
32
+ bootstrapImport = nodeFactory.createImportDeclaration(undefined, nodeFactory.createImportClause(false, undefined, nodeFactory.createNamespaceImport(bootstrapNamespace)), nodeFactory.createStringLiteral('@angular/platform-browser'));
33
+ }
34
+ replacedNodes.push(target);
35
+ return nodeFactory.updateCallExpression(node, nodeFactory.createPropertyAccessExpression(bootstrapNamespace, 'platformBrowser'), node.typeArguments, node.arguments);
36
+ }
37
+ }
38
+ return typescript_1.default.visitEachChild(node, visitNode, context);
39
+ };
40
+ return (sourceFile) => {
41
+ if (!sourceFile.text.includes(PLATFORM_BROWSER_DYNAMIC_NAME)) {
42
+ return sourceFile;
43
+ }
44
+ let updatedSourceFile = typescript_1.default.visitEachChild(sourceFile, visitNode, context);
45
+ if (bootstrapImport) {
46
+ // Remove any unused platform browser dynamic imports
47
+ const removals = elideImports(updatedSourceFile, replacedNodes, getTypeChecker, context.getCompilerOptions());
48
+ if (removals.size > 0) {
49
+ updatedSourceFile = typescript_1.default.visitEachChild(updatedSourceFile, (node) => (removals.has(node) ? undefined : node), context);
50
+ }
51
+ // Add new platform browser import
52
+ return nodeFactory.updateSourceFile(updatedSourceFile, typescript_1.default.setTextRange(nodeFactory.createNodeArray([bootstrapImport, ...updatedSourceFile.statements]), sourceFile.statements));
53
+ }
54
+ else {
55
+ return updatedSourceFile;
56
+ }
57
+ };
58
+ };
59
+ }
60
+ exports.replaceBootstrap = replaceBootstrap;
61
+ // Remove imports for which all identifiers have been removed.
62
+ // Needs type checker, and works even if it's not the first transformer.
63
+ // Works by removing imports for symbols whose identifiers have all been removed.
64
+ // Doesn't use the `symbol.declarations` because that previous transforms might have removed nodes
65
+ // but the type checker doesn't know.
66
+ // See https://github.com/Microsoft/TypeScript/issues/17552 for more information.
67
+ function elideImports(sourceFile, removedNodes, getTypeChecker, compilerOptions) {
68
+ const importNodeRemovals = new Set();
69
+ if (removedNodes.length === 0) {
70
+ return importNodeRemovals;
71
+ }
72
+ const typeChecker = getTypeChecker();
73
+ // Collect all imports and used identifiers
74
+ const usedSymbols = new Set();
75
+ const imports = [];
76
+ typescript_1.default.forEachChild(sourceFile, function visit(node) {
77
+ // Skip removed nodes.
78
+ if (removedNodes.includes(node)) {
79
+ return;
80
+ }
81
+ // Consider types for 'implements' as unused.
82
+ // A HeritageClause token can also be an 'AbstractKeyword'
83
+ // which in that case we should not elide the import.
84
+ if (typescript_1.default.isHeritageClause(node) && node.token === typescript_1.default.SyntaxKind.ImplementsKeyword) {
85
+ return;
86
+ }
87
+ // Record import and skip
88
+ if (typescript_1.default.isImportDeclaration(node)) {
89
+ if (!node.importClause?.isTypeOnly) {
90
+ imports.push(node);
91
+ }
92
+ return;
93
+ }
94
+ // Type reference imports do not need to be emitted when emitDecoratorMetadata is disabled.
95
+ if (typescript_1.default.isTypeReferenceNode(node) && !compilerOptions.emitDecoratorMetadata) {
96
+ return;
97
+ }
98
+ let symbol;
99
+ switch (node.kind) {
100
+ case typescript_1.default.SyntaxKind.Identifier:
101
+ const parent = node.parent;
102
+ if (parent && typescript_1.default.isShorthandPropertyAssignment(parent)) {
103
+ const shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(parent);
104
+ if (shorthandSymbol) {
105
+ symbol = shorthandSymbol;
106
+ }
107
+ }
108
+ else {
109
+ symbol = typeChecker.getSymbolAtLocation(node);
110
+ }
111
+ break;
112
+ case typescript_1.default.SyntaxKind.ExportSpecifier:
113
+ symbol = typeChecker.getExportSpecifierLocalTargetSymbol(node);
114
+ break;
115
+ case typescript_1.default.SyntaxKind.ShorthandPropertyAssignment:
116
+ symbol = typeChecker.getShorthandAssignmentValueSymbol(node);
117
+ break;
118
+ }
119
+ if (symbol) {
120
+ usedSymbols.add(symbol);
121
+ }
122
+ typescript_1.default.forEachChild(node, visit);
123
+ });
124
+ if (imports.length === 0) {
125
+ return importNodeRemovals;
126
+ }
127
+ const isUnused = (node) => {
128
+ // Do not remove JSX factory imports
129
+ if (node.text === compilerOptions.jsxFactory) {
130
+ return false;
131
+ }
132
+ const symbol = typeChecker.getSymbolAtLocation(node);
133
+ return symbol && !usedSymbols.has(symbol);
134
+ };
135
+ for (const node of imports) {
136
+ if (!node.importClause) {
137
+ // "import 'abc';"
138
+ continue;
139
+ }
140
+ const namedBindings = node.importClause.namedBindings;
141
+ if (namedBindings && typescript_1.default.isNamespaceImport(namedBindings)) {
142
+ // "import * as XYZ from 'abc';"
143
+ if (isUnused(namedBindings.name)) {
144
+ importNodeRemovals.add(node);
145
+ }
146
+ }
147
+ else {
148
+ const specifierNodeRemovals = [];
149
+ let clausesCount = 0;
150
+ // "import { XYZ, ... } from 'abc';"
151
+ if (namedBindings && typescript_1.default.isNamedImports(namedBindings)) {
152
+ let removedClausesCount = 0;
153
+ clausesCount += namedBindings.elements.length;
154
+ for (const specifier of namedBindings.elements) {
155
+ if (specifier.isTypeOnly || isUnused(specifier.name)) {
156
+ removedClausesCount++;
157
+ // in case we don't have any more namedImports we should remove the parent ie the {}
158
+ const nodeToRemove = clausesCount === removedClausesCount ? specifier.parent : specifier;
159
+ specifierNodeRemovals.push(nodeToRemove);
160
+ }
161
+ }
162
+ }
163
+ // "import XYZ from 'abc';"
164
+ if (node.importClause.name) {
165
+ clausesCount++;
166
+ if (node.importClause.isTypeOnly || isUnused(node.importClause.name)) {
167
+ specifierNodeRemovals.push(node.importClause.name);
168
+ }
169
+ }
170
+ if (specifierNodeRemovals.length === clausesCount) {
171
+ importNodeRemovals.add(node);
172
+ }
173
+ else {
174
+ for (const specifierNodeRemoval of specifierNodeRemovals) {
175
+ importNodeRemovals.add(specifierNodeRemoval);
176
+ }
177
+ }
178
+ }
179
+ }
180
+ return importNodeRemovals;
181
+ }
182
+ exports.elideImports = elideImports;
@@ -0,0 +1,21 @@
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 ng from '@angular/compiler-cli';
9
+ import ts from 'typescript';
10
+ import { AngularHostOptions } from '../angular-host';
11
+ import { AngularCompilation, DiagnosticModes, EmitFileResult } from './angular-compilation';
12
+ export declare class JitCompilation extends AngularCompilation {
13
+ #private;
14
+ initialize(tsconfig: string, hostOptions: AngularHostOptions, compilerOptionsTransformer?: (compilerOptions: ng.CompilerOptions) => ng.CompilerOptions): Promise<{
15
+ affectedFiles: ReadonlySet<ts.SourceFile>;
16
+ compilerOptions: ng.CompilerOptions;
17
+ referencedFiles: readonly string[];
18
+ }>;
19
+ collectDiagnostics(modes: DiagnosticModes): Iterable<ts.Diagnostic>;
20
+ emitAffectedFiles(): Iterable<EmitFileResult>;
21
+ }
@@ -0,0 +1,106 @@
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.JitCompilation = void 0;
14
+ const node_assert_1 = __importDefault(require("node:assert"));
15
+ const typescript_1 = __importDefault(require("typescript"));
16
+ const profiling_1 = require("../../profiling");
17
+ const angular_host_1 = require("../angular-host");
18
+ const jit_resource_transformer_1 = require("../jit-resource-transformer");
19
+ const web_worker_transformer_1 = require("../web-worker-transformer");
20
+ const angular_compilation_1 = require("./angular-compilation");
21
+ class JitCompilationState {
22
+ compilerHost;
23
+ typeScriptProgram;
24
+ constructorParametersDownlevelTransform;
25
+ replaceResourcesTransform;
26
+ webWorkerTransform;
27
+ constructor(compilerHost, typeScriptProgram, constructorParametersDownlevelTransform, replaceResourcesTransform, webWorkerTransform) {
28
+ this.compilerHost = compilerHost;
29
+ this.typeScriptProgram = typeScriptProgram;
30
+ this.constructorParametersDownlevelTransform = constructorParametersDownlevelTransform;
31
+ this.replaceResourcesTransform = replaceResourcesTransform;
32
+ this.webWorkerTransform = webWorkerTransform;
33
+ }
34
+ }
35
+ class JitCompilation extends angular_compilation_1.AngularCompilation {
36
+ #state;
37
+ async initialize(tsconfig, hostOptions, compilerOptionsTransformer) {
38
+ // Dynamically load the Angular compiler CLI package
39
+ const { constructorParametersDownlevelTransform } = await angular_compilation_1.AngularCompilation.loadCompilerCli();
40
+ // Load the compiler configuration and transform as needed
41
+ const { options: originalCompilerOptions, rootNames, errors: configurationDiagnostics, } = await this.loadConfiguration(tsconfig);
42
+ const compilerOptions = compilerOptionsTransformer?.(originalCompilerOptions) ?? originalCompilerOptions;
43
+ // Create Angular compiler host
44
+ const host = (0, angular_host_1.createAngularCompilerHost)(typescript_1.default, compilerOptions, hostOptions);
45
+ // Create the TypeScript Program
46
+ const typeScriptProgram = (0, profiling_1.profileSync)('TS_CREATE_PROGRAM', () => typescript_1.default.createEmitAndSemanticDiagnosticsBuilderProgram(rootNames, compilerOptions, host, this.#state?.typeScriptProgram ?? typescript_1.default.readBuilderProgram(compilerOptions, host), configurationDiagnostics));
47
+ const affectedFiles = (0, profiling_1.profileSync)('TS_FIND_AFFECTED', () => findAffectedFiles(typeScriptProgram));
48
+ this.#state = new JitCompilationState(host, typeScriptProgram, constructorParametersDownlevelTransform(typeScriptProgram.getProgram()), (0, jit_resource_transformer_1.createJitResourceTransformer)(() => typeScriptProgram.getProgram().getTypeChecker()), (0, web_worker_transformer_1.createWorkerTransformer)(hostOptions.processWebWorker.bind(hostOptions)));
49
+ const referencedFiles = typeScriptProgram
50
+ .getSourceFiles()
51
+ .map((sourceFile) => sourceFile.fileName);
52
+ return { affectedFiles, compilerOptions, referencedFiles };
53
+ }
54
+ *collectDiagnostics(modes) {
55
+ (0, node_assert_1.default)(this.#state, 'Compilation must be initialized prior to collecting diagnostics.');
56
+ const { typeScriptProgram } = this.#state;
57
+ // Collect program level diagnostics
58
+ if (modes & angular_compilation_1.DiagnosticModes.Option) {
59
+ yield* typeScriptProgram.getConfigFileParsingDiagnostics();
60
+ yield* typeScriptProgram.getOptionsDiagnostics();
61
+ }
62
+ if (modes & angular_compilation_1.DiagnosticModes.Syntactic) {
63
+ yield* typeScriptProgram.getGlobalDiagnostics();
64
+ yield* (0, profiling_1.profileSync)('NG_DIAGNOSTICS_SYNTACTIC', () => typeScriptProgram.getSyntacticDiagnostics());
65
+ }
66
+ if (modes & angular_compilation_1.DiagnosticModes.Semantic) {
67
+ yield* (0, profiling_1.profileSync)('NG_DIAGNOSTICS_SEMANTIC', () => typeScriptProgram.getSemanticDiagnostics());
68
+ }
69
+ }
70
+ emitAffectedFiles() {
71
+ (0, node_assert_1.default)(this.#state, 'Compilation must be initialized prior to emitting files.');
72
+ const { compilerHost, typeScriptProgram, constructorParametersDownlevelTransform, replaceResourcesTransform, webWorkerTransform, } = this.#state;
73
+ const buildInfoFilename = typeScriptProgram.getCompilerOptions().tsBuildInfoFile ?? '.tsbuildinfo';
74
+ const emittedFiles = [];
75
+ const writeFileCallback = (filename, contents, _a, _b, sourceFiles) => {
76
+ if (!sourceFiles?.length && filename.endsWith(buildInfoFilename)) {
77
+ // Save builder info contents to specified location
78
+ compilerHost.writeFile(filename, contents, false);
79
+ return;
80
+ }
81
+ (0, node_assert_1.default)(sourceFiles?.length === 1, 'Invalid TypeScript program emit for ' + filename);
82
+ emittedFiles.push({ filename: sourceFiles[0].fileName, contents });
83
+ };
84
+ const transformers = {
85
+ before: [
86
+ replaceResourcesTransform,
87
+ constructorParametersDownlevelTransform,
88
+ webWorkerTransform,
89
+ ],
90
+ };
91
+ // TypeScript will loop until there are no more affected files in the program
92
+ while (typeScriptProgram.emitNextAffectedFile(writeFileCallback, undefined, undefined, transformers)) {
93
+ /* empty */
94
+ }
95
+ return emittedFiles;
96
+ }
97
+ }
98
+ exports.JitCompilation = JitCompilation;
99
+ function findAffectedFiles(builder) {
100
+ const affectedFiles = new Set();
101
+ let result;
102
+ while ((result = builder.getSemanticDiagnosticsOfNextAffectedFile())) {
103
+ affectedFiles.add(result.affected);
104
+ }
105
+ return affectedFiles;
106
+ }