@angular-devkit/build-angular 18.0.0-next.2 → 18.0.0-next.4

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 (249) hide show
  1. package/builders.json +1 -5
  2. package/package.json +21 -20
  3. package/src/builders/app-shell/index.js +3 -5
  4. package/src/builders/browser/index.d.ts +1 -1
  5. package/src/builders/browser/index.js +9 -13
  6. package/src/builders/browser-esbuild/index.d.ts +2 -2
  7. package/src/builders/browser-esbuild/index.js +6 -9
  8. package/src/builders/dev-server/builder.d.ts +2 -2
  9. package/src/builders/dev-server/builder.js +11 -6
  10. package/src/builders/dev-server/index.d.ts +1 -1
  11. package/src/builders/dev-server/webpack-server.d.ts +1 -1
  12. package/src/builders/dev-server/webpack-server.js +5 -6
  13. package/src/builders/extract-i18n/application-extraction.js +2 -2
  14. package/src/builders/extract-i18n/builder.js +3 -4
  15. package/src/builders/extract-i18n/options.d.ts +1 -1
  16. package/src/builders/extract-i18n/options.js +2 -2
  17. package/src/builders/jest/index.js +2 -2
  18. package/src/builders/karma/index.js +3 -4
  19. package/src/builders/ng-packagr/index.js +8 -7
  20. package/src/builders/ng-packagr/schema.d.ts +4 -0
  21. package/src/builders/ng-packagr/schema.json +4 -0
  22. package/src/builders/prerender/index.js +2 -2
  23. package/src/builders/prerender/render-worker.js +1 -1
  24. package/src/builders/server/index.js +3 -4
  25. package/src/builders/server/platform-server-exports-loader.js +2 -1
  26. package/src/builders/ssr-dev-server/index.js +34 -34
  27. package/src/builders/web-test-runner/index.js +2 -2
  28. package/src/index.d.ts +1 -1
  29. package/src/index.js +2 -2
  30. package/src/tools/babel/presets/application.js +1 -1
  31. package/src/tools/webpack/configs/styles.js +2 -2
  32. package/src/tools/webpack/plugins/any-component-style-budget-checker.d.ts +2 -2
  33. package/src/tools/webpack/plugins/any-component-style-budget-checker.js +14 -17
  34. package/src/tools/webpack/plugins/css-optimizer-plugin.js +2 -2
  35. package/src/tools/webpack/plugins/index-html-webpack-plugin.d.ts +1 -1
  36. package/src/tools/webpack/plugins/index-html-webpack-plugin.js +3 -3
  37. package/src/tools/webpack/plugins/javascript-optimizer-plugin.js +2 -2
  38. package/src/tools/webpack/plugins/service-worker-plugin.js +2 -2
  39. package/src/tools/webpack/utils/stats.d.ts +1 -14
  40. package/src/tools/webpack/utils/stats.js +3 -207
  41. package/src/utils/action-executor.d.ts +1 -1
  42. package/src/utils/i18n-inlining.d.ts +1 -1
  43. package/src/utils/i18n-webpack.d.ts +16 -0
  44. package/src/utils/i18n-webpack.js +107 -0
  45. package/src/utils/index.d.ts +1 -2
  46. package/src/utils/index.js +4 -2
  47. package/src/utils/normalize-builder-schema.js +2 -2
  48. package/src/utils/normalize-cache.js +1 -1
  49. package/src/utils/normalize-optimization.d.ts +1 -1
  50. package/src/utils/normalize-optimization.js +0 -2
  51. package/src/utils/output-paths.d.ts +1 -1
  52. package/src/utils/webpack-browser-config.d.ts +1 -1
  53. package/src/utils/webpack-browser-config.js +2 -2
  54. package/src/builders/application/build-action.d.ts +0 -33
  55. package/src/builders/application/build-action.js +0 -183
  56. package/src/builders/application/execute-build.d.ts +0 -11
  57. package/src/builders/application/execute-build.js +0 -127
  58. package/src/builders/application/execute-post-bundle.d.ts +0 -25
  59. package/src/builders/application/execute-post-bundle.js +0 -96
  60. package/src/builders/application/i18n.d.ts +0 -29
  61. package/src/builders/application/i18n.js +0 -128
  62. package/src/builders/application/index.d.ts +0 -57
  63. package/src/builders/application/index.js +0 -121
  64. package/src/builders/application/options.d.ts +0 -149
  65. package/src/builders/application/options.js +0 -352
  66. package/src/builders/application/schema.d.ts +0 -512
  67. package/src/builders/application/schema.js +0 -58
  68. package/src/builders/application/schema.json +0 -635
  69. package/src/builders/application/setup-bundling.d.ts +0 -19
  70. package/src/builders/application/setup-bundling.js +0 -71
  71. package/src/builders/dev-server/vite-server.d.ts +0 -30
  72. package/src/builders/dev-server/vite-server.js +0 -502
  73. package/src/tools/babel/plugins/adjust-static-class-members.d.ts +0 -27
  74. package/src/tools/babel/plugins/adjust-static-class-members.js +0 -351
  75. package/src/tools/babel/plugins/adjust-typescript-enums.d.ts +0 -23
  76. package/src/tools/babel/plugins/adjust-typescript-enums.js +0 -113
  77. package/src/tools/babel/plugins/elide-angular-metadata.d.ts +0 -23
  78. package/src/tools/babel/plugins/elide-angular-metadata.js +0 -110
  79. package/src/tools/babel/plugins/index.d.ts +0 -11
  80. package/src/tools/babel/plugins/index.js +0 -21
  81. package/src/tools/babel/plugins/pure-toplevel-functions.d.ts +0 -16
  82. package/src/tools/babel/plugins/pure-toplevel-functions.js +0 -90
  83. package/src/tools/esbuild/angular/angular-host.d.ts +0 -26
  84. package/src/tools/esbuild/angular/angular-host.js +0 -72
  85. package/src/tools/esbuild/angular/compilation/angular-compilation.d.ts +0 -42
  86. package/src/tools/esbuild/angular/compilation/angular-compilation.js +0 -94
  87. package/src/tools/esbuild/angular/compilation/aot-compilation.d.ts +0 -21
  88. package/src/tools/esbuild/angular/compilation/aot-compilation.js +0 -228
  89. package/src/tools/esbuild/angular/compilation/factory.d.ts +0 -16
  90. package/src/tools/esbuild/angular/compilation/factory.js +0 -56
  91. package/src/tools/esbuild/angular/compilation/index.d.ts +0 -10
  92. package/src/tools/esbuild/angular/compilation/index.js +0 -17
  93. package/src/tools/esbuild/angular/compilation/jit-compilation.d.ts +0 -21
  94. package/src/tools/esbuild/angular/compilation/jit-compilation.js +0 -106
  95. package/src/tools/esbuild/angular/compilation/noop-compilation.d.ts +0 -20
  96. package/src/tools/esbuild/angular/compilation/noop-compilation.js +0 -26
  97. package/src/tools/esbuild/angular/compilation/parallel-compilation.d.ts +0 -42
  98. package/src/tools/esbuild/angular/compilation/parallel-compilation.js +0 -123
  99. package/src/tools/esbuild/angular/compilation/parallel-worker.d.ts +0 -33
  100. package/src/tools/esbuild/angular/compilation/parallel-worker.js +0 -90
  101. package/src/tools/esbuild/angular/compilation-state.d.ts +0 -15
  102. package/src/tools/esbuild/angular/compilation-state.js +0 -44
  103. package/src/tools/esbuild/angular/compiler-plugin.d.ts +0 -27
  104. package/src/tools/esbuild/angular/compiler-plugin.js +0 -433
  105. package/src/tools/esbuild/angular/component-stylesheets.d.ts +0 -44
  106. package/src/tools/esbuild/angular/component-stylesheets.js +0 -150
  107. package/src/tools/esbuild/angular/diagnostics.d.ts +0 -15
  108. package/src/tools/esbuild/angular/diagnostics.js +0 -69
  109. package/src/tools/esbuild/angular/file-reference-tracker.d.ts +0 -17
  110. package/src/tools/esbuild/angular/file-reference-tracker.js +0 -57
  111. package/src/tools/esbuild/angular/jit-plugin-callbacks.d.ts +0 -23
  112. package/src/tools/esbuild/angular/jit-plugin-callbacks.js +0 -117
  113. package/src/tools/esbuild/angular/jit-resource-transformer.d.ts +0 -17
  114. package/src/tools/esbuild/angular/jit-resource-transformer.js +0 -186
  115. package/src/tools/esbuild/angular/source-file-cache.d.ts +0 -18
  116. package/src/tools/esbuild/angular/source-file-cache.js +0 -65
  117. package/src/tools/esbuild/angular/uri.d.ts +0 -54
  118. package/src/tools/esbuild/angular/uri.js +0 -74
  119. package/src/tools/esbuild/angular/web-worker-transformer.d.ts +0 -17
  120. package/src/tools/esbuild/angular/web-worker-transformer.js +0 -94
  121. package/src/tools/esbuild/application-code-bundle.d.ts +0 -20
  122. package/src/tools/esbuild/application-code-bundle.js +0 -368
  123. package/src/tools/esbuild/budget-stats.d.ts +0 -19
  124. package/src/tools/esbuild/budget-stats.js +0 -59
  125. package/src/tools/esbuild/bundler-context.d.ts +0 -75
  126. package/src/tools/esbuild/bundler-context.js +0 -366
  127. package/src/tools/esbuild/bundler-execution-result.d.ts +0 -71
  128. package/src/tools/esbuild/bundler-execution-result.js +0 -131
  129. package/src/tools/esbuild/cache.d.ts +0 -88
  130. package/src/tools/esbuild/cache.js +0 -92
  131. package/src/tools/esbuild/commonjs-checker.d.ts +0 -28
  132. package/src/tools/esbuild/commonjs-checker.js +0 -151
  133. package/src/tools/esbuild/compiler-plugin-options.d.ts +0 -16
  134. package/src/tools/esbuild/compiler-plugin-options.js +0 -49
  135. package/src/tools/esbuild/external-packages-plugin.d.ts +0 -18
  136. package/src/tools/esbuild/external-packages-plugin.js +0 -70
  137. package/src/tools/esbuild/global-scripts.d.ts +0 -16
  138. package/src/tools/esbuild/global-scripts.js +0 -142
  139. package/src/tools/esbuild/global-styles.d.ts +0 -10
  140. package/src/tools/esbuild/global-styles.js +0 -74
  141. package/src/tools/esbuild/i18n-inliner-worker.d.ts +0 -42
  142. package/src/tools/esbuild/i18n-inliner-worker.js +0 -136
  143. package/src/tools/esbuild/i18n-inliner.d.ts +0 -44
  144. package/src/tools/esbuild/i18n-inliner.js +0 -150
  145. package/src/tools/esbuild/i18n-locale-plugin.d.ts +0 -22
  146. package/src/tools/esbuild/i18n-locale-plugin.js +0 -120
  147. package/src/tools/esbuild/index-html-generator.d.ts +0 -15
  148. package/src/tools/esbuild/index-html-generator.js +0 -129
  149. package/src/tools/esbuild/javascript-transformer-worker.d.ts +0 -19
  150. package/src/tools/esbuild/javascript-transformer-worker.js +0 -154
  151. package/src/tools/esbuild/javascript-transformer.d.ts +0 -54
  152. package/src/tools/esbuild/javascript-transformer.js +0 -143
  153. package/src/tools/esbuild/license-extractor.d.ts +0 -25
  154. package/src/tools/esbuild/license-extractor.js +0 -158
  155. package/src/tools/esbuild/load-result-cache.d.ts +0 -21
  156. package/src/tools/esbuild/load-result-cache.js +0 -75
  157. package/src/tools/esbuild/profiling.d.ts +0 -11
  158. package/src/tools/esbuild/profiling.js +0 -78
  159. package/src/tools/esbuild/rxjs-esm-resolution-plugin.d.ts +0 -18
  160. package/src/tools/esbuild/rxjs-esm-resolution-plugin.js +0 -44
  161. package/src/tools/esbuild/sourcemap-ignorelist-plugin.d.ts +0 -17
  162. package/src/tools/esbuild/sourcemap-ignorelist-plugin.js +0 -73
  163. package/src/tools/esbuild/stylesheets/bundle-options.d.ts +0 -35
  164. package/src/tools/esbuild/stylesheets/bundle-options.js +0 -64
  165. package/src/tools/esbuild/stylesheets/css-inline-fonts-plugin.d.ts +0 -25
  166. package/src/tools/esbuild/stylesheets/css-inline-fonts-plugin.js +0 -57
  167. package/src/tools/esbuild/stylesheets/css-language.d.ts +0 -9
  168. package/src/tools/esbuild/stylesheets/css-language.js +0 -15
  169. package/src/tools/esbuild/stylesheets/css-resource-plugin.d.ts +0 -18
  170. package/src/tools/esbuild/stylesheets/css-resource-plugin.js +0 -107
  171. package/src/tools/esbuild/stylesheets/less-language.d.ts +0 -9
  172. package/src/tools/esbuild/stylesheets/less-language.js +0 -155
  173. package/src/tools/esbuild/stylesheets/sass-language.d.ts +0 -10
  174. package/src/tools/esbuild/stylesheets/sass-language.js +0 -185
  175. package/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.d.ts +0 -58
  176. package/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.js +0 -282
  177. package/src/tools/esbuild/utils.d.ts +0 -41
  178. package/src/tools/esbuild/utils.js +0 -378
  179. package/src/tools/esbuild/virtual-module-plugin.d.ts +0 -33
  180. package/src/tools/esbuild/virtual-module-plugin.js +0 -43
  181. package/src/tools/esbuild/watcher.d.ts +0 -25
  182. package/src/tools/esbuild/watcher.js +0 -118
  183. package/src/tools/sass/lexer.d.ts +0 -18
  184. package/src/tools/sass/lexer.js +0 -161
  185. package/src/tools/sass/rebasing-importer.d.ts +0 -101
  186. package/src/tools/sass/rebasing-importer.js +0 -337
  187. package/src/tools/sass/sass-service.d.ts +0 -49
  188. package/src/tools/sass/sass-service.js +0 -213
  189. package/src/tools/sass/worker.d.ts +0 -8
  190. package/src/tools/sass/worker.js +0 -164
  191. package/src/tools/vite/angular-memory-plugin.d.ts +0 -24
  192. package/src/tools/vite/angular-memory-plugin.js +0 -268
  193. package/src/tools/vite/i18n-locale-plugin.d.ts +0 -18
  194. package/src/tools/vite/i18n-locale-plugin.js +0 -55
  195. package/src/typings.d.ts +0 -21
  196. package/src/utils/bundle-calculator.d.ts +0 -44
  197. package/src/utils/bundle-calculator.js +0 -302
  198. package/src/utils/check-port.d.ts +0 -8
  199. package/src/utils/check-port.js +0 -58
  200. package/src/utils/delete-output-dir.d.ts +0 -11
  201. package/src/utils/delete-output-dir.js +0 -46
  202. package/src/utils/i18n-options.d.ts +0 -40
  203. package/src/utils/i18n-options.js +0 -254
  204. package/src/utils/index-file/augment-index-html.d.ts +0 -40
  205. package/src/utils/index-file/augment-index-html.js +0 -238
  206. package/src/utils/index-file/html-rewriting-stream.d.ts +0 -11
  207. package/src/utils/index-file/html-rewriting-stream.js +0 -28
  208. package/src/utils/index-file/index-html-generator.d.ts +0 -47
  209. package/src/utils/index-file/index-html-generator.js +0 -119
  210. package/src/utils/index-file/inline-critical-css.d.ts +0 -24
  211. package/src/utils/index-file/inline-critical-css.js +0 -179
  212. package/src/utils/index-file/inline-fonts.d.ts +0 -23
  213. package/src/utils/index-file/inline-fonts.js +0 -267
  214. package/src/utils/index-file/style-nonce.d.ts +0 -12
  215. package/src/utils/index-file/style-nonce.js +0 -53
  216. package/src/utils/load-proxy-config.d.ts +0 -8
  217. package/src/utils/load-proxy-config.js +0 -192
  218. package/src/utils/load-translations.d.ts +0 -16
  219. package/src/utils/load-translations.js +0 -84
  220. package/src/utils/postcss-configuration.d.ts +0 -17
  221. package/src/utils/postcss-configuration.js +0 -86
  222. package/src/utils/purge-cache.d.ts +0 -10
  223. package/src/utils/purge-cache.js +0 -40
  224. package/src/utils/routes-extractor/extractor.d.ts +0 -15
  225. package/src/utils/routes-extractor/extractor.js +0 -97
  226. package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.d.ts +0 -18
  227. package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.js +0 -129
  228. package/src/utils/server-rendering/esm-in-memory-loader/register-hooks.d.ts +0 -8
  229. package/src/utils/server-rendering/esm-in-memory-loader/register-hooks.js +0 -13
  230. package/src/utils/server-rendering/fetch-patch.d.ts +0 -8
  231. package/src/utils/server-rendering/fetch-patch.js +0 -66
  232. package/src/utils/server-rendering/load-esm-from-memory.d.ts +0 -10
  233. package/src/utils/server-rendering/load-esm-from-memory.js +0 -26
  234. package/src/utils/server-rendering/main-bundle-exports.d.ts +0 -27
  235. package/src/utils/server-rendering/main-bundle-exports.js +0 -9
  236. package/src/utils/server-rendering/prerender.d.ts +0 -23
  237. package/src/utils/server-rendering/prerender.js +0 -192
  238. package/src/utils/server-rendering/render-page.d.ts +0 -26
  239. package/src/utils/server-rendering/render-page.js +0 -110
  240. package/src/utils/server-rendering/render-worker.d.ts +0 -22
  241. package/src/utils/server-rendering/render-worker.js +0 -30
  242. package/src/utils/server-rendering/routes-extractor-worker.d.ts +0 -21
  243. package/src/utils/server-rendering/routes-extractor-worker.js +0 -53
  244. package/src/utils/service-worker.d.ts +0 -25
  245. package/src/utils/service-worker.js +0 -211
  246. package/src/utils/supported-browsers.d.ts +0 -10
  247. package/src/utils/supported-browsers.js +0 -42
  248. package/src/utils/version.d.ts +0 -8
  249. package/src/utils/version.js +0 -59
@@ -1,129 +0,0 @@
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
- exports.generateIndexHtml = void 0;
37
- const node_assert_1 = __importDefault(require("node:assert"));
38
- const node_path_1 = __importDefault(require("node:path"));
39
- const index_html_generator_1 = require("../../utils/index-file/index-html-generator");
40
- const bundler_context_1 = require("./bundler-context");
41
- async function generateIndexHtml(initialFiles, outputFiles, buildOptions, lang) {
42
- // Analyze metafile for initial link-based hints.
43
- // Skip if the internal externalPackages option is enabled since this option requires
44
- // dev server cooperation to properly resolve and fetch imports.
45
- const hints = [];
46
- const { indexHtmlOptions, externalPackages, optimizationOptions, crossOrigin, subresourceIntegrity, baseHref, } = buildOptions;
47
- (0, node_assert_1.default)(indexHtmlOptions, 'indexHtmlOptions cannot be undefined.');
48
- if (!externalPackages && indexHtmlOptions.preloadInitial) {
49
- for (const [key, value] of initialFiles) {
50
- if (value.entrypoint || value.serverFile) {
51
- // Entry points are already referenced in the HTML
52
- continue;
53
- }
54
- if (value.type === 'script') {
55
- hints.push({ url: key, mode: 'modulepreload' });
56
- }
57
- else if (value.type === 'style') {
58
- // Provide an "as" value of "style" to ensure external URLs which may not have a
59
- // file extension are treated as stylesheets.
60
- hints.push({ url: key, mode: 'preload', as: 'style' });
61
- }
62
- }
63
- }
64
- /** Virtual output path to support reading in-memory files. */
65
- const browserOutputFiles = outputFiles.filter(({ type }) => type === bundler_context_1.BuildOutputFileType.Browser);
66
- const virtualOutputPath = '/';
67
- const readAsset = async function (filePath) {
68
- // Remove leading directory separator
69
- const relativefilePath = node_path_1.default.relative(virtualOutputPath, filePath);
70
- const file = browserOutputFiles.find((file) => file.path === relativefilePath);
71
- if (file) {
72
- return file.text;
73
- }
74
- throw new Error(`Output file does not exist: ${relativefilePath}`);
75
- };
76
- // Create an index HTML generator that reads from the in-memory output files
77
- const indexHtmlGenerator = new index_html_generator_1.IndexHtmlGenerator({
78
- indexPath: indexHtmlOptions.input,
79
- entrypoints: indexHtmlOptions.insertionOrder,
80
- sri: subresourceIntegrity,
81
- optimization: {
82
- ...optimizationOptions,
83
- styles: {
84
- ...optimizationOptions.styles,
85
- inlineCritical: false, // Disable critical css inline as for SSR and SSG this will be done during rendering.
86
- },
87
- },
88
- crossOrigin: crossOrigin,
89
- deployUrl: buildOptions.publicPath,
90
- postTransform: indexHtmlOptions.transformer,
91
- });
92
- indexHtmlGenerator.readAsset = readAsset;
93
- const transformResult = await indexHtmlGenerator.process({
94
- baseHref,
95
- lang,
96
- outputPath: virtualOutputPath,
97
- files: [...initialFiles]
98
- .filter(([, file]) => !file.serverFile)
99
- .map(([file, record]) => ({
100
- name: record.name ?? '',
101
- file,
102
- extension: node_path_1.default.extname(file),
103
- })),
104
- hints,
105
- });
106
- const contentWithoutCriticalCssInlined = transformResult.content;
107
- if (!optimizationOptions.styles.inlineCritical) {
108
- return {
109
- ...transformResult,
110
- contentWithoutCriticalCssInlined,
111
- };
112
- }
113
- const { InlineCriticalCssProcessor } = await Promise.resolve().then(() => __importStar(require('../../utils/index-file/inline-critical-css')));
114
- const inlineCriticalCssProcessor = new InlineCriticalCssProcessor({
115
- minify: false, // CSS has already been minified during the build.
116
- deployUrl: buildOptions.publicPath,
117
- readAsset,
118
- });
119
- const { content, errors, warnings } = await inlineCriticalCssProcessor.process(contentWithoutCriticalCssInlined, {
120
- outputPath: virtualOutputPath,
121
- });
122
- return {
123
- errors: [...transformResult.errors, ...errors],
124
- warnings: [...transformResult.warnings, ...warnings],
125
- content,
126
- contentWithoutCriticalCssInlined,
127
- };
128
- }
129
- exports.generateIndexHtml = generateIndexHtml;
@@ -1,19 +0,0 @@
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 {};
@@ -1,154 +0,0 @@
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
- }
@@ -1,54 +0,0 @@
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
- }
@@ -1,143 +0,0 @@
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
- }, { transferList: [data.buffer] }));
91
- // If there is a cache then store the result
92
- if (this.cache && cacheKey) {
93
- try {
94
- await this.cache.put(cacheKey, result);
95
- }
96
- catch {
97
- // Failure to store the value in the cache should not fail the transform
98
- }
99
- }
100
- }
101
- return result;
102
- }
103
- /**
104
- * Performs JavaScript transformations on the provided data of a file. The file does not need
105
- * to exist on the filesystem.
106
- * @param filename The full path of the file represented by the data.
107
- * @param data The data of the file that should be transformed.
108
- * @param skipLinker If true, bypass all Angular linker processing; if false, attempt linking.
109
- * @param sideEffects If false, and `advancedOptimizations` is enabled tslib decorators are wrapped.
110
- * @returns A promise that resolves to a UTF-8 encoded Uint8Array containing the result.
111
- */
112
- async transformData(filename, data, skipLinker, sideEffects) {
113
- // Perform a quick test to determine if the data needs any transformations.
114
- // This allows directly returning the data without the worker communication overhead.
115
- if (skipLinker && !this.#commonOptions.advancedOptimizations) {
116
- const keepSourcemap = this.#commonOptions.sourcemap &&
117
- (!!this.#commonOptions.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(filename));
118
- return Buffer.from(keepSourcemap ? data : data.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, ''), 'utf-8');
119
- }
120
- return this.#ensureWorkerPool().run({
121
- filename,
122
- data,
123
- skipLinker,
124
- sideEffects,
125
- ...this.#commonOptions,
126
- });
127
- }
128
- /**
129
- * Stops all active transformation tasks and shuts down all workers.
130
- * @returns A void promise that resolves when closing is complete.
131
- */
132
- async close() {
133
- if (this.#workerPool) {
134
- try {
135
- await this.#workerPool.destroy();
136
- }
137
- finally {
138
- this.#workerPool = undefined;
139
- }
140
- }
141
- }
142
- }
143
- exports.JavaScriptTransformer = JavaScriptTransformer;
@@ -1,25 +0,0 @@
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>;