@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,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 { NormalizedApplicationBuildOptions } from '../../builders/application/options';
9
+ import { BundlerOptionsFactory } from './bundler-context';
10
+ export declare function createGlobalStylesBundleOptions(options: NormalizedApplicationBuildOptions, target: string[], initial: boolean): BundlerOptionsFactory | undefined;
@@ -0,0 +1,74 @@
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.createGlobalStylesBundleOptions = void 0;
14
+ const node_assert_1 = __importDefault(require("node:assert"));
15
+ const bundle_options_1 = require("./stylesheets/bundle-options");
16
+ const virtual_module_plugin_1 = require("./virtual-module-plugin");
17
+ function createGlobalStylesBundleOptions(options, target, initial) {
18
+ const { workspaceRoot, optimizationOptions, sourcemapOptions, outputNames, globalStyles, preserveSymlinks, externalDependencies, stylePreprocessorOptions, tailwindConfiguration, postcssConfiguration, cacheOptions, } = options;
19
+ const namespace = 'angular:styles/global';
20
+ const entryPoints = {};
21
+ let found = false;
22
+ for (const style of globalStyles) {
23
+ if (style.initial === initial) {
24
+ found = true;
25
+ entryPoints[style.name] = `${namespace};${style.name}`;
26
+ }
27
+ }
28
+ // Skip if there are no entry points for the style loading type
29
+ if (found === false) {
30
+ return;
31
+ }
32
+ return (loadCache) => {
33
+ const buildOptions = (0, bundle_options_1.createStylesheetBundleOptions)({
34
+ workspaceRoot,
35
+ optimization: !!optimizationOptions.styles.minify,
36
+ inlineFonts: !!optimizationOptions.fonts.inline,
37
+ sourcemap: !!sourcemapOptions.styles,
38
+ preserveSymlinks,
39
+ target,
40
+ externalDependencies,
41
+ outputNames: initial
42
+ ? outputNames
43
+ : {
44
+ ...outputNames,
45
+ bundles: '[name]',
46
+ },
47
+ includePaths: stylePreprocessorOptions?.includePaths,
48
+ tailwindConfiguration,
49
+ postcssConfiguration,
50
+ cacheOptions,
51
+ }, loadCache);
52
+ // Keep special CSS comments `/*! comment */` in place when `removeSpecialComments` is disabled.
53
+ // These comments are special for a number of CSS tools such as Critters and PurgeCSS.
54
+ buildOptions.legalComments = optimizationOptions.styles?.removeSpecialComments
55
+ ? 'none'
56
+ : 'inline';
57
+ buildOptions.entryPoints = entryPoints;
58
+ buildOptions.plugins.unshift((0, virtual_module_plugin_1.createVirtualModulePlugin)({
59
+ namespace,
60
+ transformPath: (path) => path.split(';', 2)[1],
61
+ loadContent: (args) => {
62
+ const files = globalStyles.find(({ name }) => name === args.path)?.files;
63
+ (0, node_assert_1.default)(files, `global style name should always be found [${args.path}]`);
64
+ return {
65
+ contents: files.map((file) => `@import '${file.replace(/\\/g, '/')}';`).join('\n'),
66
+ loader: 'css',
67
+ resolveDir: workspaceRoot,
68
+ };
69
+ },
70
+ }));
71
+ return buildOptions;
72
+ };
73
+ }
74
+ exports.createGlobalStylesBundleOptions = createGlobalStylesBundleOptions;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ /**
9
+ * The options passed to the inliner for each file request
10
+ */
11
+ interface InlineRequest {
12
+ /**
13
+ * The filename that should be processed. The data for the file is provided to the Worker
14
+ * during Worker initialization.
15
+ */
16
+ filename: string;
17
+ /**
18
+ * The locale specifier that should be used during the inlining process of the file.
19
+ */
20
+ locale: string;
21
+ /**
22
+ * The translation messages for the locale that should be used during the inlining process of the file.
23
+ */
24
+ translation?: Record<string, unknown>;
25
+ }
26
+ /**
27
+ * Inlines the provided locale and translation into a JavaScript file that contains `$localize` usage.
28
+ * This function is the main entry for the Worker's action that is called by the worker pool.
29
+ *
30
+ * @param request An InlineRequest object representing the options for inlining
31
+ * @returns An array containing the inlined file and optional map content.
32
+ */
33
+ export default function inlineLocale(request: InlineRequest): Promise<{
34
+ file: string;
35
+ code: string;
36
+ map: string | undefined;
37
+ messages: {
38
+ type: "error" | "warning";
39
+ message: string;
40
+ }[];
41
+ }>;
42
+ export {};
@@ -0,0 +1,136 @@
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
+ const remapping_1 = __importDefault(require("@ampproject/remapping"));
14
+ const core_1 = require("@babel/core");
15
+ const node_assert_1 = __importDefault(require("node:assert"));
16
+ const node_worker_threads_1 = require("node:worker_threads");
17
+ const error_1 = require("../../utils/error");
18
+ const load_esm_1 = require("../../utils/load-esm");
19
+ // Extract the application files and common options used for inline requests from the Worker context
20
+ // TODO: Evaluate overall performance difference of passing translations here as well
21
+ const { files, missingTranslation, shouldOptimize } = (node_worker_threads_1.workerData || {});
22
+ /**
23
+ * Inlines the provided locale and translation into a JavaScript file that contains `$localize` usage.
24
+ * This function is the main entry for the Worker's action that is called by the worker pool.
25
+ *
26
+ * @param request An InlineRequest object representing the options for inlining
27
+ * @returns An array containing the inlined file and optional map content.
28
+ */
29
+ async function inlineLocale(request) {
30
+ const data = files.get(request.filename);
31
+ (0, node_assert_1.default)(data !== undefined, `Invalid inline request for file '${request.filename}'.`);
32
+ const code = await data.text();
33
+ const map = await files.get(request.filename + '.map')?.text();
34
+ const result = await transformWithBabel(code, map && JSON.parse(map), request);
35
+ return {
36
+ file: request.filename,
37
+ code: result.code,
38
+ map: result.map,
39
+ messages: result.diagnostics.messages,
40
+ };
41
+ }
42
+ exports.default = inlineLocale;
43
+ /**
44
+ * Cached instance of the `@angular/localize/tools` module.
45
+ * This is used to remove the need to repeatedly import the module per file translation.
46
+ */
47
+ let localizeToolsModule;
48
+ /**
49
+ * Attempts to load the `@angular/localize/tools` module containing the functionality to
50
+ * perform the file translations.
51
+ * This module must be dynamically loaded as it is an ESM module and this file is CommonJS.
52
+ */
53
+ async function loadLocalizeTools() {
54
+ // Load ESM `@angular/localize/tools` using the TypeScript dynamic import workaround.
55
+ // Once TypeScript provides support for keeping the dynamic import this workaround can be
56
+ // changed to a direct dynamic import.
57
+ localizeToolsModule ??= await (0, load_esm_1.loadEsmModule)('@angular/localize/tools');
58
+ return localizeToolsModule;
59
+ }
60
+ /**
61
+ * Creates the needed Babel plugins to inline a given locale and translation for a JavaScript file.
62
+ * @param locale A string containing the locale specifier to use.
63
+ * @param translation A object record containing locale specific messages to use.
64
+ * @returns An array of Babel plugins.
65
+ */
66
+ async function createI18nPlugins(locale, translation) {
67
+ const { Diagnostics, makeEs2015TranslatePlugin } = await loadLocalizeTools();
68
+ const plugins = [];
69
+ const diagnostics = new Diagnostics();
70
+ plugins.push(
71
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
+ makeEs2015TranslatePlugin(diagnostics, (translation || {}), {
73
+ missingTranslation: translation === undefined ? 'ignore' : missingTranslation,
74
+ }));
75
+ // Create a plugin to replace the locale specifier constant inject by the build system with the actual specifier
76
+ plugins.push({
77
+ visitor: {
78
+ StringLiteral(path) {
79
+ if (path.node.value === '___NG_LOCALE_INSERT___') {
80
+ path.replaceWith(core_1.types.stringLiteral(locale));
81
+ }
82
+ },
83
+ },
84
+ });
85
+ return { diagnostics, plugins };
86
+ }
87
+ /**
88
+ * Transforms a JavaScript file using Babel to inline the request locale and translation.
89
+ * @param code A string containing the JavaScript code to transform.
90
+ * @param map A sourcemap object for the provided JavaScript code.
91
+ * @param options The inline request options to use.
92
+ * @returns An object containing the code, map, and diagnostics from the transformation.
93
+ */
94
+ async function transformWithBabel(code, map, options) {
95
+ let ast;
96
+ try {
97
+ ast = (0, core_1.parseSync)(code, {
98
+ babelrc: false,
99
+ configFile: false,
100
+ sourceType: 'unambiguous',
101
+ filename: options.filename,
102
+ });
103
+ }
104
+ catch (error) {
105
+ (0, error_1.assertIsError)(error);
106
+ // Make the error more readable.
107
+ // Same errors will contain the full content of the file as the error message
108
+ // Which makes it hard to find the actual error message.
109
+ const index = error.message.indexOf(')\n');
110
+ const msg = index !== -1 ? error.message.slice(0, index + 1) : error.message;
111
+ throw new Error(`${msg}\nAn error occurred inlining file "${options.filename}"`);
112
+ }
113
+ if (!ast) {
114
+ throw new Error(`Unknown error occurred inlining file "${options.filename}"`);
115
+ }
116
+ const { diagnostics, plugins } = await createI18nPlugins(options.locale, options.translation);
117
+ const transformResult = await (0, core_1.transformFromAstAsync)(ast, code, {
118
+ filename: options.filename,
119
+ // false is a valid value but not included in the type definition
120
+ inputSourceMap: false,
121
+ sourceMaps: !!map,
122
+ compact: shouldOptimize,
123
+ configFile: false,
124
+ babelrc: false,
125
+ browserslistConfigFile: false,
126
+ plugins,
127
+ });
128
+ if (!transformResult || !transformResult.code) {
129
+ throw new Error(`Unknown error occurred processing bundle for "${options.filename}".`);
130
+ }
131
+ let outputMap;
132
+ if (map && transformResult.map) {
133
+ outputMap = (0, remapping_1.default)([transformResult.map, map], () => null);
134
+ }
135
+ return { code: transformResult.code, map: outputMap && JSON.stringify(outputMap), diagnostics };
136
+ }
@@ -0,0 +1,44 @@
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 { BuildOutputFile } from './bundler-context';
9
+ /**
10
+ * Inlining options that should apply to all transformed code.
11
+ */
12
+ export interface I18nInlinerOptions {
13
+ missingTranslation: 'error' | 'warning' | 'ignore';
14
+ outputFiles: BuildOutputFile[];
15
+ shouldOptimize?: boolean;
16
+ }
17
+ /**
18
+ * A class that performs i18n translation inlining of JavaScript code.
19
+ * A worker pool is used to distribute the transformation actions and allow
20
+ * parallel processing. Inlining is only performed on code that contains the
21
+ * localize function (`$localize`).
22
+ */
23
+ export declare class I18nInliner {
24
+ #private;
25
+ constructor(options: I18nInlinerOptions, maxThreads?: number);
26
+ /**
27
+ * Performs inlining of translations for the provided locale and translations. The files that
28
+ * are processed originate from the files passed to the class constructor and filter by presence
29
+ * of the localize function keyword.
30
+ * @param locale The string representing the locale to inline.
31
+ * @param translation The translation messages to use when inlining.
32
+ * @returns A promise that resolves to an array of OutputFiles representing a translated result.
33
+ */
34
+ inlineForLocale(locale: string, translation: Record<string, unknown> | undefined): Promise<{
35
+ outputFiles: BuildOutputFile[];
36
+ errors: string[];
37
+ warnings: string[];
38
+ }>;
39
+ /**
40
+ * Stops all active transformation tasks and shuts down all workers.
41
+ * @returns A void promise that resolves when closing is complete.
42
+ */
43
+ close(): Promise<void>;
44
+ }
@@ -0,0 +1,150 @@
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.I18nInliner = void 0;
14
+ const node_assert_1 = __importDefault(require("node:assert"));
15
+ const piscina_1 = __importDefault(require("piscina"));
16
+ const bundler_context_1 = require("./bundler-context");
17
+ const utils_1 = require("./utils");
18
+ /**
19
+ * A keyword used to indicate if a JavaScript file may require inlining of translations.
20
+ * This keyword is used to avoid processing files that would not otherwise need i18n processing.
21
+ */
22
+ const LOCALIZE_KEYWORD = '$localize';
23
+ /**
24
+ * A class that performs i18n translation inlining of JavaScript code.
25
+ * A worker pool is used to distribute the transformation actions and allow
26
+ * parallel processing. Inlining is only performed on code that contains the
27
+ * localize function (`$localize`).
28
+ */
29
+ class I18nInliner {
30
+ #workerPool;
31
+ #localizeFiles;
32
+ #unmodifiedFiles;
33
+ #fileToType = new Map();
34
+ constructor(options, maxThreads) {
35
+ this.#unmodifiedFiles = [];
36
+ const files = new Map();
37
+ const pendingMaps = [];
38
+ for (const file of options.outputFiles) {
39
+ if (file.type === bundler_context_1.BuildOutputFileType.Root) {
40
+ // Skip stats and similar files.
41
+ continue;
42
+ }
43
+ this.#fileToType.set(file.path, file.type);
44
+ if (file.path.endsWith('.js') || file.path.endsWith('.mjs')) {
45
+ // Check if localizations are present
46
+ const contentBuffer = Buffer.isBuffer(file.contents)
47
+ ? file.contents
48
+ : Buffer.from(file.contents.buffer, file.contents.byteOffset, file.contents.byteLength);
49
+ const hasLocalize = contentBuffer.includes(LOCALIZE_KEYWORD);
50
+ if (hasLocalize) {
51
+ // A Blob is an immutable data structure that allows sharing the data between workers
52
+ // without copying until the data is actually used within a Worker. This is useful here
53
+ // since each file may not actually be processed in each Worker and the Blob avoids
54
+ // unneeded repeat copying of potentially large JavaScript files.
55
+ files.set(file.path, new Blob([file.contents]));
56
+ continue;
57
+ }
58
+ }
59
+ else if (file.path.endsWith('.js.map')) {
60
+ // The related JS file may not have been checked yet. To ensure that map files are not
61
+ // missed, store any pending map files and check them after all output files.
62
+ pendingMaps.push(file);
63
+ continue;
64
+ }
65
+ this.#unmodifiedFiles.push(file);
66
+ }
67
+ // Check if any pending map files should be processed by checking if the parent JS file is present
68
+ for (const file of pendingMaps) {
69
+ if (files.has(file.path.slice(0, -4))) {
70
+ files.set(file.path, new Blob([file.contents]));
71
+ }
72
+ else {
73
+ this.#unmodifiedFiles.push(file);
74
+ }
75
+ }
76
+ this.#localizeFiles = files;
77
+ this.#workerPool = new piscina_1.default({
78
+ filename: require.resolve('./i18n-inliner-worker'),
79
+ maxThreads,
80
+ // Extract options to ensure only the named options are serialized and sent to the worker
81
+ workerData: {
82
+ missingTranslation: options.missingTranslation,
83
+ shouldOptimize: options.shouldOptimize,
84
+ files,
85
+ },
86
+ recordTiming: false,
87
+ });
88
+ }
89
+ /**
90
+ * Performs inlining of translations for the provided locale and translations. The files that
91
+ * are processed originate from the files passed to the class constructor and filter by presence
92
+ * of the localize function keyword.
93
+ * @param locale The string representing the locale to inline.
94
+ * @param translation The translation messages to use when inlining.
95
+ * @returns A promise that resolves to an array of OutputFiles representing a translated result.
96
+ */
97
+ async inlineForLocale(locale, translation) {
98
+ // Request inlining for each file that contains localize calls
99
+ const requests = [];
100
+ for (const filename of this.#localizeFiles.keys()) {
101
+ if (filename.endsWith('.map')) {
102
+ continue;
103
+ }
104
+ const fileRequest = this.#workerPool.run({
105
+ filename,
106
+ locale,
107
+ translation,
108
+ });
109
+ requests.push(fileRequest);
110
+ }
111
+ // Wait for all file requests to complete
112
+ const rawResults = await Promise.all(requests);
113
+ // Convert raw results to output file objects and include all unmodified files
114
+ const errors = [];
115
+ const warnings = [];
116
+ const outputFiles = [
117
+ ...rawResults.flatMap(({ file, code, map, messages }) => {
118
+ const type = this.#fileToType.get(file);
119
+ (0, node_assert_1.default)(type !== undefined, 'localized file should always have a type' + file);
120
+ const resultFiles = [(0, utils_1.createOutputFileFromText)(file, code, type)];
121
+ if (map) {
122
+ resultFiles.push((0, utils_1.createOutputFileFromText)(file + '.map', map, type));
123
+ }
124
+ for (const message of messages) {
125
+ if (message.type === 'error') {
126
+ errors.push(message.message);
127
+ }
128
+ else {
129
+ warnings.push(message.message);
130
+ }
131
+ }
132
+ return resultFiles;
133
+ }),
134
+ ...this.#unmodifiedFiles.map((file) => file.clone()),
135
+ ];
136
+ return {
137
+ outputFiles,
138
+ errors,
139
+ warnings,
140
+ };
141
+ }
142
+ /**
143
+ * Stops all active transformation tasks and shuts down all workers.
144
+ * @returns A void promise that resolves when closing is complete.
145
+ */
146
+ close() {
147
+ return this.#workerPool.destroy();
148
+ }
149
+ }
150
+ exports.I18nInliner = I18nInliner;
@@ -0,0 +1,22 @@
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 { Plugin } from 'esbuild';
9
+ /**
10
+ * The internal namespace used by generated locale import statements and Angular locale data plugin.
11
+ */
12
+ export declare const LOCALE_DATA_NAMESPACE = "angular:locale/data";
13
+ /**
14
+ * The base module location used to search for locale specific data.
15
+ */
16
+ export declare const LOCALE_DATA_BASE_MODULE = "@angular/common/locales/global";
17
+ /**
18
+ * Creates an esbuild plugin that resolves Angular locale data files from `@angular/common`.
19
+ *
20
+ * @returns An esbuild plugin.
21
+ */
22
+ export declare function createAngularLocaleDataPlugin(): Plugin;
@@ -0,0 +1,120 @@
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.createAngularLocaleDataPlugin = exports.LOCALE_DATA_BASE_MODULE = exports.LOCALE_DATA_NAMESPACE = void 0;
11
+ /**
12
+ * The internal namespace used by generated locale import statements and Angular locale data plugin.
13
+ */
14
+ exports.LOCALE_DATA_NAMESPACE = 'angular:locale/data';
15
+ /**
16
+ * The base module location used to search for locale specific data.
17
+ */
18
+ exports.LOCALE_DATA_BASE_MODULE = '@angular/common/locales/global';
19
+ /**
20
+ * Creates an esbuild plugin that resolves Angular locale data files from `@angular/common`.
21
+ *
22
+ * @returns An esbuild plugin.
23
+ */
24
+ function createAngularLocaleDataPlugin() {
25
+ return {
26
+ name: 'angular-locale-data',
27
+ setup(build) {
28
+ // If packages are configured to be external then leave the original angular locale import path.
29
+ // This happens when using the development server with caching enabled to allow Vite prebundling to work.
30
+ // There currently is no option on the esbuild resolve function to resolve while disabling the option. To
31
+ // workaround the inability to resolve the full locale location here, the Vite dev server prebundling also
32
+ // contains a plugin to allow the locales to be correctly resolved when prebundling.
33
+ // NOTE: If esbuild eventually allows controlling the external package options in a build.resolve call, this
34
+ // workaround can be removed.
35
+ if (build.initialOptions.packages === 'external') {
36
+ return;
37
+ }
38
+ build.onResolve({ filter: /^angular:locale\/data:/ }, async ({ path }) => {
39
+ // Extract the locale from the path
40
+ const rawLocaleTag = path.split(':', 3)[2];
41
+ // Extract and normalize the base name of the raw locale tag
42
+ let partialLocaleTag;
43
+ try {
44
+ const locale = new Intl.Locale(rawLocaleTag);
45
+ partialLocaleTag = locale.baseName;
46
+ }
47
+ catch {
48
+ return {
49
+ path: rawLocaleTag,
50
+ namespace: exports.LOCALE_DATA_NAMESPACE,
51
+ errors: [
52
+ {
53
+ text: `Invalid or unsupported locale provided in configuration: "${rawLocaleTag}"`,
54
+ },
55
+ ],
56
+ };
57
+ }
58
+ let exact = true;
59
+ while (partialLocaleTag) {
60
+ // Angular embeds the `en`/`en-US` locale into the framework and it does not need to be included again here.
61
+ // The onLoad hook below for the locale data namespace has an `empty` loader that will prevent inclusion.
62
+ // Angular does not contain exact locale data for `en-US` but `en` is equivalent.
63
+ if (partialLocaleTag === 'en' || partialLocaleTag === 'en-US') {
64
+ return {
65
+ path: rawLocaleTag,
66
+ namespace: exports.LOCALE_DATA_NAMESPACE,
67
+ };
68
+ }
69
+ // Attempt to resolve the locale tag data within the Angular base module location
70
+ const potentialPath = `${exports.LOCALE_DATA_BASE_MODULE}/${partialLocaleTag}`;
71
+ const result = await build.resolve(potentialPath, {
72
+ kind: 'import-statement',
73
+ resolveDir: build.initialOptions.absWorkingDir,
74
+ });
75
+ if (result.path) {
76
+ if (exact) {
77
+ return result;
78
+ }
79
+ else {
80
+ return {
81
+ ...result,
82
+ warnings: [
83
+ ...result.warnings,
84
+ {
85
+ location: null,
86
+ text: `Locale data for '${rawLocaleTag}' cannot be found. Using locale data for '${partialLocaleTag}'.`,
87
+ },
88
+ ],
89
+ };
90
+ }
91
+ }
92
+ // Remove the last subtag and try again with a less specific locale.
93
+ // Usually the match is exact so the string splitting here is not done until actually needed after the exact
94
+ // match fails to resolve.
95
+ const parts = partialLocaleTag.split('-');
96
+ partialLocaleTag = parts.slice(0, -1).join('-');
97
+ exact = false;
98
+ }
99
+ // Not found so issue a warning and use an empty loader. Framework built-in `en-US` data will be used.
100
+ // This retains existing behavior as in the Webpack-based builder.
101
+ return {
102
+ path: rawLocaleTag,
103
+ namespace: exports.LOCALE_DATA_NAMESPACE,
104
+ warnings: [
105
+ {
106
+ location: null,
107
+ text: `Locale data for '${rawLocaleTag}' cannot be found. No locale data will be included for this locale.`,
108
+ },
109
+ ],
110
+ };
111
+ });
112
+ // Locales that cannot be found will be loaded as empty content with a warning from the resolve step
113
+ build.onLoad({ filter: /./, namespace: exports.LOCALE_DATA_NAMESPACE }, () => ({
114
+ contents: '',
115
+ loader: 'empty',
116
+ }));
117
+ },
118
+ };
119
+ }
120
+ exports.createAngularLocaleDataPlugin = createAngularLocaleDataPlugin;
@@ -0,0 +1,15 @@
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 { NormalizedApplicationBuildOptions } from '../../builders/application/options';
9
+ import { BuildOutputFile, InitialFileRecord } from './bundler-context';
10
+ export declare function generateIndexHtml(initialFiles: Map<string, InitialFileRecord>, outputFiles: BuildOutputFile[], buildOptions: NormalizedApplicationBuildOptions, lang?: string): Promise<{
11
+ csrContent: string;
12
+ ssrContent?: string;
13
+ warnings: string[];
14
+ errors: string[];
15
+ }>;