@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,441 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
33
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
34
|
+
};
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createCompilerPlugin = void 0;
|
|
37
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
38
|
+
const path = __importStar(require("node:path"));
|
|
39
|
+
const environment_options_1 = require("../../../utils/environment-options");
|
|
40
|
+
const javascript_transformer_1 = require("../javascript-transformer");
|
|
41
|
+
const load_result_cache_1 = require("../load-result-cache");
|
|
42
|
+
const profiling_1 = require("../profiling");
|
|
43
|
+
const compilation_1 = require("./compilation");
|
|
44
|
+
const compilation_state_1 = require("./compilation-state");
|
|
45
|
+
const component_stylesheets_1 = require("./component-stylesheets");
|
|
46
|
+
const file_reference_tracker_1 = require("./file-reference-tracker");
|
|
47
|
+
const jit_plugin_callbacks_1 = require("./jit-plugin-callbacks");
|
|
48
|
+
// eslint-disable-next-line max-lines-per-function
|
|
49
|
+
function createCompilerPlugin(pluginOptions, styleOptions) {
|
|
50
|
+
return {
|
|
51
|
+
name: 'angular-compiler',
|
|
52
|
+
// eslint-disable-next-line max-lines-per-function
|
|
53
|
+
async setup(build) {
|
|
54
|
+
let setupWarnings = [];
|
|
55
|
+
const preserveSymlinks = build.initialOptions.preserveSymlinks;
|
|
56
|
+
// Initialize a worker pool for JavaScript transformations
|
|
57
|
+
const javascriptTransformer = new javascript_transformer_1.JavaScriptTransformer(pluginOptions, environment_options_1.maxWorkers);
|
|
58
|
+
// Setup defines based on the values used by the Angular compiler-cli
|
|
59
|
+
build.initialOptions.define ??= {};
|
|
60
|
+
build.initialOptions.define['ngI18nClosureMode'] ??= 'false';
|
|
61
|
+
// The in-memory cache of TypeScript file outputs will be used during the build in `onLoad` callbacks for TS files.
|
|
62
|
+
// A string value indicates direct TS/NG output and a Uint8Array indicates fully transformed code.
|
|
63
|
+
const typeScriptFileCache = pluginOptions.sourceFileCache?.typeScriptFileCache ??
|
|
64
|
+
new Map();
|
|
65
|
+
// The resources from component stylesheets and web workers that will be added to the build results output files
|
|
66
|
+
const additionalResults = new Map();
|
|
67
|
+
// Create new reusable compilation for the appropriate mode based on the `jit` plugin option
|
|
68
|
+
const compilation = pluginOptions.noopTypeScriptCompilation
|
|
69
|
+
? new compilation_1.NoopCompilation()
|
|
70
|
+
: await (0, compilation_1.createAngularCompilation)(!!pluginOptions.jit);
|
|
71
|
+
// Compilation is initially assumed to have errors until emitted
|
|
72
|
+
let hasCompilationErrors = true;
|
|
73
|
+
// Determines if TypeScript should process JavaScript files based on tsconfig `allowJs` option
|
|
74
|
+
let shouldTsIgnoreJs = true;
|
|
75
|
+
// Track incremental component stylesheet builds
|
|
76
|
+
const stylesheetBundler = new component_stylesheets_1.ComponentStylesheetBundler(styleOptions, pluginOptions.incremental);
|
|
77
|
+
let sharedTSCompilationState;
|
|
78
|
+
// To fully invalidate files, track resource referenced files and their referencing source
|
|
79
|
+
const referencedFileTracker = new file_reference_tracker_1.FileReferenceTracker();
|
|
80
|
+
// eslint-disable-next-line max-lines-per-function
|
|
81
|
+
build.onStart(async () => {
|
|
82
|
+
sharedTSCompilationState = (0, compilation_state_1.getSharedCompilationState)();
|
|
83
|
+
if (!(compilation instanceof compilation_1.NoopCompilation)) {
|
|
84
|
+
sharedTSCompilationState.markAsInProgress();
|
|
85
|
+
}
|
|
86
|
+
const result = {
|
|
87
|
+
warnings: setupWarnings,
|
|
88
|
+
};
|
|
89
|
+
// Reset debug performance tracking
|
|
90
|
+
(0, profiling_1.resetCumulativeDurations)();
|
|
91
|
+
// Update the reference tracker and generate a full set of modified files for the
|
|
92
|
+
// Angular compiler which does not have direct knowledge of transitive resource
|
|
93
|
+
// dependencies or web worker processing.
|
|
94
|
+
let modifiedFiles;
|
|
95
|
+
if (pluginOptions.sourceFileCache?.modifiedFiles.size &&
|
|
96
|
+
referencedFileTracker &&
|
|
97
|
+
!pluginOptions.noopTypeScriptCompilation) {
|
|
98
|
+
// TODO: Differentiate between changed input files and stale output files
|
|
99
|
+
modifiedFiles = referencedFileTracker.update(pluginOptions.sourceFileCache.modifiedFiles);
|
|
100
|
+
pluginOptions.sourceFileCache.invalidate(modifiedFiles);
|
|
101
|
+
stylesheetBundler.invalidate(modifiedFiles);
|
|
102
|
+
}
|
|
103
|
+
if (!pluginOptions.noopTypeScriptCompilation &&
|
|
104
|
+
compilation.update &&
|
|
105
|
+
pluginOptions.sourceFileCache?.modifiedFiles.size) {
|
|
106
|
+
await compilation.update(modifiedFiles ?? pluginOptions.sourceFileCache.modifiedFiles);
|
|
107
|
+
}
|
|
108
|
+
// Create Angular compiler host options
|
|
109
|
+
const hostOptions = {
|
|
110
|
+
fileReplacements: pluginOptions.fileReplacements,
|
|
111
|
+
modifiedFiles,
|
|
112
|
+
sourceFileCache: pluginOptions.sourceFileCache,
|
|
113
|
+
async transformStylesheet(data, containingFile, stylesheetFile) {
|
|
114
|
+
let stylesheetResult;
|
|
115
|
+
// Stylesheet file only exists for external stylesheets
|
|
116
|
+
if (stylesheetFile) {
|
|
117
|
+
stylesheetResult = await stylesheetBundler.bundleFile(stylesheetFile);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
stylesheetResult = await stylesheetBundler.bundleInline(data, containingFile, styleOptions.inlineStyleLanguage);
|
|
121
|
+
}
|
|
122
|
+
const { contents, outputFiles, metafile, referencedFiles, errors, warnings } = stylesheetResult;
|
|
123
|
+
if (errors) {
|
|
124
|
+
(result.errors ??= []).push(...errors);
|
|
125
|
+
}
|
|
126
|
+
(result.warnings ??= []).push(...warnings);
|
|
127
|
+
additionalResults.set(stylesheetFile ?? containingFile, {
|
|
128
|
+
outputFiles,
|
|
129
|
+
metafile,
|
|
130
|
+
});
|
|
131
|
+
if (referencedFiles) {
|
|
132
|
+
referencedFileTracker.add(containingFile, referencedFiles);
|
|
133
|
+
if (stylesheetFile) {
|
|
134
|
+
// Angular AOT compiler needs modified direct resource files to correctly invalidate its analysis
|
|
135
|
+
referencedFileTracker.add(stylesheetFile, referencedFiles);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return contents;
|
|
139
|
+
},
|
|
140
|
+
processWebWorker(workerFile, containingFile) {
|
|
141
|
+
const fullWorkerPath = path.join(path.dirname(containingFile), workerFile);
|
|
142
|
+
// The synchronous API must be used due to the TypeScript compilation currently being
|
|
143
|
+
// fully synchronous and this process callback being called from within a TypeScript
|
|
144
|
+
// transformer.
|
|
145
|
+
const workerResult = bundleWebWorker(build, pluginOptions, fullWorkerPath);
|
|
146
|
+
(result.warnings ??= []).push(...workerResult.warnings);
|
|
147
|
+
if (workerResult.errors.length > 0) {
|
|
148
|
+
(result.errors ??= []).push(...workerResult.errors);
|
|
149
|
+
// Track worker file errors to allow rebuilds on changes
|
|
150
|
+
referencedFileTracker.add(containingFile, workerResult.errors
|
|
151
|
+
.map((error) => error.location?.file)
|
|
152
|
+
.filter((file) => !!file)
|
|
153
|
+
.map((file) => path.join(build.initialOptions.absWorkingDir ?? '', file)));
|
|
154
|
+
additionalResults.set(fullWorkerPath, { errors: result.errors });
|
|
155
|
+
// Return the original path if the build failed
|
|
156
|
+
return workerFile;
|
|
157
|
+
}
|
|
158
|
+
(0, node_assert_1.default)('outputFiles' in workerResult, 'Invalid web worker bundle result.');
|
|
159
|
+
additionalResults.set(fullWorkerPath, {
|
|
160
|
+
outputFiles: workerResult.outputFiles,
|
|
161
|
+
metafile: workerResult.metafile,
|
|
162
|
+
});
|
|
163
|
+
referencedFileTracker.add(containingFile, Object.keys(workerResult.metafile.inputs).map((input) => path.join(build.initialOptions.absWorkingDir ?? '', input)));
|
|
164
|
+
// Return bundled worker file entry name to be used in the built output
|
|
165
|
+
const workerCodeFile = workerResult.outputFiles.find((file) => /^worker-[A-Z0-9]{8}.[cm]?js$/.test(path.basename(file.path)));
|
|
166
|
+
(0, node_assert_1.default)(workerCodeFile, 'Web Worker bundled code file should always be present.');
|
|
167
|
+
const workerCodePath = path.relative(build.initialOptions.outdir ?? '', workerCodeFile.path);
|
|
168
|
+
return workerCodePath.replaceAll('\\', '/');
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
// Initialize the Angular compilation for the current build.
|
|
172
|
+
// In watch mode, previous build state will be reused.
|
|
173
|
+
let referencedFiles;
|
|
174
|
+
try {
|
|
175
|
+
const initializationResult = await compilation.initialize(pluginOptions.tsconfig, hostOptions, createCompilerOptionsTransformer(setupWarnings, pluginOptions, preserveSymlinks));
|
|
176
|
+
shouldTsIgnoreJs = !initializationResult.compilerOptions.allowJs;
|
|
177
|
+
referencedFiles = initializationResult.referencedFiles;
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
(result.errors ??= []).push({
|
|
181
|
+
text: 'Angular compilation initialization failed.',
|
|
182
|
+
location: null,
|
|
183
|
+
notes: [
|
|
184
|
+
{
|
|
185
|
+
text: error instanceof Error ? error.stack ?? error.message : `${error}`,
|
|
186
|
+
location: null,
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
});
|
|
190
|
+
// Initialization failure prevents further compilation steps
|
|
191
|
+
hasCompilationErrors = true;
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
if (compilation instanceof compilation_1.NoopCompilation) {
|
|
195
|
+
hasCompilationErrors = await sharedTSCompilationState.waitUntilReady;
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
// Update TypeScript file output cache for all affected files
|
|
199
|
+
try {
|
|
200
|
+
await (0, profiling_1.profileAsync)('NG_EMIT_TS', async () => {
|
|
201
|
+
for (const { filename, contents } of await compilation.emitAffectedFiles()) {
|
|
202
|
+
typeScriptFileCache.set(path.normalize(filename), contents);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
(result.errors ??= []).push({
|
|
208
|
+
text: 'Angular compilation emit failed.',
|
|
209
|
+
location: null,
|
|
210
|
+
notes: [
|
|
211
|
+
{
|
|
212
|
+
text: error instanceof Error ? error.stack ?? error.message : `${error}`,
|
|
213
|
+
location: null,
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
const diagnostics = await compilation.diagnoseFiles(environment_options_1.useTypeChecking ? compilation_1.DiagnosticModes.All : compilation_1.DiagnosticModes.All & ~compilation_1.DiagnosticModes.Semantic);
|
|
219
|
+
if (diagnostics.errors?.length) {
|
|
220
|
+
(result.errors ??= []).push(...diagnostics.errors);
|
|
221
|
+
}
|
|
222
|
+
if (diagnostics.warnings?.length) {
|
|
223
|
+
(result.warnings ??= []).push(...diagnostics.warnings);
|
|
224
|
+
}
|
|
225
|
+
// Add errors from failed additional results.
|
|
226
|
+
// This must be done after emit to capture latest web worker results.
|
|
227
|
+
for (const { errors } of additionalResults.values()) {
|
|
228
|
+
if (errors) {
|
|
229
|
+
(result.errors ??= []).push(...errors);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// Store referenced files for updated file watching if enabled
|
|
233
|
+
if (pluginOptions.sourceFileCache) {
|
|
234
|
+
pluginOptions.sourceFileCache.referencedFiles = [
|
|
235
|
+
...referencedFiles,
|
|
236
|
+
...referencedFileTracker.referencedFiles,
|
|
237
|
+
];
|
|
238
|
+
}
|
|
239
|
+
hasCompilationErrors = !!result.errors?.length;
|
|
240
|
+
// Reset the setup warnings so that they are only shown during the first build.
|
|
241
|
+
setupWarnings = undefined;
|
|
242
|
+
sharedTSCompilationState.markAsReady(hasCompilationErrors);
|
|
243
|
+
return result;
|
|
244
|
+
});
|
|
245
|
+
build.onLoad({ filter: /\.[cm]?[jt]sx?$/ }, async (args) => {
|
|
246
|
+
const request = path.normalize(pluginOptions.fileReplacements?.[path.normalize(args.path)] ?? args.path);
|
|
247
|
+
// Skip TS load attempt if JS TypeScript compilation not enabled and file is JS
|
|
248
|
+
if (shouldTsIgnoreJs && /\.[cm]?js$/.test(request)) {
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
// The filename is currently used as a cache key. Since the cache is memory only,
|
|
252
|
+
// the options cannot change and do not need to be represented in the key. If the
|
|
253
|
+
// cache is later stored to disk, then the options that affect transform output
|
|
254
|
+
// would need to be added to the key as well as a check for any change of content.
|
|
255
|
+
let contents = typeScriptFileCache.get(request);
|
|
256
|
+
if (contents === undefined) {
|
|
257
|
+
// If the Angular compilation had errors the file may not have been emitted.
|
|
258
|
+
// To avoid additional errors about missing files, return empty contents.
|
|
259
|
+
if (hasCompilationErrors) {
|
|
260
|
+
return { contents: '', loader: 'js' };
|
|
261
|
+
}
|
|
262
|
+
// No TS result indicates the file is not part of the TypeScript program.
|
|
263
|
+
// If allowJs is enabled and the file is JS then defer to the next load hook.
|
|
264
|
+
if (!shouldTsIgnoreJs && /\.[cm]?js$/.test(request)) {
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
// Otherwise return an error
|
|
268
|
+
return {
|
|
269
|
+
errors: [
|
|
270
|
+
createMissingFileError(request, args.path, build.initialOptions.absWorkingDir ?? ''),
|
|
271
|
+
],
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
else if (typeof contents === 'string') {
|
|
275
|
+
// A string indicates untransformed output from the TS/NG compiler
|
|
276
|
+
const sideEffects = await hasSideEffects(request);
|
|
277
|
+
contents = await javascriptTransformer.transformData(request, contents, true /* skipLinker */, sideEffects);
|
|
278
|
+
// Store as the returned Uint8Array to allow caching the fully transformed code
|
|
279
|
+
typeScriptFileCache.set(request, contents);
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
contents,
|
|
283
|
+
loader: 'js',
|
|
284
|
+
};
|
|
285
|
+
});
|
|
286
|
+
build.onLoad({ filter: /\.[cm]?js$/ }, (0, load_result_cache_1.createCachedLoad)(pluginOptions.loadResultCache, async (args) => {
|
|
287
|
+
return (0, profiling_1.profileAsync)('NG_EMIT_JS*', async () => {
|
|
288
|
+
const sideEffects = await hasSideEffects(args.path);
|
|
289
|
+
const contents = await javascriptTransformer.transformFile(args.path, pluginOptions.jit, sideEffects);
|
|
290
|
+
return {
|
|
291
|
+
contents,
|
|
292
|
+
loader: 'js',
|
|
293
|
+
};
|
|
294
|
+
}, true);
|
|
295
|
+
}));
|
|
296
|
+
// Setup bundling of component templates and stylesheets when in JIT mode
|
|
297
|
+
if (pluginOptions.jit) {
|
|
298
|
+
(0, jit_plugin_callbacks_1.setupJitPluginCallbacks)(build, stylesheetBundler, additionalResults, styleOptions.inlineStyleLanguage, pluginOptions.loadResultCache);
|
|
299
|
+
}
|
|
300
|
+
build.onEnd((result) => {
|
|
301
|
+
// Ensure other compilations are unblocked if the main compilation throws during start
|
|
302
|
+
sharedTSCompilationState?.markAsReady(hasCompilationErrors);
|
|
303
|
+
for (const { outputFiles, metafile } of additionalResults.values()) {
|
|
304
|
+
// Add any additional output files to the main output files
|
|
305
|
+
if (outputFiles?.length) {
|
|
306
|
+
result.outputFiles?.push(...outputFiles);
|
|
307
|
+
}
|
|
308
|
+
// Combine additional metafiles with main metafile
|
|
309
|
+
if (result.metafile && metafile) {
|
|
310
|
+
// Append the existing object, by appending to it we prevent unnecessary new objections creations with spread
|
|
311
|
+
// mitigating significant performance overhead for large apps.
|
|
312
|
+
// See: https://bugs.chromium.org/p/v8/issues/detail?id=11536
|
|
313
|
+
Object.assign(result.metafile.inputs, metafile.inputs);
|
|
314
|
+
Object.assign(result.metafile.outputs, metafile.outputs);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
(0, profiling_1.logCumulativeDurations)();
|
|
318
|
+
});
|
|
319
|
+
build.onDispose(() => {
|
|
320
|
+
sharedTSCompilationState?.dispose();
|
|
321
|
+
void stylesheetBundler.dispose();
|
|
322
|
+
void compilation.close?.();
|
|
323
|
+
});
|
|
324
|
+
/**
|
|
325
|
+
* Checks if the file has side-effects when `advancedOptimizations` is enabled.
|
|
326
|
+
*/
|
|
327
|
+
async function hasSideEffects(path) {
|
|
328
|
+
if (!pluginOptions.advancedOptimizations) {
|
|
329
|
+
return undefined;
|
|
330
|
+
}
|
|
331
|
+
const { sideEffects } = await build.resolve(path, {
|
|
332
|
+
kind: 'import-statement',
|
|
333
|
+
resolveDir: build.initialOptions.absWorkingDir ?? '',
|
|
334
|
+
});
|
|
335
|
+
return sideEffects;
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
exports.createCompilerPlugin = createCompilerPlugin;
|
|
341
|
+
function createCompilerOptionsTransformer(setupWarnings, pluginOptions, preserveSymlinks) {
|
|
342
|
+
return (compilerOptions) => {
|
|
343
|
+
// target of 9 is ES2022 (using the number avoids an expensive import of typescript just for an enum)
|
|
344
|
+
if (compilerOptions.target === undefined || compilerOptions.target < 9 /** ES2022 */) {
|
|
345
|
+
// If 'useDefineForClassFields' is already defined in the users project leave the value as is.
|
|
346
|
+
// Otherwise fallback to false due to https://github.com/microsoft/TypeScript/issues/45995
|
|
347
|
+
// which breaks the deprecated `@Effects` NGRX decorator and potentially other existing code as well.
|
|
348
|
+
compilerOptions.target = 9 /** ES2022 */;
|
|
349
|
+
compilerOptions.useDefineForClassFields ??= false;
|
|
350
|
+
// Only add the warning on the initial build
|
|
351
|
+
setupWarnings?.push({
|
|
352
|
+
text: `TypeScript compiler options 'target' and 'useDefineForClassFields' are set to 'ES2022' and ` +
|
|
353
|
+
`'false' respectively by the Angular CLI.`,
|
|
354
|
+
location: { file: pluginOptions.tsconfig },
|
|
355
|
+
notes: [
|
|
356
|
+
{
|
|
357
|
+
text: 'To control ECMA version and features use the Browserslist configuration. ' +
|
|
358
|
+
'For more information, see https://angular.io/guide/build#configuring-browser-compatibility',
|
|
359
|
+
},
|
|
360
|
+
],
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
if (compilerOptions.compilationMode === 'partial') {
|
|
364
|
+
setupWarnings?.push({
|
|
365
|
+
text: 'Angular partial compilation mode is not supported when building applications.',
|
|
366
|
+
location: null,
|
|
367
|
+
notes: [{ text: 'Full compilation mode will be used instead.' }],
|
|
368
|
+
});
|
|
369
|
+
compilerOptions.compilationMode = 'full';
|
|
370
|
+
}
|
|
371
|
+
// Enable incremental compilation by default if caching is enabled
|
|
372
|
+
if (pluginOptions.sourceFileCache?.persistentCachePath) {
|
|
373
|
+
compilerOptions.incremental ??= true;
|
|
374
|
+
// Set the build info file location to the configured cache directory
|
|
375
|
+
compilerOptions.tsBuildInfoFile = path.join(pluginOptions.sourceFileCache?.persistentCachePath, '.tsbuildinfo');
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
compilerOptions.incremental = false;
|
|
379
|
+
}
|
|
380
|
+
if (compilerOptions.module === undefined || compilerOptions.module < 5 /** ES2015 */) {
|
|
381
|
+
compilerOptions.module = 7; /** ES2022 */
|
|
382
|
+
setupWarnings?.push({
|
|
383
|
+
text: `TypeScript compiler options 'module' values 'CommonJS', 'UMD', 'System' and 'AMD' are not supported.`,
|
|
384
|
+
location: null,
|
|
385
|
+
notes: [{ text: `The 'module' option will be set to 'ES2022' instead.` }],
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
return {
|
|
389
|
+
...compilerOptions,
|
|
390
|
+
noEmitOnError: false,
|
|
391
|
+
inlineSources: pluginOptions.sourcemap,
|
|
392
|
+
inlineSourceMap: pluginOptions.sourcemap,
|
|
393
|
+
mapRoot: undefined,
|
|
394
|
+
sourceRoot: undefined,
|
|
395
|
+
preserveSymlinks,
|
|
396
|
+
};
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
function bundleWebWorker(build, pluginOptions, workerFile) {
|
|
400
|
+
try {
|
|
401
|
+
return build.esbuild.buildSync({
|
|
402
|
+
...build.initialOptions,
|
|
403
|
+
platform: 'browser',
|
|
404
|
+
write: false,
|
|
405
|
+
bundle: true,
|
|
406
|
+
metafile: true,
|
|
407
|
+
format: 'esm',
|
|
408
|
+
entryNames: 'worker-[hash]',
|
|
409
|
+
entryPoints: [workerFile],
|
|
410
|
+
sourcemap: pluginOptions.sourcemap,
|
|
411
|
+
// Zone.js is not used in Web workers so no need to disable
|
|
412
|
+
supported: undefined,
|
|
413
|
+
// Plugins are not supported in sync esbuild calls
|
|
414
|
+
plugins: undefined,
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
if (error && typeof error === 'object' && 'errors' in error && 'warnings' in error) {
|
|
419
|
+
return error;
|
|
420
|
+
}
|
|
421
|
+
throw error;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
function createMissingFileError(request, original, root) {
|
|
425
|
+
const relativeRequest = path.relative(root, request);
|
|
426
|
+
const error = {
|
|
427
|
+
text: `File '${relativeRequest}' is missing from the TypeScript compilation.`,
|
|
428
|
+
notes: [
|
|
429
|
+
{
|
|
430
|
+
text: `Ensure the file is part of the TypeScript program via the 'files' or 'include' property.`,
|
|
431
|
+
},
|
|
432
|
+
],
|
|
433
|
+
};
|
|
434
|
+
const relativeOriginal = path.relative(root, original);
|
|
435
|
+
if (relativeRequest !== relativeOriginal) {
|
|
436
|
+
error.notes.push({
|
|
437
|
+
text: `File is requested from a file replacement of '${relativeOriginal}'.`,
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
return error;
|
|
441
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import { OutputFile } from 'esbuild';
|
|
9
|
+
import { BundleStylesheetOptions } from '../stylesheets/bundle-options';
|
|
10
|
+
/**
|
|
11
|
+
* Bundles component stylesheets. A stylesheet can be either an inline stylesheet that
|
|
12
|
+
* is contained within the Component's metadata definition or an external file referenced
|
|
13
|
+
* from the Component's metadata definition.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ComponentStylesheetBundler {
|
|
16
|
+
#private;
|
|
17
|
+
private readonly options;
|
|
18
|
+
private readonly incremental;
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param options An object containing the stylesheet bundling options.
|
|
22
|
+
* @param cache A load result cache to use when bundling.
|
|
23
|
+
*/
|
|
24
|
+
constructor(options: BundleStylesheetOptions, incremental: boolean);
|
|
25
|
+
bundleFile(entry: string): Promise<{
|
|
26
|
+
errors: import("esbuild").Message[] | undefined;
|
|
27
|
+
warnings: import("esbuild").Message[];
|
|
28
|
+
contents: string;
|
|
29
|
+
outputFiles: OutputFile[];
|
|
30
|
+
metafile: import("esbuild").Metafile | undefined;
|
|
31
|
+
referencedFiles: Set<string> | undefined;
|
|
32
|
+
}>;
|
|
33
|
+
bundleInline(data: string, filename: string, language: string): Promise<{
|
|
34
|
+
errors: import("esbuild").Message[] | undefined;
|
|
35
|
+
warnings: import("esbuild").Message[];
|
|
36
|
+
contents: string;
|
|
37
|
+
outputFiles: OutputFile[];
|
|
38
|
+
metafile: import("esbuild").Metafile | undefined;
|
|
39
|
+
referencedFiles: Set<string> | undefined;
|
|
40
|
+
}>;
|
|
41
|
+
invalidate(files: Iterable<string>): void;
|
|
42
|
+
dispose(): Promise<void>;
|
|
43
|
+
private extractResult;
|
|
44
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.ComponentStylesheetBundler = void 0;
|
|
14
|
+
const node_crypto_1 = require("node:crypto");
|
|
15
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
16
|
+
const bundler_context_1 = require("../bundler-context");
|
|
17
|
+
const cache_1 = require("../cache");
|
|
18
|
+
const bundle_options_1 = require("../stylesheets/bundle-options");
|
|
19
|
+
/**
|
|
20
|
+
* Bundles component stylesheets. A stylesheet can be either an inline stylesheet that
|
|
21
|
+
* is contained within the Component's metadata definition or an external file referenced
|
|
22
|
+
* from the Component's metadata definition.
|
|
23
|
+
*/
|
|
24
|
+
class ComponentStylesheetBundler {
|
|
25
|
+
options;
|
|
26
|
+
incremental;
|
|
27
|
+
#fileContexts = new cache_1.MemoryCache();
|
|
28
|
+
#inlineContexts = new cache_1.MemoryCache();
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param options An object containing the stylesheet bundling options.
|
|
32
|
+
* @param cache A load result cache to use when bundling.
|
|
33
|
+
*/
|
|
34
|
+
constructor(options, incremental) {
|
|
35
|
+
this.options = options;
|
|
36
|
+
this.incremental = incremental;
|
|
37
|
+
}
|
|
38
|
+
async bundleFile(entry) {
|
|
39
|
+
const bundlerContext = await this.#fileContexts.getOrCreate(entry, () => {
|
|
40
|
+
return new bundler_context_1.BundlerContext(this.options.workspaceRoot, this.incremental, (loadCache) => {
|
|
41
|
+
const buildOptions = (0, bundle_options_1.createStylesheetBundleOptions)(this.options, loadCache);
|
|
42
|
+
buildOptions.entryPoints = [entry];
|
|
43
|
+
return buildOptions;
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
return this.extractResult(await bundlerContext.bundle(), bundlerContext.watchFiles);
|
|
47
|
+
}
|
|
48
|
+
async bundleInline(data, filename, language) {
|
|
49
|
+
// Use a hash of the inline stylesheet content to ensure a consistent identifier. External stylesheets will resolve
|
|
50
|
+
// to the actual stylesheet file path.
|
|
51
|
+
// TODO: Consider xxhash instead for hashing
|
|
52
|
+
const id = (0, node_crypto_1.createHash)('sha256').update(data).digest('hex');
|
|
53
|
+
const entry = [language, id, filename].join(';');
|
|
54
|
+
const bundlerContext = await this.#inlineContexts.getOrCreate(entry, () => {
|
|
55
|
+
const namespace = 'angular:styles/component';
|
|
56
|
+
return new bundler_context_1.BundlerContext(this.options.workspaceRoot, this.incremental, (loadCache) => {
|
|
57
|
+
const buildOptions = (0, bundle_options_1.createStylesheetBundleOptions)(this.options, loadCache, {
|
|
58
|
+
[entry]: data,
|
|
59
|
+
});
|
|
60
|
+
buildOptions.entryPoints = [`${namespace};${entry}`];
|
|
61
|
+
buildOptions.plugins.push({
|
|
62
|
+
name: 'angular-component-styles',
|
|
63
|
+
setup(build) {
|
|
64
|
+
build.onResolve({ filter: /^angular:styles\/component;/ }, (args) => {
|
|
65
|
+
if (args.kind !== 'entry-point') {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
path: entry,
|
|
70
|
+
namespace,
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
build.onLoad({ filter: /^css;/, namespace }, () => {
|
|
74
|
+
return {
|
|
75
|
+
contents: data,
|
|
76
|
+
loader: 'css',
|
|
77
|
+
resolveDir: node_path_1.default.dirname(filename),
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
return buildOptions;
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
// Extract the result of the bundling from the output files
|
|
86
|
+
return this.extractResult(await bundlerContext.bundle(), bundlerContext.watchFiles);
|
|
87
|
+
}
|
|
88
|
+
invalidate(files) {
|
|
89
|
+
if (!this.incremental) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const normalizedFiles = [...files].map(node_path_1.default.normalize);
|
|
93
|
+
for (const bundler of this.#fileContexts.values()) {
|
|
94
|
+
bundler.invalidate(normalizedFiles);
|
|
95
|
+
}
|
|
96
|
+
for (const bundler of this.#inlineContexts.values()) {
|
|
97
|
+
bundler.invalidate(normalizedFiles);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async dispose() {
|
|
101
|
+
const contexts = [...this.#fileContexts.values(), ...this.#inlineContexts.values()];
|
|
102
|
+
this.#fileContexts.clear();
|
|
103
|
+
this.#inlineContexts.clear();
|
|
104
|
+
await Promise.allSettled(contexts.map((context) => context.dispose()));
|
|
105
|
+
}
|
|
106
|
+
extractResult(result, referencedFiles) {
|
|
107
|
+
let contents = '';
|
|
108
|
+
let metafile;
|
|
109
|
+
const outputFiles = [];
|
|
110
|
+
if (!result.errors) {
|
|
111
|
+
for (const outputFile of result.outputFiles) {
|
|
112
|
+
const filename = node_path_1.default.basename(outputFile.path);
|
|
113
|
+
if (outputFile.type === bundler_context_1.BuildOutputFileType.Media || filename.endsWith('.css.map')) {
|
|
114
|
+
// The output files could also contain resources (images/fonts/etc.) that were referenced and the map files.
|
|
115
|
+
// Clone the output file to avoid amending the original path which would causes problems during rebuild.
|
|
116
|
+
const clonedOutputFile = outputFile.clone();
|
|
117
|
+
// Needed for Bazel as otherwise the files will not be written in the correct place,
|
|
118
|
+
// this is because esbuild will resolve the output file from the outdir which is currently set to `workspaceRoot` twice,
|
|
119
|
+
// once in the stylesheet and the other in the application code bundler.
|
|
120
|
+
// Ex: `../../../../../app.component.css.map`.
|
|
121
|
+
clonedOutputFile.path = node_path_1.default.join(this.options.workspaceRoot, outputFile.path);
|
|
122
|
+
outputFiles.push(clonedOutputFile);
|
|
123
|
+
}
|
|
124
|
+
else if (filename.endsWith('.css')) {
|
|
125
|
+
contents = outputFile.text;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
throw new Error(`Unexpected non CSS/Media file "${filename}" outputted during component stylesheet processing.`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
metafile = result.metafile;
|
|
132
|
+
// Remove entryPoint fields from outputs to prevent the internal component styles from being
|
|
133
|
+
// treated as initial files. Also mark the entry as a component resource for stat reporting.
|
|
134
|
+
Object.values(metafile.outputs).forEach((output) => {
|
|
135
|
+
delete output.entryPoint;
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
137
|
+
output['ng-component'] = true;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
errors: result.errors,
|
|
142
|
+
warnings: result.warnings,
|
|
143
|
+
contents,
|
|
144
|
+
outputFiles,
|
|
145
|
+
metafile,
|
|
146
|
+
referencedFiles,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.ComponentStylesheetBundler = ComponentStylesheetBundler;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import type { PartialMessage } from 'esbuild';
|
|
9
|
+
import type ts from 'typescript';
|
|
10
|
+
/**
|
|
11
|
+
* Converts a TypeScript Diagnostic message into an esbuild compatible message object.
|
|
12
|
+
* @param diagnostic The TypeScript diagnostic to convert.
|
|
13
|
+
* @returns An esbuild diagnostic message as a PartialMessage object
|
|
14
|
+
*/
|
|
15
|
+
export declare function convertTypeScriptDiagnostic(typescript: typeof ts, diagnostic: ts.Diagnostic): PartialMessage;
|