@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,74 @@
|
|
|
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.parseJitUri = exports.generateJitInlineUri = exports.generateJitFileUri = exports.JIT_NAMESPACE_REGEXP = exports.JIT_TEMPLATE_NAMESPACE = exports.JIT_STYLE_NAMESPACE = void 0;
|
|
11
|
+
/**
|
|
12
|
+
* A string value representing the base namespace for Angular JIT mode related imports.
|
|
13
|
+
*/
|
|
14
|
+
const JIT_BASE_NAMESPACE = 'angular:jit';
|
|
15
|
+
/**
|
|
16
|
+
* A string value representing the namespace for Angular JIT mode related imports for
|
|
17
|
+
* Component styles. This namespace is used for both inline (`styles`) and external
|
|
18
|
+
* (`styleUrls`) styles.
|
|
19
|
+
*/
|
|
20
|
+
exports.JIT_STYLE_NAMESPACE = `${JIT_BASE_NAMESPACE}:style`;
|
|
21
|
+
/**
|
|
22
|
+
* A string value representing the namespace for Angular JIT mode related imports for
|
|
23
|
+
* Component templates. This namespace is currently only used for external (`templateUrl`)
|
|
24
|
+
* templates.
|
|
25
|
+
*/
|
|
26
|
+
exports.JIT_TEMPLATE_NAMESPACE = `${JIT_BASE_NAMESPACE}:template`;
|
|
27
|
+
/**
|
|
28
|
+
* A regular expression that can be used to match a Angular JIT mode namespace URI.
|
|
29
|
+
* It contains capture groups for the type (template/style), origin (file/inline), and specifier.
|
|
30
|
+
* The {@link parseJitUri} function can be used to parse and return an object representation of a JIT URI.
|
|
31
|
+
*/
|
|
32
|
+
exports.JIT_NAMESPACE_REGEXP = new RegExp(`^${JIT_BASE_NAMESPACE}:(template|style):(file|inline);(.*)$`);
|
|
33
|
+
/**
|
|
34
|
+
* Generates an Angular JIT mode namespace URI for a given file.
|
|
35
|
+
* @param file The path of the file to be included.
|
|
36
|
+
* @param type The type of the file (`style` or `template`).
|
|
37
|
+
* @returns A string containing the full JIT namespace URI.
|
|
38
|
+
*/
|
|
39
|
+
function generateJitFileUri(file, type) {
|
|
40
|
+
return `${JIT_BASE_NAMESPACE}:${type}:file;${file}`;
|
|
41
|
+
}
|
|
42
|
+
exports.generateJitFileUri = generateJitFileUri;
|
|
43
|
+
/**
|
|
44
|
+
* Generates an Angular JIT mode namespace URI for a given inline style or template.
|
|
45
|
+
* The provided content is base64 encoded and included in the URI.
|
|
46
|
+
* @param data The content to encode within the URI.
|
|
47
|
+
* @param type The type of the content (`style` or `template`).
|
|
48
|
+
* @returns A string containing the full JIT namespace URI.
|
|
49
|
+
*/
|
|
50
|
+
function generateJitInlineUri(data, type) {
|
|
51
|
+
return `${JIT_BASE_NAMESPACE}:${type}:inline;${Buffer.from(data).toString('base64')}`;
|
|
52
|
+
}
|
|
53
|
+
exports.generateJitInlineUri = generateJitInlineUri;
|
|
54
|
+
/**
|
|
55
|
+
* Parses a string containing a JIT namespace URI.
|
|
56
|
+
* JIT namespace URIs are used to encode the information for an Angular component's stylesheets
|
|
57
|
+
* and templates when compiled in JIT mode.
|
|
58
|
+
* @param uri The URI to parse into its underlying components.
|
|
59
|
+
* @returns An object containing the namespace, type, origin, and specifier of the URI;
|
|
60
|
+
* `undefined` if not a JIT namespace URI.
|
|
61
|
+
*/
|
|
62
|
+
function parseJitUri(uri) {
|
|
63
|
+
const matches = exports.JIT_NAMESPACE_REGEXP.exec(uri);
|
|
64
|
+
if (!matches) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
namespace: `${JIT_BASE_NAMESPACE}:${matches[1]}`,
|
|
69
|
+
type: matches[1],
|
|
70
|
+
origin: matches[2],
|
|
71
|
+
specifier: matches[3],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
exports.parseJitUri = parseJitUri;
|
|
@@ -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 ts from 'typescript';
|
|
9
|
+
/**
|
|
10
|
+
* Creates a TypeScript Transformer to process Worker and SharedWorker entry points and transform
|
|
11
|
+
* the URL instances to reference the built and bundled worker code. This uses a callback process
|
|
12
|
+
* similar to the component stylesheets to allow the main esbuild plugin to process files as needed.
|
|
13
|
+
* Unsupported worker expressions will be left in their origin form.
|
|
14
|
+
* @param getTypeChecker A function that returns a TypeScript TypeChecker instance for the program.
|
|
15
|
+
* @returns A TypeScript transformer factory.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createWorkerTransformer(fileProcessor: (file: string, importer: string) => string): ts.TransformerFactory<ts.SourceFile>;
|
|
@@ -0,0 +1,94 @@
|
|
|
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.createWorkerTransformer = void 0;
|
|
14
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
15
|
+
/**
|
|
16
|
+
* Creates a TypeScript Transformer to process Worker and SharedWorker entry points and transform
|
|
17
|
+
* the URL instances to reference the built and bundled worker code. This uses a callback process
|
|
18
|
+
* similar to the component stylesheets to allow the main esbuild plugin to process files as needed.
|
|
19
|
+
* Unsupported worker expressions will be left in their origin form.
|
|
20
|
+
* @param getTypeChecker A function that returns a TypeScript TypeChecker instance for the program.
|
|
21
|
+
* @returns A TypeScript transformer factory.
|
|
22
|
+
*/
|
|
23
|
+
function createWorkerTransformer(fileProcessor) {
|
|
24
|
+
return (context) => {
|
|
25
|
+
const nodeFactory = context.factory;
|
|
26
|
+
const visitNode = (node) => {
|
|
27
|
+
// Check if the node is a valid new expression for a Worker or SharedWorker
|
|
28
|
+
// TODO: Add global scope check
|
|
29
|
+
if (!typescript_1.default.isNewExpression(node) ||
|
|
30
|
+
!typescript_1.default.isIdentifier(node.expression) ||
|
|
31
|
+
(node.expression.text !== 'Worker' && node.expression.text !== 'SharedWorker')) {
|
|
32
|
+
// Visit child nodes of non-Worker expressions
|
|
33
|
+
return typescript_1.default.visitEachChild(node, visitNode, context);
|
|
34
|
+
}
|
|
35
|
+
// Worker should have atleast one argument but not more than two
|
|
36
|
+
if (!node.arguments || node.arguments.length < 1 || node.arguments.length > 2) {
|
|
37
|
+
return node;
|
|
38
|
+
}
|
|
39
|
+
// First argument must be a new URL expression
|
|
40
|
+
const workerUrlNode = node.arguments[0];
|
|
41
|
+
// TODO: Add global scope check
|
|
42
|
+
if (!typescript_1.default.isNewExpression(workerUrlNode) ||
|
|
43
|
+
!typescript_1.default.isIdentifier(workerUrlNode.expression) ||
|
|
44
|
+
workerUrlNode.expression.text !== 'URL') {
|
|
45
|
+
return node;
|
|
46
|
+
}
|
|
47
|
+
// URL must have 2 arguments
|
|
48
|
+
if (!workerUrlNode.arguments || workerUrlNode.arguments.length !== 2) {
|
|
49
|
+
return node;
|
|
50
|
+
}
|
|
51
|
+
// URL arguments must be a string and then `import.meta.url`
|
|
52
|
+
if (!typescript_1.default.isStringLiteralLike(workerUrlNode.arguments[0]) ||
|
|
53
|
+
!typescript_1.default.isPropertyAccessExpression(workerUrlNode.arguments[1]) ||
|
|
54
|
+
!typescript_1.default.isMetaProperty(workerUrlNode.arguments[1].expression) ||
|
|
55
|
+
workerUrlNode.arguments[1].name.text !== 'url') {
|
|
56
|
+
return node;
|
|
57
|
+
}
|
|
58
|
+
const filePath = workerUrlNode.arguments[0].text;
|
|
59
|
+
const importer = node.getSourceFile().fileName;
|
|
60
|
+
// Process the file
|
|
61
|
+
const replacementPath = fileProcessor(filePath, importer);
|
|
62
|
+
// Update if the path changed
|
|
63
|
+
if (replacementPath !== filePath) {
|
|
64
|
+
return nodeFactory.updateNewExpression(node, node.expression, node.typeArguments,
|
|
65
|
+
// Update Worker arguments
|
|
66
|
+
typescript_1.default.setTextRange(nodeFactory.createNodeArray([
|
|
67
|
+
nodeFactory.updateNewExpression(workerUrlNode, workerUrlNode.expression, workerUrlNode.typeArguments,
|
|
68
|
+
// Update URL arguments
|
|
69
|
+
typescript_1.default.setTextRange(nodeFactory.createNodeArray([
|
|
70
|
+
nodeFactory.createStringLiteral(replacementPath),
|
|
71
|
+
workerUrlNode.arguments[1],
|
|
72
|
+
], workerUrlNode.arguments.hasTrailingComma), workerUrlNode.arguments)),
|
|
73
|
+
// Use the second Worker argument (options) if present.
|
|
74
|
+
// Otherwise create a default options object for module Workers.
|
|
75
|
+
node.arguments[1] ??
|
|
76
|
+
nodeFactory.createObjectLiteralExpression([
|
|
77
|
+
nodeFactory.createPropertyAssignment('type', nodeFactory.createStringLiteral('module')),
|
|
78
|
+
]),
|
|
79
|
+
], node.arguments.hasTrailingComma), node.arguments));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
return node;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
return (sourceFile) => {
|
|
86
|
+
// Skip transformer if there are no Workers
|
|
87
|
+
if (!sourceFile.text.includes('Worker')) {
|
|
88
|
+
return sourceFile;
|
|
89
|
+
}
|
|
90
|
+
return typescript_1.default.visitEachChild(sourceFile, visitNode, context);
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
exports.createWorkerTransformer = createWorkerTransformer;
|
|
@@ -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
|
+
import type { BuildOptions } from 'esbuild';
|
|
9
|
+
import type { NormalizedApplicationBuildOptions } from '../../builders/application/options';
|
|
10
|
+
import { SourceFileCache } from './angular/source-file-cache';
|
|
11
|
+
import { BundlerOptionsFactory } from './bundler-context';
|
|
12
|
+
export declare function createBrowserCodeBundleOptions(options: NormalizedApplicationBuildOptions, target: string[], sourceFileCache?: SourceFileCache): BuildOptions;
|
|
13
|
+
export declare function createBrowserPolyfillBundleOptions(options: NormalizedApplicationBuildOptions, target: string[], sourceFileCache?: SourceFileCache): BuildOptions | BundlerOptionsFactory | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Create an esbuild 'build' options object for the server bundle.
|
|
16
|
+
* @param options The builder's user-provider normalized options.
|
|
17
|
+
* @returns An esbuild BuildOptions object.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createServerCodeBundleOptions(options: NormalizedApplicationBuildOptions, target: string[], sourceFileCache: SourceFileCache): BuildOptions;
|
|
20
|
+
export declare function createServerPolyfillBundleOptions(options: NormalizedApplicationBuildOptions, target: string[], sourceFileCache?: SourceFileCache): BundlerOptionsFactory | undefined;
|
|
@@ -0,0 +1,368 @@
|
|
|
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.createServerPolyfillBundleOptions = exports.createServerCodeBundleOptions = exports.createBrowserPolyfillBundleOptions = exports.createBrowserCodeBundleOptions = void 0;
|
|
14
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
15
|
+
const node_crypto_1 = require("node:crypto");
|
|
16
|
+
const promises_1 = require("node:fs/promises");
|
|
17
|
+
const node_path_1 = require("node:path");
|
|
18
|
+
const environment_options_1 = require("../../utils/environment-options");
|
|
19
|
+
const compiler_plugin_1 = require("./angular/compiler-plugin");
|
|
20
|
+
const compiler_plugin_options_1 = require("./compiler-plugin-options");
|
|
21
|
+
const external_packages_plugin_1 = require("./external-packages-plugin");
|
|
22
|
+
const i18n_locale_plugin_1 = require("./i18n-locale-plugin");
|
|
23
|
+
const rxjs_esm_resolution_plugin_1 = require("./rxjs-esm-resolution-plugin");
|
|
24
|
+
const sourcemap_ignorelist_plugin_1 = require("./sourcemap-ignorelist-plugin");
|
|
25
|
+
const utils_1 = require("./utils");
|
|
26
|
+
const virtual_module_plugin_1 = require("./virtual-module-plugin");
|
|
27
|
+
function createBrowserCodeBundleOptions(options, target, sourceFileCache) {
|
|
28
|
+
const { entryPoints, outputNames, polyfills } = options;
|
|
29
|
+
const { pluginOptions, styleOptions } = (0, compiler_plugin_options_1.createCompilerPluginOptions)(options, target, sourceFileCache);
|
|
30
|
+
const buildOptions = {
|
|
31
|
+
...getEsBuildCommonOptions(options),
|
|
32
|
+
platform: 'browser',
|
|
33
|
+
// Note: `es2015` is needed for RxJS v6. If not specified, `module` would
|
|
34
|
+
// match and the ES5 distribution would be bundled and ends up breaking at
|
|
35
|
+
// runtime with the RxJS testing library.
|
|
36
|
+
// More details: https://github.com/angular/angular-cli/issues/25405.
|
|
37
|
+
mainFields: ['es2020', 'es2015', 'browser', 'module', 'main'],
|
|
38
|
+
entryNames: outputNames.bundles,
|
|
39
|
+
entryPoints,
|
|
40
|
+
target,
|
|
41
|
+
supported: (0, utils_1.getFeatureSupport)(target, (0, utils_1.isZonelessApp)(polyfills)),
|
|
42
|
+
plugins: [
|
|
43
|
+
(0, sourcemap_ignorelist_plugin_1.createSourcemapIgnorelistPlugin)(),
|
|
44
|
+
(0, compiler_plugin_1.createCompilerPlugin)(
|
|
45
|
+
// JS/TS options
|
|
46
|
+
pluginOptions,
|
|
47
|
+
// Component stylesheet options
|
|
48
|
+
styleOptions),
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
if (options.plugins) {
|
|
52
|
+
buildOptions.plugins?.push(...options.plugins);
|
|
53
|
+
}
|
|
54
|
+
if (options.externalPackages) {
|
|
55
|
+
// Package files affected by a customized loader should not be implicitly marked as external
|
|
56
|
+
if (options.loaderExtensions ||
|
|
57
|
+
options.plugins ||
|
|
58
|
+
typeof options.externalPackages === 'object') {
|
|
59
|
+
// Plugin must be added after custom plugins to ensure any added loader options are considered
|
|
60
|
+
buildOptions.plugins?.push((0, external_packages_plugin_1.createExternalPackagesPlugin)(options.externalPackages !== true ? options.externalPackages : undefined));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// Safe to use the packages external option directly
|
|
64
|
+
buildOptions.packages = 'external';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return buildOptions;
|
|
68
|
+
}
|
|
69
|
+
exports.createBrowserCodeBundleOptions = createBrowserCodeBundleOptions;
|
|
70
|
+
function createBrowserPolyfillBundleOptions(options, target, sourceFileCache) {
|
|
71
|
+
const namespace = 'angular:polyfills';
|
|
72
|
+
const polyfillBundleOptions = getEsBuildCommonPolyfillsOptions(options, namespace, true, sourceFileCache);
|
|
73
|
+
if (!polyfillBundleOptions) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const { outputNames, polyfills } = options;
|
|
77
|
+
const hasTypeScriptEntries = polyfills?.some((entry) => /\.[cm]?tsx?$/.test(entry));
|
|
78
|
+
const buildOptions = {
|
|
79
|
+
...polyfillBundleOptions,
|
|
80
|
+
platform: 'browser',
|
|
81
|
+
// Note: `es2015` is needed for RxJS v6. If not specified, `module` would
|
|
82
|
+
// match and the ES5 distribution would be bundled and ends up breaking at
|
|
83
|
+
// runtime with the RxJS testing library.
|
|
84
|
+
// More details: https://github.com/angular/angular-cli/issues/25405.
|
|
85
|
+
mainFields: ['es2020', 'es2015', 'browser', 'module', 'main'],
|
|
86
|
+
entryNames: outputNames.bundles,
|
|
87
|
+
target,
|
|
88
|
+
entryPoints: {
|
|
89
|
+
'polyfills': namespace,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
// Only add the Angular TypeScript compiler if TypeScript files are provided in the polyfills
|
|
93
|
+
if (hasTypeScriptEntries) {
|
|
94
|
+
buildOptions.plugins ??= [];
|
|
95
|
+
const { pluginOptions, styleOptions } = (0, compiler_plugin_options_1.createCompilerPluginOptions)(options, target, sourceFileCache);
|
|
96
|
+
buildOptions.plugins.push((0, compiler_plugin_1.createCompilerPlugin)(
|
|
97
|
+
// JS/TS options
|
|
98
|
+
{ ...pluginOptions, noopTypeScriptCompilation: true },
|
|
99
|
+
// Component stylesheet options are unused for polyfills but required by the plugin
|
|
100
|
+
styleOptions));
|
|
101
|
+
}
|
|
102
|
+
// Use an options factory to allow fully incremental bundling when no TypeScript files are present.
|
|
103
|
+
// The TypeScript compilation is not currently integrated into the bundler invalidation so
|
|
104
|
+
// cannot be used with fully incremental bundling yet.
|
|
105
|
+
return hasTypeScriptEntries ? buildOptions : () => buildOptions;
|
|
106
|
+
}
|
|
107
|
+
exports.createBrowserPolyfillBundleOptions = createBrowserPolyfillBundleOptions;
|
|
108
|
+
/**
|
|
109
|
+
* Create an esbuild 'build' options object for the server bundle.
|
|
110
|
+
* @param options The builder's user-provider normalized options.
|
|
111
|
+
* @returns An esbuild BuildOptions object.
|
|
112
|
+
*/
|
|
113
|
+
function createServerCodeBundleOptions(options, target, sourceFileCache) {
|
|
114
|
+
const { serverEntryPoint, workspaceRoot, ssrOptions, watch, externalPackages, prerenderOptions, polyfills, } = options;
|
|
115
|
+
(0, node_assert_1.default)(serverEntryPoint, 'createServerCodeBundleOptions should not be called without a defined serverEntryPoint.');
|
|
116
|
+
const { pluginOptions, styleOptions } = (0, compiler_plugin_options_1.createCompilerPluginOptions)(options, target, sourceFileCache);
|
|
117
|
+
const mainServerNamespace = 'angular:server-render-utils';
|
|
118
|
+
const entryPoints = {
|
|
119
|
+
'render-utils.server': mainServerNamespace,
|
|
120
|
+
'main.server': serverEntryPoint,
|
|
121
|
+
};
|
|
122
|
+
const ssrEntryPoint = ssrOptions?.entry;
|
|
123
|
+
if (ssrEntryPoint) {
|
|
124
|
+
entryPoints['server'] = ssrEntryPoint;
|
|
125
|
+
}
|
|
126
|
+
const buildOptions = {
|
|
127
|
+
...getEsBuildCommonOptions(options),
|
|
128
|
+
platform: 'node',
|
|
129
|
+
splitting: true,
|
|
130
|
+
outExtension: { '.js': '.mjs' },
|
|
131
|
+
// Note: `es2015` is needed for RxJS v6. If not specified, `module` would
|
|
132
|
+
// match and the ES5 distribution would be bundled and ends up breaking at
|
|
133
|
+
// runtime with the RxJS testing library.
|
|
134
|
+
// More details: https://github.com/angular/angular-cli/issues/25405.
|
|
135
|
+
mainFields: ['es2020', 'es2015', 'module', 'main'],
|
|
136
|
+
entryNames: '[name]',
|
|
137
|
+
target,
|
|
138
|
+
banner: {
|
|
139
|
+
js: `import './polyfills.server.mjs';`,
|
|
140
|
+
},
|
|
141
|
+
entryPoints,
|
|
142
|
+
supported: (0, utils_1.getFeatureSupport)(target, (0, utils_1.isZonelessApp)(polyfills)),
|
|
143
|
+
plugins: [
|
|
144
|
+
(0, sourcemap_ignorelist_plugin_1.createSourcemapIgnorelistPlugin)(),
|
|
145
|
+
(0, compiler_plugin_1.createCompilerPlugin)(
|
|
146
|
+
// JS/TS options
|
|
147
|
+
{ ...pluginOptions, noopTypeScriptCompilation: true },
|
|
148
|
+
// Component stylesheet options
|
|
149
|
+
styleOptions),
|
|
150
|
+
],
|
|
151
|
+
};
|
|
152
|
+
buildOptions.plugins ??= [];
|
|
153
|
+
if (externalPackages) {
|
|
154
|
+
buildOptions.packages = 'external';
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
buildOptions.plugins.push((0, rxjs_esm_resolution_plugin_1.createRxjsEsmResolutionPlugin)());
|
|
158
|
+
}
|
|
159
|
+
buildOptions.plugins.push((0, virtual_module_plugin_1.createVirtualModulePlugin)({
|
|
160
|
+
namespace: mainServerNamespace,
|
|
161
|
+
cache: sourceFileCache?.loadResultCache,
|
|
162
|
+
loadContent: async () => {
|
|
163
|
+
const contents = [
|
|
164
|
+
`export { ɵConsole } from '@angular/core';`,
|
|
165
|
+
`export { renderApplication, renderModule, ɵSERVER_CONTEXT } from '@angular/platform-server';`,
|
|
166
|
+
];
|
|
167
|
+
if (watch) {
|
|
168
|
+
contents.push(`export { ɵresetCompiledComponents } from '@angular/core';`);
|
|
169
|
+
}
|
|
170
|
+
if (prerenderOptions?.discoverRoutes) {
|
|
171
|
+
// We do not import it directly so that node.js modules are resolved using the correct context.
|
|
172
|
+
const routesExtractorCode = await (0, promises_1.readFile)((0, node_path_1.join)(__dirname, '../../utils/routes-extractor/extractor.js'), 'utf-8');
|
|
173
|
+
// Remove source map URL comments from the code if a sourcemap is present as this will not match the file.
|
|
174
|
+
contents.push(routesExtractorCode.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, ''));
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
contents: contents.join('\n'),
|
|
178
|
+
loader: 'js',
|
|
179
|
+
resolveDir: workspaceRoot,
|
|
180
|
+
};
|
|
181
|
+
},
|
|
182
|
+
}));
|
|
183
|
+
if (options.plugins) {
|
|
184
|
+
buildOptions.plugins.push(...options.plugins);
|
|
185
|
+
}
|
|
186
|
+
return buildOptions;
|
|
187
|
+
}
|
|
188
|
+
exports.createServerCodeBundleOptions = createServerCodeBundleOptions;
|
|
189
|
+
function createServerPolyfillBundleOptions(options, target, sourceFileCache) {
|
|
190
|
+
const serverPolyfills = [];
|
|
191
|
+
const polyfillsFromConfig = new Set(options.polyfills);
|
|
192
|
+
if (!(0, utils_1.isZonelessApp)(options.polyfills)) {
|
|
193
|
+
serverPolyfills.push('zone.js/node');
|
|
194
|
+
}
|
|
195
|
+
if (polyfillsFromConfig.has('@angular/localize') ||
|
|
196
|
+
polyfillsFromConfig.has('@angular/localize/init')) {
|
|
197
|
+
serverPolyfills.push('@angular/localize/init');
|
|
198
|
+
}
|
|
199
|
+
serverPolyfills.push('@angular/platform-server/init');
|
|
200
|
+
const namespace = 'angular:polyfills-server';
|
|
201
|
+
const polyfillBundleOptions = getEsBuildCommonPolyfillsOptions({
|
|
202
|
+
...options,
|
|
203
|
+
polyfills: serverPolyfills,
|
|
204
|
+
}, namespace, false, sourceFileCache);
|
|
205
|
+
if (!polyfillBundleOptions) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const buildOptions = {
|
|
209
|
+
...polyfillBundleOptions,
|
|
210
|
+
platform: 'node',
|
|
211
|
+
outExtension: { '.js': '.mjs' },
|
|
212
|
+
// Note: `es2015` is needed for RxJS v6. If not specified, `module` would
|
|
213
|
+
// match and the ES5 distribution would be bundled and ends up breaking at
|
|
214
|
+
// runtime with the RxJS testing library.
|
|
215
|
+
// More details: https://github.com/angular/angular-cli/issues/25405.
|
|
216
|
+
mainFields: ['es2020', 'es2015', 'module', 'main'],
|
|
217
|
+
entryNames: '[name]',
|
|
218
|
+
banner: {
|
|
219
|
+
js: [
|
|
220
|
+
// Note: Needed as esbuild does not provide require shims / proxy from ESModules.
|
|
221
|
+
// See: https://github.com/evanw/esbuild/issues/1921.
|
|
222
|
+
`import { createRequire } from 'node:module';`,
|
|
223
|
+
`globalThis['require'] ??= createRequire(import.meta.url);`,
|
|
224
|
+
].join('\n'),
|
|
225
|
+
},
|
|
226
|
+
target,
|
|
227
|
+
entryPoints: {
|
|
228
|
+
'polyfills.server': namespace,
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
return () => buildOptions;
|
|
232
|
+
}
|
|
233
|
+
exports.createServerPolyfillBundleOptions = createServerPolyfillBundleOptions;
|
|
234
|
+
function getEsBuildCommonOptions(options) {
|
|
235
|
+
const { workspaceRoot, outExtension, optimizationOptions, sourcemapOptions, tsconfig, externalDependencies, outputNames, preserveSymlinks, jit, loaderExtensions, jsonLogs, } = options;
|
|
236
|
+
// Ensure unique hashes for i18n translation changes when using post-process inlining.
|
|
237
|
+
// This hash value is added as a footer to each file and ensures that the output file names (with hashes)
|
|
238
|
+
// change when translation files have changed. If this is not done the post processed files may have
|
|
239
|
+
// different content but would retain identical production file names which would lead to browser caching problems.
|
|
240
|
+
let footer;
|
|
241
|
+
if (options.i18nOptions.shouldInline) {
|
|
242
|
+
// Update file hashes to include translation file content
|
|
243
|
+
const i18nHash = Object.values(options.i18nOptions.locales).reduce((data, locale) => data + locale.files.map((file) => file.integrity || '').join('|'), '');
|
|
244
|
+
footer = { js: `/**i18n:${(0, node_crypto_1.createHash)('sha256').update(i18nHash).digest('hex')}*/` };
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
absWorkingDir: workspaceRoot,
|
|
248
|
+
bundle: true,
|
|
249
|
+
format: 'esm',
|
|
250
|
+
assetNames: outputNames.media,
|
|
251
|
+
conditions: ['es2020', 'es2015', 'module'],
|
|
252
|
+
resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
|
|
253
|
+
metafile: true,
|
|
254
|
+
legalComments: options.extractLicenses ? 'none' : 'eof',
|
|
255
|
+
logLevel: options.verbose && !jsonLogs ? 'debug' : 'silent',
|
|
256
|
+
minifyIdentifiers: optimizationOptions.scripts && environment_options_1.allowMangle,
|
|
257
|
+
minifySyntax: optimizationOptions.scripts,
|
|
258
|
+
minifyWhitespace: optimizationOptions.scripts,
|
|
259
|
+
pure: ['forwardRef'],
|
|
260
|
+
outdir: workspaceRoot,
|
|
261
|
+
outExtension: outExtension ? { '.js': `.${outExtension}` } : undefined,
|
|
262
|
+
sourcemap: sourcemapOptions.scripts && (sourcemapOptions.hidden ? 'external' : true),
|
|
263
|
+
splitting: true,
|
|
264
|
+
chunkNames: options.namedChunks ? '[name]-[hash]' : 'chunk-[hash]',
|
|
265
|
+
tsconfig,
|
|
266
|
+
external: externalDependencies,
|
|
267
|
+
write: false,
|
|
268
|
+
preserveSymlinks,
|
|
269
|
+
define: {
|
|
270
|
+
...options.define,
|
|
271
|
+
// Only set to false when script optimizations are enabled. It should not be set to true because
|
|
272
|
+
// Angular turns `ngDevMode` into an object for development debugging purposes when not defined
|
|
273
|
+
// which a constant true value would break.
|
|
274
|
+
...(optimizationOptions.scripts ? { 'ngDevMode': 'false' } : undefined),
|
|
275
|
+
'ngJitMode': jit ? 'true' : 'false',
|
|
276
|
+
},
|
|
277
|
+
loader: loaderExtensions,
|
|
278
|
+
footer,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
function getEsBuildCommonPolyfillsOptions(options, namespace, tryToResolvePolyfillsAsRelative, sourceFileCache) {
|
|
282
|
+
const { jit, workspaceRoot, i18nOptions } = options;
|
|
283
|
+
const buildOptions = {
|
|
284
|
+
...getEsBuildCommonOptions(options),
|
|
285
|
+
splitting: false,
|
|
286
|
+
plugins: [(0, sourcemap_ignorelist_plugin_1.createSourcemapIgnorelistPlugin)()],
|
|
287
|
+
};
|
|
288
|
+
const polyfills = options.polyfills ? [...options.polyfills] : [];
|
|
289
|
+
// Angular JIT mode requires the runtime compiler
|
|
290
|
+
if (jit) {
|
|
291
|
+
polyfills.unshift('@angular/compiler');
|
|
292
|
+
}
|
|
293
|
+
// Add Angular's global locale data if i18n options are present.
|
|
294
|
+
// Locale data should go first so that project provided polyfill code can augment if needed.
|
|
295
|
+
let needLocaleDataPlugin = false;
|
|
296
|
+
if (i18nOptions.shouldInline) {
|
|
297
|
+
// Add locale data for all active locales
|
|
298
|
+
// TODO: Inject each individually within the inlining process itself
|
|
299
|
+
for (const locale of i18nOptions.inlineLocales) {
|
|
300
|
+
polyfills.unshift(`angular:locale/data:${locale}`);
|
|
301
|
+
}
|
|
302
|
+
needLocaleDataPlugin = true;
|
|
303
|
+
}
|
|
304
|
+
else if (i18nOptions.hasDefinedSourceLocale) {
|
|
305
|
+
// When not inlining and a source local is present, use the source locale data directly
|
|
306
|
+
polyfills.unshift(`angular:locale/data:${i18nOptions.sourceLocale}`);
|
|
307
|
+
needLocaleDataPlugin = true;
|
|
308
|
+
}
|
|
309
|
+
if (needLocaleDataPlugin) {
|
|
310
|
+
buildOptions.plugins?.push((0, i18n_locale_plugin_1.createAngularLocaleDataPlugin)());
|
|
311
|
+
}
|
|
312
|
+
if (polyfills.length === 0) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
buildOptions.plugins?.push((0, virtual_module_plugin_1.createVirtualModulePlugin)({
|
|
316
|
+
namespace,
|
|
317
|
+
cache: sourceFileCache?.loadResultCache,
|
|
318
|
+
loadContent: async (_, build) => {
|
|
319
|
+
let hasLocalizePolyfill = false;
|
|
320
|
+
let polyfillPaths = polyfills;
|
|
321
|
+
if (tryToResolvePolyfillsAsRelative) {
|
|
322
|
+
polyfillPaths = await Promise.all(polyfills.map(async (path) => {
|
|
323
|
+
hasLocalizePolyfill ||= path.startsWith('@angular/localize');
|
|
324
|
+
if (path.startsWith('zone.js') || !(0, node_path_1.extname)(path)) {
|
|
325
|
+
return path;
|
|
326
|
+
}
|
|
327
|
+
const potentialPathRelative = './' + path;
|
|
328
|
+
const result = await build.resolve(potentialPathRelative, {
|
|
329
|
+
kind: 'import-statement',
|
|
330
|
+
resolveDir: workspaceRoot,
|
|
331
|
+
});
|
|
332
|
+
return result.path ? potentialPathRelative : path;
|
|
333
|
+
}));
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
hasLocalizePolyfill = polyfills.some((p) => p.startsWith('@angular/localize'));
|
|
337
|
+
}
|
|
338
|
+
if (!i18nOptions.shouldInline && !hasLocalizePolyfill) {
|
|
339
|
+
const result = await build.resolve('@angular/localize', {
|
|
340
|
+
kind: 'import-statement',
|
|
341
|
+
resolveDir: workspaceRoot,
|
|
342
|
+
});
|
|
343
|
+
if (result.path) {
|
|
344
|
+
polyfillPaths.push('@angular/localize/init');
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
// Generate module contents with an import statement per defined polyfill
|
|
348
|
+
let contents = polyfillPaths
|
|
349
|
+
.map((file) => `import '${file.replace(/\\/g, '/')}';`)
|
|
350
|
+
.join('\n');
|
|
351
|
+
// The below should be done after loading `$localize` as otherwise the locale will be overridden.
|
|
352
|
+
if (i18nOptions.shouldInline) {
|
|
353
|
+
// When inlining, a placeholder is used to allow the post-processing step to inject the $localize locale identifier.
|
|
354
|
+
contents += '(globalThis.$localize ??= {}).locale = "___NG_LOCALE_INSERT___";\n';
|
|
355
|
+
}
|
|
356
|
+
else if (i18nOptions.hasDefinedSourceLocale) {
|
|
357
|
+
// If not inlining translations and source locale is defined, inject the locale specifier.
|
|
358
|
+
contents += `(globalThis.$localize ??= {}).locale = "${i18nOptions.sourceLocale}";\n`;
|
|
359
|
+
}
|
|
360
|
+
return {
|
|
361
|
+
contents,
|
|
362
|
+
loader: 'js',
|
|
363
|
+
resolveDir: workspaceRoot,
|
|
364
|
+
};
|
|
365
|
+
},
|
|
366
|
+
}));
|
|
367
|
+
return buildOptions;
|
|
368
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import type { Metafile } from 'esbuild';
|
|
9
|
+
import type { BudgetStats } from '../../utils/bundle-calculator';
|
|
10
|
+
import type { InitialFileRecord } from './bundler-context';
|
|
11
|
+
/**
|
|
12
|
+
* Generates a bundle budget calculator compatible stats object that provides
|
|
13
|
+
* the necessary information for the Webpack-based bundle budget code to
|
|
14
|
+
* interoperate with the esbuild-based builders.
|
|
15
|
+
* @param metafile The esbuild metafile of a build to use.
|
|
16
|
+
* @param initialFiles The records of all initial files of a build.
|
|
17
|
+
* @returns A bundle budget compatible stats object.
|
|
18
|
+
*/
|
|
19
|
+
export declare function generateBudgetStats(metafile: Metafile, initialFiles: Map<string, InitialFileRecord>): BudgetStats;
|
|
@@ -0,0 +1,59 @@
|
|
|
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.generateBudgetStats = void 0;
|
|
11
|
+
const node_path_1 = require("node:path");
|
|
12
|
+
/**
|
|
13
|
+
* Generates a bundle budget calculator compatible stats object that provides
|
|
14
|
+
* the necessary information for the Webpack-based bundle budget code to
|
|
15
|
+
* interoperate with the esbuild-based builders.
|
|
16
|
+
* @param metafile The esbuild metafile of a build to use.
|
|
17
|
+
* @param initialFiles The records of all initial files of a build.
|
|
18
|
+
* @returns A bundle budget compatible stats object.
|
|
19
|
+
*/
|
|
20
|
+
function generateBudgetStats(metafile, initialFiles) {
|
|
21
|
+
const stats = {
|
|
22
|
+
chunks: [],
|
|
23
|
+
assets: [],
|
|
24
|
+
};
|
|
25
|
+
for (const [file, entry] of Object.entries(metafile.outputs)) {
|
|
26
|
+
if (!file.endsWith('.js') && !file.endsWith('.css')) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
// Exclude server bundles
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
+
if (entry['ng-platform-server']) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const initialRecord = initialFiles.get(file);
|
|
35
|
+
let name = initialRecord?.name;
|
|
36
|
+
if (name === undefined && entry.entryPoint) {
|
|
37
|
+
// For non-initial lazy modules, convert the entry point file into a Webpack compatible name
|
|
38
|
+
name = (0, node_path_1.basename)(entry.entryPoint)
|
|
39
|
+
.replace(/\.[cm]?[jt]s$/, '')
|
|
40
|
+
.replace(/[\\/.]/g, '-');
|
|
41
|
+
}
|
|
42
|
+
stats.chunks.push({
|
|
43
|
+
files: [file],
|
|
44
|
+
initial: !!initialRecord,
|
|
45
|
+
names: name ? [name] : undefined,
|
|
46
|
+
});
|
|
47
|
+
// 'ng-component' is set by the angular plugin's component stylesheet bundler
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
const componentStyle = entry['ng-component'];
|
|
50
|
+
stats.assets.push({
|
|
51
|
+
// Component styles use the input file while all other outputs use the result file
|
|
52
|
+
name: (componentStyle && Object.keys(entry.inputs)[0]) || file,
|
|
53
|
+
size: entry.bytes,
|
|
54
|
+
componentStyle,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return stats;
|
|
58
|
+
}
|
|
59
|
+
exports.generateBudgetStats = generateBudgetStats;
|