@nx/angular-rspack 20.8.2 → 21.0.0-beta.0
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/dist/lib/config/config-utils/browser-config.d.ts +4 -0
- package/dist/lib/config/config-utils/browser-config.d.ts.map +1 -0
- package/dist/lib/config/config-utils/browser-config.js +79 -0
- package/dist/lib/config/config-utils/common-config.d.ts +3 -0
- package/dist/lib/config/config-utils/common-config.d.ts.map +1 -0
- package/dist/lib/config/config-utils/common-config.js +143 -0
- package/dist/lib/config/config-utils/dev-server-config-utils.d.ts +4 -0
- package/dist/lib/config/config-utils/dev-server-config-utils.d.ts.map +1 -0
- package/dist/lib/config/config-utils/dev-server-config-utils.js +257 -0
- package/dist/lib/config/{entry-points.d.ts → config-utils/entry-points.d.ts} +1 -1
- package/dist/lib/config/config-utils/entry-points.d.ts.map +1 -0
- package/dist/lib/config/config-utils/get-stats-options.d.ts +3 -0
- package/dist/lib/config/config-utils/get-stats-options.d.ts.map +1 -0
- package/dist/lib/config/config-utils/get-stats-options.js +39 -0
- package/dist/lib/config/config-utils/helpers.d.ts +13 -0
- package/dist/lib/config/config-utils/helpers.d.ts.map +1 -0
- package/dist/lib/config/{helpers.js → config-utils/helpers.js} +33 -0
- package/dist/lib/config/config-utils/optimization-config.d.ts +5 -0
- package/dist/lib/config/config-utils/optimization-config.d.ts.map +1 -0
- package/dist/lib/config/config-utils/optimization-config.js +69 -0
- package/dist/lib/config/config-utils/server-config.d.ts +4 -0
- package/dist/lib/config/config-utils/server-config.d.ts.map +1 -0
- package/dist/lib/config/config-utils/server-config.js +88 -0
- package/dist/lib/config/config-utils/sourcemap-utils.d.ts +7 -0
- package/dist/lib/config/config-utils/sourcemap-utils.d.ts.map +1 -0
- package/dist/lib/config/config-utils/sourcemap-utils.js +48 -0
- package/dist/lib/config/config-utils/style-config-utils.d.ts +7 -0
- package/dist/lib/config/config-utils/style-config-utils.d.ts.map +1 -0
- package/dist/lib/config/config-utils/style-config-utils.js +352 -0
- package/dist/lib/config/config-utils/user-defined-config-helpers.d.ts +71 -0
- package/dist/lib/config/config-utils/user-defined-config-helpers.d.ts.map +1 -0
- package/dist/lib/config/config-utils/user-defined-config-helpers.js +23 -0
- package/dist/lib/config/create-config.d.ts +2 -75
- package/dist/lib/config/create-config.d.ts.map +1 -1
- package/dist/lib/config/create-config.js +17 -473
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +9 -0
- package/dist/lib/models/angular-rspack-plugin-options.d.ts +141 -10
- package/dist/lib/models/angular-rspack-plugin-options.d.ts.map +1 -1
- package/dist/lib/models/augmented-compilation.d.ts +2 -2
- package/dist/lib/models/augmented-compilation.d.ts.map +1 -1
- package/dist/lib/models/normalize-options.d.ts +2 -2
- package/dist/lib/models/normalize-options.d.ts.map +1 -1
- package/dist/lib/models/normalize-options.js +114 -80
- package/dist/lib/plugins/angular-rspack-plugin.d.ts.map +1 -1
- package/dist/lib/plugins/angular-rspack-plugin.js +58 -19
- package/dist/lib/plugins/angular-ssr-dev-server.d.ts +2 -2
- package/dist/lib/plugins/angular-ssr-dev-server.d.ts.map +1 -1
- package/dist/lib/plugins/angular-ssr-dev-server.js +19 -9
- package/dist/lib/plugins/any-component-style-budget-checker-plugin.d.ts +19 -0
- package/dist/lib/plugins/any-component-style-budget-checker-plugin.d.ts.map +1 -0
- package/dist/lib/plugins/any-component-style-budget-checker-plugin.js +65 -0
- package/dist/lib/plugins/i18n-inline-plugin.d.ts.map +1 -1
- package/dist/lib/plugins/i18n-inline-plugin.js +5 -3
- package/dist/lib/plugins/index-html-plugin.d.ts.map +1 -1
- package/dist/lib/plugins/index-html-plugin.js +2 -7
- package/dist/lib/plugins/loaders/angular-partial-transform.loader.d.ts.map +1 -1
- package/dist/lib/plugins/loaders/angular-partial-transform.loader.js +4 -1
- package/dist/lib/plugins/loaders/hmr-accept-loader.d.ts +11 -0
- package/dist/lib/plugins/loaders/hmr-accept-loader.d.ts.map +1 -0
- package/dist/lib/plugins/loaders/hmr-accept-loader.js +24 -0
- package/dist/lib/plugins/loaders/hmr-accept.d.ts +9 -0
- package/dist/lib/plugins/loaders/hmr-accept.d.ts.map +1 -0
- package/dist/lib/plugins/loaders/hmr-accept.js +183 -0
- package/dist/lib/plugins/loaders/platform-server-exports.loader.d.ts +5 -0
- package/dist/lib/plugins/loaders/platform-server-exports.loader.d.ts.map +1 -0
- package/dist/lib/plugins/loaders/platform-server-exports.loader.js +18 -0
- package/dist/lib/plugins/ng-rspack.d.ts.map +1 -1
- package/dist/lib/plugins/ng-rspack.js +38 -18
- package/dist/lib/plugins/prerender-plugin.d.ts +8 -0
- package/dist/lib/plugins/prerender-plugin.d.ts.map +1 -0
- package/dist/lib/plugins/prerender-plugin.js +219 -0
- package/dist/lib/plugins/progress-plugin.d.ts +12 -0
- package/dist/lib/plugins/progress-plugin.d.ts.map +1 -0
- package/dist/lib/plugins/progress-plugin.js +36 -0
- package/dist/lib/plugins/stats-json-plugin.d.ts +14 -0
- package/dist/lib/plugins/stats-json-plugin.d.ts.map +1 -0
- package/dist/lib/plugins/stats-json-plugin.js +70 -0
- package/dist/lib/plugins/suppress-js-for-css-chunks-plugin.d.ts +5 -0
- package/dist/lib/plugins/suppress-js-for-css-chunks-plugin.d.ts.map +1 -0
- package/dist/lib/plugins/suppress-js-for-css-chunks-plugin.js +34 -0
- package/dist/lib/plugins/tools/dev-tools-ignore-plugin.d.ts.map +1 -1
- package/dist/lib/plugins/tools/dev-tools-ignore-plugin.js +1 -1
- package/dist/lib/plugins/tools/render-worker.d.ts +31 -0
- package/dist/lib/plugins/tools/render-worker.d.ts.map +1 -0
- package/dist/lib/plugins/tools/render-worker.js +103 -0
- package/dist/lib/plugins/tools/routes-extractor-worker.d.ts +21 -0
- package/dist/lib/plugins/tools/routes-extractor-worker.d.ts.map +1 -0
- package/dist/lib/plugins/tools/routes-extractor-worker.js +46 -0
- package/dist/lib/plugins/tools/worker-pool.d.ts +13 -0
- package/dist/lib/plugins/tools/worker-pool.d.ts.map +1 -0
- package/dist/lib/plugins/tools/worker-pool.js +26 -0
- package/dist/lib/plugins/transfer-size-plugin.d.ts +12 -0
- package/dist/lib/plugins/transfer-size-plugin.d.ts.map +1 -0
- package/dist/lib/plugins/transfer-size-plugin.js +49 -0
- package/dist/lib/plugins/watch-file-logs-plugin.d.ts +12 -0
- package/dist/lib/plugins/watch-file-logs-plugin.d.ts.map +1 -0
- package/dist/lib/plugins/watch-file-logs-plugin.js +27 -0
- package/dist/lib/utils/async-chunks.d.ts +17 -0
- package/dist/lib/utils/async-chunks.d.ts.map +1 -0
- package/dist/lib/utils/async-chunks.js +44 -0
- package/dist/lib/utils/color.d.ts +11 -0
- package/dist/lib/utils/color.d.ts.map +1 -0
- package/dist/lib/utils/color.js +41 -0
- package/dist/lib/utils/index-file/add-body-script.d.ts +2 -0
- package/dist/lib/utils/index-file/add-body-script.d.ts.map +1 -0
- package/dist/lib/utils/index-file/add-body-script.js +15 -0
- package/dist/lib/utils/index-file/get-index-input-file.d.ts +3 -0
- package/dist/lib/utils/index-file/get-index-input-file.d.ts.map +1 -0
- package/dist/lib/utils/index-file/get-index-input-file.js +9 -0
- package/dist/lib/utils/index-file/get-index-output-file.d.ts +3 -0
- package/dist/lib/utils/index-file/get-index-output-file.d.ts.map +1 -0
- package/dist/lib/utils/index-file/get-index-output-file.js +10 -0
- package/dist/lib/utils/max-workers.d.ts +2 -0
- package/dist/lib/utils/max-workers.d.ts.map +1 -0
- package/dist/lib/utils/max-workers.js +21 -0
- package/dist/lib/utils/misc-helpers.d.ts +1 -0
- package/dist/lib/utils/misc-helpers.d.ts.map +1 -1
- package/dist/lib/utils/misc-helpers.js +4 -0
- package/dist/lib/utils/postcss-cli-resources.d.ts +22 -0
- package/dist/lib/utils/postcss-cli-resources.d.ts.map +1 -0
- package/dist/lib/utils/postcss-cli-resources.js +158 -0
- package/dist/lib/utils/postcss-configuration.d.ts +18 -0
- package/dist/lib/utils/postcss-configuration.d.ts.map +1 -0
- package/dist/lib/utils/postcss-configuration.js +89 -0
- package/dist/lib/utils/rspack-diagnostics.d.ts +3 -3
- package/dist/lib/utils/rspack-diagnostics.d.ts.map +1 -1
- package/dist/lib/utils/rspack-diagnostics.js +16 -4
- package/dist/lib/utils/spinner.d.ts +21 -0
- package/dist/lib/utils/spinner.d.ts.map +1 -0
- package/dist/lib/utils/spinner.js +53 -0
- package/dist/lib/utils/stats.d.ts +35 -0
- package/dist/lib/utils/stats.d.ts.map +1 -0
- package/dist/lib/utils/stats.js +312 -0
- package/dist/lib/utils/tty.d.ts +9 -0
- package/dist/lib/utils/tty.d.ts.map +1 -0
- package/dist/lib/utils/tty.js +22 -0
- package/package.json +23 -5
- package/dist/lib/config/dev-server-config-utils.d.ts +0 -4
- package/dist/lib/config/dev-server-config-utils.d.ts.map +0 -1
- package/dist/lib/config/dev-server-config-utils.js +0 -107
- package/dist/lib/config/entry-points.d.ts.map +0 -1
- package/dist/lib/config/helpers.d.ts +0 -14
- package/dist/lib/config/helpers.d.ts.map +0 -1
- package/dist/lib/config/style-config-utils.d.ts +0 -22
- package/dist/lib/config/style-config-utils.d.ts.map +0 -1
- package/dist/lib/config/style-config-utils.js +0 -202
- package/dist/lib/models/unsupported-options.d.ts +0 -46
- package/dist/lib/models/unsupported-options.d.ts.map +0 -1
- package/dist/lib/models/unsupported-options.js +0 -26
- package/dist/lib/utils/tailwind.d.ts +0 -2
- package/dist/lib/utils/tailwind.d.ts.map +0 -1
- package/dist/lib/utils/tailwind.js +0 -31
- /package/dist/lib/config/{entry-points.js → config-utils/entry-points.js} +0 -0
|
@@ -8,11 +8,15 @@ const core_1 = require("@rspack/core");
|
|
|
8
8
|
const node_path_1 = require("node:path");
|
|
9
9
|
const models_1 = require("../models");
|
|
10
10
|
const get_locale_base_href_1 = require("../utils/get-locale-base-href");
|
|
11
|
+
const rspack_diagnostics_1 = require("../utils/rspack-diagnostics");
|
|
12
|
+
const misc_helpers_1 = require("../utils/misc-helpers");
|
|
13
|
+
const stats_1 = require("../utils/stats");
|
|
14
|
+
const get_stats_options_1 = require("../config/config-utils/get-stats-options");
|
|
11
15
|
const PLUGIN_NAME = 'AngularRspackPlugin';
|
|
12
16
|
class AngularRspackPlugin {
|
|
13
17
|
#_options;
|
|
14
18
|
#i18n;
|
|
15
|
-
#
|
|
19
|
+
#sourceFileCache;
|
|
16
20
|
#javascriptTransformer;
|
|
17
21
|
// This will be defined in the apply method correctly
|
|
18
22
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -21,7 +25,7 @@ class AngularRspackPlugin {
|
|
|
21
25
|
constructor(options, i18nOptions) {
|
|
22
26
|
this.#_options = options;
|
|
23
27
|
this.#i18n = i18nOptions;
|
|
24
|
-
this.#
|
|
28
|
+
this.#sourceFileCache = new angular_rspack_compiler_1.SourceFileCache();
|
|
25
29
|
this.#javascriptTransformer = new angular_rspack_compiler_1.JavaScriptTransformer({
|
|
26
30
|
/**
|
|
27
31
|
* Matches https://github.com/angular/angular-cli/blob/33ed6e875e509ebbaa0cbdb57be9e932f9915dff/packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts#L89
|
|
@@ -41,16 +45,9 @@ class AngularRspackPlugin {
|
|
|
41
45
|
compiler.hooks.beforeRun.tapAsync(PLUGIN_NAME, async (compiler, callback) => {
|
|
42
46
|
await this.setupCompilation(root, compiler.options.resolve.tsConfig);
|
|
43
47
|
compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, async (params, callback) => {
|
|
44
|
-
await (0, angular_rspack_compiler_1.
|
|
48
|
+
await (0, angular_rspack_compiler_1.buildAndAnalyze)(this.#angularCompilation, this.#sourceFileCache.typeScriptFileCache, this.#javascriptTransformer);
|
|
45
49
|
callback();
|
|
46
50
|
});
|
|
47
|
-
compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {
|
|
48
|
-
if (stats.hasErrors() || stats.hasWarnings()) {
|
|
49
|
-
setTimeout(() => {
|
|
50
|
-
process.exit(stats.hasErrors() ? 1 : 0);
|
|
51
|
-
}, 1000);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
51
|
callback();
|
|
55
52
|
});
|
|
56
53
|
compiler.hooks.watchRun.tapAsync(PLUGIN_NAME, async (compiler, callback) => {
|
|
@@ -60,9 +57,13 @@ class AngularRspackPlugin {
|
|
|
60
57
|
?.modifiedFiles
|
|
61
58
|
? new Set(compiler.watching.compiler.modifiedFiles)
|
|
62
59
|
: new Set();
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
if (this.#angularCompilation) {
|
|
61
|
+
this.#sourceFileCache.invalidate(watchingModifiedFiles);
|
|
62
|
+
}
|
|
63
|
+
await this.setupCompilation(root, compiler.options.resolve.tsConfig, watchingModifiedFiles.size > 0
|
|
64
|
+
? watchingModifiedFiles
|
|
65
|
+
: undefined);
|
|
66
|
+
await (0, angular_rspack_compiler_1.buildAndAnalyze)(this.#angularCompilation, this.#sourceFileCache.typeScriptFileCache, this.#javascriptTransformer);
|
|
66
67
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
67
68
|
watchingModifiedFiles.forEach((file) => {
|
|
68
69
|
compilation.fileDependencies.add(file);
|
|
@@ -100,7 +101,7 @@ class AngularRspackPlugin {
|
|
|
100
101
|
setLocaleContent += `(globalThis.$localize ??= {}).locale = "${this.#i18n.sourceLocale}";\n`;
|
|
101
102
|
}
|
|
102
103
|
const concatLocaleSource = new core_1.sources.ConcatSource(setLocaleContent, originalSource);
|
|
103
|
-
compilation.updateAsset(assetName, concatLocaleSource);
|
|
104
|
+
compilation.updateAsset(assetName, concatLocaleSource, (assetInfo) => assetInfo);
|
|
104
105
|
}
|
|
105
106
|
});
|
|
106
107
|
});
|
|
@@ -128,10 +129,46 @@ class AngularRspackPlugin {
|
|
|
128
129
|
});
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
|
-
await this.#angularCompilation.close();
|
|
132
132
|
await this.#javascriptTransformer.close();
|
|
133
133
|
callback();
|
|
134
134
|
});
|
|
135
|
+
compiler.hooks.afterEmit.tap(PLUGIN_NAME, (compilation) => {
|
|
136
|
+
// Check for budget errors and display them to the user.
|
|
137
|
+
const budgets = this.#_options.budgets;
|
|
138
|
+
let budgetFailures;
|
|
139
|
+
compiler.hooks.done.tap(PLUGIN_NAME, (statsValue) => {
|
|
140
|
+
const stats = statsValue.toJson();
|
|
141
|
+
if (budgets?.length) {
|
|
142
|
+
budgetFailures = [...(0, private_1.checkBudgets)(budgets, stats)];
|
|
143
|
+
for (const { severity, message } of budgetFailures) {
|
|
144
|
+
switch (severity) {
|
|
145
|
+
case private_1.ThresholdSeverity.Warning:
|
|
146
|
+
(0, rspack_diagnostics_1.addWarning)(compilation, {
|
|
147
|
+
message,
|
|
148
|
+
name: PLUGIN_NAME,
|
|
149
|
+
hideStack: true,
|
|
150
|
+
});
|
|
151
|
+
break;
|
|
152
|
+
case private_1.ThresholdSeverity.Error:
|
|
153
|
+
(0, rspack_diagnostics_1.addError)(compilation, {
|
|
154
|
+
message,
|
|
155
|
+
name: PLUGIN_NAME,
|
|
156
|
+
hideStack: true,
|
|
157
|
+
});
|
|
158
|
+
break;
|
|
159
|
+
default:
|
|
160
|
+
(0, misc_helpers_1.assertNever)(severity);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
compiler.hooks.afterDone.tap(PLUGIN_NAME, (stats) => {
|
|
166
|
+
(0, stats_1.rspackStatsLogger)(stats, (0, get_stats_options_1.getStatsOptions)(this.#_options.verbose));
|
|
167
|
+
if (stats.hasErrors()) {
|
|
168
|
+
process.exit(1);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
135
172
|
compiler.hooks.normalModuleFactory.tap(PLUGIN_NAME, (normalModuleFactory) => {
|
|
136
173
|
normalModuleFactory.hooks.beforeResolve.tap(PLUGIN_NAME, (data) => {
|
|
137
174
|
if (data.request.startsWith('angular:jit:')) {
|
|
@@ -144,7 +181,7 @@ class AngularRspackPlugin {
|
|
|
144
181
|
compilation[models_1.NG_RSPACK_SYMBOL_NAME] = () => ({
|
|
145
182
|
javascriptTransformer: this
|
|
146
183
|
.#javascriptTransformer,
|
|
147
|
-
typescriptFileCache: this.#
|
|
184
|
+
typescriptFileCache: this.#sourceFileCache.typeScriptFileCache,
|
|
148
185
|
i18n: this.#i18n,
|
|
149
186
|
});
|
|
150
187
|
});
|
|
@@ -171,13 +208,13 @@ class AngularRspackPlugin {
|
|
|
171
208
|
});
|
|
172
209
|
}
|
|
173
210
|
}
|
|
174
|
-
async setupCompilation(root, tsConfig) {
|
|
211
|
+
async setupCompilation(root, tsConfig, modifiedFiles) {
|
|
175
212
|
const tsconfigPath = tsConfig
|
|
176
213
|
? typeof tsConfig === 'string'
|
|
177
214
|
? tsConfig
|
|
178
215
|
: tsConfig.configFile
|
|
179
216
|
: this.#_options.tsConfig;
|
|
180
|
-
this.#angularCompilation = await (0, angular_rspack_compiler_1.
|
|
217
|
+
this.#angularCompilation = await (0, angular_rspack_compiler_1.setupCompilationWithAngularCompilation)({
|
|
181
218
|
source: {
|
|
182
219
|
tsconfigPath: tsconfigPath,
|
|
183
220
|
},
|
|
@@ -189,7 +226,9 @@ class AngularRspackPlugin {
|
|
|
189
226
|
fileReplacements: this.#_options.fileReplacements,
|
|
190
227
|
useTsProjectReferences: this.#_options.useTsProjectReferences,
|
|
191
228
|
hasServer: this.#_options.hasServer,
|
|
192
|
-
|
|
229
|
+
includePaths: this.#_options.stylePreprocessorOptions?.includePaths,
|
|
230
|
+
sass: this.#_options.stylePreprocessorOptions?.sass,
|
|
231
|
+
}, this.#sourceFileCache, this.#angularCompilation, modifiedFiles);
|
|
193
232
|
}
|
|
194
233
|
}
|
|
195
234
|
exports.AngularRspackPlugin = AngularRspackPlugin;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
2
|
-
import {
|
|
2
|
+
import { NormalizedAngularRspackPluginOptions } from '../models';
|
|
3
3
|
export declare class AngularSsrDevServer implements RspackPluginInstance {
|
|
4
4
|
#private;
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(options: NormalizedAngularRspackPluginOptions);
|
|
6
6
|
apply(compiler: Compiler): void;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=angular-ssr-dev-server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"angular-ssr-dev-server.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/angular-ssr-dev-server.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"angular-ssr-dev-server.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/angular-ssr-dev-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EACR,oBAAoB,EAErB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,oCAAoC,EAAE,MAAM,WAAW,CAAC;AAQjE,qBAAa,mBAAoB,YAAW,oBAAoB;;gBAKlD,OAAO,EAAE,oCAAoC;IAKzD,KAAK,CAAC,QAAQ,EAAE,QAAQ;CA6DzB"}
|
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AngularSsrDevServer = void 0;
|
|
4
|
+
const core_1 = require("@rspack/core");
|
|
4
5
|
const child_process_1 = require("child_process");
|
|
5
6
|
const ssr_reload_server_1 = require("./server/ssr-reload-server");
|
|
6
7
|
const node_path_1 = require("node:path");
|
|
7
8
|
const node_fs_1 = require("node:fs");
|
|
9
|
+
const get_index_output_file_1 = require("../utils/index-file/get-index-output-file");
|
|
10
|
+
const add_body_script_1 = require("../utils/index-file/add-body-script");
|
|
8
11
|
const PLUGIN_NAME = 'AngularSsrDevServer';
|
|
9
12
|
class AngularSsrDevServer {
|
|
10
13
|
#devServerProcess;
|
|
11
14
|
#wsServer;
|
|
12
|
-
#
|
|
13
|
-
constructor(
|
|
14
|
-
this.#outputPath = outputPath;
|
|
15
|
+
#options;
|
|
16
|
+
constructor(options) {
|
|
15
17
|
this.#wsServer = new ssr_reload_server_1.SsrReloadServer();
|
|
18
|
+
this.#options = options;
|
|
16
19
|
}
|
|
17
20
|
apply(compiler) {
|
|
18
21
|
compiler.hooks.entryOption.tap(PLUGIN_NAME, (context, entry) => {
|
|
19
22
|
const keys = Object.keys(entry);
|
|
20
23
|
for (const key of keys) {
|
|
21
24
|
const entryValue = entry[key];
|
|
22
|
-
entryValue.import = [
|
|
23
|
-
...entryValue.import,
|
|
24
|
-
require.resolve(`${__dirname}/client/ssr-reload-client.js`),
|
|
25
|
-
];
|
|
25
|
+
entryValue.import = [...entryValue.import];
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
28
|
compiler.hooks.watchRun.tapAsync(PLUGIN_NAME, async (compiler, callback) => {
|
|
29
|
-
compiler.hooks.afterEmit.tapAsync(PLUGIN_NAME, async (
|
|
30
|
-
|
|
29
|
+
compiler.hooks.afterEmit.tapAsync(PLUGIN_NAME, async (compilation, callback) => {
|
|
30
|
+
await this.#attachSSRReloadClient(compilation);
|
|
31
|
+
const serverPath = (0, node_path_1.join)(this.#options.outputPath.server, 'server.js');
|
|
31
32
|
if (this.#devServerProcess) {
|
|
32
33
|
this.#devServerProcess.kill();
|
|
33
34
|
this.#devServerProcess = undefined;
|
|
@@ -45,5 +46,14 @@ class AngularSsrDevServer {
|
|
|
45
46
|
callback();
|
|
46
47
|
});
|
|
47
48
|
}
|
|
49
|
+
async #attachSSRReloadClient(compilation) {
|
|
50
|
+
const clientPath = require.resolve(`${__dirname}/client/ssr-reload-client.js`);
|
|
51
|
+
const pathToIndex = (0, node_path_1.join)(this.#options.outputPath.browser, (0, get_index_output_file_1.getIndexOutputFile)(this.#options.index));
|
|
52
|
+
const html = (0, node_fs_1.readFileSync)(pathToIndex, 'utf-8');
|
|
53
|
+
const updatedHtml = await (0, add_body_script_1.addBodyScript)(html, (0, node_fs_1.readFileSync)(clientPath, 'utf-8'));
|
|
54
|
+
const source = new core_1.sources.RawSource(updatedHtml);
|
|
55
|
+
const relativePathToIndex = pathToIndex.replace(this.#options.outputPath.browser, '');
|
|
56
|
+
compilation.emitAsset(relativePathToIndex, source);
|
|
57
|
+
}
|
|
48
58
|
}
|
|
49
59
|
exports.AngularSsrDevServer = AngularSsrDevServer;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import { BudgetEntry } from '@angular/build/private';
|
|
9
|
+
import { type Compiler, RspackPluginInstance } from '@rspack/core';
|
|
10
|
+
/**
|
|
11
|
+
* Check budget sizes for component styles by emitting a warning or error if a
|
|
12
|
+
* budget is exceeded by a particular component's styles.
|
|
13
|
+
*/
|
|
14
|
+
export declare class AnyComponentStyleBudgetChecker implements RspackPluginInstance {
|
|
15
|
+
private readonly budgets;
|
|
16
|
+
constructor(budgets: BudgetEntry[]);
|
|
17
|
+
apply(compiler: Compiler): void;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=any-component-style-budget-checker-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"any-component-style-budget-checker-plugin.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/any-component-style-budget-checker-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAEL,WAAW,EAIZ,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAe,KAAK,QAAQ,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAMhF;;;GAGG;AACH,qBAAa,8BAA+B,YAAW,oBAAoB;IACzE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;gBAE5B,OAAO,EAAE,WAAW,EAAE;IAMlC,KAAK,CAAC,QAAQ,EAAE,QAAQ;CAgDzB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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.dev/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.AnyComponentStyleBudgetChecker = void 0;
|
|
11
|
+
const tslib_1 = require("tslib");
|
|
12
|
+
const private_1 = require("@angular/build/private");
|
|
13
|
+
const path = tslib_1.__importStar(require("node:path"));
|
|
14
|
+
const core_1 = require("@rspack/core");
|
|
15
|
+
const rspack_diagnostics_1 = require("../utils/rspack-diagnostics");
|
|
16
|
+
const misc_helpers_1 = require("../utils/misc-helpers");
|
|
17
|
+
const PLUGIN_NAME = 'AnyComponentStyleBudgetChecker';
|
|
18
|
+
/**
|
|
19
|
+
* Check budget sizes for component styles by emitting a warning or error if a
|
|
20
|
+
* budget is exceeded by a particular component's styles.
|
|
21
|
+
*/
|
|
22
|
+
class AnyComponentStyleBudgetChecker {
|
|
23
|
+
budgets;
|
|
24
|
+
constructor(budgets) {
|
|
25
|
+
this.budgets = budgets.filter((budget) => budget.type === private_1.BudgetType.AnyComponentStyle);
|
|
26
|
+
}
|
|
27
|
+
apply(compiler) {
|
|
28
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
29
|
+
compilation.hooks.processAssets.tap({
|
|
30
|
+
name: PLUGIN_NAME,
|
|
31
|
+
stage: core_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE,
|
|
32
|
+
}, () => {
|
|
33
|
+
// No budgets.
|
|
34
|
+
if (this.budgets.length === 0) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
// In AOT compilations component styles get processed in child compilations.
|
|
38
|
+
if (!compilation.compiler.parentCompilation) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const cssExtensions = ['.css', '.scss', '.less', '.sass'];
|
|
42
|
+
const componentStyles = Object.keys(compilation.assets)
|
|
43
|
+
.filter((name) => cssExtensions.includes(path.extname(name)))
|
|
44
|
+
.map((name) => ({
|
|
45
|
+
name,
|
|
46
|
+
size: compilation.assets[name].size(),
|
|
47
|
+
componentStyle: true,
|
|
48
|
+
}));
|
|
49
|
+
for (const { severity, message } of (0, private_1.checkBudgets)(this.budgets, { chunks: [], assets: componentStyles }, true)) {
|
|
50
|
+
switch (severity) {
|
|
51
|
+
case private_1.ThresholdSeverity.Warning:
|
|
52
|
+
(0, rspack_diagnostics_1.addWarning)(compilation, message);
|
|
53
|
+
break;
|
|
54
|
+
case private_1.ThresholdSeverity.Error:
|
|
55
|
+
(0, rspack_diagnostics_1.addError)(compilation, message);
|
|
56
|
+
break;
|
|
57
|
+
default:
|
|
58
|
+
(0, misc_helpers_1.assertNever)(severity);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.AnyComponentStyleBudgetChecker = AnyComponentStyleBudgetChecker;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18n-inline-plugin.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/i18n-inline-plugin.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,oBAAoB,EAE1B,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EACV,WAAW,EACX,oCAAoC,EACrC,MAAM,WAAW,CAAC;AAWnB,qBAAa,gBAAiB,YAAW,oBAAoB;;gBAWzD,aAAa,EAAE,oCAAoC,EACnD,WAAW,EAAE,WAAW;IAO1B,KAAK,CAAC,QAAQ,EAAE,QAAQ;
|
|
1
|
+
{"version":3,"file":"i18n-inline-plugin.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/i18n-inline-plugin.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,oBAAoB,EAE1B,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EACV,WAAW,EACX,oCAAoC,EACrC,MAAM,WAAW,CAAC;AAWnB,qBAAa,gBAAiB,YAAW,oBAAoB;;gBAWzD,aAAa,EAAE,oCAAoC,EACnD,WAAW,EAAE,WAAW;IAO1B,KAAK,CAAC,QAAQ,EAAE,QAAQ;CAsOzB"}
|
|
@@ -66,11 +66,13 @@ class I18nInlinePlugin {
|
|
|
66
66
|
for (const [localeSubPath, files] of filesToOutput.entries()) {
|
|
67
67
|
for (const [filename, { text, map }] of files.entries()) {
|
|
68
68
|
const localeFileName = `${localeSubPath}/${filename}`;
|
|
69
|
+
const asset = compilation.getAsset(filename);
|
|
70
|
+
const assetInfo = asset?.info;
|
|
69
71
|
if (map) {
|
|
70
|
-
compilation.emitAsset(localeFileName, new core_2.sources.SourceMapSource(text, localeFileName, map));
|
|
72
|
+
compilation.emitAsset(localeFileName, new core_2.sources.SourceMapSource(text, localeFileName, map), (newAssetInfo) => ({ ...assetInfo, ...newAssetInfo }));
|
|
71
73
|
}
|
|
72
|
-
compilation.emitAsset(localeFileName, new core_2.sources.RawSource(text));
|
|
73
|
-
if (
|
|
74
|
+
compilation.emitAsset(localeFileName, new core_2.sources.RawSource(text), (newAssetInfo) => ({ ...assetInfo, ...newAssetInfo }));
|
|
75
|
+
if (asset) {
|
|
74
76
|
compilation.deleteAsset(filename);
|
|
75
77
|
}
|
|
76
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-html-plugin.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/index-html-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAElB,KAAK,yBAAyB,EAC/B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEhF,OAAO,KAAK,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index-html-plugin.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/index-html-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAElB,KAAK,yBAAyB,EAC/B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEhF,OAAO,KAAK,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAQtE,MAAM,WAAW,sBAAuB,SAAQ,yBAAyB;IACvE,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,uBAAuB,CAAC;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB;AAID,qBAAa,eACX,SAAQ,kBACR,YAAW,oBAAoB;aAWD,OAAO,EAAE,sBAAsB;IAT7D,OAAO,CAAC,YAAY,CAA0B;IAC9C,IAAI,WAAW,IAAI,WAAW,CAM7B;gBAE6B,OAAO,EAAE,sBAAsB;IAI7D,KAAK,CAAC,QAAQ,EAAE,QAAQ;IAoET,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;cAM9B,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAsBjE,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAgBtD"}
|
|
@@ -9,6 +9,7 @@ const misc_helpers_1 = require("../utils/misc-helpers");
|
|
|
9
9
|
const i18n_1 = require("../utils/i18n");
|
|
10
10
|
const rspack_diagnostics_1 = require("../utils/rspack-diagnostics");
|
|
11
11
|
const url_join_1 = require("../utils/url-join");
|
|
12
|
+
const get_index_output_file_1 = require("../utils/index-file/get-index-output-file");
|
|
12
13
|
const PLUGIN_NAME = 'IndexHtmlPlugin';
|
|
13
14
|
class IndexHtmlPlugin extends private_1.IndexHtmlGenerator {
|
|
14
15
|
options;
|
|
@@ -59,7 +60,7 @@ class IndexHtmlPlugin extends private_1.IndexHtmlGenerator {
|
|
|
59
60
|
html = await (0, add_event_dispatch_contract_1.addEventDispatchContract)(csrContent);
|
|
60
61
|
}
|
|
61
62
|
const { RawSource } = compiler.rspack.sources;
|
|
62
|
-
compilation.emitAsset((0, node_path_1.join)(outputPath, getIndexOutputFile(this.options.index)), new RawSource(html));
|
|
63
|
+
compilation.emitAsset((0, node_path_1.join)(outputPath, (0, get_index_output_file_1.getIndexOutputFile)(this.options.index)), new RawSource(html));
|
|
63
64
|
warnings.forEach((msg) => (0, rspack_diagnostics_1.addWarning)(compilation, msg));
|
|
64
65
|
errors.forEach((msg) => (0, rspack_diagnostics_1.addError)(compilation, msg));
|
|
65
66
|
}
|
|
@@ -106,9 +107,3 @@ class IndexHtmlPlugin extends private_1.IndexHtmlGenerator {
|
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
109
|
exports.IndexHtmlPlugin = IndexHtmlPlugin;
|
|
109
|
-
function getIndexOutputFile(index) {
|
|
110
|
-
if (typeof index === 'string') {
|
|
111
|
-
return (0, node_path_1.basename)(index);
|
|
112
|
-
}
|
|
113
|
-
return index.output || 'index.html';
|
|
114
|
-
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"angular-partial-transform.loader.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/loaders/angular-partial-transform.loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"angular-partial-transform.loader.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/loaders/angular-partial-transform.loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,QA2C3E"}
|
|
@@ -22,7 +22,10 @@ function loader(content) {
|
|
|
22
22
|
}
|
|
23
23
|
const existingTransform = typescriptFileCache.get(request);
|
|
24
24
|
if (existingTransform) {
|
|
25
|
-
|
|
25
|
+
const existingContents = typeof existingTransform === 'string'
|
|
26
|
+
? existingTransform
|
|
27
|
+
: Buffer.from(existingTransform).toString('utf8');
|
|
28
|
+
callback(null, existingContents);
|
|
26
29
|
return;
|
|
27
30
|
}
|
|
28
31
|
javascriptTransformer
|
|
@@ -0,0 +1,11 @@
|
|
|
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.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import { LoaderContext, LoaderDefinitionFunction } from '@rspack/core';
|
|
9
|
+
export declare const HmrLoader: string;
|
|
10
|
+
export default function localizeExtractLoader(this: LoaderContext, content: string, map: Parameters<LoaderDefinitionFunction>[1]): void;
|
|
11
|
+
//# sourceMappingURL=hmr-accept-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmr-accept-loader.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/loaders/hmr-accept-loader.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAEvE,eAAO,MAAM,SAAS,QAAa,CAAC;AAGpC,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAC3C,IAAI,EAAE,aAAa,EACnB,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,UAAU,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,QAY7C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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.dev/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.HmrLoader = void 0;
|
|
11
|
+
exports.default = localizeExtractLoader;
|
|
12
|
+
const node_path_1 = require("node:path");
|
|
13
|
+
exports.HmrLoader = __filename;
|
|
14
|
+
const hmrAcceptPath = (0, node_path_1.join)(__dirname, './hmr-accept.js').replace(/\\/g, '/');
|
|
15
|
+
function localizeExtractLoader(content, map) {
|
|
16
|
+
const source = `${content}
|
|
17
|
+
|
|
18
|
+
// HMR Accept Code
|
|
19
|
+
import ngHmrAccept from '${hmrAcceptPath}';
|
|
20
|
+
ngHmrAccept(module);
|
|
21
|
+
`;
|
|
22
|
+
this.callback(null, source, map);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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.dev/license
|
|
7
|
+
*/
|
|
8
|
+
export default function (mod: any): void;
|
|
9
|
+
//# sourceMappingURL=hmr-accept.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmr-accept.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/loaders/hmr-accept.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAqBH,MAAM,CAAC,OAAO,WAAW,GAAG,EAAE,GAAG,GAAG,IAAI,CA+FvC"}
|
|
@@ -0,0 +1,183 @@
|
|
|
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.dev/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.default = default_1;
|
|
11
|
+
const core_1 = require("@angular/core");
|
|
12
|
+
const rxjs_1 = require("rxjs");
|
|
13
|
+
function default_1(mod) {
|
|
14
|
+
if (!mod['hot']) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (!(0, core_1.isDevMode)()) {
|
|
18
|
+
console.error(`[NG HMR] Cannot use HMR when Angular is running in production mode. To prevent production mode, do not call 'enableProdMode()'.`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
mod['hot'].accept();
|
|
22
|
+
mod['hot'].dispose(() => {
|
|
23
|
+
if (typeof ng === 'undefined') {
|
|
24
|
+
console.warn(`[NG HMR] Cannot find global 'ng'. Likely this is caused because scripts optimization is enabled.`);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!ng.getInjector) {
|
|
28
|
+
// View Engine
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// Reset JIT compiled components cache
|
|
32
|
+
(0, core_1.ɵresetCompiledComponents)();
|
|
33
|
+
const appRoot = getAppRoot();
|
|
34
|
+
if (!appRoot) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const appRef = getApplicationRef(appRoot);
|
|
38
|
+
if (!appRef) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
// Inputs that are hidden should be ignored
|
|
42
|
+
const oldInputs = document.querySelectorAll('input:not([type="hidden"]), textarea');
|
|
43
|
+
const oldOptions = document.querySelectorAll('option');
|
|
44
|
+
// Create new application
|
|
45
|
+
appRef.components.forEach((cp) => {
|
|
46
|
+
const element = cp.location.nativeElement;
|
|
47
|
+
const parentNode = element.parentNode;
|
|
48
|
+
parentNode.insertBefore(document.createElement(element.tagName), element);
|
|
49
|
+
parentNode.removeChild(element);
|
|
50
|
+
});
|
|
51
|
+
// Destroy old application, injectors, <style..., etc..
|
|
52
|
+
const platformRef = getPlatformRef(appRoot);
|
|
53
|
+
if (platformRef) {
|
|
54
|
+
platformRef.destroy();
|
|
55
|
+
}
|
|
56
|
+
// Restore all inputs and options
|
|
57
|
+
const bodyElement = document.body;
|
|
58
|
+
if (oldInputs.length + oldOptions.length === 0 || !bodyElement) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
// Use a `MutationObserver` to wait until the app-root element has been bootstrapped.
|
|
62
|
+
// ie: when the ng-version attribute is added.
|
|
63
|
+
new MutationObserver((_mutationsList, observer) => {
|
|
64
|
+
observer.disconnect();
|
|
65
|
+
const newAppRoot = getAppRoot();
|
|
66
|
+
if (!newAppRoot) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const newAppRef = getApplicationRef(newAppRoot);
|
|
70
|
+
if (!newAppRef) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
// Wait until the application isStable to restore the form values
|
|
74
|
+
newAppRef.isStable
|
|
75
|
+
.pipe((0, rxjs_1.filter)((isStable) => !!isStable), (0, rxjs_1.take)(1))
|
|
76
|
+
.subscribe(() => restoreFormValues(oldInputs, oldOptions));
|
|
77
|
+
}).observe(bodyElement, {
|
|
78
|
+
attributes: true,
|
|
79
|
+
subtree: true,
|
|
80
|
+
attributeFilter: ['ng-version'],
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function getAppRoot() {
|
|
85
|
+
const appRoot = document.querySelector('[ng-version]');
|
|
86
|
+
if (!appRoot) {
|
|
87
|
+
console.warn('[NG HMR] Cannot find the application root component.');
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
return appRoot;
|
|
91
|
+
}
|
|
92
|
+
function getToken(appRoot, token) {
|
|
93
|
+
return ((typeof ng === 'object' && ng.getInjector(appRoot).get(token)) || undefined);
|
|
94
|
+
}
|
|
95
|
+
function getApplicationRef(appRoot) {
|
|
96
|
+
const appRef = getToken(appRoot, core_1.ApplicationRef);
|
|
97
|
+
if (!appRef) {
|
|
98
|
+
console.warn(`[NG HMR] Cannot get 'ApplicationRef'.`);
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
return appRef;
|
|
102
|
+
}
|
|
103
|
+
function getPlatformRef(appRoot) {
|
|
104
|
+
const platformRef = getToken(appRoot, core_1.PlatformRef);
|
|
105
|
+
if (!platformRef) {
|
|
106
|
+
console.warn(`[NG HMR] Cannot get 'PlatformRef'.`);
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
return platformRef;
|
|
110
|
+
}
|
|
111
|
+
function dispatchEvents(element) {
|
|
112
|
+
element.dispatchEvent(new Event('input', {
|
|
113
|
+
bubbles: true,
|
|
114
|
+
cancelable: true,
|
|
115
|
+
}));
|
|
116
|
+
element.blur();
|
|
117
|
+
element.dispatchEvent(new KeyboardEvent('keyup', { key: 'Enter' }));
|
|
118
|
+
}
|
|
119
|
+
function restoreFormValues(oldInputs, oldOptions) {
|
|
120
|
+
// Restore input that are not hidden
|
|
121
|
+
const newInputs = document.querySelectorAll('input:not([type="hidden"]), textarea');
|
|
122
|
+
if (newInputs.length && newInputs.length === oldInputs.length) {
|
|
123
|
+
console.log('[NG HMR] Restoring input/textarea values.');
|
|
124
|
+
for (let index = 0; index < newInputs.length; index++) {
|
|
125
|
+
const newElement = newInputs[index];
|
|
126
|
+
const oldElement = oldInputs[index];
|
|
127
|
+
switch (oldElement.type) {
|
|
128
|
+
case 'button':
|
|
129
|
+
case 'image':
|
|
130
|
+
case 'submit':
|
|
131
|
+
case 'reset':
|
|
132
|
+
// These types don't need any value change.
|
|
133
|
+
continue;
|
|
134
|
+
case 'radio':
|
|
135
|
+
case 'checkbox':
|
|
136
|
+
newElement.checked = oldElement.checked;
|
|
137
|
+
break;
|
|
138
|
+
case 'color':
|
|
139
|
+
case 'date':
|
|
140
|
+
case 'datetime-local':
|
|
141
|
+
case 'email':
|
|
142
|
+
case 'hidden':
|
|
143
|
+
case 'month':
|
|
144
|
+
case 'number':
|
|
145
|
+
case 'password':
|
|
146
|
+
case 'range':
|
|
147
|
+
case 'search':
|
|
148
|
+
case 'tel':
|
|
149
|
+
case 'text':
|
|
150
|
+
case 'textarea':
|
|
151
|
+
case 'time':
|
|
152
|
+
case 'url':
|
|
153
|
+
case 'week':
|
|
154
|
+
newElement.value = oldElement.value;
|
|
155
|
+
break;
|
|
156
|
+
case 'file':
|
|
157
|
+
// Ignored due: Uncaught DOMException: Failed to set the 'value' property on 'HTMLInputElement':
|
|
158
|
+
// This input element accepts a filename, which may only be programmatically set to the empty string.
|
|
159
|
+
break;
|
|
160
|
+
default:
|
|
161
|
+
console.warn('[NG HMR] Unknown input type ' + oldElement.type + '.');
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
dispatchEvents(newElement);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else if (oldInputs.length) {
|
|
168
|
+
console.warn('[NG HMR] Cannot restore input/textarea values.');
|
|
169
|
+
}
|
|
170
|
+
// Restore option
|
|
171
|
+
const newOptions = document.querySelectorAll('option');
|
|
172
|
+
if (newOptions.length && newOptions.length === oldOptions.length) {
|
|
173
|
+
console.log('[NG HMR] Restoring selected options.');
|
|
174
|
+
for (let index = 0; index < newOptions.length; index++) {
|
|
175
|
+
const newElement = newOptions[index];
|
|
176
|
+
newElement.selected = oldOptions[index].selected;
|
|
177
|
+
dispatchEvents(newElement);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else if (oldOptions.length) {
|
|
181
|
+
console.warn('[NG HMR] Cannot restore selected options.');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type LoaderContext, type LoaderDefinitionFunction } from '@rspack/core';
|
|
2
|
+
export default function loader(this: LoaderContext<{
|
|
3
|
+
angularSSRInstalled: boolean;
|
|
4
|
+
}>, content: string, map: Parameters<LoaderDefinitionFunction>[1]): void;
|
|
5
|
+
//# sourceMappingURL=platform-server-exports.loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-server-exports.loader.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/loaders/platform-server-exports.loader.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,wBAAwB,EAC9B,MAAM,cAAc,CAAC;AAEtB,MAAM,CAAC,OAAO,UAAU,MAAM,CAC5B,IAAI,EAAE,aAAa,CAAC;IAAE,mBAAmB,EAAE,OAAO,CAAA;CAAE,CAAC,EACrD,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,UAAU,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,QAmB7C"}
|