@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,213 @@
|
|
|
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.SassWorkerImplementation = void 0;
|
|
11
|
+
const node_path_1 = require("node:path");
|
|
12
|
+
const node_url_1 = require("node:url");
|
|
13
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
|
14
|
+
const environment_options_1 = require("../../utils/environment-options");
|
|
15
|
+
/**
|
|
16
|
+
* The maximum number of Workers that will be created to execute render requests.
|
|
17
|
+
*/
|
|
18
|
+
const MAX_RENDER_WORKERS = environment_options_1.maxWorkers;
|
|
19
|
+
/**
|
|
20
|
+
* A Sass renderer implementation that provides an interface that can be used by Webpack's
|
|
21
|
+
* `sass-loader`. The implementation uses a Worker thread to perform the Sass rendering
|
|
22
|
+
* with the `dart-sass` package. The `dart-sass` synchronous render function is used within
|
|
23
|
+
* the worker which can be up to two times faster than the asynchronous variant.
|
|
24
|
+
*/
|
|
25
|
+
class SassWorkerImplementation {
|
|
26
|
+
rebase;
|
|
27
|
+
workers = [];
|
|
28
|
+
availableWorkers = [];
|
|
29
|
+
requests = new Map();
|
|
30
|
+
workerPath = (0, node_path_1.join)(__dirname, './worker.js');
|
|
31
|
+
idCounter = 1;
|
|
32
|
+
nextWorkerIndex = 0;
|
|
33
|
+
constructor(rebase = false) {
|
|
34
|
+
this.rebase = rebase;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Provides information about the Sass implementation.
|
|
38
|
+
* This mimics enough of the `dart-sass` value to be used with the `sass-loader`.
|
|
39
|
+
*/
|
|
40
|
+
get info() {
|
|
41
|
+
return 'dart-sass\tworker';
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The synchronous render function is not used by the `sass-loader`.
|
|
45
|
+
*/
|
|
46
|
+
compileString() {
|
|
47
|
+
throw new Error('Sass compileString is not supported.');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Asynchronously request a Sass stylesheet to be renderered.
|
|
51
|
+
*
|
|
52
|
+
* @param source The contents to compile.
|
|
53
|
+
* @param options The `dart-sass` options to use when rendering the stylesheet.
|
|
54
|
+
*/
|
|
55
|
+
compileStringAsync(source, options) {
|
|
56
|
+
// The `functions`, `logger` and `importer` options are JavaScript functions that cannot be transferred.
|
|
57
|
+
// If any additional function options are added in the future, they must be excluded as well.
|
|
58
|
+
const { functions, importers, url, logger, ...serializableOptions } = options;
|
|
59
|
+
// The CLI's configuration does not use or expose the ability to defined custom Sass functions
|
|
60
|
+
if (functions && Object.keys(functions).length > 0) {
|
|
61
|
+
throw new Error('Sass custom functions are not supported.');
|
|
62
|
+
}
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
let workerIndex = this.availableWorkers.pop();
|
|
65
|
+
if (workerIndex === undefined) {
|
|
66
|
+
if (this.workers.length < MAX_RENDER_WORKERS) {
|
|
67
|
+
workerIndex = this.workers.length;
|
|
68
|
+
this.workers.push(this.createWorker());
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
workerIndex = this.nextWorkerIndex++;
|
|
72
|
+
if (this.nextWorkerIndex >= this.workers.length) {
|
|
73
|
+
this.nextWorkerIndex = 0;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const callback = (error, result) => {
|
|
78
|
+
if (error) {
|
|
79
|
+
const url = error.span?.url;
|
|
80
|
+
if (url) {
|
|
81
|
+
error.span.url = (0, node_url_1.pathToFileURL)(url);
|
|
82
|
+
}
|
|
83
|
+
reject(error);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (!result) {
|
|
87
|
+
reject(new Error('No result.'));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
resolve(result);
|
|
91
|
+
};
|
|
92
|
+
const request = this.createRequest(workerIndex, callback, logger, importers);
|
|
93
|
+
this.requests.set(request.id, request);
|
|
94
|
+
this.workers[workerIndex].postMessage({
|
|
95
|
+
id: request.id,
|
|
96
|
+
source,
|
|
97
|
+
hasImporter: !!importers?.length,
|
|
98
|
+
hasLogger: !!logger,
|
|
99
|
+
rebase: this.rebase,
|
|
100
|
+
options: {
|
|
101
|
+
...serializableOptions,
|
|
102
|
+
// URL is not serializable so to convert to string here and back to URL in the worker.
|
|
103
|
+
url: url ? (0, node_url_1.fileURLToPath)(url) : undefined,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Shutdown the Sass render worker.
|
|
110
|
+
* Executing this method will stop any pending render requests.
|
|
111
|
+
*/
|
|
112
|
+
close() {
|
|
113
|
+
for (const worker of this.workers) {
|
|
114
|
+
try {
|
|
115
|
+
void worker.terminate();
|
|
116
|
+
}
|
|
117
|
+
catch { }
|
|
118
|
+
}
|
|
119
|
+
this.requests.clear();
|
|
120
|
+
}
|
|
121
|
+
createWorker() {
|
|
122
|
+
const { port1: mainImporterPort, port2: workerImporterPort } = new node_worker_threads_1.MessageChannel();
|
|
123
|
+
const importerSignal = new Int32Array(new SharedArrayBuffer(4));
|
|
124
|
+
const worker = new node_worker_threads_1.Worker(this.workerPath, {
|
|
125
|
+
workerData: { workerImporterPort, importerSignal },
|
|
126
|
+
transferList: [workerImporterPort],
|
|
127
|
+
});
|
|
128
|
+
worker.on('message', (response) => {
|
|
129
|
+
const request = this.requests.get(response.id);
|
|
130
|
+
if (!request) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
this.requests.delete(response.id);
|
|
134
|
+
this.availableWorkers.push(request.workerIndex);
|
|
135
|
+
if (response.warnings && request.logger?.warn) {
|
|
136
|
+
for (const { message, span, ...options } of response.warnings) {
|
|
137
|
+
request.logger.warn(message, {
|
|
138
|
+
...options,
|
|
139
|
+
span: span && {
|
|
140
|
+
...span,
|
|
141
|
+
url: span.url ? (0, node_url_1.pathToFileURL)(span.url) : undefined,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (response.result) {
|
|
147
|
+
request.callback(undefined, {
|
|
148
|
+
...response.result,
|
|
149
|
+
// URL is not serializable so in the worker we convert to string and here back to URL.
|
|
150
|
+
loadedUrls: response.result.loadedUrls.map((p) => (0, node_url_1.pathToFileURL)(p)),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
request.callback(response.error);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
mainImporterPort.on('message', ({ id, url, options }) => {
|
|
158
|
+
const request = this.requests.get(id);
|
|
159
|
+
if (!request?.importers) {
|
|
160
|
+
mainImporterPort.postMessage(null);
|
|
161
|
+
Atomics.store(importerSignal, 0, 1);
|
|
162
|
+
Atomics.notify(importerSignal, 0);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
this.processImporters(request.importers, url, {
|
|
166
|
+
...options,
|
|
167
|
+
// URL is not serializable so in the worker we convert to string and here back to URL.
|
|
168
|
+
containingUrl: options.containingUrl
|
|
169
|
+
? (0, node_url_1.pathToFileURL)(options.containingUrl)
|
|
170
|
+
: null,
|
|
171
|
+
})
|
|
172
|
+
.then((result) => {
|
|
173
|
+
mainImporterPort.postMessage(result);
|
|
174
|
+
})
|
|
175
|
+
.catch((error) => {
|
|
176
|
+
mainImporterPort.postMessage(error);
|
|
177
|
+
})
|
|
178
|
+
.finally(() => {
|
|
179
|
+
Atomics.store(importerSignal, 0, 1);
|
|
180
|
+
Atomics.notify(importerSignal, 0);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
mainImporterPort.unref();
|
|
184
|
+
return worker;
|
|
185
|
+
}
|
|
186
|
+
async processImporters(importers, url, options) {
|
|
187
|
+
for (const importer of importers) {
|
|
188
|
+
if (!this.isFileImporter(importer)) {
|
|
189
|
+
// Importer
|
|
190
|
+
throw new Error('Only File Importers are supported.');
|
|
191
|
+
}
|
|
192
|
+
// File importer (Can be sync or aync).
|
|
193
|
+
const result = await importer.findFileUrl(url, options);
|
|
194
|
+
if (result) {
|
|
195
|
+
return (0, node_url_1.fileURLToPath)(result);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
createRequest(workerIndex, callback, logger, importers) {
|
|
201
|
+
return {
|
|
202
|
+
id: this.idCounter++,
|
|
203
|
+
workerIndex,
|
|
204
|
+
callback,
|
|
205
|
+
logger,
|
|
206
|
+
importers,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
isFileImporter(value) {
|
|
210
|
+
return 'findFileUrl' in value;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
exports.SassWorkerImplementation = SassWorkerImplementation;
|
|
@@ -0,0 +1,192 @@
|
|
|
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
|
+
const remapping_1 = __importDefault(require("@ampproject/remapping"));
|
|
14
|
+
const node_path_1 = require("node:path");
|
|
15
|
+
const node_url_1 = require("node:url");
|
|
16
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
|
17
|
+
const sass_1 = require("sass");
|
|
18
|
+
const rebasing_importer_1 = require("./rebasing-importer");
|
|
19
|
+
if (!node_worker_threads_1.parentPort || !node_worker_threads_1.workerData) {
|
|
20
|
+
throw new Error('Sass worker must be executed as a Worker.');
|
|
21
|
+
}
|
|
22
|
+
// The importer variables are used to proxy import requests to the main thread
|
|
23
|
+
const { workerImporterPort, importerSignal } = node_worker_threads_1.workerData;
|
|
24
|
+
node_worker_threads_1.parentPort.on('message', (message) => {
|
|
25
|
+
if (!node_worker_threads_1.parentPort) {
|
|
26
|
+
throw new Error('"parentPort" is not defined. Sass worker must be executed as a Worker.');
|
|
27
|
+
}
|
|
28
|
+
const { id, hasImporter, hasLogger, source, options, rebase } = message;
|
|
29
|
+
const entryDirectory = (0, node_path_1.dirname)(options.url);
|
|
30
|
+
let warnings;
|
|
31
|
+
try {
|
|
32
|
+
const directoryCache = new Map();
|
|
33
|
+
const rebaseSourceMaps = options.sourceMap ? new Map() : undefined;
|
|
34
|
+
if (hasImporter) {
|
|
35
|
+
// When a custom importer function is present, the importer request must be proxied
|
|
36
|
+
// back to the main thread where it can be executed.
|
|
37
|
+
// This process must be synchronous from the perspective of dart-sass. The `Atomics`
|
|
38
|
+
// functions combined with the shared memory `importSignal` and the Node.js
|
|
39
|
+
// `receiveMessageOnPort` function are used to ensure synchronous behavior.
|
|
40
|
+
const proxyImporter = {
|
|
41
|
+
findFileUrl: (url, options) => {
|
|
42
|
+
Atomics.store(importerSignal, 0, 0);
|
|
43
|
+
workerImporterPort.postMessage({
|
|
44
|
+
id,
|
|
45
|
+
url,
|
|
46
|
+
options: {
|
|
47
|
+
...options,
|
|
48
|
+
containingUrl: options.containingUrl ? (0, node_url_1.fileURLToPath)(options.containingUrl) : null,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
Atomics.wait(importerSignal, 0, 0);
|
|
52
|
+
const result = (0, node_worker_threads_1.receiveMessageOnPort)(workerImporterPort)?.message;
|
|
53
|
+
return result ? (0, node_url_1.pathToFileURL)(result) : null;
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
options.importers = [
|
|
57
|
+
rebase
|
|
58
|
+
? (0, rebasing_importer_1.sassBindWorkaround)(new rebasing_importer_1.ModuleUrlRebasingImporter(entryDirectory, directoryCache, rebaseSourceMaps, proxyImporter.findFileUrl))
|
|
59
|
+
: proxyImporter,
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
if (rebase && options.loadPaths?.length) {
|
|
63
|
+
options.importers ??= [];
|
|
64
|
+
options.importers.push((0, rebasing_importer_1.sassBindWorkaround)(new rebasing_importer_1.LoadPathsUrlRebasingImporter(entryDirectory, directoryCache, rebaseSourceMaps, options.loadPaths)));
|
|
65
|
+
options.loadPaths = undefined;
|
|
66
|
+
}
|
|
67
|
+
let relativeImporter;
|
|
68
|
+
if (rebase) {
|
|
69
|
+
relativeImporter = (0, rebasing_importer_1.sassBindWorkaround)(new rebasing_importer_1.RelativeUrlRebasingImporter(entryDirectory, directoryCache, rebaseSourceMaps));
|
|
70
|
+
}
|
|
71
|
+
// The synchronous Sass render function can be up to two times faster than the async variant
|
|
72
|
+
const result = (0, sass_1.compileString)(source, {
|
|
73
|
+
...options,
|
|
74
|
+
// URL is not serializable so to convert to string in the parent and back to URL here.
|
|
75
|
+
url: (0, node_url_1.pathToFileURL)(options.url),
|
|
76
|
+
// The `importer` option (singular) handles relative imports
|
|
77
|
+
importer: relativeImporter,
|
|
78
|
+
logger: hasLogger
|
|
79
|
+
? {
|
|
80
|
+
warn(message, warnOptions) {
|
|
81
|
+
warnings ??= [];
|
|
82
|
+
warnings.push({
|
|
83
|
+
...warnOptions,
|
|
84
|
+
message,
|
|
85
|
+
span: warnOptions.span && convertSourceSpan(warnOptions.span),
|
|
86
|
+
...convertDeprecation(warnOptions.deprecation,
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
|
+
warnOptions.deprecationType),
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
}
|
|
92
|
+
: undefined,
|
|
93
|
+
});
|
|
94
|
+
if (result.sourceMap && rebaseSourceMaps?.size) {
|
|
95
|
+
// Merge the intermediate rebasing source maps into the final Sass generated source map.
|
|
96
|
+
// Casting is required due to small but compatible differences in typings between the packages.
|
|
97
|
+
result.sourceMap = (0, remapping_1.default)(result.sourceMap,
|
|
98
|
+
// To prevent an infinite lookup loop, skip getting the source when the rebasing source map
|
|
99
|
+
// is referencing its original self.
|
|
100
|
+
(file, context) => (file !== context.importer ? rebaseSourceMaps.get(file) : null));
|
|
101
|
+
}
|
|
102
|
+
node_worker_threads_1.parentPort.postMessage({
|
|
103
|
+
id,
|
|
104
|
+
warnings,
|
|
105
|
+
result: {
|
|
106
|
+
...result,
|
|
107
|
+
// URL is not serializable so to convert to string here and back to URL in the parent.
|
|
108
|
+
loadedUrls: result.loadedUrls.map((p) => (0, node_url_1.fileURLToPath)(p)),
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
// Needed because V8 will only serialize the message and stack properties of an Error instance.
|
|
114
|
+
if (error instanceof sass_1.Exception) {
|
|
115
|
+
const { span, message, stack, sassMessage, sassStack } = error;
|
|
116
|
+
node_worker_threads_1.parentPort.postMessage({
|
|
117
|
+
id,
|
|
118
|
+
warnings,
|
|
119
|
+
error: {
|
|
120
|
+
span: convertSourceSpan(span),
|
|
121
|
+
message,
|
|
122
|
+
stack,
|
|
123
|
+
sassMessage,
|
|
124
|
+
sassStack,
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
else if (error instanceof Error) {
|
|
129
|
+
const { message, stack } = error;
|
|
130
|
+
node_worker_threads_1.parentPort.postMessage({ id, warnings, error: { message, stack } });
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
node_worker_threads_1.parentPort.postMessage({
|
|
134
|
+
id,
|
|
135
|
+
warnings,
|
|
136
|
+
error: { message: 'An unknown error has occurred.' },
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
/**
|
|
142
|
+
* Converts a Sass SourceSpan object into a serializable form.
|
|
143
|
+
* The SourceSpan object contains a URL property which must be converted into a string.
|
|
144
|
+
* Also, most of the interface's properties are get accessors and are not automatically
|
|
145
|
+
* serialized when sent back from the worker.
|
|
146
|
+
*
|
|
147
|
+
* @param span The Sass SourceSpan object to convert.
|
|
148
|
+
* @returns A serializable form of the SourceSpan object.
|
|
149
|
+
*/
|
|
150
|
+
function convertSourceSpan(span) {
|
|
151
|
+
return {
|
|
152
|
+
text: span.text,
|
|
153
|
+
context: span.context,
|
|
154
|
+
end: {
|
|
155
|
+
column: span.end.column,
|
|
156
|
+
offset: span.end.offset,
|
|
157
|
+
line: span.end.line,
|
|
158
|
+
},
|
|
159
|
+
start: {
|
|
160
|
+
column: span.start.column,
|
|
161
|
+
offset: span.start.offset,
|
|
162
|
+
line: span.start.line,
|
|
163
|
+
},
|
|
164
|
+
url: span.url ? (0, node_url_1.fileURLToPath)(span.url) : undefined,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function convertDeprecation(deprecation, deprecationType) {
|
|
168
|
+
if (!deprecation || !deprecationType) {
|
|
169
|
+
return { deprecation: false };
|
|
170
|
+
}
|
|
171
|
+
const { obsoleteIn, deprecatedIn, ...rest } = deprecationType;
|
|
172
|
+
return {
|
|
173
|
+
deprecation: true,
|
|
174
|
+
deprecationType: {
|
|
175
|
+
...rest,
|
|
176
|
+
obsoleteIn: obsoleteIn
|
|
177
|
+
? {
|
|
178
|
+
major: obsoleteIn.major,
|
|
179
|
+
minor: obsoleteIn.minor,
|
|
180
|
+
patch: obsoleteIn.patch,
|
|
181
|
+
}
|
|
182
|
+
: null,
|
|
183
|
+
deprecatedIn: deprecatedIn
|
|
184
|
+
? {
|
|
185
|
+
major: deprecatedIn.major,
|
|
186
|
+
minor: deprecatedIn.minor,
|
|
187
|
+
patch: deprecatedIn.patch,
|
|
188
|
+
}
|
|
189
|
+
: null,
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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 { Connect, Plugin } from 'vite';
|
|
9
|
+
export interface AngularMemoryPluginOptions {
|
|
10
|
+
workspaceRoot: string;
|
|
11
|
+
virtualProjectRoot: string;
|
|
12
|
+
outputFiles: Map<string, {
|
|
13
|
+
contents: Uint8Array;
|
|
14
|
+
servable: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
assets: Map<string, string>;
|
|
17
|
+
ssr: boolean;
|
|
18
|
+
external?: string[];
|
|
19
|
+
extensionMiddleware?: Connect.NextHandleFunction[];
|
|
20
|
+
extraHeaders?: Record<string, string>;
|
|
21
|
+
indexHtmlTransformer?: (content: string) => Promise<string>;
|
|
22
|
+
normalizePath: (path: string) => string;
|
|
23
|
+
}
|
|
24
|
+
export declare function createAngularMemoryPlugin(options: AngularMemoryPluginOptions): Plugin;
|