@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.
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/builders.json +14 -0
- package/package.json +87 -0
- package/src/builders/application/build-action.d.ts +33 -0
- package/src/builders/application/build-action.js +183 -0
- package/src/builders/application/execute-build.d.ts +11 -0
- package/src/builders/application/execute-build.js +125 -0
- package/src/builders/application/execute-post-bundle.d.ts +25 -0
- package/src/builders/application/execute-post-bundle.js +93 -0
- package/src/builders/application/i18n.d.ts +29 -0
- package/src/builders/application/i18n.js +128 -0
- package/src/builders/application/index.d.ts +57 -0
- package/src/builders/application/index.js +121 -0
- package/src/builders/application/options.d.ts +149 -0
- package/src/builders/application/options.js +369 -0
- package/src/builders/application/schema.d.ts +512 -0
- package/src/builders/application/schema.js +58 -0
- package/src/builders/application/schema.json +635 -0
- package/src/builders/application/setup-bundling.d.ts +19 -0
- package/src/builders/application/setup-bundling.js +71 -0
- package/src/builders/dev-server/builder.d.ts +32 -0
- package/src/builders/dev-server/builder.js +70 -0
- package/src/builders/dev-server/index.d.ts +14 -0
- package/src/builders/dev-server/index.js +15 -0
- package/src/builders/dev-server/internal.d.ts +19 -0
- package/src/builders/dev-server/internal.js +29 -0
- package/src/builders/dev-server/options.d.ts +47 -0
- package/src/builders/dev-server/options.js +65 -0
- package/src/builders/dev-server/output.d.ts +16 -0
- package/src/builders/dev-server/output.js +9 -0
- package/src/builders/dev-server/schema.d.ts +118 -0
- package/src/builders/dev-server/schema.js +4 -0
- package/src/builders/dev-server/schema.json +131 -0
- package/src/builders/dev-server/vite-server.d.ts +31 -0
- package/src/builders/dev-server/vite-server.js +504 -0
- package/src/index.d.ts +11 -0
- package/src/index.js +16 -0
- package/src/private.d.ts +35 -0
- package/src/private.js +70 -0
- package/src/tools/babel/plugins/adjust-static-class-members.d.ts +26 -0
- package/src/tools/babel/plugins/adjust-static-class-members.js +351 -0
- package/src/tools/babel/plugins/adjust-typescript-enums.d.ts +22 -0
- package/src/tools/babel/plugins/adjust-typescript-enums.js +113 -0
- package/src/tools/babel/plugins/elide-angular-metadata.d.ts +22 -0
- package/src/tools/babel/plugins/elide-angular-metadata.js +110 -0
- package/src/tools/babel/plugins/index.d.ts +11 -0
- package/src/tools/babel/plugins/index.js +21 -0
- package/src/tools/babel/plugins/pure-toplevel-functions.d.ts +15 -0
- package/src/tools/babel/plugins/pure-toplevel-functions.js +90 -0
- package/src/tools/babel/typings.d.ts +21 -0
- package/src/tools/esbuild/angular/angular-host.d.ts +26 -0
- package/src/tools/esbuild/angular/angular-host.js +134 -0
- package/src/tools/esbuild/angular/compilation/angular-compilation.d.ts +42 -0
- package/src/tools/esbuild/angular/compilation/angular-compilation.js +94 -0
- package/src/tools/esbuild/angular/compilation/aot-compilation.d.ts +21 -0
- package/src/tools/esbuild/angular/compilation/aot-compilation.js +224 -0
- package/src/tools/esbuild/angular/compilation/factory.d.ts +16 -0
- package/src/tools/esbuild/angular/compilation/factory.js +56 -0
- package/src/tools/esbuild/angular/compilation/index.d.ts +10 -0
- package/src/tools/esbuild/angular/compilation/index.js +17 -0
- package/src/tools/esbuild/angular/compilation/jit-bootstrap-transformer.d.ts +10 -0
- package/src/tools/esbuild/angular/compilation/jit-bootstrap-transformer.js +182 -0
- package/src/tools/esbuild/angular/compilation/jit-compilation.d.ts +21 -0
- package/src/tools/esbuild/angular/compilation/jit-compilation.js +106 -0
- package/src/tools/esbuild/angular/compilation/noop-compilation.d.ts +20 -0
- package/src/tools/esbuild/angular/compilation/noop-compilation.js +26 -0
- package/src/tools/esbuild/angular/compilation/parallel-compilation.d.ts +42 -0
- package/src/tools/esbuild/angular/compilation/parallel-compilation.js +123 -0
- package/src/tools/esbuild/angular/compilation/parallel-worker.d.ts +33 -0
- package/src/tools/esbuild/angular/compilation/parallel-worker.js +90 -0
- package/src/tools/esbuild/angular/compilation-state.d.ts +15 -0
- package/src/tools/esbuild/angular/compilation-state.js +44 -0
- package/src/tools/esbuild/angular/compiler-plugin.d.ts +27 -0
- package/src/tools/esbuild/angular/compiler-plugin.js +441 -0
- package/src/tools/esbuild/angular/component-stylesheets.d.ts +44 -0
- package/src/tools/esbuild/angular/component-stylesheets.js +150 -0
- package/src/tools/esbuild/angular/diagnostics.d.ts +15 -0
- package/src/tools/esbuild/angular/diagnostics.js +69 -0
- package/src/tools/esbuild/angular/file-reference-tracker.d.ts +17 -0
- package/src/tools/esbuild/angular/file-reference-tracker.js +57 -0
- package/src/tools/esbuild/angular/jit-plugin-callbacks.d.ts +23 -0
- package/src/tools/esbuild/angular/jit-plugin-callbacks.js +117 -0
- package/src/tools/esbuild/angular/jit-resource-transformer.d.ts +17 -0
- package/src/tools/esbuild/angular/jit-resource-transformer.js +186 -0
- package/src/tools/esbuild/angular/source-file-cache.d.ts +18 -0
- package/src/tools/esbuild/angular/source-file-cache.js +65 -0
- package/src/tools/esbuild/angular/uri.d.ts +54 -0
- package/src/tools/esbuild/angular/uri.js +74 -0
- package/src/tools/esbuild/angular/web-worker-transformer.d.ts +17 -0
- package/src/tools/esbuild/angular/web-worker-transformer.js +94 -0
- package/src/tools/esbuild/application-code-bundle.d.ts +20 -0
- package/src/tools/esbuild/application-code-bundle.js +368 -0
- package/src/tools/esbuild/budget-stats.d.ts +19 -0
- package/src/tools/esbuild/budget-stats.js +59 -0
- package/src/tools/esbuild/bundler-context.d.ts +75 -0
- package/src/tools/esbuild/bundler-context.js +366 -0
- package/src/tools/esbuild/bundler-execution-result.d.ts +71 -0
- package/src/tools/esbuild/bundler-execution-result.js +131 -0
- package/src/tools/esbuild/cache.d.ts +88 -0
- package/src/tools/esbuild/cache.js +92 -0
- package/src/tools/esbuild/commonjs-checker.d.ts +28 -0
- package/src/tools/esbuild/commonjs-checker.js +151 -0
- package/src/tools/esbuild/compiler-plugin-options.d.ts +16 -0
- package/src/tools/esbuild/compiler-plugin-options.js +49 -0
- package/src/tools/esbuild/external-packages-plugin.d.ts +18 -0
- package/src/tools/esbuild/external-packages-plugin.js +70 -0
- package/src/tools/esbuild/global-scripts.d.ts +16 -0
- package/src/tools/esbuild/global-scripts.js +142 -0
- package/src/tools/esbuild/global-styles.d.ts +10 -0
- package/src/tools/esbuild/global-styles.js +74 -0
- package/src/tools/esbuild/i18n-inliner-worker.d.ts +42 -0
- package/src/tools/esbuild/i18n-inliner-worker.js +136 -0
- package/src/tools/esbuild/i18n-inliner.d.ts +44 -0
- package/src/tools/esbuild/i18n-inliner.js +150 -0
- package/src/tools/esbuild/i18n-locale-plugin.d.ts +22 -0
- package/src/tools/esbuild/i18n-locale-plugin.js +120 -0
- package/src/tools/esbuild/index-html-generator.d.ts +15 -0
- package/src/tools/esbuild/index-html-generator.js +81 -0
- package/src/tools/esbuild/javascript-transformer-worker.d.ts +19 -0
- package/src/tools/esbuild/javascript-transformer-worker.js +154 -0
- package/src/tools/esbuild/javascript-transformer.d.ts +54 -0
- package/src/tools/esbuild/javascript-transformer.js +147 -0
- package/src/tools/esbuild/license-extractor.d.ts +25 -0
- package/src/tools/esbuild/license-extractor.js +158 -0
- package/src/tools/esbuild/load-result-cache.d.ts +21 -0
- package/src/tools/esbuild/load-result-cache.js +75 -0
- package/src/tools/esbuild/profiling.d.ts +11 -0
- package/src/tools/esbuild/profiling.js +78 -0
- package/src/tools/esbuild/rxjs-esm-resolution-plugin.d.ts +18 -0
- package/src/tools/esbuild/rxjs-esm-resolution-plugin.js +44 -0
- package/src/tools/esbuild/sourcemap-ignorelist-plugin.d.ts +17 -0
- package/src/tools/esbuild/sourcemap-ignorelist-plugin.js +73 -0
- package/src/tools/esbuild/stylesheets/bundle-options.d.ts +35 -0
- package/src/tools/esbuild/stylesheets/bundle-options.js +64 -0
- package/src/tools/esbuild/stylesheets/css-inline-fonts-plugin.d.ts +25 -0
- package/src/tools/esbuild/stylesheets/css-inline-fonts-plugin.js +57 -0
- package/src/tools/esbuild/stylesheets/css-language.d.ts +9 -0
- package/src/tools/esbuild/stylesheets/css-language.js +15 -0
- package/src/tools/esbuild/stylesheets/css-resource-plugin.d.ts +18 -0
- package/src/tools/esbuild/stylesheets/css-resource-plugin.js +114 -0
- package/src/tools/esbuild/stylesheets/less-language.d.ts +9 -0
- package/src/tools/esbuild/stylesheets/less-language.js +155 -0
- package/src/tools/esbuild/stylesheets/sass-language.d.ts +10 -0
- package/src/tools/esbuild/stylesheets/sass-language.js +185 -0
- package/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.d.ts +58 -0
- package/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.js +282 -0
- package/src/tools/esbuild/utils.d.ts +49 -0
- package/src/tools/esbuild/utils.js +392 -0
- package/src/tools/esbuild/virtual-module-plugin.d.ts +33 -0
- package/src/tools/esbuild/virtual-module-plugin.js +43 -0
- package/src/tools/esbuild/watcher.d.ts +25 -0
- package/src/tools/esbuild/watcher.js +118 -0
- package/src/tools/sass/lexer.d.ts +18 -0
- package/src/tools/sass/lexer.js +161 -0
- package/src/tools/sass/rebasing-importer.d.ts +101 -0
- package/src/tools/sass/rebasing-importer.js +334 -0
- package/src/tools/sass/sass-service.d.ts +72 -0
- package/src/tools/sass/sass-service.js +213 -0
- package/src/tools/sass/worker.d.ts +8 -0
- package/src/tools/sass/worker.js +192 -0
- package/src/tools/vite/angular-memory-plugin.d.ts +24 -0
- package/src/tools/vite/angular-memory-plugin.js +268 -0
- package/src/tools/vite/i18n-locale-plugin.d.ts +18 -0
- package/src/tools/vite/i18n-locale-plugin.js +55 -0
- package/src/utils/bundle-calculator.d.ts +44 -0
- package/src/utils/bundle-calculator.js +303 -0
- package/src/utils/check-port.d.ts +8 -0
- package/src/utils/check-port.js +58 -0
- package/src/utils/color.d.ts +10 -0
- package/src/utils/color.js +63 -0
- package/src/utils/delete-output-dir.d.ts +11 -0
- package/src/utils/delete-output-dir.js +46 -0
- package/src/utils/environment-options.d.ts +16 -0
- package/src/utils/environment-options.js +79 -0
- package/src/utils/error.d.ts +10 -0
- package/src/utils/error.js +21 -0
- package/src/utils/format-bytes.d.ts +8 -0
- package/src/utils/format-bytes.js +22 -0
- package/src/utils/i18n-options.d.ts +33 -0
- package/src/utils/i18n-options.js +161 -0
- package/src/utils/index-file/add-event-dispatch-contract.d.ts +8 -0
- package/src/utils/index-file/add-event-dispatch-contract.js +28 -0
- package/src/utils/index-file/augment-index-html.d.ts +40 -0
- package/src/utils/index-file/augment-index-html.js +239 -0
- package/src/utils/index-file/html-rewriting-stream.d.ts +11 -0
- package/src/utils/index-file/html-rewriting-stream.js +28 -0
- package/src/utils/index-file/index-html-generator.d.ts +57 -0
- package/src/utils/index-file/index-html-generator.js +135 -0
- package/src/utils/index-file/inline-critical-css.d.ts +24 -0
- package/src/utils/index-file/inline-critical-css.js +179 -0
- package/src/utils/index-file/inline-fonts.d.ts +23 -0
- package/src/utils/index-file/inline-fonts.js +267 -0
- package/src/utils/index-file/nonce.d.ts +12 -0
- package/src/utils/index-file/nonce.js +55 -0
- package/src/utils/index-file/style-nonce.d.ts +12 -0
- package/src/utils/index-file/style-nonce.js +55 -0
- package/src/utils/index.d.ts +11 -0
- package/src/utils/index.js +27 -0
- package/src/utils/load-esm.d.ts +20 -0
- package/src/utils/load-esm.js +31 -0
- package/src/utils/load-proxy-config.d.ts +8 -0
- package/src/utils/load-proxy-config.js +189 -0
- package/src/utils/load-translations.d.ts +16 -0
- package/src/utils/load-translations.js +84 -0
- package/src/utils/normalize-asset-patterns.d.ts +14 -0
- package/src/utils/normalize-asset-patterns.js +96 -0
- package/src/utils/normalize-cache.d.ts +16 -0
- package/src/utils/normalize-cache.js +44 -0
- package/src/utils/normalize-optimization.d.ts +13 -0
- package/src/utils/normalize-optimization.js +42 -0
- package/src/utils/normalize-source-maps.d.ts +9 -0
- package/src/utils/normalize-source-maps.js +23 -0
- package/src/utils/postcss-configuration.d.ts +17 -0
- package/src/utils/postcss-configuration.js +86 -0
- package/src/utils/purge-cache.d.ts +10 -0
- package/src/utils/purge-cache.js +40 -0
- package/src/utils/resolve-assets.d.ts +18 -0
- package/src/utils/resolve-assets.js +35 -0
- package/src/utils/routes-extractor/extractor.d.ts +15 -0
- package/src/utils/routes-extractor/extractor.js +97 -0
- package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.d.ts +18 -0
- package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.js +129 -0
- package/src/utils/server-rendering/esm-in-memory-loader/register-hooks.d.ts +8 -0
- package/src/utils/server-rendering/esm-in-memory-loader/register-hooks.js +13 -0
- package/src/utils/server-rendering/fetch-patch.d.ts +8 -0
- package/src/utils/server-rendering/fetch-patch.js +66 -0
- package/src/utils/server-rendering/load-esm-from-memory.d.ts +10 -0
- package/src/utils/server-rendering/load-esm-from-memory.js +26 -0
- package/src/utils/server-rendering/main-bundle-exports.d.ts +27 -0
- package/src/utils/server-rendering/main-bundle-exports.js +9 -0
- package/src/utils/server-rendering/prerender.d.ts +23 -0
- package/src/utils/server-rendering/prerender.js +192 -0
- package/src/utils/server-rendering/render-page.d.ts +26 -0
- package/src/utils/server-rendering/render-page.js +110 -0
- package/src/utils/server-rendering/render-worker.d.ts +22 -0
- package/src/utils/server-rendering/render-worker.js +30 -0
- package/src/utils/server-rendering/routes-extractor-worker.d.ts +21 -0
- package/src/utils/server-rendering/routes-extractor-worker.js +53 -0
- package/src/utils/service-worker.d.ts +25 -0
- package/src/utils/service-worker.js +211 -0
- package/src/utils/spinner.d.ts +20 -0
- package/src/utils/spinner.js +55 -0
- package/src/utils/stats-table.d.ts +20 -0
- package/src/utils/stats-table.js +205 -0
- package/src/utils/supported-browsers.d.ts +10 -0
- package/src/utils/supported-browsers.js +42 -0
- package/src/utils/tty.d.ts +8 -0
- package/src/utils/tty.js +23 -0
- package/src/utils/url.d.ts +8 -0
- package/src/utils/url.js +18 -0
- package/src/utils/version.d.ts +8 -0
- 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>;
|