@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,81 @@
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.generateIndexHtml = void 0;
14
+ const node_assert_1 = __importDefault(require("node:assert"));
15
+ const node_path_1 = __importDefault(require("node:path"));
16
+ const index_html_generator_1 = require("../../utils/index-file/index-html-generator");
17
+ const bundler_context_1 = require("./bundler-context");
18
+ async function generateIndexHtml(initialFiles, outputFiles, buildOptions, lang) {
19
+ // Analyze metafile for initial link-based hints.
20
+ // Skip if the internal externalPackages option is enabled since this option requires
21
+ // dev server cooperation to properly resolve and fetch imports.
22
+ const hints = [];
23
+ const { indexHtmlOptions, externalPackages, optimizationOptions, crossOrigin, subresourceIntegrity, baseHref, } = buildOptions;
24
+ (0, node_assert_1.default)(indexHtmlOptions, 'indexHtmlOptions cannot be undefined.');
25
+ if (!externalPackages && indexHtmlOptions.preloadInitial) {
26
+ for (const [key, value] of initialFiles) {
27
+ if (value.entrypoint || value.serverFile) {
28
+ // Entry points are already referenced in the HTML
29
+ continue;
30
+ }
31
+ if (value.type === 'script') {
32
+ hints.push({ url: key, mode: 'modulepreload' });
33
+ }
34
+ else if (value.type === 'style') {
35
+ // Provide an "as" value of "style" to ensure external URLs which may not have a
36
+ // file extension are treated as stylesheets.
37
+ hints.push({ url: key, mode: 'preload', as: 'style' });
38
+ }
39
+ }
40
+ }
41
+ /** Virtual output path to support reading in-memory files. */
42
+ const browserOutputFiles = outputFiles.filter(({ type }) => type === bundler_context_1.BuildOutputFileType.Browser);
43
+ const virtualOutputPath = '/';
44
+ const readAsset = async function (filePath) {
45
+ // Remove leading directory separator
46
+ const relativefilePath = node_path_1.default.relative(virtualOutputPath, filePath);
47
+ const file = browserOutputFiles.find((file) => file.path === relativefilePath);
48
+ if (file) {
49
+ return file.text;
50
+ }
51
+ throw new Error(`Output file does not exist: ${relativefilePath}`);
52
+ };
53
+ // Create an index HTML generator that reads from the in-memory output files
54
+ const indexHtmlGenerator = new index_html_generator_1.IndexHtmlGenerator({
55
+ indexPath: indexHtmlOptions.input,
56
+ entrypoints: indexHtmlOptions.insertionOrder,
57
+ sri: subresourceIntegrity,
58
+ optimization: optimizationOptions,
59
+ crossOrigin: crossOrigin,
60
+ deployUrl: buildOptions.publicPath,
61
+ postTransform: indexHtmlOptions.transformer,
62
+ generateDedicatedSSRContent: !!(buildOptions.ssrOptions ||
63
+ buildOptions.prerenderOptions ||
64
+ buildOptions.appShellOptions),
65
+ });
66
+ indexHtmlGenerator.readAsset = readAsset;
67
+ return indexHtmlGenerator.process({
68
+ baseHref,
69
+ lang,
70
+ outputPath: virtualOutputPath,
71
+ files: [...initialFiles]
72
+ .filter(([, file]) => !file.serverFile)
73
+ .map(([file, record]) => ({
74
+ name: record.name ?? '',
75
+ file,
76
+ extension: node_path_1.default.extname(file),
77
+ })),
78
+ hints,
79
+ });
80
+ }
81
+ exports.generateIndexHtml = generateIndexHtml;
@@ -0,0 +1,19 @@
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
+ interface JavaScriptTransformRequest {
9
+ filename: string;
10
+ data: string | Uint8Array;
11
+ sourcemap: boolean;
12
+ thirdPartySourcemaps: boolean;
13
+ advancedOptimizations: boolean;
14
+ skipLinker?: boolean;
15
+ sideEffects?: boolean;
16
+ jit: boolean;
17
+ }
18
+ export default function transformJavaScript(request: JavaScriptTransformRequest): Promise<unknown>;
19
+ export {};
@@ -0,0 +1,154 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
33
+ return (mod && mod.__esModule) ? mod : { "default": mod };
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const core_1 = require("@babel/core");
37
+ const node_fs_1 = __importDefault(require("node:fs"));
38
+ const node_path_1 = __importDefault(require("node:path"));
39
+ const piscina_1 = __importDefault(require("piscina"));
40
+ const load_esm_1 = require("../../utils/load-esm");
41
+ const textDecoder = new TextDecoder();
42
+ const textEncoder = new TextEncoder();
43
+ async function transformJavaScript(request) {
44
+ const { filename, data, ...options } = request;
45
+ const textData = typeof data === 'string' ? data : textDecoder.decode(data);
46
+ const transformedData = await transformWithBabel(filename, textData, options);
47
+ // Transfer the data via `move` instead of cloning
48
+ return piscina_1.default.move(textEncoder.encode(transformedData));
49
+ }
50
+ exports.default = transformJavaScript;
51
+ /**
52
+ * Cached instance of the compiler-cli linker's createEs2015LinkerPlugin function.
53
+ */
54
+ let linkerPluginCreator;
55
+ /**
56
+ * Cached instance of the compiler-cli linker's needsLinking function.
57
+ */
58
+ let needsLinking;
59
+ async function transformWithBabel(filename, data, options) {
60
+ const shouldLink = !options.skipLinker && (await requiresLinking(filename, data));
61
+ const useInputSourcemap = options.sourcemap &&
62
+ (!!options.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(filename));
63
+ const plugins = [];
64
+ // Lazy load the linker plugin only when linking is required
65
+ if (shouldLink) {
66
+ const linkerPlugin = await createLinkerPlugin(options);
67
+ plugins.push(linkerPlugin);
68
+ }
69
+ if (options.advancedOptimizations) {
70
+ const sideEffectFree = options.sideEffects === false;
71
+ const safeAngularPackage = sideEffectFree && /[\\/]node_modules[\\/]@angular[\\/]/.test(filename);
72
+ const { adjustStaticMembers, adjustTypeScriptEnums, elideAngularMetadata, markTopLevelPure } = await Promise.resolve().then(() => __importStar(require('../babel/plugins')));
73
+ if (safeAngularPackage) {
74
+ plugins.push(markTopLevelPure);
75
+ }
76
+ plugins.push(elideAngularMetadata, adjustTypeScriptEnums, [
77
+ adjustStaticMembers,
78
+ { wrapDecorators: sideEffectFree },
79
+ ]);
80
+ }
81
+ // If no additional transformations are needed, return the data directly
82
+ if (plugins.length === 0) {
83
+ // Strip sourcemaps if they should not be used
84
+ return useInputSourcemap ? data : data.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, '');
85
+ }
86
+ const result = await (0, core_1.transformAsync)(data, {
87
+ filename,
88
+ inputSourceMap: (useInputSourcemap ? undefined : false),
89
+ sourceMaps: useInputSourcemap ? 'inline' : false,
90
+ compact: false,
91
+ configFile: false,
92
+ babelrc: false,
93
+ browserslistConfigFile: false,
94
+ plugins,
95
+ });
96
+ const outputCode = result?.code ?? data;
97
+ // Strip sourcemaps if they should not be used.
98
+ // Babel will keep the original comments even if sourcemaps are disabled.
99
+ return useInputSourcemap
100
+ ? outputCode
101
+ : outputCode.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, '');
102
+ }
103
+ async function requiresLinking(path, source) {
104
+ // @angular/core and @angular/compiler will cause false positives
105
+ // Also, TypeScript files do not require linking
106
+ if (/[\\/]@angular[\\/](?:compiler|core)|\.tsx?$/.test(path)) {
107
+ return false;
108
+ }
109
+ if (!needsLinking) {
110
+ // Load ESM `@angular/compiler-cli/linker` using the TypeScript dynamic import workaround.
111
+ // Once TypeScript provides support for keeping the dynamic import this workaround can be
112
+ // changed to a direct dynamic import.
113
+ const linkerModule = await (0, load_esm_1.loadEsmModule)('@angular/compiler-cli/linker');
114
+ needsLinking = linkerModule.needsLinking;
115
+ }
116
+ return needsLinking(path, source);
117
+ }
118
+ async function createLinkerPlugin(options) {
119
+ linkerPluginCreator ??= (await (0, load_esm_1.loadEsmModule)('@angular/compiler-cli/linker/babel')).createEs2015LinkerPlugin;
120
+ const linkerPlugin = linkerPluginCreator({
121
+ linkerJitMode: options.jit,
122
+ // This is a workaround until https://github.com/angular/angular/issues/42769 is fixed.
123
+ sourceMapping: false,
124
+ logger: {
125
+ level: 1, // Info level
126
+ debug(...args) {
127
+ // eslint-disable-next-line no-console
128
+ console.debug(args);
129
+ },
130
+ info(...args) {
131
+ // eslint-disable-next-line no-console
132
+ console.info(args);
133
+ },
134
+ warn(...args) {
135
+ // eslint-disable-next-line no-console
136
+ console.warn(args);
137
+ },
138
+ error(...args) {
139
+ // eslint-disable-next-line no-console
140
+ console.error(args);
141
+ },
142
+ },
143
+ fileSystem: {
144
+ resolve: node_path_1.default.resolve,
145
+ exists: node_fs_1.default.existsSync,
146
+ dirname: node_path_1.default.dirname,
147
+ relative: node_path_1.default.relative,
148
+ readFile: node_fs_1.default.readFileSync,
149
+ // Node.JS types don't overlap the Compiler types.
150
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
151
+ },
152
+ });
153
+ return linkerPlugin;
154
+ }
@@ -0,0 +1,54 @@
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 { Cache } from './cache';
9
+ /**
10
+ * Transformation options that should apply to all transformed files and data.
11
+ */
12
+ export interface JavaScriptTransformerOptions {
13
+ sourcemap: boolean;
14
+ thirdPartySourcemaps?: boolean;
15
+ advancedOptimizations?: boolean;
16
+ jit?: boolean;
17
+ }
18
+ /**
19
+ * A class that performs transformation of JavaScript files and raw data.
20
+ * A worker pool is used to distribute the transformation actions and allow
21
+ * parallel processing. Transformation behavior is based on the filename and
22
+ * data. Transformations may include: async downleveling, Angular linking,
23
+ * and advanced optimizations.
24
+ */
25
+ export declare class JavaScriptTransformer {
26
+ #private;
27
+ readonly maxThreads: number;
28
+ private readonly cache?;
29
+ constructor(options: JavaScriptTransformerOptions, maxThreads: number, cache?: Cache<Uint8Array, import("./cache").CacheStore<Uint8Array>> | undefined);
30
+ /**
31
+ * Performs JavaScript transformations on a file from the filesystem.
32
+ * If no transformations are required, the data for the original file will be returned.
33
+ * @param filename The full path to the file.
34
+ * @param skipLinker If true, bypass all Angular linker processing; if false, attempt linking.
35
+ * @param sideEffects If false, and `advancedOptimizations` is enabled tslib decorators are wrapped.
36
+ * @returns A promise that resolves to a UTF-8 encoded Uint8Array containing the result.
37
+ */
38
+ transformFile(filename: string, skipLinker?: boolean, sideEffects?: boolean): Promise<Uint8Array>;
39
+ /**
40
+ * Performs JavaScript transformations on the provided data of a file. The file does not need
41
+ * to exist on the filesystem.
42
+ * @param filename The full path of the file represented by the data.
43
+ * @param data The data of the file that should be transformed.
44
+ * @param skipLinker If true, bypass all Angular linker processing; if false, attempt linking.
45
+ * @param sideEffects If false, and `advancedOptimizations` is enabled tslib decorators are wrapped.
46
+ * @returns A promise that resolves to a UTF-8 encoded Uint8Array containing the result.
47
+ */
48
+ transformData(filename: string, data: string, skipLinker: boolean, sideEffects?: boolean): Promise<Uint8Array>;
49
+ /**
50
+ * Stops all active transformation tasks and shuts down all workers.
51
+ * @returns A void promise that resolves when closing is complete.
52
+ */
53
+ close(): Promise<void>;
54
+ }
@@ -0,0 +1,147 @@
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.JavaScriptTransformer = void 0;
14
+ const node_crypto_1 = require("node:crypto");
15
+ const promises_1 = require("node:fs/promises");
16
+ const piscina_1 = __importDefault(require("piscina"));
17
+ /**
18
+ * A class that performs transformation of JavaScript files and raw data.
19
+ * A worker pool is used to distribute the transformation actions and allow
20
+ * parallel processing. Transformation behavior is based on the filename and
21
+ * data. Transformations may include: async downleveling, Angular linking,
22
+ * and advanced optimizations.
23
+ */
24
+ class JavaScriptTransformer {
25
+ maxThreads;
26
+ cache;
27
+ #workerPool;
28
+ #commonOptions;
29
+ #fileCacheKeyBase;
30
+ constructor(options, maxThreads, cache) {
31
+ this.maxThreads = maxThreads;
32
+ this.cache = cache;
33
+ // Extract options to ensure only the named options are serialized and sent to the worker
34
+ const { sourcemap, thirdPartySourcemaps = false, advancedOptimizations = false, jit = false, } = options;
35
+ this.#commonOptions = {
36
+ sourcemap,
37
+ thirdPartySourcemaps,
38
+ advancedOptimizations,
39
+ jit,
40
+ };
41
+ this.#fileCacheKeyBase = Buffer.from(JSON.stringify(this.#commonOptions), 'utf-8');
42
+ }
43
+ #ensureWorkerPool() {
44
+ this.#workerPool ??= new piscina_1.default({
45
+ filename: require.resolve('./javascript-transformer-worker'),
46
+ minThreads: 1,
47
+ maxThreads: this.maxThreads,
48
+ // Shutdown idle threads after 1 second of inactivity
49
+ idleTimeout: 1000,
50
+ recordTiming: false,
51
+ });
52
+ return this.#workerPool;
53
+ }
54
+ /**
55
+ * Performs JavaScript transformations on a file from the filesystem.
56
+ * If no transformations are required, the data for the original file will be returned.
57
+ * @param filename The full path to the file.
58
+ * @param skipLinker If true, bypass all Angular linker processing; if false, attempt linking.
59
+ * @param sideEffects If false, and `advancedOptimizations` is enabled tslib decorators are wrapped.
60
+ * @returns A promise that resolves to a UTF-8 encoded Uint8Array containing the result.
61
+ */
62
+ async transformFile(filename, skipLinker, sideEffects) {
63
+ const data = await (0, promises_1.readFile)(filename);
64
+ let result;
65
+ let cacheKey;
66
+ if (this.cache) {
67
+ // Create a cache key from the file data and options that effect the output.
68
+ // NOTE: If additional options are added, this may need to be updated.
69
+ // TODO: Consider xxhash or similar instead of SHA256
70
+ const hash = (0, node_crypto_1.createHash)('sha256');
71
+ hash.update(`${!!skipLinker}--${!!sideEffects}`);
72
+ hash.update(data);
73
+ hash.update(this.#fileCacheKeyBase);
74
+ cacheKey = hash.digest('hex');
75
+ try {
76
+ result = await this.cache?.get(cacheKey);
77
+ }
78
+ catch {
79
+ // Failure to get the value should not fail the transform
80
+ }
81
+ }
82
+ if (result === undefined) {
83
+ // If there is no cache or no cached entry, process the file
84
+ result = (await this.#ensureWorkerPool().run({
85
+ filename,
86
+ data,
87
+ skipLinker,
88
+ sideEffects,
89
+ ...this.#commonOptions,
90
+ }, {
91
+ // The below is disable as with Yarn PNP this causes build failures with the below message
92
+ // `Unable to deserialize cloned data`.
93
+ transferList: process.versions.pnp ? undefined : [data.buffer],
94
+ }));
95
+ // If there is a cache then store the result
96
+ if (this.cache && cacheKey) {
97
+ try {
98
+ await this.cache.put(cacheKey, result);
99
+ }
100
+ catch {
101
+ // Failure to store the value in the cache should not fail the transform
102
+ }
103
+ }
104
+ }
105
+ return result;
106
+ }
107
+ /**
108
+ * Performs JavaScript transformations on the provided data of a file. The file does not need
109
+ * to exist on the filesystem.
110
+ * @param filename The full path of the file represented by the data.
111
+ * @param data The data of the file that should be transformed.
112
+ * @param skipLinker If true, bypass all Angular linker processing; if false, attempt linking.
113
+ * @param sideEffects If false, and `advancedOptimizations` is enabled tslib decorators are wrapped.
114
+ * @returns A promise that resolves to a UTF-8 encoded Uint8Array containing the result.
115
+ */
116
+ async transformData(filename, data, skipLinker, sideEffects) {
117
+ // Perform a quick test to determine if the data needs any transformations.
118
+ // This allows directly returning the data without the worker communication overhead.
119
+ if (skipLinker && !this.#commonOptions.advancedOptimizations) {
120
+ const keepSourcemap = this.#commonOptions.sourcemap &&
121
+ (!!this.#commonOptions.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(filename));
122
+ return Buffer.from(keepSourcemap ? data : data.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, ''), 'utf-8');
123
+ }
124
+ return this.#ensureWorkerPool().run({
125
+ filename,
126
+ data,
127
+ skipLinker,
128
+ sideEffects,
129
+ ...this.#commonOptions,
130
+ });
131
+ }
132
+ /**
133
+ * Stops all active transformation tasks and shuts down all workers.
134
+ * @returns A void promise that resolves when closing is complete.
135
+ */
136
+ async close() {
137
+ if (this.#workerPool) {
138
+ try {
139
+ await this.#workerPool.destroy();
140
+ }
141
+ finally {
142
+ this.#workerPool = undefined;
143
+ }
144
+ }
145
+ }
146
+ }
147
+ exports.JavaScriptTransformer = JavaScriptTransformer;
@@ -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
+ import type { Metafile } from 'esbuild';
9
+ /**
10
+ * Extracts license information for each node module package included in the output
11
+ * files of the built code. This includes JavaScript and CSS output files. The esbuild
12
+ * metafile generated during the bundling steps is used as the source of information
13
+ * regarding what input files where included and where they are located. A path segment
14
+ * of `node_modules` is used to indicate that a file belongs to a package and its license
15
+ * should be include in the output licenses file.
16
+ *
17
+ * The package name and license field are extracted from the `package.json` file for the
18
+ * package. If a license file (e.g., `LICENSE`) is present in the root of the package, it
19
+ * will also be included in the output licenses file.
20
+ *
21
+ * @param metafile An esbuild metafile object.
22
+ * @param rootDirectory The root directory of the workspace.
23
+ * @returns A string containing the content of the output licenses file.
24
+ */
25
+ export declare function extractLicenses(metafile: Metafile, rootDirectory: string): Promise<string>;
@@ -0,0 +1,158 @@
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.extractLicenses = void 0;
14
+ const promises_1 = require("node:fs/promises");
15
+ const node_path_1 = __importDefault(require("node:path"));
16
+ /**
17
+ * The path segment used to signify that a file is part of a package.
18
+ */
19
+ const NODE_MODULE_SEGMENT = 'node_modules';
20
+ /**
21
+ * String constant for the NPM recommended custom license wording.
22
+ *
23
+ * See: https://docs.npmjs.com/cli/v9/configuring-npm/package-json#license
24
+ *
25
+ * Example:
26
+ * ```
27
+ * {
28
+ * "license" : "SEE LICENSE IN <filename>"
29
+ * }
30
+ * ```
31
+ */
32
+ const CUSTOM_LICENSE_TEXT = 'SEE LICENSE IN ';
33
+ /**
34
+ * A list of commonly named license files found within packages.
35
+ */
36
+ const LICENSE_FILES = ['LICENSE', 'LICENSE.txt', 'LICENSE.md'];
37
+ /**
38
+ * Header text that will be added to the top of the output license extraction file.
39
+ */
40
+ const EXTRACTION_FILE_HEADER = '';
41
+ /**
42
+ * The package entry separator to use within the output license extraction file.
43
+ */
44
+ const EXTRACTION_FILE_SEPARATOR = '-'.repeat(80) + '\n';
45
+ /**
46
+ * Extracts license information for each node module package included in the output
47
+ * files of the built code. This includes JavaScript and CSS output files. The esbuild
48
+ * metafile generated during the bundling steps is used as the source of information
49
+ * regarding what input files where included and where they are located. A path segment
50
+ * of `node_modules` is used to indicate that a file belongs to a package and its license
51
+ * should be include in the output licenses file.
52
+ *
53
+ * The package name and license field are extracted from the `package.json` file for the
54
+ * package. If a license file (e.g., `LICENSE`) is present in the root of the package, it
55
+ * will also be included in the output licenses file.
56
+ *
57
+ * @param metafile An esbuild metafile object.
58
+ * @param rootDirectory The root directory of the workspace.
59
+ * @returns A string containing the content of the output licenses file.
60
+ */
61
+ async function extractLicenses(metafile, rootDirectory) {
62
+ let extractedLicenseContent = `${EXTRACTION_FILE_HEADER}\n${EXTRACTION_FILE_SEPARATOR}`;
63
+ const seenPaths = new Set();
64
+ const seenPackages = new Set();
65
+ for (const entry of Object.values(metafile.outputs)) {
66
+ for (const [inputPath, { bytesInOutput }] of Object.entries(entry.inputs)) {
67
+ // Skip if not included in output
68
+ if (bytesInOutput <= 0) {
69
+ continue;
70
+ }
71
+ // Skip already processed paths
72
+ if (seenPaths.has(inputPath)) {
73
+ continue;
74
+ }
75
+ seenPaths.add(inputPath);
76
+ // Skip non-package paths
77
+ if (!inputPath.includes(NODE_MODULE_SEGMENT)) {
78
+ continue;
79
+ }
80
+ // Extract the package name from the path
81
+ let baseDirectory = node_path_1.default.join(rootDirectory, inputPath);
82
+ let nameOrScope, nameOrFile;
83
+ let found = false;
84
+ while (baseDirectory !== node_path_1.default.dirname(baseDirectory)) {
85
+ const segment = node_path_1.default.basename(baseDirectory);
86
+ if (segment === NODE_MODULE_SEGMENT) {
87
+ found = true;
88
+ break;
89
+ }
90
+ nameOrFile = nameOrScope;
91
+ nameOrScope = segment;
92
+ baseDirectory = node_path_1.default.dirname(baseDirectory);
93
+ }
94
+ // Skip non-package path edge cases that are not caught in the includes check above
95
+ if (!found || !nameOrScope) {
96
+ continue;
97
+ }
98
+ const packageName = nameOrScope.startsWith('@')
99
+ ? `${nameOrScope}/${nameOrFile}`
100
+ : nameOrScope;
101
+ const packageDirectory = node_path_1.default.join(baseDirectory, packageName);
102
+ // Load the package's metadata to find the package's name, version, and license type
103
+ const packageJsonPath = node_path_1.default.join(packageDirectory, 'package.json');
104
+ let packageJson;
105
+ try {
106
+ packageJson = JSON.parse(await (0, promises_1.readFile)(packageJsonPath, 'utf-8'));
107
+ }
108
+ catch {
109
+ // Invalid package
110
+ continue;
111
+ }
112
+ // Skip already processed packages
113
+ const packageId = `${packageName}@${packageJson.version}`;
114
+ if (seenPackages.has(packageId)) {
115
+ continue;
116
+ }
117
+ seenPackages.add(packageId);
118
+ // Attempt to find license text inside package
119
+ let licenseText = '';
120
+ if (typeof packageJson.license === 'string' &&
121
+ packageJson.license.toLowerCase().startsWith(CUSTOM_LICENSE_TEXT)) {
122
+ // Attempt to load the package's custom license
123
+ let customLicensePath;
124
+ const customLicenseFile = node_path_1.default.normalize(packageJson.license.slice(CUSTOM_LICENSE_TEXT.length + 1).trim());
125
+ if (customLicenseFile.startsWith('..') || node_path_1.default.isAbsolute(customLicenseFile)) {
126
+ // Path is attempting to access files outside of the package
127
+ // TODO: Issue warning?
128
+ }
129
+ else {
130
+ customLicensePath = node_path_1.default.join(packageDirectory, customLicenseFile);
131
+ try {
132
+ licenseText = await (0, promises_1.readFile)(customLicensePath, 'utf-8');
133
+ break;
134
+ }
135
+ catch { }
136
+ }
137
+ }
138
+ else {
139
+ // Search for a license file within the root of the package
140
+ for (const potentialLicense of LICENSE_FILES) {
141
+ const packageLicensePath = node_path_1.default.join(packageDirectory, potentialLicense);
142
+ try {
143
+ licenseText = await (0, promises_1.readFile)(packageLicensePath, 'utf-8');
144
+ break;
145
+ }
146
+ catch { }
147
+ }
148
+ }
149
+ // Generate the package's license entry in the output content
150
+ extractedLicenseContent += `Package: ${packageJson.name}\n`;
151
+ extractedLicenseContent += `License: ${JSON.stringify(packageJson.license, null, 2)}\n`;
152
+ extractedLicenseContent += `\n${licenseText}\n`;
153
+ extractedLicenseContent += EXTRACTION_FILE_SEPARATOR;
154
+ }
155
+ }
156
+ return extractedLicenseContent;
157
+ }
158
+ exports.extractLicenses = extractLicenses;
@@ -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 { OnLoadResult, PluginBuild } from 'esbuild';
9
+ export interface LoadResultCache {
10
+ get(path: string): OnLoadResult | undefined;
11
+ put(path: string, result: OnLoadResult): Promise<void>;
12
+ readonly watchFiles: ReadonlyArray<string>;
13
+ }
14
+ export declare function createCachedLoad(cache: LoadResultCache | undefined, callback: Parameters<PluginBuild['onLoad']>[1]): Parameters<PluginBuild['onLoad']>[1];
15
+ export declare class MemoryLoadResultCache implements LoadResultCache {
16
+ #private;
17
+ get(path: string): OnLoadResult | undefined;
18
+ put(path: string, result: OnLoadResult): Promise<void>;
19
+ invalidate(path: string): boolean;
20
+ get watchFiles(): string[];
21
+ }