@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,75 @@
|
|
|
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.MemoryLoadResultCache = exports.createCachedLoad = void 0;
|
|
11
|
+
const node_path_1 = require("node:path");
|
|
12
|
+
function createCachedLoad(cache, callback) {
|
|
13
|
+
if (cache === undefined) {
|
|
14
|
+
return callback;
|
|
15
|
+
}
|
|
16
|
+
return async (args) => {
|
|
17
|
+
const loadCacheKey = `${args.namespace}:${args.path}`;
|
|
18
|
+
let result = cache.get(loadCacheKey);
|
|
19
|
+
if (result === undefined) {
|
|
20
|
+
result = await callback(args);
|
|
21
|
+
// Do not cache null or undefined
|
|
22
|
+
if (result) {
|
|
23
|
+
// Ensure requested path is included if it was a resolved file
|
|
24
|
+
if (args.namespace === 'file') {
|
|
25
|
+
result.watchFiles ??= [];
|
|
26
|
+
result.watchFiles.push(args.path);
|
|
27
|
+
}
|
|
28
|
+
await cache.put(loadCacheKey, result);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
exports.createCachedLoad = createCachedLoad;
|
|
35
|
+
class MemoryLoadResultCache {
|
|
36
|
+
#loadResults = new Map();
|
|
37
|
+
#fileDependencies = new Map();
|
|
38
|
+
get(path) {
|
|
39
|
+
return this.#loadResults.get(path);
|
|
40
|
+
}
|
|
41
|
+
async put(path, result) {
|
|
42
|
+
this.#loadResults.set(path, result);
|
|
43
|
+
if (result.watchFiles) {
|
|
44
|
+
for (const watchFile of result.watchFiles) {
|
|
45
|
+
// Normalize the watch file path to ensure OS consistent paths
|
|
46
|
+
const normalizedWatchFile = (0, node_path_1.normalize)(watchFile);
|
|
47
|
+
let affected = this.#fileDependencies.get(normalizedWatchFile);
|
|
48
|
+
if (affected === undefined) {
|
|
49
|
+
affected = new Set();
|
|
50
|
+
this.#fileDependencies.set(normalizedWatchFile, affected);
|
|
51
|
+
}
|
|
52
|
+
affected.add(path);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
invalidate(path) {
|
|
57
|
+
const affectedPaths = this.#fileDependencies.get(path);
|
|
58
|
+
let found = false;
|
|
59
|
+
if (affectedPaths) {
|
|
60
|
+
for (const affected of affectedPaths) {
|
|
61
|
+
if (this.#loadResults.delete(affected)) {
|
|
62
|
+
found = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
this.#fileDependencies.delete(path);
|
|
66
|
+
}
|
|
67
|
+
return found;
|
|
68
|
+
}
|
|
69
|
+
get watchFiles() {
|
|
70
|
+
// this.#loadResults.keys() is not included here because the keys
|
|
71
|
+
// are namespaced request paths and not disk-based file paths.
|
|
72
|
+
return [...this.#fileDependencies.keys()];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.MemoryLoadResultCache = MemoryLoadResultCache;
|
|
@@ -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 declare function resetCumulativeDurations(): void;
|
|
9
|
+
export declare function logCumulativeDurations(): void;
|
|
10
|
+
export declare function profileAsync<T>(name: string, action: () => Promise<T>, cumulative?: boolean): Promise<T>;
|
|
11
|
+
export declare function profileSync<T>(name: string, action: () => T, cumulative?: boolean): T;
|
|
@@ -0,0 +1,78 @@
|
|
|
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.profileSync = exports.profileAsync = exports.logCumulativeDurations = exports.resetCumulativeDurations = void 0;
|
|
11
|
+
const environment_options_1 = require("../../utils/environment-options");
|
|
12
|
+
let cumulativeDurations;
|
|
13
|
+
function resetCumulativeDurations() {
|
|
14
|
+
cumulativeDurations?.clear();
|
|
15
|
+
}
|
|
16
|
+
exports.resetCumulativeDurations = resetCumulativeDurations;
|
|
17
|
+
function logCumulativeDurations() {
|
|
18
|
+
if (!environment_options_1.debugPerformance || !cumulativeDurations) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
for (const [name, durations] of cumulativeDurations) {
|
|
22
|
+
let total = 0;
|
|
23
|
+
let min;
|
|
24
|
+
let max;
|
|
25
|
+
for (const duration of durations) {
|
|
26
|
+
total += duration;
|
|
27
|
+
if (min === undefined || duration < min) {
|
|
28
|
+
min = duration;
|
|
29
|
+
}
|
|
30
|
+
if (max === undefined || duration > max) {
|
|
31
|
+
max = duration;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const average = total / durations.length;
|
|
35
|
+
// eslint-disable-next-line no-console
|
|
36
|
+
console.log(`DURATION[${name}]: ${total.toFixed(9)}s [count: ${durations.length}; avg: ${average.toFixed(9)}s; min: ${min?.toFixed(9)}s; max: ${max?.toFixed(9)}s]`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.logCumulativeDurations = logCumulativeDurations;
|
|
40
|
+
function recordDuration(name, startTime, cumulative) {
|
|
41
|
+
const duration = Number(process.hrtime.bigint() - startTime) / 10 ** 9;
|
|
42
|
+
if (cumulative) {
|
|
43
|
+
cumulativeDurations ??= new Map();
|
|
44
|
+
const durations = cumulativeDurations.get(name) ?? [];
|
|
45
|
+
durations.push(duration);
|
|
46
|
+
cumulativeDurations.set(name, durations);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
// eslint-disable-next-line no-console
|
|
50
|
+
console.log(`DURATION[${name}]: ${duration.toFixed(9)}s`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async function profileAsync(name, action, cumulative) {
|
|
54
|
+
if (!environment_options_1.debugPerformance) {
|
|
55
|
+
return action();
|
|
56
|
+
}
|
|
57
|
+
const startTime = process.hrtime.bigint();
|
|
58
|
+
try {
|
|
59
|
+
return await action();
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
recordDuration(name, startTime, cumulative);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.profileAsync = profileAsync;
|
|
66
|
+
function profileSync(name, action, cumulative) {
|
|
67
|
+
if (!environment_options_1.debugPerformance) {
|
|
68
|
+
return action();
|
|
69
|
+
}
|
|
70
|
+
const startTime = process.hrtime.bigint();
|
|
71
|
+
try {
|
|
72
|
+
return action();
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
recordDuration(name, startTime, cumulative);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.profileSync = profileSync;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import type { Plugin } from 'esbuild';
|
|
9
|
+
/**
|
|
10
|
+
* Creates a plugin that forces ESM resolution of rxjs.
|
|
11
|
+
* This is needed as when targeting node, the CJS version is used to the current package conditional exports.
|
|
12
|
+
* @see: https://github.com/ReactiveX/rxjs/blob/2947583bb33e97f3db9e6d9f6cea70c62a173060/package.json#L19.
|
|
13
|
+
*
|
|
14
|
+
* NOTE: This can be removed when and if rxjs adds an import condition that allows ESM usage on Node.js.
|
|
15
|
+
*
|
|
16
|
+
* @returns An esbuild plugin.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createRxjsEsmResolutionPlugin(): Plugin;
|
|
@@ -0,0 +1,44 @@
|
|
|
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.createRxjsEsmResolutionPlugin = void 0;
|
|
11
|
+
const RXJS_ESM_RESOLUTION = Symbol('RXJS_ESM_RESOLUTION');
|
|
12
|
+
/**
|
|
13
|
+
* Creates a plugin that forces ESM resolution of rxjs.
|
|
14
|
+
* This is needed as when targeting node, the CJS version is used to the current package conditional exports.
|
|
15
|
+
* @see: https://github.com/ReactiveX/rxjs/blob/2947583bb33e97f3db9e6d9f6cea70c62a173060/package.json#L19.
|
|
16
|
+
*
|
|
17
|
+
* NOTE: This can be removed when and if rxjs adds an import condition that allows ESM usage on Node.js.
|
|
18
|
+
*
|
|
19
|
+
* @returns An esbuild plugin.
|
|
20
|
+
*/
|
|
21
|
+
function createRxjsEsmResolutionPlugin() {
|
|
22
|
+
return {
|
|
23
|
+
name: 'angular-rxjs-resolution',
|
|
24
|
+
setup(build) {
|
|
25
|
+
build.onResolve({ filter: /^rxjs/ }, async (args) => {
|
|
26
|
+
if (args.pluginData?.[RXJS_ESM_RESOLUTION]) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const { importer, kind, resolveDir, namespace, pluginData = {} } = args;
|
|
30
|
+
pluginData[RXJS_ESM_RESOLUTION] = true;
|
|
31
|
+
const result = await build.resolve(args.path, {
|
|
32
|
+
importer,
|
|
33
|
+
kind,
|
|
34
|
+
namespace,
|
|
35
|
+
pluginData,
|
|
36
|
+
resolveDir,
|
|
37
|
+
});
|
|
38
|
+
result.path = result.path.replace(/([\\/]dist[\\/])cjs([\\/])/, '$1esm$2');
|
|
39
|
+
return result;
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
exports.createRxjsEsmResolutionPlugin = createRxjsEsmResolutionPlugin;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import type { Plugin } from 'esbuild';
|
|
9
|
+
/**
|
|
10
|
+
* Creates an esbuild plugin that updates generated sourcemaps to include the Chrome
|
|
11
|
+
* DevTools ignore list extension. All source files that originate from a node modules
|
|
12
|
+
* directory are added to the ignore list by this plugin.
|
|
13
|
+
*
|
|
14
|
+
* For more information, see https://developer.chrome.com/articles/x-google-ignore-list/
|
|
15
|
+
* @returns An esbuild plugin.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createSourcemapIgnorelistPlugin(): Plugin;
|
|
@@ -0,0 +1,73 @@
|
|
|
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.createSourcemapIgnorelistPlugin = void 0;
|
|
11
|
+
/**
|
|
12
|
+
* The field identifier for the sourcemap Chrome Devtools ignore list extension.
|
|
13
|
+
*
|
|
14
|
+
* Following the naming conventions from https://sourcemaps.info/spec.html#h.ghqpj1ytqjbm
|
|
15
|
+
*/
|
|
16
|
+
const IGNORE_LIST_ID = 'x_google_ignoreList';
|
|
17
|
+
/**
|
|
18
|
+
* The UTF-8 bytes for the node modules check text used to avoid unnecessary parsing
|
|
19
|
+
* of a full source map if not present in the source map data.
|
|
20
|
+
*/
|
|
21
|
+
const NODE_MODULE_BYTES = Buffer.from('node_modules/', 'utf-8');
|
|
22
|
+
/**
|
|
23
|
+
* Creates an esbuild plugin that updates generated sourcemaps to include the Chrome
|
|
24
|
+
* DevTools ignore list extension. All source files that originate from a node modules
|
|
25
|
+
* directory are added to the ignore list by this plugin.
|
|
26
|
+
*
|
|
27
|
+
* For more information, see https://developer.chrome.com/articles/x-google-ignore-list/
|
|
28
|
+
* @returns An esbuild plugin.
|
|
29
|
+
*/
|
|
30
|
+
function createSourcemapIgnorelistPlugin() {
|
|
31
|
+
return {
|
|
32
|
+
name: 'angular-sourcemap-ignorelist',
|
|
33
|
+
setup(build) {
|
|
34
|
+
if (!build.initialOptions.sourcemap) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
build.onEnd((result) => {
|
|
38
|
+
if (!result.outputFiles) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
for (const file of result.outputFiles) {
|
|
42
|
+
// Only process sourcemap files
|
|
43
|
+
if (!file.path.endsWith('.map')) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
// Create a Buffer object that shares the memory of the output file contents
|
|
47
|
+
const contents = Buffer.from(file.contents.buffer, file.contents.byteOffset, file.contents.byteLength);
|
|
48
|
+
// Avoid parsing sourcemaps that have no node modules references
|
|
49
|
+
if (!contents.includes(NODE_MODULE_BYTES)) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const map = JSON.parse(contents.toString('utf-8'));
|
|
53
|
+
const ignoreList = [];
|
|
54
|
+
// Check and store the index of each source originating from a node modules directory
|
|
55
|
+
for (let index = 0; index < map.sources.length; ++index) {
|
|
56
|
+
const location = map.sources[index].indexOf('node_modules/');
|
|
57
|
+
if (location === 0 || (location > 0 && map.sources[index][location - 1] === '/')) {
|
|
58
|
+
ignoreList.push(index);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Avoid regenerating the source map if nothing changed
|
|
62
|
+
if (ignoreList.length === 0) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
// Update the sourcemap in the output file
|
|
66
|
+
map[IGNORE_LIST_ID] = ignoreList;
|
|
67
|
+
file.contents = Buffer.from(JSON.stringify(map), 'utf-8');
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
exports.createSourcemapIgnorelistPlugin = createSourcemapIgnorelistPlugin;
|
|
@@ -0,0 +1,35 @@
|
|
|
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 { BuildOptions } from 'esbuild';
|
|
9
|
+
import { NormalizedCachedOptions } from '../../../utils/normalize-cache';
|
|
10
|
+
import { PostcssConfiguration } from '../../../utils/postcss-configuration';
|
|
11
|
+
import { LoadResultCache } from '../load-result-cache';
|
|
12
|
+
export interface BundleStylesheetOptions {
|
|
13
|
+
workspaceRoot: string;
|
|
14
|
+
optimization: boolean;
|
|
15
|
+
inlineFonts: boolean;
|
|
16
|
+
preserveSymlinks?: boolean;
|
|
17
|
+
sourcemap: boolean | 'external' | 'inline' | 'linked';
|
|
18
|
+
outputNames: {
|
|
19
|
+
bundles: string;
|
|
20
|
+
media: string;
|
|
21
|
+
};
|
|
22
|
+
includePaths?: string[];
|
|
23
|
+
externalDependencies?: string[];
|
|
24
|
+
target: string[];
|
|
25
|
+
tailwindConfiguration?: {
|
|
26
|
+
file: string;
|
|
27
|
+
package: string;
|
|
28
|
+
};
|
|
29
|
+
postcssConfiguration?: PostcssConfiguration;
|
|
30
|
+
publicPath?: string;
|
|
31
|
+
cacheOptions: NormalizedCachedOptions;
|
|
32
|
+
}
|
|
33
|
+
export declare function createStylesheetBundleOptions(options: BundleStylesheetOptions, cache?: LoadResultCache, inlineComponentData?: Record<string, string>): BuildOptions & {
|
|
34
|
+
plugins: NonNullable<BuildOptions['plugins']>;
|
|
35
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
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.createStylesheetBundleOptions = void 0;
|
|
14
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
15
|
+
const css_inline_fonts_plugin_1 = require("./css-inline-fonts-plugin");
|
|
16
|
+
const css_language_1 = require("./css-language");
|
|
17
|
+
const css_resource_plugin_1 = require("./css-resource-plugin");
|
|
18
|
+
const less_language_1 = require("./less-language");
|
|
19
|
+
const sass_language_1 = require("./sass-language");
|
|
20
|
+
const stylesheet_plugin_factory_1 = require("./stylesheet-plugin-factory");
|
|
21
|
+
function createStylesheetBundleOptions(options, cache, inlineComponentData) {
|
|
22
|
+
// Ensure preprocessor include paths are absolute based on the workspace root
|
|
23
|
+
const includePaths = options.includePaths?.map((includePath) => node_path_1.default.resolve(options.workspaceRoot, includePath));
|
|
24
|
+
const pluginFactory = new stylesheet_plugin_factory_1.StylesheetPluginFactory({
|
|
25
|
+
sourcemap: !!options.sourcemap,
|
|
26
|
+
includePaths,
|
|
27
|
+
inlineComponentData,
|
|
28
|
+
tailwindConfiguration: options.tailwindConfiguration,
|
|
29
|
+
postcssConfiguration: options.postcssConfiguration,
|
|
30
|
+
}, cache);
|
|
31
|
+
const plugins = [
|
|
32
|
+
pluginFactory.create(sass_language_1.SassStylesheetLanguage),
|
|
33
|
+
pluginFactory.create(less_language_1.LessStylesheetLanguage),
|
|
34
|
+
pluginFactory.create(css_language_1.CssStylesheetLanguage),
|
|
35
|
+
(0, css_resource_plugin_1.createCssResourcePlugin)(cache),
|
|
36
|
+
];
|
|
37
|
+
if (options.inlineFonts) {
|
|
38
|
+
plugins.push((0, css_inline_fonts_plugin_1.createCssInlineFontsPlugin)({ cache, cacheOptions: options.cacheOptions }));
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
absWorkingDir: options.workspaceRoot,
|
|
42
|
+
bundle: true,
|
|
43
|
+
entryNames: options.outputNames.bundles,
|
|
44
|
+
assetNames: options.outputNames.media,
|
|
45
|
+
logLevel: 'silent',
|
|
46
|
+
minify: options.optimization,
|
|
47
|
+
metafile: true,
|
|
48
|
+
sourcemap: options.sourcemap,
|
|
49
|
+
outdir: options.workspaceRoot,
|
|
50
|
+
write: false,
|
|
51
|
+
platform: 'browser',
|
|
52
|
+
target: options.target,
|
|
53
|
+
preserveSymlinks: options.preserveSymlinks,
|
|
54
|
+
external: options.externalDependencies,
|
|
55
|
+
publicPath: options.publicPath,
|
|
56
|
+
conditions: ['style', 'sass', 'less'],
|
|
57
|
+
mainFields: ['style', 'sass'],
|
|
58
|
+
// Unlike JS, CSS does not have implicit file extensions in the general case.
|
|
59
|
+
// Preprocessor specific behavior is handled in each stylesheet language plugin.
|
|
60
|
+
resolveExtensions: [],
|
|
61
|
+
plugins,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
exports.createStylesheetBundleOptions = createStylesheetBundleOptions;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import type { Plugin } from 'esbuild';
|
|
9
|
+
import { NormalizedCachedOptions } from '../../../utils/normalize-cache';
|
|
10
|
+
import { LoadResultCache } from '../load-result-cache';
|
|
11
|
+
/**
|
|
12
|
+
* Options for the createCssInlineFontsPlugin
|
|
13
|
+
* @see createCssInlineFontsPlugin
|
|
14
|
+
*/
|
|
15
|
+
export interface CssInlineFontsPluginOptions {
|
|
16
|
+
/** Disk cache normalized options */
|
|
17
|
+
cacheOptions?: NormalizedCachedOptions;
|
|
18
|
+
/** Load results cache. */
|
|
19
|
+
cache?: LoadResultCache;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates an esbuild {@link Plugin} that inlines fonts imported via import-rule.
|
|
23
|
+
* within the build configuration.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createCssInlineFontsPlugin({ cache, cacheOptions, }: CssInlineFontsPluginOptions): Plugin;
|
|
@@ -0,0 +1,57 @@
|
|
|
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.createCssInlineFontsPlugin = void 0;
|
|
11
|
+
const inline_fonts_1 = require("../../../utils/index-file/inline-fonts");
|
|
12
|
+
const load_result_cache_1 = require("../load-result-cache");
|
|
13
|
+
/**
|
|
14
|
+
* Creates an esbuild {@link Plugin} that inlines fonts imported via import-rule.
|
|
15
|
+
* within the build configuration.
|
|
16
|
+
*/
|
|
17
|
+
function createCssInlineFontsPlugin({ cache, cacheOptions, }) {
|
|
18
|
+
return {
|
|
19
|
+
name: 'angular-css-inline-fonts-plugin',
|
|
20
|
+
setup(build) {
|
|
21
|
+
const inlineFontsProcessor = new inline_fonts_1.InlineFontsProcessor({ cache: cacheOptions, minify: false });
|
|
22
|
+
build.onResolve({ filter: /fonts\.googleapis\.com|use\.typekit\.net/ }, (args) => {
|
|
23
|
+
// Only attempt to resolve import-rule tokens which only exist inside CSS.
|
|
24
|
+
if (args.kind !== 'import-rule') {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
if (!inlineFontsProcessor.canInlineRequest(args.path)) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
path: args.path,
|
|
32
|
+
namespace: 'css-inline-fonts',
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
build.onLoad({ filter: /./, namespace: 'css-inline-fonts' }, (0, load_result_cache_1.createCachedLoad)(cache, async (args) => {
|
|
36
|
+
try {
|
|
37
|
+
return {
|
|
38
|
+
contents: await inlineFontsProcessor.processURL(args.path),
|
|
39
|
+
loader: 'css',
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
return {
|
|
44
|
+
loader: 'css',
|
|
45
|
+
errors: [
|
|
46
|
+
{
|
|
47
|
+
text: `Failed to inline external stylesheet '${args.path}'.`,
|
|
48
|
+
detail: error,
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}));
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
exports.createCssInlineFontsPlugin = createCssInlineFontsPlugin;
|
|
@@ -0,0 +1,9 @@
|
|
|
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 { StylesheetLanguage } from './stylesheet-plugin-factory';
|
|
9
|
+
export declare const CssStylesheetLanguage: Readonly<StylesheetLanguage>;
|
|
@@ -0,0 +1,15 @@
|
|
|
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.CssStylesheetLanguage = void 0;
|
|
11
|
+
exports.CssStylesheetLanguage = Object.freeze({
|
|
12
|
+
name: 'css',
|
|
13
|
+
componentFilter: /^css;/,
|
|
14
|
+
fileFilter: /\.css$/,
|
|
15
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import type { Plugin } from 'esbuild';
|
|
9
|
+
import { LoadResultCache } from '../load-result-cache';
|
|
10
|
+
/**
|
|
11
|
+
* Creates an esbuild {@link Plugin} that loads all CSS url token references using the
|
|
12
|
+
* built-in esbuild `file` loader. A plugin is used to allow for all file extensions
|
|
13
|
+
* and types to be supported without needing to manually specify all extensions
|
|
14
|
+
* within the build configuration.
|
|
15
|
+
*
|
|
16
|
+
* @returns An esbuild {@link Plugin} instance.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createCssResourcePlugin(cache?: LoadResultCache): Plugin;
|
|
@@ -0,0 +1,114 @@
|
|
|
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.createCssResourcePlugin = void 0;
|
|
11
|
+
const promises_1 = require("node:fs/promises");
|
|
12
|
+
const node_path_1 = require("node:path");
|
|
13
|
+
const load_result_cache_1 = require("../load-result-cache");
|
|
14
|
+
const CSS_RESOURCE_NAMESPACE = 'angular:css-resource';
|
|
15
|
+
/**
|
|
16
|
+
* Symbol marker used to indicate CSS resource resolution is being attempted.
|
|
17
|
+
* This is used to prevent an infinite loop within the plugin's resolve hook.
|
|
18
|
+
*/
|
|
19
|
+
const CSS_RESOURCE_RESOLUTION = Symbol('CSS_RESOURCE_RESOLUTION');
|
|
20
|
+
/**
|
|
21
|
+
* Creates an esbuild {@link Plugin} that loads all CSS url token references using the
|
|
22
|
+
* built-in esbuild `file` loader. A plugin is used to allow for all file extensions
|
|
23
|
+
* and types to be supported without needing to manually specify all extensions
|
|
24
|
+
* within the build configuration.
|
|
25
|
+
*
|
|
26
|
+
* @returns An esbuild {@link Plugin} instance.
|
|
27
|
+
*/
|
|
28
|
+
function createCssResourcePlugin(cache) {
|
|
29
|
+
return {
|
|
30
|
+
name: 'angular-css-resource',
|
|
31
|
+
setup(build) {
|
|
32
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
33
|
+
const { importer, path, kind, resolveDir, namespace, pluginData = {} } = args;
|
|
34
|
+
// Only attempt to resolve url tokens which only exist inside CSS.
|
|
35
|
+
// Also, skip this plugin if already attempting to resolve the url-token.
|
|
36
|
+
if (kind !== 'url-token' || pluginData[CSS_RESOURCE_RESOLUTION]) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
let [containingDir, resourceUrl] = path.split('||file:', 2);
|
|
40
|
+
if (resourceUrl === undefined) {
|
|
41
|
+
// This can happen due to early exit checks in rebasing-importer
|
|
42
|
+
// logic such as when the url is an external URL.
|
|
43
|
+
resourceUrl = containingDir;
|
|
44
|
+
containingDir = '';
|
|
45
|
+
}
|
|
46
|
+
// If root-relative, absolute or protocol relative url, mark as external to leave the
|
|
47
|
+
// path/URL in place.
|
|
48
|
+
if (/^((?:\w+:)?\/\/|data:|chrome:|#|\/)/.test(resourceUrl)) {
|
|
49
|
+
return {
|
|
50
|
+
path: resourceUrl,
|
|
51
|
+
external: true,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
pluginData[CSS_RESOURCE_RESOLUTION] = true;
|
|
55
|
+
const result = await build.resolve(resourceUrl, {
|
|
56
|
+
importer,
|
|
57
|
+
kind,
|
|
58
|
+
namespace,
|
|
59
|
+
pluginData,
|
|
60
|
+
resolveDir: (0, node_path_1.join)(resolveDir, containingDir),
|
|
61
|
+
});
|
|
62
|
+
if (result.errors.length) {
|
|
63
|
+
const error = result.errors[0];
|
|
64
|
+
if (resourceUrl[0] === '~') {
|
|
65
|
+
error.notes = [
|
|
66
|
+
{
|
|
67
|
+
location: null,
|
|
68
|
+
text: 'You can remove the tilde and use a relative path to reference it, which should remove this error.',
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
else if (resourceUrl[0] === '^') {
|
|
73
|
+
error.notes = [
|
|
74
|
+
{
|
|
75
|
+
location: null,
|
|
76
|
+
text: 'You can remove the caret and add the path to the `externalDependencies` build option,' +
|
|
77
|
+
' which should remove this error.',
|
|
78
|
+
},
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
const extension = importer && (0, node_path_1.extname)(importer);
|
|
82
|
+
if (extension !== '.css') {
|
|
83
|
+
error.notes.push({
|
|
84
|
+
location: null,
|
|
85
|
+
text: 'Preprocessor stylesheets may not show the exact file location of the error.',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Return results that are not files since these are most likely specific to another plugin
|
|
90
|
+
// and cannot be loaded by this plugin.
|
|
91
|
+
if (result.namespace !== 'file') {
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
// All file results are considered CSS resources and will be loaded via the file loader
|
|
95
|
+
return {
|
|
96
|
+
...result,
|
|
97
|
+
// Use a relative path to prevent fully resolved paths in the metafile (JSON stats file).
|
|
98
|
+
// This is only necessary for custom namespaces. esbuild will handle the file namespace.
|
|
99
|
+
path: (0, node_path_1.relative)(build.initialOptions.absWorkingDir ?? '', result.path),
|
|
100
|
+
namespace: CSS_RESOURCE_NAMESPACE,
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
build.onLoad({ filter: /./, namespace: CSS_RESOURCE_NAMESPACE }, (0, load_result_cache_1.createCachedLoad)(cache, async (args) => {
|
|
104
|
+
const resourcePath = (0, node_path_1.join)(build.initialOptions.absWorkingDir ?? '', args.path);
|
|
105
|
+
return {
|
|
106
|
+
contents: await (0, promises_1.readFile)(resourcePath),
|
|
107
|
+
loader: 'file',
|
|
108
|
+
watchFiles: [resourcePath],
|
|
109
|
+
};
|
|
110
|
+
}));
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
exports.createCssResourcePlugin = createCssResourcePlugin;
|