@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,23 @@
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 { NormalizedCachedOptions } from '../normalize-cache';
9
+ export interface InlineFontsOptions {
10
+ minify?: boolean;
11
+ cache?: NormalizedCachedOptions;
12
+ }
13
+ export declare class InlineFontsProcessor {
14
+ private options;
15
+ private readonly cachePath;
16
+ constructor(options: InlineFontsOptions);
17
+ process(content: string): Promise<string>;
18
+ private getResponse;
19
+ processURL(url: string | URL): Promise<string | undefined>;
20
+ canInlineRequest(url: string): boolean;
21
+ private getFontProviderDetails;
22
+ private createNormalizedUrl;
23
+ }
@@ -0,0 +1,267 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.InlineFontsProcessor = void 0;
34
+ const https_proxy_agent_1 = require("https-proxy-agent");
35
+ const node_crypto_1 = require("node:crypto");
36
+ const promises_1 = require("node:fs/promises");
37
+ const https = __importStar(require("node:https"));
38
+ const node_path_1 = require("node:path");
39
+ const html_rewriting_stream_1 = require("./html-rewriting-stream");
40
+ const SUPPORTED_PROVIDERS = {
41
+ 'fonts.googleapis.com': {
42
+ preconnectUrl: 'https://fonts.gstatic.com',
43
+ },
44
+ 'use.typekit.net': {
45
+ preconnectUrl: 'https://use.typekit.net',
46
+ },
47
+ };
48
+ /**
49
+ * Hash algorithm used for cached files.
50
+ */
51
+ const CONTENT_HASH_ALGORITHM = 'sha256';
52
+ /**
53
+ * String length of the SHA-256 content hash stored in cached files.
54
+ */
55
+ const CONTENT_HASH_LENGTH = 64;
56
+ class InlineFontsProcessor {
57
+ options;
58
+ cachePath;
59
+ constructor(options) {
60
+ this.options = options;
61
+ const { path: cacheDirectory, enabled } = this.options.cache || {};
62
+ if (cacheDirectory && enabled) {
63
+ this.cachePath = (0, node_path_1.join)(cacheDirectory, 'angular-build-fonts');
64
+ }
65
+ }
66
+ async process(content) {
67
+ const hrefList = [];
68
+ const existingPreconnect = new Set();
69
+ // Collector link tags with href
70
+ const { rewriter: collectorStream, transformedContent: initCollectorStream } = await (0, html_rewriting_stream_1.htmlRewritingStream)(content);
71
+ collectorStream.on('startTag', (tag) => {
72
+ const { tagName, attrs } = tag;
73
+ if (tagName !== 'link') {
74
+ return;
75
+ }
76
+ let hrefValue;
77
+ let relValue;
78
+ for (const { name, value } of attrs) {
79
+ switch (name) {
80
+ case 'rel':
81
+ relValue = value;
82
+ break;
83
+ case 'href':
84
+ hrefValue = value;
85
+ break;
86
+ }
87
+ if (hrefValue && relValue) {
88
+ switch (relValue) {
89
+ case 'stylesheet':
90
+ // <link rel="stylesheet" href="https://example.com/main.css">
91
+ hrefList.push(hrefValue);
92
+ break;
93
+ case 'preconnect':
94
+ // <link rel="preconnect" href="https://example.com">
95
+ existingPreconnect.add(hrefValue.replace(/\/$/, ''));
96
+ break;
97
+ }
98
+ return;
99
+ }
100
+ }
101
+ });
102
+ initCollectorStream().catch(() => {
103
+ // We don't really care about any errors here because it just initializes
104
+ // the rewriting stream, as we are waiting for `finish` below.
105
+ });
106
+ await new Promise((resolve) => collectorStream.on('finish', resolve));
107
+ // Download stylesheets
108
+ const hrefsContent = new Map();
109
+ const newPreconnectUrls = new Set();
110
+ for (const hrefItem of hrefList) {
111
+ const url = this.createNormalizedUrl(hrefItem);
112
+ if (!url) {
113
+ continue;
114
+ }
115
+ const content = await this.processURL(url);
116
+ if (content === undefined) {
117
+ continue;
118
+ }
119
+ hrefsContent.set(hrefItem, content);
120
+ // Add preconnect
121
+ const preconnectUrl = this.getFontProviderDetails(url)?.preconnectUrl;
122
+ if (preconnectUrl && !existingPreconnect.has(preconnectUrl)) {
123
+ newPreconnectUrls.add(preconnectUrl);
124
+ }
125
+ }
126
+ if (hrefsContent.size === 0) {
127
+ return content;
128
+ }
129
+ // Replace link with style tag.
130
+ const { rewriter, transformedContent } = await (0, html_rewriting_stream_1.htmlRewritingStream)(content);
131
+ rewriter.on('startTag', (tag) => {
132
+ const { tagName, attrs } = tag;
133
+ switch (tagName) {
134
+ case 'head':
135
+ rewriter.emitStartTag(tag);
136
+ for (const url of newPreconnectUrls) {
137
+ rewriter.emitRaw(`<link rel="preconnect" href="${url}" crossorigin>`);
138
+ }
139
+ break;
140
+ case 'link':
141
+ const hrefAttr = attrs.some(({ name, value }) => name === 'rel' && value === 'stylesheet') &&
142
+ attrs.find(({ name, value }) => name === 'href' && hrefsContent.has(value));
143
+ if (hrefAttr) {
144
+ const href = hrefAttr.value;
145
+ const cssContent = hrefsContent.get(href);
146
+ rewriter.emitRaw(`<style>${cssContent}</style>`);
147
+ }
148
+ else {
149
+ rewriter.emitStartTag(tag);
150
+ }
151
+ break;
152
+ default:
153
+ rewriter.emitStartTag(tag);
154
+ break;
155
+ }
156
+ });
157
+ return transformedContent();
158
+ }
159
+ async getResponse(url) {
160
+ let cacheFile;
161
+ if (this.cachePath) {
162
+ const key = (0, node_crypto_1.createHash)(CONTENT_HASH_ALGORITHM).update(`${url}`).digest('hex');
163
+ cacheFile = (0, node_path_1.join)(this.cachePath, key);
164
+ }
165
+ if (cacheFile) {
166
+ try {
167
+ const data = await (0, promises_1.readFile)(cacheFile, 'utf8');
168
+ // Check for valid content via stored hash
169
+ if (data.length > CONTENT_HASH_LENGTH) {
170
+ const storedHash = data.slice(0, CONTENT_HASH_LENGTH);
171
+ const content = data.slice(CONTENT_HASH_LENGTH);
172
+ const contentHash = (0, node_crypto_1.createHash)(CONTENT_HASH_ALGORITHM).update(content).digest('base64');
173
+ if (storedHash === contentHash) {
174
+ // Return valid content
175
+ return content;
176
+ }
177
+ else {
178
+ // Delete corrupted cache content
179
+ await (0, promises_1.rm)(cacheFile);
180
+ }
181
+ }
182
+ }
183
+ catch { }
184
+ }
185
+ let agent;
186
+ const httpsProxy = process.env.HTTPS_PROXY ?? process.env.https_proxy;
187
+ if (httpsProxy) {
188
+ agent = new https_proxy_agent_1.HttpsProxyAgent(httpsProxy);
189
+ }
190
+ const data = await new Promise((resolve, reject) => {
191
+ let rawResponse = '';
192
+ https
193
+ .get(url, {
194
+ agent,
195
+ headers: {
196
+ /**
197
+ * Always use a Windows UA. This is because Google fonts will including hinting in fonts for Windows.
198
+ * Hinting is a technique used with Windows files to improve appearance however
199
+ * results in 20-50% larger file sizes.
200
+ *
201
+ * @see http://google3/java/com/google/fonts/css/OpenSansWebFontsCssBuilder.java?l=22
202
+ * @see https://fonts.google.com/knowledge/glossary/hinting (short)
203
+ * @see https://glyphsapp.com/learn/hinting-manual-truetype-hinting (deep dive)
204
+ */
205
+ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
206
+ },
207
+ }, (res) => {
208
+ if (res.statusCode !== 200) {
209
+ reject(new Error(`Inlining of fonts failed. ${url} returned status code: ${res.statusCode}.`));
210
+ return;
211
+ }
212
+ res.on('data', (chunk) => (rawResponse += chunk)).on('end', () => resolve(rawResponse));
213
+ })
214
+ .on('error', (e) => reject(new Error(`Inlining of fonts failed. An error has occurred while retrieving ${url} over the internet.\n` +
215
+ e.message)));
216
+ });
217
+ if (cacheFile) {
218
+ try {
219
+ const dataHash = (0, node_crypto_1.createHash)(CONTENT_HASH_ALGORITHM).update(data).digest('hex');
220
+ await (0, promises_1.writeFile)(cacheFile, dataHash + data);
221
+ }
222
+ catch { }
223
+ }
224
+ return data;
225
+ }
226
+ async processURL(url) {
227
+ const normalizedURL = url instanceof URL ? url : this.createNormalizedUrl(url);
228
+ if (!normalizedURL) {
229
+ return;
230
+ }
231
+ const provider = this.getFontProviderDetails(normalizedURL);
232
+ if (!provider) {
233
+ return undefined;
234
+ }
235
+ let cssContent = await this.getResponse(normalizedURL);
236
+ if (this.options.minify) {
237
+ cssContent = cssContent
238
+ // Comments.
239
+ .replace(/\/\*([\s\S]*?)\*\//g, '')
240
+ // New lines.
241
+ .replace(/\n/g, '')
242
+ // Safe spaces.
243
+ .replace(/\s?[{:;]\s+/g, (s) => s.trim());
244
+ }
245
+ return cssContent;
246
+ }
247
+ canInlineRequest(url) {
248
+ const normalizedUrl = this.createNormalizedUrl(url);
249
+ return normalizedUrl ? !!this.getFontProviderDetails(normalizedUrl) : false;
250
+ }
251
+ getFontProviderDetails(url) {
252
+ return SUPPORTED_PROVIDERS[url.hostname];
253
+ }
254
+ createNormalizedUrl(value) {
255
+ // Need to convert '//' to 'https://' because the URL parser will fail with '//'.
256
+ const url = new URL(value.startsWith('//') ? `https:${value}` : value, 'resolve://');
257
+ switch (url.protocol) {
258
+ case 'http:':
259
+ case 'https:':
260
+ url.protocol = 'https:';
261
+ return url;
262
+ default:
263
+ return undefined;
264
+ }
265
+ }
266
+ }
267
+ exports.InlineFontsProcessor = InlineFontsProcessor;
@@ -0,0 +1,12 @@
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
+ * Finds the `ngCspNonce` value and copies it to all inline `<style>` and `<script> `tags.
10
+ * @param html Markup that should be processed.
11
+ */
12
+ export declare function addNonce(html: string): Promise<string>;
@@ -0,0 +1,55 @@
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.addNonce = void 0;
11
+ const html_rewriting_stream_1 = require("./html-rewriting-stream");
12
+ /**
13
+ * Pattern matching the name of the Angular nonce attribute. Note that this is
14
+ * case-insensitive, because HTML attribute names are case-insensitive as well.
15
+ */
16
+ const NONCE_ATTR_PATTERN = /ngCspNonce/i;
17
+ /**
18
+ * Finds the `ngCspNonce` value and copies it to all inline `<style>` and `<script> `tags.
19
+ * @param html Markup that should be processed.
20
+ */
21
+ async function addNonce(html) {
22
+ const nonce = await findNonce(html);
23
+ if (!nonce) {
24
+ return html;
25
+ }
26
+ const { rewriter, transformedContent } = await (0, html_rewriting_stream_1.htmlRewritingStream)(html);
27
+ rewriter.on('startTag', (tag) => {
28
+ if ((tag.tagName === 'style' ||
29
+ (tag.tagName === 'script' && !tag.attrs.some((attr) => attr.name === 'src'))) &&
30
+ !tag.attrs.some((attr) => attr.name === 'nonce')) {
31
+ tag.attrs.push({ name: 'nonce', value: nonce });
32
+ }
33
+ rewriter.emitStartTag(tag);
34
+ });
35
+ return transformedContent();
36
+ }
37
+ exports.addNonce = addNonce;
38
+ /** Finds the Angular nonce in an HTML string. */
39
+ async function findNonce(html) {
40
+ // Inexpensive check to avoid parsing the HTML when we're sure there's no nonce.
41
+ if (!NONCE_ATTR_PATTERN.test(html)) {
42
+ return null;
43
+ }
44
+ const { rewriter, transformedContent } = await (0, html_rewriting_stream_1.htmlRewritingStream)(html);
45
+ let nonce = null;
46
+ rewriter.on('startTag', (tag) => {
47
+ const nonceAttr = tag.attrs.find((attr) => NONCE_ATTR_PATTERN.test(attr.name));
48
+ if (nonceAttr?.value) {
49
+ nonce = nonceAttr.value;
50
+ rewriter.stop(); // Stop parsing since we've found the nonce.
51
+ }
52
+ });
53
+ await transformedContent();
54
+ return nonce;
55
+ }
@@ -0,0 +1,12 @@
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
+ * Finds the `ngCspNonce` value and copies it to all inline `<style>` and `<script> `tags.
10
+ * @param html Markup that should be processed.
11
+ */
12
+ export declare function addNonce(html: string): Promise<string>;
@@ -0,0 +1,55 @@
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.addNonce = void 0;
11
+ const html_rewriting_stream_1 = require("./html-rewriting-stream");
12
+ /**
13
+ * Pattern matching the name of the Angular nonce attribute. Note that this is
14
+ * case-insensitive, because HTML attribute names are case-insensitive as well.
15
+ */
16
+ const NONCE_ATTR_PATTERN = /ngCspNonce/i;
17
+ /**
18
+ * Finds the `ngCspNonce` value and copies it to all inline `<style>` and `<script> `tags.
19
+ * @param html Markup that should be processed.
20
+ */
21
+ async function addNonce(html) {
22
+ const nonce = await findNonce(html);
23
+ if (!nonce) {
24
+ return html;
25
+ }
26
+ const { rewriter, transformedContent } = await (0, html_rewriting_stream_1.htmlRewritingStream)(html);
27
+ rewriter.on('startTag', (tag) => {
28
+ if ((tag.tagName === 'style' ||
29
+ (tag.tagName === 'script' && !tag.attrs.some((attr) => attr.name === 'src'))) &&
30
+ !tag.attrs.some((attr) => attr.name === 'nonce')) {
31
+ tag.attrs.push({ name: 'nonce', value: nonce });
32
+ }
33
+ rewriter.emitStartTag(tag);
34
+ });
35
+ return transformedContent();
36
+ }
37
+ exports.addNonce = addNonce;
38
+ /** Finds the Angular nonce in an HTML string. */
39
+ async function findNonce(html) {
40
+ // Inexpensive check to avoid parsing the HTML when we're sure there's no nonce.
41
+ if (!NONCE_ATTR_PATTERN.test(html)) {
42
+ return null;
43
+ }
44
+ const { rewriter, transformedContent } = await (0, html_rewriting_stream_1.htmlRewritingStream)(html);
45
+ let nonce = null;
46
+ rewriter.on('startTag', (tag) => {
47
+ const nonceAttr = tag.attrs.find((attr) => NONCE_ATTR_PATTERN.test(attr.name));
48
+ if (nonceAttr?.value) {
49
+ nonce = nonceAttr.value;
50
+ rewriter.stop(); // Stop parsing since we've found the nonce.
51
+ }
52
+ });
53
+ await transformedContent();
54
+ return nonce;
55
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ export * from './normalize-asset-patterns';
9
+ export * from './normalize-optimization';
10
+ export * from './normalize-source-maps';
11
+ export * from './load-proxy-config';
@@ -0,0 +1,27 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
21
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ __exportStar(require("./normalize-asset-patterns"), exports);
25
+ __exportStar(require("./normalize-optimization"), exports);
26
+ __exportStar(require("./normalize-source-maps"), exports);
27
+ __exportStar(require("./load-proxy-config"), exports);
@@ -0,0 +1,20 @@
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
+ * This uses a dynamic import to load a module which may be ESM.
10
+ * CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
11
+ * will currently, unconditionally downlevel dynamic import into a require call.
12
+ * require calls cannot load ESM code and will result in a runtime error. To workaround
13
+ * this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
14
+ * Once TypeScript provides support for keeping the dynamic import this workaround can
15
+ * be dropped.
16
+ *
17
+ * @param modulePath The path of the module to load.
18
+ * @returns A Promise that resolves to the dynamically imported module.
19
+ */
20
+ export declare function loadEsmModule<T>(modulePath: string | URL): Promise<T>;
@@ -0,0 +1,31 @@
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.loadEsmModule = void 0;
11
+ /**
12
+ * Lazily compiled dynamic import loader function.
13
+ */
14
+ let load;
15
+ /**
16
+ * This uses a dynamic import to load a module which may be ESM.
17
+ * CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
18
+ * will currently, unconditionally downlevel dynamic import into a require call.
19
+ * require calls cannot load ESM code and will result in a runtime error. To workaround
20
+ * this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
21
+ * Once TypeScript provides support for keeping the dynamic import this workaround can
22
+ * be dropped.
23
+ *
24
+ * @param modulePath The path of the module to load.
25
+ * @returns A Promise that resolves to the dynamically imported module.
26
+ */
27
+ function loadEsmModule(modulePath) {
28
+ load ??= new Function('modulePath', `return import(modulePath);`);
29
+ return load(modulePath);
30
+ }
31
+ exports.loadEsmModule = loadEsmModule;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ export declare function loadProxyConfiguration(root: string, proxyConfig: string | undefined): Promise<Record<string, object> | undefined>;