@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,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @fileoverview
|
|
10
|
+
* Provides infrastructure for common caching functionality within the build system.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* A backing data store for one or more Cache instances.
|
|
14
|
+
* The interface is intentionally designed to support using a JavaScript
|
|
15
|
+
* Map instance as a potential cache store.
|
|
16
|
+
*/
|
|
17
|
+
export interface CacheStore<V> {
|
|
18
|
+
/**
|
|
19
|
+
* Returns the specified value from the cache store or `undefined` if not found.
|
|
20
|
+
* @param key The key to retrieve from the store.
|
|
21
|
+
*/
|
|
22
|
+
get(key: string): V | undefined | Promise<V | undefined>;
|
|
23
|
+
/**
|
|
24
|
+
* Returns whether the provided key is present in the cache store.
|
|
25
|
+
* @param key The key to check from the store.
|
|
26
|
+
*/
|
|
27
|
+
has(key: string): boolean | Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Adds a new value to the cache store if the key is not present.
|
|
30
|
+
* Updates the value for the key if already present.
|
|
31
|
+
* @param key The key to associate with the value in the cache store.
|
|
32
|
+
* @param value The value to add to the cache store.
|
|
33
|
+
*/
|
|
34
|
+
set(key: string, value: V): this | Promise<this>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A cache object that allows accessing and storing key/value pairs in
|
|
38
|
+
* an underlying CacheStore. This class is the primary method for consumers
|
|
39
|
+
* to use a cache.
|
|
40
|
+
*/
|
|
41
|
+
export declare class Cache<V, S extends CacheStore<V> = CacheStore<V>> {
|
|
42
|
+
protected readonly store: S;
|
|
43
|
+
readonly namespace?: string | undefined;
|
|
44
|
+
constructor(store: S, namespace?: string | undefined);
|
|
45
|
+
/**
|
|
46
|
+
* Prefixes a key with the cache namespace if present.
|
|
47
|
+
* @param key A key string to prefix.
|
|
48
|
+
* @returns A prefixed key if a namespace is present. Otherwise the provided key.
|
|
49
|
+
*/
|
|
50
|
+
protected withNamespace(key: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Gets the value associated with a provided key if available.
|
|
53
|
+
* Otherwise, creates a value using the factory creator function, puts the value
|
|
54
|
+
* in the cache, and returns the new value.
|
|
55
|
+
* @param key A key associated with the value.
|
|
56
|
+
* @param creator A factory function for the value if no value is present.
|
|
57
|
+
* @returns A value associated with the provided key.
|
|
58
|
+
*/
|
|
59
|
+
getOrCreate(key: string, creator: () => V | Promise<V>): Promise<V>;
|
|
60
|
+
/**
|
|
61
|
+
* Gets the value associated with a provided key if available.
|
|
62
|
+
* @param key A key associated with the value.
|
|
63
|
+
* @returns A value associated with the provided key if present. Otherwise, `undefined`.
|
|
64
|
+
*/
|
|
65
|
+
get(key: string): Promise<V | undefined>;
|
|
66
|
+
/**
|
|
67
|
+
* Puts a value in the cache and associates it with the provided key.
|
|
68
|
+
* If the key is already present, the value is updated instead.
|
|
69
|
+
* @param key A key associated with the value.
|
|
70
|
+
* @param value A value to put in the cache.
|
|
71
|
+
*/
|
|
72
|
+
put(key: string, value: V): Promise<void>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A lightweight in-memory cache implementation based on a JavaScript Map object.
|
|
76
|
+
*/
|
|
77
|
+
export declare class MemoryCache<V> extends Cache<V, Map<string, V>> {
|
|
78
|
+
constructor();
|
|
79
|
+
/**
|
|
80
|
+
* Removes all entries from the cache instance.
|
|
81
|
+
*/
|
|
82
|
+
clear(): void;
|
|
83
|
+
/**
|
|
84
|
+
* Provides all the values currently present in the cache instance.
|
|
85
|
+
* @returns An iterable of all values in the cache.
|
|
86
|
+
*/
|
|
87
|
+
values(): IterableIterator<V>;
|
|
88
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
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.MemoryCache = exports.Cache = void 0;
|
|
11
|
+
/**
|
|
12
|
+
* A cache object that allows accessing and storing key/value pairs in
|
|
13
|
+
* an underlying CacheStore. This class is the primary method for consumers
|
|
14
|
+
* to use a cache.
|
|
15
|
+
*/
|
|
16
|
+
class Cache {
|
|
17
|
+
store;
|
|
18
|
+
namespace;
|
|
19
|
+
constructor(store, namespace) {
|
|
20
|
+
this.store = store;
|
|
21
|
+
this.namespace = namespace;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Prefixes a key with the cache namespace if present.
|
|
25
|
+
* @param key A key string to prefix.
|
|
26
|
+
* @returns A prefixed key if a namespace is present. Otherwise the provided key.
|
|
27
|
+
*/
|
|
28
|
+
withNamespace(key) {
|
|
29
|
+
if (this.namespace) {
|
|
30
|
+
return `${this.namespace}:${key}`;
|
|
31
|
+
}
|
|
32
|
+
return key;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Gets the value associated with a provided key if available.
|
|
36
|
+
* Otherwise, creates a value using the factory creator function, puts the value
|
|
37
|
+
* in the cache, and returns the new value.
|
|
38
|
+
* @param key A key associated with the value.
|
|
39
|
+
* @param creator A factory function for the value if no value is present.
|
|
40
|
+
* @returns A value associated with the provided key.
|
|
41
|
+
*/
|
|
42
|
+
async getOrCreate(key, creator) {
|
|
43
|
+
const namespacedKey = this.withNamespace(key);
|
|
44
|
+
let value = await this.store.get(namespacedKey);
|
|
45
|
+
if (value === undefined) {
|
|
46
|
+
value = await creator();
|
|
47
|
+
await this.store.set(namespacedKey, value);
|
|
48
|
+
}
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Gets the value associated with a provided key if available.
|
|
53
|
+
* @param key A key associated with the value.
|
|
54
|
+
* @returns A value associated with the provided key if present. Otherwise, `undefined`.
|
|
55
|
+
*/
|
|
56
|
+
async get(key) {
|
|
57
|
+
const value = await this.store.get(this.withNamespace(key));
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Puts a value in the cache and associates it with the provided key.
|
|
62
|
+
* If the key is already present, the value is updated instead.
|
|
63
|
+
* @param key A key associated with the value.
|
|
64
|
+
* @param value A value to put in the cache.
|
|
65
|
+
*/
|
|
66
|
+
async put(key, value) {
|
|
67
|
+
await this.store.set(this.withNamespace(key), value);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.Cache = Cache;
|
|
71
|
+
/**
|
|
72
|
+
* A lightweight in-memory cache implementation based on a JavaScript Map object.
|
|
73
|
+
*/
|
|
74
|
+
class MemoryCache extends Cache {
|
|
75
|
+
constructor() {
|
|
76
|
+
super(new Map());
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Removes all entries from the cache instance.
|
|
80
|
+
*/
|
|
81
|
+
clear() {
|
|
82
|
+
this.store.clear();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Provides all the values currently present in the cache instance.
|
|
86
|
+
* @returns An iterable of all values in the cache.
|
|
87
|
+
*/
|
|
88
|
+
values() {
|
|
89
|
+
return this.store.values();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.MemoryCache = MemoryCache;
|
|
@@ -0,0 +1,28 @@
|
|
|
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, PartialMessage } from 'esbuild';
|
|
9
|
+
/**
|
|
10
|
+
* Checks the input files of a build to determine if any of the files included
|
|
11
|
+
* in the build are not ESM. ESM files can be tree-shaken and otherwise optimized
|
|
12
|
+
* in ways that CommonJS and other module formats cannot. The esbuild metafile
|
|
13
|
+
* information is used as the basis for the analysis as it contains information
|
|
14
|
+
* for each input file including its respective format.
|
|
15
|
+
*
|
|
16
|
+
* If any allowed dependencies are provided via the `allowedCommonJsDependencies`
|
|
17
|
+
* parameter, both the direct import and any deep imports will be ignored and no
|
|
18
|
+
* diagnostic will be generated. Use `'*'` as entry to skip the check.
|
|
19
|
+
*
|
|
20
|
+
* If a module has been issued a diagnostic message, then all descendant modules
|
|
21
|
+
* will not be checked. This prevents a potential massive amount of inactionable
|
|
22
|
+
* messages since the initial module import is the cause of the problem.
|
|
23
|
+
*
|
|
24
|
+
* @param metafile An esbuild metafile object to check.
|
|
25
|
+
* @param allowedCommonJsDependencies An optional list of allowed dependencies.
|
|
26
|
+
* @returns Zero or more diagnostic messages for any non-ESM modules.
|
|
27
|
+
*/
|
|
28
|
+
export declare function checkCommonJSModules(metafile: Metafile, allowedCommonJsDependencies?: string[]): PartialMessage[];
|
|
@@ -0,0 +1,151 @@
|
|
|
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.checkCommonJSModules = void 0;
|
|
11
|
+
/**
|
|
12
|
+
* Checks the input files of a build to determine if any of the files included
|
|
13
|
+
* in the build are not ESM. ESM files can be tree-shaken and otherwise optimized
|
|
14
|
+
* in ways that CommonJS and other module formats cannot. The esbuild metafile
|
|
15
|
+
* information is used as the basis for the analysis as it contains information
|
|
16
|
+
* for each input file including its respective format.
|
|
17
|
+
*
|
|
18
|
+
* If any allowed dependencies are provided via the `allowedCommonJsDependencies`
|
|
19
|
+
* parameter, both the direct import and any deep imports will be ignored and no
|
|
20
|
+
* diagnostic will be generated. Use `'*'` as entry to skip the check.
|
|
21
|
+
*
|
|
22
|
+
* If a module has been issued a diagnostic message, then all descendant modules
|
|
23
|
+
* will not be checked. This prevents a potential massive amount of inactionable
|
|
24
|
+
* messages since the initial module import is the cause of the problem.
|
|
25
|
+
*
|
|
26
|
+
* @param metafile An esbuild metafile object to check.
|
|
27
|
+
* @param allowedCommonJsDependencies An optional list of allowed dependencies.
|
|
28
|
+
* @returns Zero or more diagnostic messages for any non-ESM modules.
|
|
29
|
+
*/
|
|
30
|
+
function checkCommonJSModules(metafile, allowedCommonJsDependencies) {
|
|
31
|
+
const messages = [];
|
|
32
|
+
const allowedRequests = new Set(allowedCommonJsDependencies);
|
|
33
|
+
if (allowedRequests.has('*')) {
|
|
34
|
+
return messages;
|
|
35
|
+
}
|
|
36
|
+
// Ignore Angular locale definitions which are currently UMD
|
|
37
|
+
allowedRequests.add('@angular/common/locales');
|
|
38
|
+
// Ignore zone.js due to it currently being built with a UMD like structure.
|
|
39
|
+
// Once the build output is updated to be fully ESM, this can be removed.
|
|
40
|
+
allowedRequests.add('zone.js');
|
|
41
|
+
// Used by '@angular/platform-server' and is in a seperate chunk that is unused when
|
|
42
|
+
// using `provideHttpClient(withFetch())`.
|
|
43
|
+
allowedRequests.add('xhr2');
|
|
44
|
+
// Packages used by @angular/ssr.
|
|
45
|
+
// While critters is ESM it has a number of direct and transtive CJS deps.
|
|
46
|
+
allowedRequests.add('express');
|
|
47
|
+
allowedRequests.add('critters');
|
|
48
|
+
// Find all entry points that contain code (JS/TS)
|
|
49
|
+
const files = [];
|
|
50
|
+
for (const { entryPoint } of Object.values(metafile.outputs)) {
|
|
51
|
+
if (!entryPoint) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (!isPathCode(entryPoint)) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
files.push(entryPoint);
|
|
58
|
+
}
|
|
59
|
+
// Track seen files so they are only analyzed once.
|
|
60
|
+
// Bundler runtime code is also ignored since it cannot be actionable.
|
|
61
|
+
const seenFiles = new Set(['<runtime>']);
|
|
62
|
+
// Analyze the files present by walking the import graph
|
|
63
|
+
let currentFile;
|
|
64
|
+
while ((currentFile = files.shift())) {
|
|
65
|
+
const input = metafile.inputs[currentFile];
|
|
66
|
+
for (const imported of input.imports) {
|
|
67
|
+
// Ignore imports that were already seen or not originally in the code (bundler injected)
|
|
68
|
+
if (!imported.original || seenFiles.has(imported.path)) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
seenFiles.add(imported.path);
|
|
72
|
+
// If the dependency is allowed ignore all other checks
|
|
73
|
+
if (allowedRequests.has(imported.original)) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
// Only check actual code files
|
|
77
|
+
if (!isPathCode(imported.path)) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
// Check if non-relative import is ESM format and issue a diagnostic if the file is not allowed
|
|
81
|
+
if (!isPotentialRelative(imported.original) &&
|
|
82
|
+
metafile.inputs[imported.path].format !== 'esm') {
|
|
83
|
+
const request = imported.original;
|
|
84
|
+
let notAllowed = true;
|
|
85
|
+
if (allowedRequests.has(request)) {
|
|
86
|
+
notAllowed = false;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// Check for deep imports of allowed requests
|
|
90
|
+
for (const allowed of allowedRequests) {
|
|
91
|
+
if (request.startsWith(allowed + '/')) {
|
|
92
|
+
notAllowed = false;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (notAllowed) {
|
|
98
|
+
// Issue a diagnostic message for CommonJS module
|
|
99
|
+
messages.push(createCommonJSModuleError(request, currentFile));
|
|
100
|
+
}
|
|
101
|
+
// Skip all descendants since they are also most likely not ESM but solved by addressing this import
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
// Add the path so that its imports can be checked
|
|
105
|
+
files.push(imported.path);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return messages;
|
|
109
|
+
}
|
|
110
|
+
exports.checkCommonJSModules = checkCommonJSModules;
|
|
111
|
+
/**
|
|
112
|
+
* Determines if a file path has an extension that is a JavaScript or TypeScript
|
|
113
|
+
* code file.
|
|
114
|
+
*
|
|
115
|
+
* @param name A path to check for code file extensions.
|
|
116
|
+
* @returns True, if a code file path; false, otherwise.
|
|
117
|
+
*/
|
|
118
|
+
function isPathCode(name) {
|
|
119
|
+
return /\.[cm]?[jt]sx?$/.test(name);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Test an import module specifier to determine if the string potentially references a relative file.
|
|
123
|
+
* npm packages should not start with a period so if the first character is a period than it is not a
|
|
124
|
+
* package. While this is sufficient for the use case in the CommmonJS checker, only checking the
|
|
125
|
+
* first character does not definitely indicate the specifier is a relative path.
|
|
126
|
+
*
|
|
127
|
+
* @param specifier An import module specifier.
|
|
128
|
+
* @returns True, if specifier is potentially relative; false, otherwise.
|
|
129
|
+
*/
|
|
130
|
+
function isPotentialRelative(specifier) {
|
|
131
|
+
return specifier[0] === '.';
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Creates an esbuild diagnostic message for a given non-ESM module request.
|
|
135
|
+
*
|
|
136
|
+
* @param request The requested non-ESM module name.
|
|
137
|
+
* @param importer The path of the file containing the import.
|
|
138
|
+
* @returns A message representing the diagnostic.
|
|
139
|
+
*/
|
|
140
|
+
function createCommonJSModuleError(request, importer) {
|
|
141
|
+
const error = {
|
|
142
|
+
text: `Module '${request}' used by '${importer}' is not ESM`,
|
|
143
|
+
notes: [
|
|
144
|
+
{
|
|
145
|
+
text: 'CommonJS or AMD dependencies can cause optimization bailouts.\n' +
|
|
146
|
+
'For more information see: https://angular.io/guide/build#configuring-commonjs-dependencies',
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
};
|
|
150
|
+
return error;
|
|
151
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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 { NormalizedApplicationBuildOptions } from '../../builders/application/options';
|
|
9
|
+
import type { createCompilerPlugin } from './angular/compiler-plugin';
|
|
10
|
+
import type { SourceFileCache } from './angular/source-file-cache';
|
|
11
|
+
type CreateCompilerPluginParameters = Parameters<typeof createCompilerPlugin>;
|
|
12
|
+
export declare function createCompilerPluginOptions(options: NormalizedApplicationBuildOptions, target: string[], sourceFileCache?: SourceFileCache): {
|
|
13
|
+
pluginOptions: CreateCompilerPluginParameters[0];
|
|
14
|
+
styleOptions: CreateCompilerPluginParameters[1];
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
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.createCompilerPluginOptions = void 0;
|
|
11
|
+
function createCompilerPluginOptions(options, target, sourceFileCache) {
|
|
12
|
+
const { workspaceRoot, optimizationOptions, sourcemapOptions, tsconfig, outputNames, fileReplacements, externalDependencies, preserveSymlinks, stylePreprocessorOptions, advancedOptimizations, inlineStyleLanguage, jit, cacheOptions, tailwindConfiguration, postcssConfiguration, publicPath, } = options;
|
|
13
|
+
return {
|
|
14
|
+
// JS/TS options
|
|
15
|
+
pluginOptions: {
|
|
16
|
+
sourcemap: !!sourcemapOptions.scripts,
|
|
17
|
+
thirdPartySourcemaps: sourcemapOptions.vendor,
|
|
18
|
+
tsconfig,
|
|
19
|
+
jit,
|
|
20
|
+
advancedOptimizations,
|
|
21
|
+
fileReplacements,
|
|
22
|
+
sourceFileCache,
|
|
23
|
+
loadResultCache: sourceFileCache?.loadResultCache,
|
|
24
|
+
incremental: !!options.watch,
|
|
25
|
+
},
|
|
26
|
+
// Component stylesheet options
|
|
27
|
+
styleOptions: {
|
|
28
|
+
workspaceRoot,
|
|
29
|
+
inlineFonts: !!optimizationOptions.fonts.inline,
|
|
30
|
+
optimization: !!optimizationOptions.styles.minify,
|
|
31
|
+
sourcemap:
|
|
32
|
+
// Hidden component stylesheet sourcemaps are inaccessible which is effectively
|
|
33
|
+
// the same as being disabled. Disabling has the advantage of avoiding the overhead
|
|
34
|
+
// of sourcemap processing.
|
|
35
|
+
sourcemapOptions.styles && !sourcemapOptions.hidden ? 'linked' : false,
|
|
36
|
+
outputNames,
|
|
37
|
+
includePaths: stylePreprocessorOptions?.includePaths,
|
|
38
|
+
externalDependencies,
|
|
39
|
+
target,
|
|
40
|
+
inlineStyleLanguage,
|
|
41
|
+
preserveSymlinks,
|
|
42
|
+
tailwindConfiguration,
|
|
43
|
+
postcssConfiguration,
|
|
44
|
+
cacheOptions,
|
|
45
|
+
publicPath,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
exports.createCompilerPluginOptions = createCompilerPluginOptions;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import type { Plugin } from 'esbuild';
|
|
9
|
+
/**
|
|
10
|
+
* Creates a plugin that marks any resolved path as external if it is within a node modules directory.
|
|
11
|
+
* This is used instead of the esbuild `packages` option to avoid marking files that should be loaded
|
|
12
|
+
* via customized loaders. This is necessary to prevent Vite development server pre-bundling errors.
|
|
13
|
+
*
|
|
14
|
+
* @returns An esbuild plugin.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createExternalPackagesPlugin(options?: {
|
|
17
|
+
exclude?: string[];
|
|
18
|
+
}): Plugin;
|
|
@@ -0,0 +1,70 @@
|
|
|
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.createExternalPackagesPlugin = void 0;
|
|
11
|
+
const node_path_1 = require("node:path");
|
|
12
|
+
const EXTERNAL_PACKAGE_RESOLUTION = Symbol('EXTERNAL_PACKAGE_RESOLUTION');
|
|
13
|
+
/**
|
|
14
|
+
* Creates a plugin that marks any resolved path as external if it is within a node modules directory.
|
|
15
|
+
* This is used instead of the esbuild `packages` option to avoid marking files that should be loaded
|
|
16
|
+
* via customized loaders. This is necessary to prevent Vite development server pre-bundling errors.
|
|
17
|
+
*
|
|
18
|
+
* @returns An esbuild plugin.
|
|
19
|
+
*/
|
|
20
|
+
function createExternalPackagesPlugin(options) {
|
|
21
|
+
const exclusions = options?.exclude?.length ? new Set(options.exclude) : undefined;
|
|
22
|
+
return {
|
|
23
|
+
name: 'angular-external-packages',
|
|
24
|
+
setup(build) {
|
|
25
|
+
const loaderOptionKeys = build.initialOptions.loader && Object.keys(build.initialOptions.loader);
|
|
26
|
+
// Safe to use native packages external option if no loader options or exclusions present
|
|
27
|
+
if (!exclusions && !loaderOptionKeys?.length) {
|
|
28
|
+
build.initialOptions.packages = 'external';
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const loaderFileExtensions = new Set(loaderOptionKeys);
|
|
32
|
+
// Only attempt resolve of non-relative and non-absolute paths
|
|
33
|
+
build.onResolve({ filter: /^[^./]/ }, async (args) => {
|
|
34
|
+
if (args.pluginData?.[EXTERNAL_PACKAGE_RESOLUTION]) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
if (exclusions?.has(args.path)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const { importer, kind, resolveDir, namespace, pluginData = {} } = args;
|
|
41
|
+
pluginData[EXTERNAL_PACKAGE_RESOLUTION] = true;
|
|
42
|
+
const result = await build.resolve(args.path, {
|
|
43
|
+
importer,
|
|
44
|
+
kind,
|
|
45
|
+
namespace,
|
|
46
|
+
pluginData,
|
|
47
|
+
resolveDir,
|
|
48
|
+
});
|
|
49
|
+
// Return result if unable to resolve or explicitly marked external (externalDependencies option)
|
|
50
|
+
if (!result.path || result.external) {
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
// Allow customized loaders to run against configured paths regardless of location
|
|
54
|
+
if (loaderFileExtensions.has((0, node_path_1.extname)(result.path))) {
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
// Mark paths from a node modules directory as external
|
|
58
|
+
if (/[\\/]node_modules[\\/]/.test(result.path)) {
|
|
59
|
+
return {
|
|
60
|
+
path: args.path,
|
|
61
|
+
external: true,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// Otherwise return original result
|
|
65
|
+
return result;
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
exports.createExternalPackagesPlugin = createExternalPackagesPlugin;
|
|
@@ -0,0 +1,16 @@
|
|
|
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 { NormalizedApplicationBuildOptions } from '../../builders/application/options';
|
|
9
|
+
import { BundlerOptionsFactory } from './bundler-context';
|
|
10
|
+
/**
|
|
11
|
+
* Create an esbuild 'build' options object for all global scripts defined in the user provied
|
|
12
|
+
* build options.
|
|
13
|
+
* @param options The builder's user-provider normalized options.
|
|
14
|
+
* @returns An esbuild BuildOptions object.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createGlobalScriptsBundleOptions(options: NormalizedApplicationBuildOptions, target: string[], initial: boolean): BundlerOptionsFactory | undefined;
|
|
@@ -0,0 +1,142 @@
|
|
|
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.createGlobalScriptsBundleOptions = void 0;
|
|
37
|
+
const magic_string_1 = __importStar(require("magic-string"));
|
|
38
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
39
|
+
const promises_1 = require("node:fs/promises");
|
|
40
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
41
|
+
const error_1 = require("../../utils/error");
|
|
42
|
+
const load_result_cache_1 = require("./load-result-cache");
|
|
43
|
+
const sourcemap_ignorelist_plugin_1 = require("./sourcemap-ignorelist-plugin");
|
|
44
|
+
const virtual_module_plugin_1 = require("./virtual-module-plugin");
|
|
45
|
+
/**
|
|
46
|
+
* Create an esbuild 'build' options object for all global scripts defined in the user provied
|
|
47
|
+
* build options.
|
|
48
|
+
* @param options The builder's user-provider normalized options.
|
|
49
|
+
* @returns An esbuild BuildOptions object.
|
|
50
|
+
*/
|
|
51
|
+
function createGlobalScriptsBundleOptions(options, target, initial) {
|
|
52
|
+
const { globalScripts, optimizationOptions, outputNames, preserveSymlinks, sourcemapOptions, jsonLogs, workspaceRoot, } = options;
|
|
53
|
+
const namespace = 'angular:script/global';
|
|
54
|
+
const entryPoints = {};
|
|
55
|
+
let found = false;
|
|
56
|
+
for (const script of globalScripts) {
|
|
57
|
+
if (script.initial === initial) {
|
|
58
|
+
found = true;
|
|
59
|
+
entryPoints[script.name] = `${namespace}:${script.name}`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Skip if there are no entry points for the style loading type
|
|
63
|
+
if (found === false) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
return (loadCache) => {
|
|
67
|
+
return {
|
|
68
|
+
absWorkingDir: workspaceRoot,
|
|
69
|
+
bundle: false,
|
|
70
|
+
splitting: false,
|
|
71
|
+
entryPoints,
|
|
72
|
+
entryNames: initial ? outputNames.bundles : '[name]',
|
|
73
|
+
assetNames: outputNames.media,
|
|
74
|
+
mainFields: ['script', 'browser', 'main'],
|
|
75
|
+
conditions: ['script'],
|
|
76
|
+
resolveExtensions: ['.mjs', '.js'],
|
|
77
|
+
logLevel: options.verbose && !jsonLogs ? 'debug' : 'silent',
|
|
78
|
+
metafile: true,
|
|
79
|
+
minify: optimizationOptions.scripts,
|
|
80
|
+
outdir: workspaceRoot,
|
|
81
|
+
sourcemap: sourcemapOptions.scripts && (sourcemapOptions.hidden ? 'external' : true),
|
|
82
|
+
write: false,
|
|
83
|
+
platform: 'neutral',
|
|
84
|
+
target,
|
|
85
|
+
preserveSymlinks,
|
|
86
|
+
plugins: [
|
|
87
|
+
(0, sourcemap_ignorelist_plugin_1.createSourcemapIgnorelistPlugin)(),
|
|
88
|
+
(0, virtual_module_plugin_1.createVirtualModulePlugin)({
|
|
89
|
+
namespace,
|
|
90
|
+
external: true,
|
|
91
|
+
// Add the `js` extension here so that esbuild generates an output file with the extension
|
|
92
|
+
transformPath: (path) => path.slice(namespace.length + 1) + '.js',
|
|
93
|
+
loadContent: (args, build) => (0, load_result_cache_1.createCachedLoad)(loadCache, async (args) => {
|
|
94
|
+
const files = globalScripts.find(({ name }) => name === args.path.slice(0, -3))?.files;
|
|
95
|
+
(0, node_assert_1.default)(files, `Invalid operation: global scripts name not found [${args.path}]`);
|
|
96
|
+
// Global scripts are concatenated using magic-string instead of bundled via esbuild.
|
|
97
|
+
const bundleContent = new magic_string_1.Bundle();
|
|
98
|
+
const watchFiles = [];
|
|
99
|
+
for (const filename of files) {
|
|
100
|
+
let fileContent;
|
|
101
|
+
try {
|
|
102
|
+
// Attempt to read as a relative path from the workspace root
|
|
103
|
+
const fullPath = node_path_1.default.join(workspaceRoot, filename);
|
|
104
|
+
fileContent = await (0, promises_1.readFile)(fullPath, 'utf-8');
|
|
105
|
+
watchFiles.push(fullPath);
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
(0, error_1.assertIsError)(e);
|
|
109
|
+
if (e.code !== 'ENOENT') {
|
|
110
|
+
throw e;
|
|
111
|
+
}
|
|
112
|
+
// If not found, attempt to resolve as a module specifier
|
|
113
|
+
const resolveResult = await build.resolve(filename, {
|
|
114
|
+
kind: 'entry-point',
|
|
115
|
+
resolveDir: workspaceRoot,
|
|
116
|
+
});
|
|
117
|
+
if (resolveResult.errors.length) {
|
|
118
|
+
// Remove resolution failure notes about marking as external since it doesn't apply
|
|
119
|
+
// to global scripts.
|
|
120
|
+
resolveResult.errors.forEach((error) => (error.notes = []));
|
|
121
|
+
return {
|
|
122
|
+
errors: resolveResult.errors,
|
|
123
|
+
warnings: resolveResult.warnings,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
watchFiles.push(resolveResult.path);
|
|
127
|
+
fileContent = await (0, promises_1.readFile)(resolveResult.path, 'utf-8');
|
|
128
|
+
}
|
|
129
|
+
bundleContent.addSource(new magic_string_1.default(fileContent, { filename }));
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
contents: bundleContent.toString(),
|
|
133
|
+
loader: 'js',
|
|
134
|
+
watchFiles,
|
|
135
|
+
};
|
|
136
|
+
}).call(build, args),
|
|
137
|
+
}),
|
|
138
|
+
],
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
exports.createGlobalScriptsBundleOptions = createGlobalScriptsBundleOptions;
|