@angular-devkit/build-angular 18.0.0-next.2 → 18.0.0-next.4
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/builders.json +1 -5
- package/package.json +21 -20
- package/src/builders/app-shell/index.js +3 -5
- package/src/builders/browser/index.d.ts +1 -1
- package/src/builders/browser/index.js +9 -13
- package/src/builders/browser-esbuild/index.d.ts +2 -2
- package/src/builders/browser-esbuild/index.js +6 -9
- package/src/builders/dev-server/builder.d.ts +2 -2
- package/src/builders/dev-server/builder.js +11 -6
- package/src/builders/dev-server/index.d.ts +1 -1
- package/src/builders/dev-server/webpack-server.d.ts +1 -1
- package/src/builders/dev-server/webpack-server.js +5 -6
- package/src/builders/extract-i18n/application-extraction.js +2 -2
- package/src/builders/extract-i18n/builder.js +3 -4
- package/src/builders/extract-i18n/options.d.ts +1 -1
- package/src/builders/extract-i18n/options.js +2 -2
- package/src/builders/jest/index.js +2 -2
- package/src/builders/karma/index.js +3 -4
- package/src/builders/ng-packagr/index.js +8 -7
- package/src/builders/ng-packagr/schema.d.ts +4 -0
- package/src/builders/ng-packagr/schema.json +4 -0
- package/src/builders/prerender/index.js +2 -2
- package/src/builders/prerender/render-worker.js +1 -1
- package/src/builders/server/index.js +3 -4
- package/src/builders/server/platform-server-exports-loader.js +2 -1
- package/src/builders/ssr-dev-server/index.js +34 -34
- package/src/builders/web-test-runner/index.js +2 -2
- package/src/index.d.ts +1 -1
- package/src/index.js +2 -2
- package/src/tools/babel/presets/application.js +1 -1
- package/src/tools/webpack/configs/styles.js +2 -2
- package/src/tools/webpack/plugins/any-component-style-budget-checker.d.ts +2 -2
- package/src/tools/webpack/plugins/any-component-style-budget-checker.js +14 -17
- package/src/tools/webpack/plugins/css-optimizer-plugin.js +2 -2
- package/src/tools/webpack/plugins/index-html-webpack-plugin.d.ts +1 -1
- package/src/tools/webpack/plugins/index-html-webpack-plugin.js +3 -3
- package/src/tools/webpack/plugins/javascript-optimizer-plugin.js +2 -2
- package/src/tools/webpack/plugins/service-worker-plugin.js +2 -2
- package/src/tools/webpack/utils/stats.d.ts +1 -14
- package/src/tools/webpack/utils/stats.js +3 -207
- package/src/utils/action-executor.d.ts +1 -1
- package/src/utils/i18n-inlining.d.ts +1 -1
- package/src/utils/i18n-webpack.d.ts +16 -0
- package/src/utils/i18n-webpack.js +107 -0
- package/src/utils/index.d.ts +1 -2
- package/src/utils/index.js +4 -2
- package/src/utils/normalize-builder-schema.js +2 -2
- package/src/utils/normalize-cache.js +1 -1
- package/src/utils/normalize-optimization.d.ts +1 -1
- package/src/utils/normalize-optimization.js +0 -2
- package/src/utils/output-paths.d.ts +1 -1
- package/src/utils/webpack-browser-config.d.ts +1 -1
- package/src/utils/webpack-browser-config.js +2 -2
- package/src/builders/application/build-action.d.ts +0 -33
- package/src/builders/application/build-action.js +0 -183
- package/src/builders/application/execute-build.d.ts +0 -11
- package/src/builders/application/execute-build.js +0 -127
- package/src/builders/application/execute-post-bundle.d.ts +0 -25
- package/src/builders/application/execute-post-bundle.js +0 -96
- package/src/builders/application/i18n.d.ts +0 -29
- package/src/builders/application/i18n.js +0 -128
- package/src/builders/application/index.d.ts +0 -57
- package/src/builders/application/index.js +0 -121
- package/src/builders/application/options.d.ts +0 -149
- package/src/builders/application/options.js +0 -352
- package/src/builders/application/schema.d.ts +0 -512
- package/src/builders/application/schema.js +0 -58
- package/src/builders/application/schema.json +0 -635
- package/src/builders/application/setup-bundling.d.ts +0 -19
- package/src/builders/application/setup-bundling.js +0 -71
- package/src/builders/dev-server/vite-server.d.ts +0 -30
- package/src/builders/dev-server/vite-server.js +0 -502
- package/src/tools/babel/plugins/adjust-static-class-members.d.ts +0 -27
- package/src/tools/babel/plugins/adjust-static-class-members.js +0 -351
- package/src/tools/babel/plugins/adjust-typescript-enums.d.ts +0 -23
- package/src/tools/babel/plugins/adjust-typescript-enums.js +0 -113
- package/src/tools/babel/plugins/elide-angular-metadata.d.ts +0 -23
- package/src/tools/babel/plugins/elide-angular-metadata.js +0 -110
- package/src/tools/babel/plugins/index.d.ts +0 -11
- package/src/tools/babel/plugins/index.js +0 -21
- package/src/tools/babel/plugins/pure-toplevel-functions.d.ts +0 -16
- package/src/tools/babel/plugins/pure-toplevel-functions.js +0 -90
- package/src/tools/esbuild/angular/angular-host.d.ts +0 -26
- package/src/tools/esbuild/angular/angular-host.js +0 -72
- package/src/tools/esbuild/angular/compilation/angular-compilation.d.ts +0 -42
- package/src/tools/esbuild/angular/compilation/angular-compilation.js +0 -94
- package/src/tools/esbuild/angular/compilation/aot-compilation.d.ts +0 -21
- package/src/tools/esbuild/angular/compilation/aot-compilation.js +0 -228
- package/src/tools/esbuild/angular/compilation/factory.d.ts +0 -16
- package/src/tools/esbuild/angular/compilation/factory.js +0 -56
- package/src/tools/esbuild/angular/compilation/index.d.ts +0 -10
- package/src/tools/esbuild/angular/compilation/index.js +0 -17
- package/src/tools/esbuild/angular/compilation/jit-compilation.d.ts +0 -21
- package/src/tools/esbuild/angular/compilation/jit-compilation.js +0 -106
- package/src/tools/esbuild/angular/compilation/noop-compilation.d.ts +0 -20
- package/src/tools/esbuild/angular/compilation/noop-compilation.js +0 -26
- package/src/tools/esbuild/angular/compilation/parallel-compilation.d.ts +0 -42
- package/src/tools/esbuild/angular/compilation/parallel-compilation.js +0 -123
- package/src/tools/esbuild/angular/compilation/parallel-worker.d.ts +0 -33
- package/src/tools/esbuild/angular/compilation/parallel-worker.js +0 -90
- package/src/tools/esbuild/angular/compilation-state.d.ts +0 -15
- package/src/tools/esbuild/angular/compilation-state.js +0 -44
- package/src/tools/esbuild/angular/compiler-plugin.d.ts +0 -27
- package/src/tools/esbuild/angular/compiler-plugin.js +0 -433
- package/src/tools/esbuild/angular/component-stylesheets.d.ts +0 -44
- package/src/tools/esbuild/angular/component-stylesheets.js +0 -150
- package/src/tools/esbuild/angular/diagnostics.d.ts +0 -15
- package/src/tools/esbuild/angular/diagnostics.js +0 -69
- package/src/tools/esbuild/angular/file-reference-tracker.d.ts +0 -17
- package/src/tools/esbuild/angular/file-reference-tracker.js +0 -57
- package/src/tools/esbuild/angular/jit-plugin-callbacks.d.ts +0 -23
- package/src/tools/esbuild/angular/jit-plugin-callbacks.js +0 -117
- package/src/tools/esbuild/angular/jit-resource-transformer.d.ts +0 -17
- package/src/tools/esbuild/angular/jit-resource-transformer.js +0 -186
- package/src/tools/esbuild/angular/source-file-cache.d.ts +0 -18
- package/src/tools/esbuild/angular/source-file-cache.js +0 -65
- package/src/tools/esbuild/angular/uri.d.ts +0 -54
- package/src/tools/esbuild/angular/uri.js +0 -74
- package/src/tools/esbuild/angular/web-worker-transformer.d.ts +0 -17
- package/src/tools/esbuild/angular/web-worker-transformer.js +0 -94
- package/src/tools/esbuild/application-code-bundle.d.ts +0 -20
- package/src/tools/esbuild/application-code-bundle.js +0 -368
- package/src/tools/esbuild/budget-stats.d.ts +0 -19
- package/src/tools/esbuild/budget-stats.js +0 -59
- package/src/tools/esbuild/bundler-context.d.ts +0 -75
- package/src/tools/esbuild/bundler-context.js +0 -366
- package/src/tools/esbuild/bundler-execution-result.d.ts +0 -71
- package/src/tools/esbuild/bundler-execution-result.js +0 -131
- package/src/tools/esbuild/cache.d.ts +0 -88
- package/src/tools/esbuild/cache.js +0 -92
- package/src/tools/esbuild/commonjs-checker.d.ts +0 -28
- package/src/tools/esbuild/commonjs-checker.js +0 -151
- package/src/tools/esbuild/compiler-plugin-options.d.ts +0 -16
- package/src/tools/esbuild/compiler-plugin-options.js +0 -49
- package/src/tools/esbuild/external-packages-plugin.d.ts +0 -18
- package/src/tools/esbuild/external-packages-plugin.js +0 -70
- package/src/tools/esbuild/global-scripts.d.ts +0 -16
- package/src/tools/esbuild/global-scripts.js +0 -142
- package/src/tools/esbuild/global-styles.d.ts +0 -10
- package/src/tools/esbuild/global-styles.js +0 -74
- package/src/tools/esbuild/i18n-inliner-worker.d.ts +0 -42
- package/src/tools/esbuild/i18n-inliner-worker.js +0 -136
- package/src/tools/esbuild/i18n-inliner.d.ts +0 -44
- package/src/tools/esbuild/i18n-inliner.js +0 -150
- package/src/tools/esbuild/i18n-locale-plugin.d.ts +0 -22
- package/src/tools/esbuild/i18n-locale-plugin.js +0 -120
- package/src/tools/esbuild/index-html-generator.d.ts +0 -15
- package/src/tools/esbuild/index-html-generator.js +0 -129
- package/src/tools/esbuild/javascript-transformer-worker.d.ts +0 -19
- package/src/tools/esbuild/javascript-transformer-worker.js +0 -154
- package/src/tools/esbuild/javascript-transformer.d.ts +0 -54
- package/src/tools/esbuild/javascript-transformer.js +0 -143
- package/src/tools/esbuild/license-extractor.d.ts +0 -25
- package/src/tools/esbuild/license-extractor.js +0 -158
- package/src/tools/esbuild/load-result-cache.d.ts +0 -21
- package/src/tools/esbuild/load-result-cache.js +0 -75
- package/src/tools/esbuild/profiling.d.ts +0 -11
- package/src/tools/esbuild/profiling.js +0 -78
- package/src/tools/esbuild/rxjs-esm-resolution-plugin.d.ts +0 -18
- package/src/tools/esbuild/rxjs-esm-resolution-plugin.js +0 -44
- package/src/tools/esbuild/sourcemap-ignorelist-plugin.d.ts +0 -17
- package/src/tools/esbuild/sourcemap-ignorelist-plugin.js +0 -73
- package/src/tools/esbuild/stylesheets/bundle-options.d.ts +0 -35
- package/src/tools/esbuild/stylesheets/bundle-options.js +0 -64
- package/src/tools/esbuild/stylesheets/css-inline-fonts-plugin.d.ts +0 -25
- package/src/tools/esbuild/stylesheets/css-inline-fonts-plugin.js +0 -57
- package/src/tools/esbuild/stylesheets/css-language.d.ts +0 -9
- package/src/tools/esbuild/stylesheets/css-language.js +0 -15
- package/src/tools/esbuild/stylesheets/css-resource-plugin.d.ts +0 -18
- package/src/tools/esbuild/stylesheets/css-resource-plugin.js +0 -107
- package/src/tools/esbuild/stylesheets/less-language.d.ts +0 -9
- package/src/tools/esbuild/stylesheets/less-language.js +0 -155
- package/src/tools/esbuild/stylesheets/sass-language.d.ts +0 -10
- package/src/tools/esbuild/stylesheets/sass-language.js +0 -185
- package/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.d.ts +0 -58
- package/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.js +0 -282
- package/src/tools/esbuild/utils.d.ts +0 -41
- package/src/tools/esbuild/utils.js +0 -378
- package/src/tools/esbuild/virtual-module-plugin.d.ts +0 -33
- package/src/tools/esbuild/virtual-module-plugin.js +0 -43
- package/src/tools/esbuild/watcher.d.ts +0 -25
- package/src/tools/esbuild/watcher.js +0 -118
- package/src/tools/sass/lexer.d.ts +0 -18
- package/src/tools/sass/lexer.js +0 -161
- package/src/tools/sass/rebasing-importer.d.ts +0 -101
- package/src/tools/sass/rebasing-importer.js +0 -337
- package/src/tools/sass/sass-service.d.ts +0 -49
- package/src/tools/sass/sass-service.js +0 -213
- package/src/tools/sass/worker.d.ts +0 -8
- package/src/tools/sass/worker.js +0 -164
- package/src/tools/vite/angular-memory-plugin.d.ts +0 -24
- package/src/tools/vite/angular-memory-plugin.js +0 -268
- package/src/tools/vite/i18n-locale-plugin.d.ts +0 -18
- package/src/tools/vite/i18n-locale-plugin.js +0 -55
- package/src/typings.d.ts +0 -21
- package/src/utils/bundle-calculator.d.ts +0 -44
- package/src/utils/bundle-calculator.js +0 -302
- package/src/utils/check-port.d.ts +0 -8
- package/src/utils/check-port.js +0 -58
- package/src/utils/delete-output-dir.d.ts +0 -11
- package/src/utils/delete-output-dir.js +0 -46
- package/src/utils/i18n-options.d.ts +0 -40
- package/src/utils/i18n-options.js +0 -254
- package/src/utils/index-file/augment-index-html.d.ts +0 -40
- package/src/utils/index-file/augment-index-html.js +0 -238
- package/src/utils/index-file/html-rewriting-stream.d.ts +0 -11
- package/src/utils/index-file/html-rewriting-stream.js +0 -28
- package/src/utils/index-file/index-html-generator.d.ts +0 -47
- package/src/utils/index-file/index-html-generator.js +0 -119
- package/src/utils/index-file/inline-critical-css.d.ts +0 -24
- package/src/utils/index-file/inline-critical-css.js +0 -179
- package/src/utils/index-file/inline-fonts.d.ts +0 -23
- package/src/utils/index-file/inline-fonts.js +0 -267
- package/src/utils/index-file/style-nonce.d.ts +0 -12
- package/src/utils/index-file/style-nonce.js +0 -53
- package/src/utils/load-proxy-config.d.ts +0 -8
- package/src/utils/load-proxy-config.js +0 -192
- package/src/utils/load-translations.d.ts +0 -16
- package/src/utils/load-translations.js +0 -84
- package/src/utils/postcss-configuration.d.ts +0 -17
- package/src/utils/postcss-configuration.js +0 -86
- package/src/utils/purge-cache.d.ts +0 -10
- package/src/utils/purge-cache.js +0 -40
- package/src/utils/routes-extractor/extractor.d.ts +0 -15
- package/src/utils/routes-extractor/extractor.js +0 -97
- package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.d.ts +0 -18
- package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.js +0 -129
- package/src/utils/server-rendering/esm-in-memory-loader/register-hooks.d.ts +0 -8
- package/src/utils/server-rendering/esm-in-memory-loader/register-hooks.js +0 -13
- package/src/utils/server-rendering/fetch-patch.d.ts +0 -8
- package/src/utils/server-rendering/fetch-patch.js +0 -66
- package/src/utils/server-rendering/load-esm-from-memory.d.ts +0 -10
- package/src/utils/server-rendering/load-esm-from-memory.js +0 -26
- package/src/utils/server-rendering/main-bundle-exports.d.ts +0 -27
- package/src/utils/server-rendering/main-bundle-exports.js +0 -9
- package/src/utils/server-rendering/prerender.d.ts +0 -23
- package/src/utils/server-rendering/prerender.js +0 -192
- package/src/utils/server-rendering/render-page.d.ts +0 -26
- package/src/utils/server-rendering/render-page.js +0 -110
- package/src/utils/server-rendering/render-worker.d.ts +0 -22
- package/src/utils/server-rendering/render-worker.js +0 -30
- package/src/utils/server-rendering/routes-extractor-worker.d.ts +0 -21
- package/src/utils/server-rendering/routes-extractor-worker.js +0 -53
- package/src/utils/service-worker.d.ts +0 -25
- package/src/utils/service-worker.js +0 -211
- package/src/utils/supported-browsers.d.ts +0 -10
- package/src/utils/supported-browsers.js +0 -42
- package/src/utils/version.d.ts +0 -8
- package/src/utils/version.js +0 -59
|
@@ -1,213 +0,0 @@
|
|
|
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;
|
package/src/tools/sass/worker.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
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, { deprecation, span, stack }) {
|
|
81
|
-
warnings ??= [];
|
|
82
|
-
warnings.push({
|
|
83
|
-
message,
|
|
84
|
-
deprecation,
|
|
85
|
-
stack,
|
|
86
|
-
span: span && convertSourceSpan(span),
|
|
87
|
-
});
|
|
88
|
-
},
|
|
89
|
-
}
|
|
90
|
-
: undefined,
|
|
91
|
-
});
|
|
92
|
-
if (result.sourceMap && rebaseSourceMaps?.size) {
|
|
93
|
-
// Merge the intermediate rebasing source maps into the final Sass generated source map.
|
|
94
|
-
// Casting is required due to small but compatible differences in typings between the packages.
|
|
95
|
-
result.sourceMap = (0, remapping_1.default)(result.sourceMap,
|
|
96
|
-
// To prevent an infinite lookup loop, skip getting the source when the rebasing source map
|
|
97
|
-
// is referencing its original self.
|
|
98
|
-
(file, context) => (file !== context.importer ? rebaseSourceMaps.get(file) : null));
|
|
99
|
-
}
|
|
100
|
-
node_worker_threads_1.parentPort.postMessage({
|
|
101
|
-
id,
|
|
102
|
-
warnings,
|
|
103
|
-
result: {
|
|
104
|
-
...result,
|
|
105
|
-
// URL is not serializable so to convert to string here and back to URL in the parent.
|
|
106
|
-
loadedUrls: result.loadedUrls.map((p) => (0, node_url_1.fileURLToPath)(p)),
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
// Needed because V8 will only serialize the message and stack properties of an Error instance.
|
|
112
|
-
if (error instanceof sass_1.Exception) {
|
|
113
|
-
const { span, message, stack, sassMessage, sassStack } = error;
|
|
114
|
-
node_worker_threads_1.parentPort.postMessage({
|
|
115
|
-
id,
|
|
116
|
-
warnings,
|
|
117
|
-
error: {
|
|
118
|
-
span: convertSourceSpan(span),
|
|
119
|
-
message,
|
|
120
|
-
stack,
|
|
121
|
-
sassMessage,
|
|
122
|
-
sassStack,
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
else if (error instanceof Error) {
|
|
127
|
-
const { message, stack } = error;
|
|
128
|
-
node_worker_threads_1.parentPort.postMessage({ id, warnings, error: { message, stack } });
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
node_worker_threads_1.parentPort.postMessage({
|
|
132
|
-
id,
|
|
133
|
-
warnings,
|
|
134
|
-
error: { message: 'An unknown error has occurred.' },
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
/**
|
|
140
|
-
* Converts a Sass SourceSpan object into a serializable form.
|
|
141
|
-
* The SourceSpan object contains a URL property which must be converted into a string.
|
|
142
|
-
* Also, most of the interface's properties are get accessors and are not automatically
|
|
143
|
-
* serialized when sent back from the worker.
|
|
144
|
-
*
|
|
145
|
-
* @param span The Sass SourceSpan object to convert.
|
|
146
|
-
* @returns A serializable form of the SourceSpan object.
|
|
147
|
-
*/
|
|
148
|
-
function convertSourceSpan(span) {
|
|
149
|
-
return {
|
|
150
|
-
text: span.text,
|
|
151
|
-
context: span.context,
|
|
152
|
-
end: {
|
|
153
|
-
column: span.end.column,
|
|
154
|
-
offset: span.end.offset,
|
|
155
|
-
line: span.end.line,
|
|
156
|
-
},
|
|
157
|
-
start: {
|
|
158
|
-
column: span.start.column,
|
|
159
|
-
offset: span.start.offset,
|
|
160
|
-
line: span.start.line,
|
|
161
|
-
},
|
|
162
|
-
url: span.url ? (0, node_url_1.fileURLToPath)(span.url) : undefined,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
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;
|
|
@@ -1,268 +0,0 @@
|
|
|
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.createAngularMemoryPlugin = void 0;
|
|
14
|
-
const remapping_1 = __importDefault(require("@ampproject/remapping"));
|
|
15
|
-
const mrmime_1 = require("mrmime");
|
|
16
|
-
const node_assert_1 = __importDefault(require("node:assert"));
|
|
17
|
-
const promises_1 = require("node:fs/promises");
|
|
18
|
-
const node_path_1 = require("node:path");
|
|
19
|
-
const render_page_1 = require("../../utils/server-rendering/render-page");
|
|
20
|
-
// eslint-disable-next-line max-lines-per-function
|
|
21
|
-
function createAngularMemoryPlugin(options) {
|
|
22
|
-
const { workspaceRoot, virtualProjectRoot, outputFiles, assets, external, ssr, extensionMiddleware, extraHeaders, indexHtmlTransformer, normalizePath, } = options;
|
|
23
|
-
return {
|
|
24
|
-
name: 'vite:angular-memory',
|
|
25
|
-
// Ensures plugin hooks run before built-in Vite hooks
|
|
26
|
-
enforce: 'pre',
|
|
27
|
-
async resolveId(source, importer) {
|
|
28
|
-
// Prevent vite from resolving an explicit external dependency (`externalDependencies` option)
|
|
29
|
-
if (external?.includes(source)) {
|
|
30
|
-
// This is still not ideal since Vite will still transform the import specifier to
|
|
31
|
-
// `/@id/${source}` but is currently closer to a raw external than a resolved file path.
|
|
32
|
-
return source;
|
|
33
|
-
}
|
|
34
|
-
if (importer && source[0] === '.' && importer.startsWith(virtualProjectRoot)) {
|
|
35
|
-
// Remove query if present
|
|
36
|
-
const [importerFile] = importer.split('?', 1);
|
|
37
|
-
source =
|
|
38
|
-
'/' + normalizePath((0, node_path_1.join)((0, node_path_1.dirname)((0, node_path_1.relative)(virtualProjectRoot, importerFile)), source));
|
|
39
|
-
}
|
|
40
|
-
const [file] = source.split('?', 1);
|
|
41
|
-
if (outputFiles.has(file)) {
|
|
42
|
-
return (0, node_path_1.join)(virtualProjectRoot, source);
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
async load(id) {
|
|
46
|
-
const [file] = id.split('?', 1);
|
|
47
|
-
const relativeFile = '/' + normalizePath((0, node_path_1.relative)(virtualProjectRoot, file));
|
|
48
|
-
const codeContents = outputFiles.get(relativeFile)?.contents;
|
|
49
|
-
if (codeContents === undefined) {
|
|
50
|
-
if (relativeFile.endsWith('/node_modules/vite/dist/client/client.mjs')) {
|
|
51
|
-
return {
|
|
52
|
-
code: await loadViteClientCode(file),
|
|
53
|
-
map: await (0, promises_1.readFile)(file + '.map', 'utf-8'),
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const code = Buffer.from(codeContents).toString('utf-8');
|
|
59
|
-
const mapContents = outputFiles.get(relativeFile + '.map')?.contents;
|
|
60
|
-
return {
|
|
61
|
-
// Remove source map URL comments from the code if a sourcemap is present.
|
|
62
|
-
// Vite will inline and add an additional sourcemap URL for the sourcemap.
|
|
63
|
-
code: mapContents ? code.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, '') : code,
|
|
64
|
-
map: mapContents && Buffer.from(mapContents).toString('utf-8'),
|
|
65
|
-
};
|
|
66
|
-
},
|
|
67
|
-
// eslint-disable-next-line max-lines-per-function
|
|
68
|
-
configureServer(server) {
|
|
69
|
-
const originalssrTransform = server.ssrTransform;
|
|
70
|
-
server.ssrTransform = async (code, map, url, originalCode) => {
|
|
71
|
-
const result = await originalssrTransform(code, null, url, originalCode);
|
|
72
|
-
if (!result || !result.map || !map) {
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
const remappedMap = (0, remapping_1.default)([result.map, map], () => null);
|
|
76
|
-
// Set the sourcemap root to the workspace root. This is needed since we set a virtual path as root.
|
|
77
|
-
remappedMap.sourceRoot = normalizePath(workspaceRoot) + '/';
|
|
78
|
-
return {
|
|
79
|
-
...result,
|
|
80
|
-
map: remappedMap,
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
// Assets and resources get handled first
|
|
84
|
-
server.middlewares.use(function angularAssetsMiddleware(req, res, next) {
|
|
85
|
-
if (req.url === undefined || res.writableEnded) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
// Parse the incoming request.
|
|
89
|
-
// The base of the URL is unused but required to parse the URL.
|
|
90
|
-
const pathname = pathnameWithoutBasePath(req.url, server.config.base);
|
|
91
|
-
const extension = (0, node_path_1.extname)(pathname);
|
|
92
|
-
// Rewrite all build assets to a vite raw fs URL
|
|
93
|
-
const assetSourcePath = assets.get(pathname);
|
|
94
|
-
if (assetSourcePath !== undefined) {
|
|
95
|
-
// Workaround to disable Vite transformer middleware.
|
|
96
|
-
// See: https://github.com/vitejs/vite/blob/746a1daab0395f98f0afbdee8f364cb6cf2f3b3f/packages/vite/src/node/server/middlewares/transform.ts#L201 and
|
|
97
|
-
// https://github.com/vitejs/vite/blob/746a1daab0395f98f0afbdee8f364cb6cf2f3b3f/packages/vite/src/node/server/transformRequest.ts#L204-L206
|
|
98
|
-
req.headers.accept = 'text/html';
|
|
99
|
-
// The encoding needs to match what happens in the vite static middleware.
|
|
100
|
-
// ref: https://github.com/vitejs/vite/blob/d4f13bd81468961c8c926438e815ab6b1c82735e/packages/vite/src/node/server/middlewares/static.ts#L163
|
|
101
|
-
req.url = `${server.config.base}@fs/${encodeURI(assetSourcePath)}`;
|
|
102
|
-
next();
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
// HTML fallbacking
|
|
106
|
-
// This matches what happens in the vite html fallback middleware.
|
|
107
|
-
// ref: https://github.com/vitejs/vite/blob/main/packages/vite/src/node/server/middlewares/htmlFallback.ts#L9
|
|
108
|
-
const htmlAssetSourcePath = pathname[pathname.length - 1] === '/'
|
|
109
|
-
? // Trailing slash check for `index.html`.
|
|
110
|
-
assets.get(pathname + 'index.html')
|
|
111
|
-
: // Non-trailing slash check for fallback `.html`
|
|
112
|
-
assets.get(pathname + '.html');
|
|
113
|
-
if (htmlAssetSourcePath) {
|
|
114
|
-
req.url = `${server.config.base}@fs/${encodeURI(htmlAssetSourcePath)}`;
|
|
115
|
-
next();
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
// Resource files are handled directly.
|
|
119
|
-
// Global stylesheets (CSS files) are currently considered resources to workaround
|
|
120
|
-
// dev server sourcemap issues with stylesheets.
|
|
121
|
-
if (extension !== '.js' && extension !== '.html') {
|
|
122
|
-
const outputFile = outputFiles.get(pathname);
|
|
123
|
-
if (outputFile?.servable) {
|
|
124
|
-
const mimeType = (0, mrmime_1.lookup)(extension);
|
|
125
|
-
if (mimeType) {
|
|
126
|
-
res.setHeader('Content-Type', mimeType);
|
|
127
|
-
}
|
|
128
|
-
res.setHeader('Cache-Control', 'no-cache');
|
|
129
|
-
if (extraHeaders) {
|
|
130
|
-
Object.entries(extraHeaders).forEach(([name, value]) => res.setHeader(name, value));
|
|
131
|
-
}
|
|
132
|
-
res.end(outputFile.contents);
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
next();
|
|
137
|
-
});
|
|
138
|
-
if (extensionMiddleware?.length) {
|
|
139
|
-
extensionMiddleware.forEach((middleware) => server.middlewares.use(middleware));
|
|
140
|
-
}
|
|
141
|
-
// Returning a function, installs middleware after the main transform middleware but
|
|
142
|
-
// before the built-in HTML middleware
|
|
143
|
-
return () => {
|
|
144
|
-
server.middlewares.use(angularHtmlFallbackMiddleware);
|
|
145
|
-
function angularSSRMiddleware(req, res, next) {
|
|
146
|
-
const url = req.originalUrl;
|
|
147
|
-
if (!req.url ||
|
|
148
|
-
// Skip if path is not defined.
|
|
149
|
-
!url ||
|
|
150
|
-
// Skip if path is like a file.
|
|
151
|
-
// NOTE: We use a mime type lookup to mitigate against matching requests like: /browse/pl.0ef59752c0cd457dbf1391f08cbd936f
|
|
152
|
-
lookupMimeTypeFromRequest(url)) {
|
|
153
|
-
next();
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
const rawHtml = outputFiles.get('/index.server.html')?.contents;
|
|
157
|
-
if (!rawHtml) {
|
|
158
|
-
next();
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
transformIndexHtmlAndAddHeaders(req.url, rawHtml, res, next, async (html) => {
|
|
162
|
-
const resolvedUrls = server.resolvedUrls;
|
|
163
|
-
const baseUrl = resolvedUrls?.local[0] ?? resolvedUrls?.network[0];
|
|
164
|
-
const { content } = await (0, render_page_1.renderPage)({
|
|
165
|
-
document: html,
|
|
166
|
-
route: new URL(req.originalUrl ?? '/', baseUrl).toString(),
|
|
167
|
-
serverContext: 'ssr',
|
|
168
|
-
loadBundle: (uri) =>
|
|
169
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
170
|
-
server.ssrLoadModule(uri.slice(1)),
|
|
171
|
-
// Files here are only needed for critical CSS inlining.
|
|
172
|
-
outputFiles: {},
|
|
173
|
-
// TODO: add support for critical css inlining.
|
|
174
|
-
inlineCriticalCss: false,
|
|
175
|
-
});
|
|
176
|
-
return indexHtmlTransformer && content ? await indexHtmlTransformer(content) : content;
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
if (ssr) {
|
|
180
|
-
server.middlewares.use(angularSSRMiddleware);
|
|
181
|
-
}
|
|
182
|
-
server.middlewares.use(function angularIndexMiddleware(req, res, next) {
|
|
183
|
-
if (!req.url) {
|
|
184
|
-
next();
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
// Parse the incoming request.
|
|
188
|
-
// The base of the URL is unused but required to parse the URL.
|
|
189
|
-
const pathname = pathnameWithoutBasePath(req.url, server.config.base);
|
|
190
|
-
if (pathname === '/' || pathname === `/index.html`) {
|
|
191
|
-
const rawHtml = outputFiles.get('/index.html')?.contents;
|
|
192
|
-
if (rawHtml) {
|
|
193
|
-
transformIndexHtmlAndAddHeaders(req.url, rawHtml, res, next, indexHtmlTransformer);
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
next();
|
|
198
|
-
});
|
|
199
|
-
};
|
|
200
|
-
function transformIndexHtmlAndAddHeaders(url, rawHtml, res, next, additionalTransformer) {
|
|
201
|
-
server
|
|
202
|
-
.transformIndexHtml(url, Buffer.from(rawHtml).toString('utf-8'))
|
|
203
|
-
.then(async (processedHtml) => {
|
|
204
|
-
if (additionalTransformer) {
|
|
205
|
-
const content = await additionalTransformer(processedHtml);
|
|
206
|
-
if (!content) {
|
|
207
|
-
next();
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
processedHtml = content;
|
|
211
|
-
}
|
|
212
|
-
res.setHeader('Content-Type', 'text/html');
|
|
213
|
-
res.setHeader('Cache-Control', 'no-cache');
|
|
214
|
-
if (extraHeaders) {
|
|
215
|
-
Object.entries(extraHeaders).forEach(([name, value]) => res.setHeader(name, value));
|
|
216
|
-
}
|
|
217
|
-
res.end(processedHtml);
|
|
218
|
-
})
|
|
219
|
-
.catch((error) => next(error));
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
exports.createAngularMemoryPlugin = createAngularMemoryPlugin;
|
|
225
|
-
/**
|
|
226
|
-
* Reads the resolved Vite client code from disk and updates the content to remove
|
|
227
|
-
* an unactionable suggestion to update the Vite configuration file to disable the
|
|
228
|
-
* error overlay. The Vite configuration file is not present when used in the Angular
|
|
229
|
-
* CLI.
|
|
230
|
-
* @param file The absolute path to the Vite client code.
|
|
231
|
-
* @returns
|
|
232
|
-
*/
|
|
233
|
-
async function loadViteClientCode(file) {
|
|
234
|
-
const originalContents = await (0, promises_1.readFile)(file, 'utf-8');
|
|
235
|
-
const updatedContents = originalContents.replace(`h('br'), 'You can also disable this overlay by setting ', ` +
|
|
236
|
-
`h('code', { part: 'config-option-name' }, 'server.hmr.overlay'), '` +
|
|
237
|
-
` to ', h('code', { part: 'config-option-value' }, 'false'), ' in ', h('code', { part: 'config-file-name' }, hmrConfigName), '.'`, '');
|
|
238
|
-
(0, node_assert_1.default)(originalContents !== updatedContents, 'Failed to update Vite client error overlay text.');
|
|
239
|
-
return updatedContents;
|
|
240
|
-
}
|
|
241
|
-
function pathnameWithoutBasePath(url, basePath) {
|
|
242
|
-
const parsedUrl = new URL(url, 'http://localhost');
|
|
243
|
-
const pathname = decodeURIComponent(parsedUrl.pathname);
|
|
244
|
-
// slice(basePath.length - 1) to retain the trailing slash
|
|
245
|
-
return basePath !== '/' && pathname.startsWith(basePath)
|
|
246
|
-
? pathname.slice(basePath.length - 1)
|
|
247
|
-
: pathname;
|
|
248
|
-
}
|
|
249
|
-
function angularHtmlFallbackMiddleware(req, res, next) {
|
|
250
|
-
// Similar to how it is handled in vite
|
|
251
|
-
// https://github.com/vitejs/vite/blob/main/packages/vite/src/node/server/middlewares/htmlFallback.ts#L15C19-L15C45
|
|
252
|
-
if ((req.method === 'GET' || req.method === 'HEAD') &&
|
|
253
|
-
(!req.url || !lookupMimeTypeFromRequest(req.url)) &&
|
|
254
|
-
(!req.headers.accept ||
|
|
255
|
-
req.headers.accept.includes('text/html') ||
|
|
256
|
-
req.headers.accept.includes('text/*') ||
|
|
257
|
-
req.headers.accept.includes('*/*'))) {
|
|
258
|
-
req.url = '/index.html';
|
|
259
|
-
}
|
|
260
|
-
next();
|
|
261
|
-
}
|
|
262
|
-
function lookupMimeTypeFromRequest(url) {
|
|
263
|
-
const extension = (0, node_path_1.extname)(url.split('?')[0]);
|
|
264
|
-
if (extension === '.ico') {
|
|
265
|
-
return 'image/x-icon';
|
|
266
|
-
}
|
|
267
|
-
return extension && (0, mrmime_1.lookup)(extension);
|
|
268
|
-
}
|