@nx/angular-rspack 0.0.0-pr-32422-a3285be
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 +22 -0
- package/README.md +98 -0
- package/README.md__tpl__ +48 -0
- 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 +83 -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 +144 -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 +258 -0
- package/dist/lib/config/config-utils/entry-points.d.ts +9 -0
- package/dist/lib/config/config-utils/entry-points.d.ts.map +1 -0
- package/dist/lib/config/config-utils/entry-points.js +36 -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/config-utils/helpers.js +106 -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 +92 -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 +353 -0
- package/dist/lib/config/config-utils/user-defined-config-helpers.d.ts +73 -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 +11 -0
- package/dist/lib/config/create-config.d.ts.map +1 -0
- package/dist/lib/config/create-config.js +35 -0
- package/dist/lib/config/i18n/create-i18n-options.d.ts +6 -0
- package/dist/lib/config/i18n/create-i18n-options.d.ts.map +1 -0
- package/dist/lib/config/i18n/create-i18n-options.js +124 -0
- package/dist/lib/index.d.ts +7 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +14 -0
- package/dist/lib/models/angular-rspack-plugin-options.d.ts +344 -0
- package/dist/lib/models/angular-rspack-plugin-options.d.ts.map +1 -0
- package/dist/lib/models/angular-rspack-plugin-options.js +2 -0
- package/dist/lib/models/augmented-compilation.d.ts +13 -0
- package/dist/lib/models/augmented-compilation.d.ts.map +1 -0
- package/dist/lib/models/augmented-compilation.js +4 -0
- package/dist/lib/models/i18n.d.ts +33 -0
- package/dist/lib/models/i18n.d.ts.map +1 -0
- package/dist/lib/models/i18n.js +41 -0
- package/dist/lib/models/index.d.ts +5 -0
- package/dist/lib/models/index.d.ts.map +1 -0
- package/dist/lib/models/index.js +7 -0
- package/dist/lib/models/normalize-options.d.ts +16 -0
- package/dist/lib/models/normalize-options.d.ts.map +1 -0
- package/dist/lib/models/normalize-options.js +424 -0
- package/dist/lib/plugins/angular-rspack-plugin.d.ts +9 -0
- package/dist/lib/plugins/angular-rspack-plugin.d.ts.map +1 -0
- package/dist/lib/plugins/angular-rspack-plugin.js +234 -0
- package/dist/lib/plugins/angular-ssr-dev-server.d.ts +8 -0
- package/dist/lib/plugins/angular-ssr-dev-server.d.ts.map +1 -0
- package/dist/lib/plugins/angular-ssr-dev-server.js +62 -0
- 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 +64 -0
- package/dist/lib/plugins/client/ssr-reload-client.d.ts +2 -0
- package/dist/lib/plugins/client/ssr-reload-client.d.ts.map +1 -0
- package/dist/lib/plugins/client/ssr-reload-client.js +15 -0
- package/dist/lib/plugins/i18n-inline-plugin.d.ts +8 -0
- package/dist/lib/plugins/i18n-inline-plugin.d.ts.map +1 -0
- package/dist/lib/plugins/i18n-inline-plugin.js +201 -0
- package/dist/lib/plugins/index-html-plugin.d.ts +21 -0
- package/dist/lib/plugins/index-html-plugin.d.ts.map +1 -0
- package/dist/lib/plugins/index-html-plugin.js +107 -0
- package/dist/lib/plugins/loaders/angular-partial-transform.loader.d.ts +3 -0
- package/dist/lib/plugins/loaders/angular-partial-transform.loader.d.ts.map +1 -0
- package/dist/lib/plugins/loaders/angular-partial-transform.loader.js +39 -0
- package/dist/lib/plugins/loaders/angular-transform.loader.d.ts +7 -0
- package/dist/lib/plugins/loaders/angular-transform.loader.d.ts.map +1 -0
- package/dist/lib/plugins/loaders/angular-transform.loader.js +40 -0
- 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 +13 -0
- package/dist/lib/plugins/ng-rspack.d.ts.map +1 -0
- package/dist/lib/plugins/ng-rspack.js +134 -0
- 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 +216 -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/rxjs-esm-resolution.d.ts +5 -0
- package/dist/lib/plugins/rxjs-esm-resolution.d.ts.map +1 -0
- package/dist/lib/plugins/rxjs-esm-resolution.js +15 -0
- package/dist/lib/plugins/server/ssr-reload-server.d.ts +6 -0
- package/dist/lib/plugins/server/ssr-reload-server.d.ts.map +1 -0
- package/dist/lib/plugins/server/ssr-reload-server.js +21 -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 +69 -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 +17 -0
- package/dist/lib/plugins/tools/dev-tools-ignore-plugin.d.ts.map +1 -0
- package/dist/lib/plugins/tools/dev-tools-ignore-plugin.js +57 -0
- 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 +105 -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 +48 -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 +23 -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/find-project-for-path.d.ts +16 -0
- package/dist/lib/utils/find-project-for-path.d.ts.map +1 -0
- package/dist/lib/utils/find-project-for-path.js +42 -0
- package/dist/lib/utils/get-locale-base-href.d.ts +3 -0
- package/dist/lib/utils/get-locale-base-href.d.ts.map +1 -0
- package/dist/lib/utils/get-locale-base-href.js +17 -0
- package/dist/lib/utils/graph.d.ts +3 -0
- package/dist/lib/utils/graph.d.ts.map +1 -0
- package/dist/lib/utils/graph.js +25 -0
- package/dist/lib/utils/i18n.d.ts +4 -0
- package/dist/lib/utils/i18n.d.ts.map +1 -0
- package/dist/lib/utils/i18n.js +25 -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/add-event-dispatch-contract.d.ts +9 -0
- package/dist/lib/utils/index-file/add-event-dispatch-contract.d.ts.map +1 -0
- package/dist/lib/utils/index-file/add-event-dispatch-contract.js +27 -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/index-file/html-rewriting-stream.d.ts +16 -0
- package/dist/lib/utils/index-file/html-rewriting-stream.d.ts.map +1 -0
- package/dist/lib/utils/index-file/html-rewriting-stream.js +27 -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 +7 -0
- package/dist/lib/utils/misc-helpers.d.ts.map +1 -0
- package/dist/lib/utils/misc-helpers.js +34 -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 +159 -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 +92 -0
- package/dist/lib/utils/rspack-diagnostics.d.ts +4 -0
- package/dist/lib/utils/rspack-diagnostics.d.ts.map +1 -0
- package/dist/lib/utils/rspack-diagnostics.js +22 -0
- 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 +54 -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 +313 -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/dist/lib/utils/url-join.d.ts +9 -0
- package/dist/lib/utils/url-join.d.ts.map +1 -0
- package/dist/lib/utils/url-join.js +17 -0
- package/package.json +150 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.INDEX_HTML_CSR = void 0;
|
|
4
|
+
exports.resolveFileReplacements = resolveFileReplacements;
|
|
5
|
+
exports.getHasServer = getHasServer;
|
|
6
|
+
exports.validateSsr = validateSsr;
|
|
7
|
+
exports.normalizeOptions = normalizeOptions;
|
|
8
|
+
exports.normalizeOptimization = normalizeOptimization;
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const private_1 = require("@angular/build/private");
|
|
11
|
+
const devkit_1 = require("@nx/devkit");
|
|
12
|
+
const node_assert_1 = tslib_1.__importDefault(require("node:assert"));
|
|
13
|
+
const node_fs_1 = require("node:fs");
|
|
14
|
+
const node_path_1 = require("node:path");
|
|
15
|
+
const find_project_for_path_1 = require("../utils/find-project-for-path");
|
|
16
|
+
const graph_1 = require("../utils/graph");
|
|
17
|
+
exports.INDEX_HTML_CSR = 'index.csr.html';
|
|
18
|
+
/**
|
|
19
|
+
* Resolves file replacement paths to absolute paths based on the provided root directory.
|
|
20
|
+
*
|
|
21
|
+
* @param fileReplacements - Array of file replacements with relative paths.
|
|
22
|
+
* @param root - The root directory to resolve the paths against.
|
|
23
|
+
* @returns Array of file replacements resolved against the root.
|
|
24
|
+
*/
|
|
25
|
+
function resolveFileReplacements(fileReplacements, root) {
|
|
26
|
+
return fileReplacements.map((fileReplacement) => ({
|
|
27
|
+
replace: (0, node_path_1.resolve)(root, fileReplacement.replace),
|
|
28
|
+
with: (0, node_path_1.resolve)(root, fileReplacement.with),
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
function getHasServer(root, server, ssr) {
|
|
32
|
+
return !!(server &&
|
|
33
|
+
ssr &&
|
|
34
|
+
ssr.entry &&
|
|
35
|
+
(0, node_fs_1.existsSync)((0, node_path_1.join)(root, server)) &&
|
|
36
|
+
(0, node_fs_1.existsSync)((0, node_path_1.join)(root, ssr.entry)));
|
|
37
|
+
}
|
|
38
|
+
function validateSsr(ssr) {
|
|
39
|
+
if (!ssr) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (ssr === true) {
|
|
43
|
+
throw new Error('The "ssr" option should be an object or false. Please check the documentation.');
|
|
44
|
+
}
|
|
45
|
+
if (typeof ssr === 'object')
|
|
46
|
+
if (!ssr.entry) {
|
|
47
|
+
throw new Error('The "ssr" option should have an "entry" property. Please check the documentation.');
|
|
48
|
+
}
|
|
49
|
+
else if (ssr.experimentalPlatform === 'neutral') {
|
|
50
|
+
console.warn('The "ssr.experimentalPlatform" option is not currently supported. Node will be used as the platform.');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async function normalizeOptions(options) {
|
|
54
|
+
const { fileReplacements = [], server, ssr, optimization } = options;
|
|
55
|
+
validateSsr(ssr);
|
|
56
|
+
const normalizedSsr = !ssr
|
|
57
|
+
? false
|
|
58
|
+
: typeof ssr === 'object'
|
|
59
|
+
? {
|
|
60
|
+
entry: ssr.entry,
|
|
61
|
+
experimentalPlatform: 'node', // @TODO: Add support for neutral platform
|
|
62
|
+
}
|
|
63
|
+
: ssr;
|
|
64
|
+
const normalizedOptimization = normalizeOptimization(optimization);
|
|
65
|
+
const root = options.root ?? process.cwd();
|
|
66
|
+
const tsConfig = options.tsConfig
|
|
67
|
+
? (0, node_path_1.resolve)(root, options.tsConfig)
|
|
68
|
+
: (0, node_path_1.join)(root, 'tsconfig.app.json');
|
|
69
|
+
const aot = options.aot ?? true;
|
|
70
|
+
const advancedOptimizations = aot && normalizedOptimization.scripts;
|
|
71
|
+
const project = await getProject(root);
|
|
72
|
+
const assets = project && options.assets?.length
|
|
73
|
+
? normalizeAssetPatterns(options.assets, root, project.data.root, project.data.sourceRoot)
|
|
74
|
+
: [];
|
|
75
|
+
const globalStyles = normalizeGlobalEntries(options.styles, 'styles');
|
|
76
|
+
const globalScripts = normalizeGlobalEntries(options.scripts, 'scripts');
|
|
77
|
+
if (options.index === false) {
|
|
78
|
+
console.warn('Disabling the "index" option is not yet supported. Defaulting to "src/index.html".');
|
|
79
|
+
options.index = (0, node_path_1.join)(root, 'src/index.html');
|
|
80
|
+
}
|
|
81
|
+
else if (!options.index) {
|
|
82
|
+
options.index = (0, node_path_1.join)(root, 'src/index.html');
|
|
83
|
+
}
|
|
84
|
+
// index can never have a value of `true` but in the schema it's of type `boolean`.
|
|
85
|
+
let indexOutput;
|
|
86
|
+
// The output file will be created within the configured output path
|
|
87
|
+
if (typeof options.index === 'string') {
|
|
88
|
+
indexOutput = options.index;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
if (options.index.preloadInitial) {
|
|
92
|
+
console.warn(`The "index.preloadInitial" option is not yet supported.`);
|
|
93
|
+
}
|
|
94
|
+
if (options.index.output) {
|
|
95
|
+
console.warn(`The "index.output" option is not yet supported.`);
|
|
96
|
+
}
|
|
97
|
+
indexOutput = options.index.output || 'index.html';
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* If SSR is activated, create a distinct entry file for the `index.html`.
|
|
101
|
+
* This is necessary because numerous server/cloud providers automatically serve the `index.html` as a static file
|
|
102
|
+
* if it exists (handling SSG).
|
|
103
|
+
*
|
|
104
|
+
* For instance, accessing `foo.com/` would lead to `foo.com/index.html` being served instead of hitting the server.
|
|
105
|
+
*
|
|
106
|
+
* This approach can also be applied to service workers, where the `index.csr.html` is served instead of the prerendered `index.html`.
|
|
107
|
+
*/
|
|
108
|
+
const indexBaseName = (0, node_path_1.basename)(indexOutput);
|
|
109
|
+
// @TODO: use this once we properly support SSR/SSG options
|
|
110
|
+
// (normalizedSsr || prerenderOptions) && indexBaseName === 'index.html'
|
|
111
|
+
// ? INDEX_HTML_CSR
|
|
112
|
+
// : indexBaseName;
|
|
113
|
+
indexOutput = indexBaseName;
|
|
114
|
+
const entryPoints = [
|
|
115
|
+
['runtime', !options.devServer?.hmr],
|
|
116
|
+
['polyfills', true],
|
|
117
|
+
...globalStyles.filter((s) => s.initial).map((s) => [s.name, false]),
|
|
118
|
+
...globalScripts.filter((s) => s.initial).map((s) => [s.name, false]),
|
|
119
|
+
['vendor', true],
|
|
120
|
+
['main', true],
|
|
121
|
+
];
|
|
122
|
+
const duplicates = entryPoints.filter(([name]) => entryPoints[0].indexOf(name) !== entryPoints[0].lastIndexOf(name));
|
|
123
|
+
if (duplicates.length > 0) {
|
|
124
|
+
throw new Error(`Multiple bundles have been named the same: '${duplicates.join(`', '`)}'.`);
|
|
125
|
+
}
|
|
126
|
+
const index = {
|
|
127
|
+
input: (0, node_path_1.resolve)(root, typeof options.index === 'string' ? options.index : options.index.input),
|
|
128
|
+
output: indexOutput,
|
|
129
|
+
transformer: typeof options.index === 'object' ? options.index.transformer : undefined,
|
|
130
|
+
// Preload initial defaults to true
|
|
131
|
+
preloadInitial: typeof options.index !== 'object' ||
|
|
132
|
+
(options.index.preloadInitial ?? true),
|
|
133
|
+
};
|
|
134
|
+
const budgets = !options.budgets
|
|
135
|
+
? []
|
|
136
|
+
: options.budgets.map((budget) => ({
|
|
137
|
+
...budget,
|
|
138
|
+
type: budget.type,
|
|
139
|
+
}));
|
|
140
|
+
const zoneless = options.polyfills
|
|
141
|
+
? !options.polyfills.includes('zone.js')
|
|
142
|
+
: true;
|
|
143
|
+
const stylePreprocessorOptions = options.stylePreprocessorOptions ?? {};
|
|
144
|
+
if (stylePreprocessorOptions.includePaths?.length) {
|
|
145
|
+
stylePreprocessorOptions.includePaths = [
|
|
146
|
+
...stylePreprocessorOptions.includePaths,
|
|
147
|
+
'node_modules',
|
|
148
|
+
];
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
advancedOptimizations,
|
|
152
|
+
appShell: options.appShell ?? false,
|
|
153
|
+
assets,
|
|
154
|
+
aot,
|
|
155
|
+
baseHref: options.baseHref,
|
|
156
|
+
browser: options.browser ?? './src/main.ts',
|
|
157
|
+
budgets,
|
|
158
|
+
commonChunk: options.commonChunk ?? true,
|
|
159
|
+
crossOrigin: options.crossOrigin ?? 'none',
|
|
160
|
+
define: options.define ?? {},
|
|
161
|
+
deleteOutputPath: options.deleteOutputPath ?? true,
|
|
162
|
+
deployUrl: options.deployUrl,
|
|
163
|
+
devServer: normalizeDevServer(options.devServer),
|
|
164
|
+
externalDependencies: options.externalDependencies ?? [],
|
|
165
|
+
extractLicenses: options.extractLicenses ?? true,
|
|
166
|
+
fileReplacements: resolveFileReplacements(fileReplacements, root),
|
|
167
|
+
globalStyles,
|
|
168
|
+
globalScripts,
|
|
169
|
+
hasServer: getHasServer(root, server, normalizedSsr),
|
|
170
|
+
index,
|
|
171
|
+
inlineStyleLanguage: options.inlineStyleLanguage ?? 'css',
|
|
172
|
+
namedChunks: options.namedChunks ?? false,
|
|
173
|
+
ngswConfigPath: options.ngswConfigPath,
|
|
174
|
+
optimization: normalizedOptimization,
|
|
175
|
+
outputHashing: options.outputHashing ?? 'none',
|
|
176
|
+
outputPath: normalizeOutputPath(root, options.outputPath),
|
|
177
|
+
poll: options.poll ?? undefined,
|
|
178
|
+
polyfills: options.polyfills ?? [],
|
|
179
|
+
prerender: options.prerender ?? false,
|
|
180
|
+
projectName: project?.name ?? undefined,
|
|
181
|
+
progress: options.progress ?? true,
|
|
182
|
+
root,
|
|
183
|
+
scripts: options.scripts ?? [],
|
|
184
|
+
serviceWorker: options.serviceWorker,
|
|
185
|
+
server,
|
|
186
|
+
skipTypeChecking: options.skipTypeChecking ?? false,
|
|
187
|
+
sourceMap: normalizeSourceMap(options.sourceMap),
|
|
188
|
+
ssr: normalizedSsr,
|
|
189
|
+
statsJson: options.statsJson ?? false,
|
|
190
|
+
styles: options.styles ?? [],
|
|
191
|
+
stylePreprocessorOptions,
|
|
192
|
+
subresourceIntegrity: options.subresourceIntegrity ?? false,
|
|
193
|
+
supportedBrowsers: (0, private_1.getSupportedBrowsers)(root, { warn: console.warn }),
|
|
194
|
+
tsConfig,
|
|
195
|
+
useTsProjectReferences: options.useTsProjectReferences ?? false,
|
|
196
|
+
vendorChunk: options.vendorChunk ?? false,
|
|
197
|
+
verbose: options.verbose ?? false,
|
|
198
|
+
watch: options.watch ?? false,
|
|
199
|
+
zoneless,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function normalizeOptimization(optimization) {
|
|
203
|
+
if (typeof optimization === 'boolean') {
|
|
204
|
+
return {
|
|
205
|
+
fonts: {
|
|
206
|
+
inline: optimization,
|
|
207
|
+
},
|
|
208
|
+
scripts: optimization,
|
|
209
|
+
styles: {
|
|
210
|
+
minify: optimization,
|
|
211
|
+
inlineCritical: optimization,
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
else if (optimization === undefined) {
|
|
216
|
+
return {
|
|
217
|
+
fonts: {
|
|
218
|
+
inline: true,
|
|
219
|
+
},
|
|
220
|
+
scripts: true,
|
|
221
|
+
styles: {
|
|
222
|
+
minify: true,
|
|
223
|
+
inlineCritical: true,
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
fonts: {
|
|
229
|
+
inline: optimization.fonts === undefined
|
|
230
|
+
? true
|
|
231
|
+
: typeof optimization.fonts === 'boolean'
|
|
232
|
+
? optimization.fonts
|
|
233
|
+
: optimization.fonts.inline ?? true,
|
|
234
|
+
},
|
|
235
|
+
scripts: optimization.scripts ?? true,
|
|
236
|
+
styles: {
|
|
237
|
+
minify: optimization.styles === undefined
|
|
238
|
+
? true
|
|
239
|
+
: typeof optimization.styles === 'boolean'
|
|
240
|
+
? optimization.styles
|
|
241
|
+
: optimization.styles.minify ?? true,
|
|
242
|
+
inlineCritical: optimization.styles === undefined
|
|
243
|
+
? true
|
|
244
|
+
: typeof optimization.styles === 'boolean'
|
|
245
|
+
? optimization.styles
|
|
246
|
+
: optimization.styles.inlineCritical ?? true,
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function normalizeSourceMap(sourceMap) {
|
|
251
|
+
if (sourceMap === undefined) {
|
|
252
|
+
return {
|
|
253
|
+
scripts: false,
|
|
254
|
+
styles: false,
|
|
255
|
+
hidden: false,
|
|
256
|
+
vendor: false,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
if (typeof sourceMap === 'boolean') {
|
|
260
|
+
return {
|
|
261
|
+
scripts: sourceMap,
|
|
262
|
+
styles: sourceMap,
|
|
263
|
+
hidden: sourceMap,
|
|
264
|
+
vendor: sourceMap,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
scripts: sourceMap.scripts ?? true,
|
|
269
|
+
styles: sourceMap.styles ?? true,
|
|
270
|
+
hidden: sourceMap.hidden ?? false,
|
|
271
|
+
vendor: sourceMap.vendor ?? false,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
function normalizeDevServer(devServer) {
|
|
275
|
+
const defaultHost = 'localhost';
|
|
276
|
+
const defaultPort = 4200;
|
|
277
|
+
if (!devServer) {
|
|
278
|
+
return {
|
|
279
|
+
allowedHosts: [],
|
|
280
|
+
host: defaultHost,
|
|
281
|
+
liveReload: true,
|
|
282
|
+
port: defaultPort,
|
|
283
|
+
open: false,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
...devServer,
|
|
288
|
+
open: devServer.open ?? false,
|
|
289
|
+
allowedHosts: devServer.allowedHosts ?? [],
|
|
290
|
+
host: devServer.host ?? defaultHost,
|
|
291
|
+
liveReload: devServer.liveReload ?? true,
|
|
292
|
+
port: devServer.port ?? defaultPort,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
function normalizeOutputPath(root, outputPath) {
|
|
296
|
+
let base = typeof outputPath === 'string' ? outputPath : outputPath?.base ?? 'dist';
|
|
297
|
+
if (!base.startsWith(root)) {
|
|
298
|
+
base = (0, node_path_1.join)(root, base);
|
|
299
|
+
}
|
|
300
|
+
const browser = typeof outputPath === 'string' || !outputPath?.browser
|
|
301
|
+
? (0, node_path_1.join)(base, 'browser')
|
|
302
|
+
: (0, node_path_1.join)(base, outputPath.browser);
|
|
303
|
+
const server = typeof outputPath === 'string' || !outputPath?.server
|
|
304
|
+
? (0, node_path_1.join)(base, 'server')
|
|
305
|
+
: (0, node_path_1.join)(base, outputPath.server);
|
|
306
|
+
const media = typeof outputPath === 'string' || !outputPath?.media
|
|
307
|
+
? (0, node_path_1.join)(browser, 'media')
|
|
308
|
+
: (0, node_path_1.join)(browser, outputPath.media);
|
|
309
|
+
return { base, browser, server, media };
|
|
310
|
+
}
|
|
311
|
+
function normalizeAssetPatterns(assets, root, projectRoot, projectSourceRoot) {
|
|
312
|
+
if (assets.length === 0) {
|
|
313
|
+
return [];
|
|
314
|
+
}
|
|
315
|
+
// When sourceRoot is not available, we default to ${projectRoot}/src.
|
|
316
|
+
const resolvedSourceRoot = projectSourceRoot
|
|
317
|
+
? (0, node_path_1.join)(devkit_1.workspaceRoot, projectSourceRoot)
|
|
318
|
+
: (0, node_path_1.join)(devkit_1.workspaceRoot, projectRoot, 'src');
|
|
319
|
+
return assets.map((assetPattern) => {
|
|
320
|
+
// Normalize string asset patterns to objects.
|
|
321
|
+
if (typeof assetPattern === 'string') {
|
|
322
|
+
const assetPath = (0, node_path_1.normalize)(assetPattern);
|
|
323
|
+
const resolvedAssetPath = (0, node_path_1.resolve)(root, assetPath);
|
|
324
|
+
// Check if the string asset is within sourceRoot.
|
|
325
|
+
if (!resolvedAssetPath.startsWith(resolvedSourceRoot)) {
|
|
326
|
+
throw new Error(`The ${assetPattern} asset path must start with the project source root.`);
|
|
327
|
+
}
|
|
328
|
+
let glob, input;
|
|
329
|
+
let isDirectory = false;
|
|
330
|
+
try {
|
|
331
|
+
isDirectory = (0, node_fs_1.statSync)(resolvedAssetPath).isDirectory();
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
isDirectory = true;
|
|
335
|
+
}
|
|
336
|
+
if (isDirectory) {
|
|
337
|
+
// Folders get a recursive star glob.
|
|
338
|
+
glob = '**/*';
|
|
339
|
+
// Input directory is their original path.
|
|
340
|
+
input = assetPath;
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
// Files are their own glob.
|
|
344
|
+
glob = (0, node_path_1.basename)(assetPath);
|
|
345
|
+
// Input directory is their original dirname.
|
|
346
|
+
input = (0, node_path_1.dirname)(assetPath);
|
|
347
|
+
}
|
|
348
|
+
// Output directory for both is the relative path from source root to input.
|
|
349
|
+
const output = (0, node_path_1.relative)(resolvedSourceRoot, (0, node_path_1.resolve)(root, input));
|
|
350
|
+
assetPattern = { glob, input, output };
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
assetPattern.output = (0, node_path_1.join)('.', assetPattern.output ?? '');
|
|
354
|
+
}
|
|
355
|
+
(0, node_assert_1.default)(assetPattern.output !== undefined);
|
|
356
|
+
if (assetPattern.output.startsWith('..')) {
|
|
357
|
+
throw new Error('An asset cannot be written to a location outside of the output path.');
|
|
358
|
+
}
|
|
359
|
+
return assetPattern;
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
function normalizeGlobalEntries(rawEntries, defaultName) {
|
|
363
|
+
if (!rawEntries?.length) {
|
|
364
|
+
return [];
|
|
365
|
+
}
|
|
366
|
+
const bundles = new Map();
|
|
367
|
+
for (const rawEntry of rawEntries) {
|
|
368
|
+
let entry;
|
|
369
|
+
if (typeof rawEntry === 'string') {
|
|
370
|
+
// string entries use default bundle name and inject values
|
|
371
|
+
entry = { input: rawEntry };
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
entry = rawEntry;
|
|
375
|
+
}
|
|
376
|
+
const { bundleName, input, inject = true } = entry;
|
|
377
|
+
// Non-injected entries default to the file name
|
|
378
|
+
const name = bundleName || (inject ? defaultName : (0, node_path_1.basename)(input, (0, node_path_1.extname)(input)));
|
|
379
|
+
const existing = bundles.get(name);
|
|
380
|
+
if (!existing) {
|
|
381
|
+
bundles.set(name, { name, files: [input], initial: inject });
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (existing.initial !== inject) {
|
|
385
|
+
throw new Error(`The "${name}" bundle is mixing injected and non-injected entries. ` +
|
|
386
|
+
'Verify that the project options are correct.');
|
|
387
|
+
}
|
|
388
|
+
existing.files.push(input);
|
|
389
|
+
}
|
|
390
|
+
return [...bundles.values()];
|
|
391
|
+
}
|
|
392
|
+
async function getProject(root) {
|
|
393
|
+
if (global.NX_GRAPH_CREATION) {
|
|
394
|
+
return undefined;
|
|
395
|
+
}
|
|
396
|
+
const projectGraph = await (0, graph_1.retrieveOrCreateProjectGraph)();
|
|
397
|
+
let projectName = process.env.NX_TASK_TARGET_PROJECT;
|
|
398
|
+
if (projectGraph) {
|
|
399
|
+
if (!projectName) {
|
|
400
|
+
const projectRootMappings = createProjectRootMappings(projectGraph.nodes);
|
|
401
|
+
projectName =
|
|
402
|
+
(0, find_project_for_path_1.findProjectForPath)(node_path_1.posix.relative(devkit_1.workspaceRoot, root), projectRootMappings) ?? undefined;
|
|
403
|
+
}
|
|
404
|
+
if (projectName) {
|
|
405
|
+
return projectGraph.nodes[projectName];
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return {
|
|
409
|
+
name: undefined,
|
|
410
|
+
data: {
|
|
411
|
+
name: undefined,
|
|
412
|
+
root: root,
|
|
413
|
+
sourceRoot: undefined,
|
|
414
|
+
},
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
function createProjectRootMappings(nodes) {
|
|
418
|
+
const projectRootMappings = new Map();
|
|
419
|
+
for (const projectName of Object.keys(nodes)) {
|
|
420
|
+
const root = nodes[projectName].data.root;
|
|
421
|
+
projectRootMappings.set((0, find_project_for_path_1.normalizeProjectRoot)(root), projectName);
|
|
422
|
+
}
|
|
423
|
+
return projectRootMappings;
|
|
424
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Compiler, type RspackPluginInstance } from '@rspack/core';
|
|
2
|
+
import { type I18nOptions, type NormalizedAngularRspackPluginOptions } from '../models';
|
|
3
|
+
export declare class AngularRspackPlugin implements RspackPluginInstance {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(options: NormalizedAngularRspackPluginOptions, i18nOptions?: I18nOptions);
|
|
6
|
+
apply(compiler: Compiler): void;
|
|
7
|
+
private setupCompilation;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=angular-rspack-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"angular-rspack-plugin.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/angular-rspack-plugin.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,KAAK,QAAQ,EAEb,KAAK,oBAAoB,EAE1B,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,KAAK,WAAW,EAGhB,KAAK,oCAAoC,EAC1C,MAAM,WAAW,CAAC;AAUnB,qBAAa,mBAAoB,YAAW,oBAAoB;;gBAS5D,OAAO,EAAE,oCAAoC,EAC7C,WAAW,CAAC,EAAE,WAAW;IAuB3B,KAAK,CAAC,QAAQ,EAAE,QAAQ;YA8PV,gBAAgB;CAgC/B"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _AngularRspackPlugin__options, _AngularRspackPlugin_i18n, _AngularRspackPlugin_sourceFileCache, _AngularRspackPlugin_javascriptTransformer, _AngularRspackPlugin_angularCompilation;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.AngularRspackPlugin = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const private_1 = require("@angular/build/private");
|
|
7
|
+
const angular_rspack_compiler_1 = require("@nx/angular-rspack-compiler");
|
|
8
|
+
const devkit_1 = require("@nx/devkit");
|
|
9
|
+
const core_1 = require("@rspack/core");
|
|
10
|
+
const node_path_1 = require("node:path");
|
|
11
|
+
const models_1 = require("../models");
|
|
12
|
+
const get_locale_base_href_1 = require("../utils/get-locale-base-href");
|
|
13
|
+
const rspack_diagnostics_1 = require("../utils/rspack-diagnostics");
|
|
14
|
+
const misc_helpers_1 = require("../utils/misc-helpers");
|
|
15
|
+
const stats_1 = require("../utils/stats");
|
|
16
|
+
const get_stats_options_1 = require("../config/config-utils/get-stats-options");
|
|
17
|
+
const PLUGIN_NAME = 'AngularRspackPlugin';
|
|
18
|
+
class AngularRspackPlugin {
|
|
19
|
+
constructor(options, i18nOptions) {
|
|
20
|
+
_AngularRspackPlugin__options.set(this, void 0);
|
|
21
|
+
_AngularRspackPlugin_i18n.set(this, void 0);
|
|
22
|
+
_AngularRspackPlugin_sourceFileCache.set(this, void 0);
|
|
23
|
+
_AngularRspackPlugin_javascriptTransformer.set(this, void 0);
|
|
24
|
+
// This will be defined in the apply method correctly
|
|
25
|
+
_AngularRspackPlugin_angularCompilation.set(this, void 0);
|
|
26
|
+
tslib_1.__classPrivateFieldSet(this, _AngularRspackPlugin__options, options, "f");
|
|
27
|
+
tslib_1.__classPrivateFieldSet(this, _AngularRspackPlugin_i18n, i18nOptions, "f");
|
|
28
|
+
tslib_1.__classPrivateFieldSet(this, _AngularRspackPlugin_sourceFileCache, new angular_rspack_compiler_1.SourceFileCache(), "f");
|
|
29
|
+
tslib_1.__classPrivateFieldSet(this, _AngularRspackPlugin_javascriptTransformer, new angular_rspack_compiler_1.JavaScriptTransformer({
|
|
30
|
+
/**
|
|
31
|
+
* Matches https://github.com/angular/angular-cli/blob/33ed6e875e509ebbaa0cbdb57be9e932f9915dff/packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts#L89
|
|
32
|
+
* where pluginOptions.sourcemap is set https://github.com/angular/angular-cli/blob/61d98fde122468978de9b17bd79761befdbf2fac/packages/angular/build/src/tools/esbuild/compiler-plugin-options.ts#L34
|
|
33
|
+
*/
|
|
34
|
+
sourcemap: !!(tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").sourceMap.scripts &&
|
|
35
|
+
(tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").sourceMap.hidden ? 'external' : true)),
|
|
36
|
+
thirdPartySourcemaps: tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").sourceMap.vendor,
|
|
37
|
+
advancedOptimizations: tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").advancedOptimizations,
|
|
38
|
+
jit: !tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").aot,
|
|
39
|
+
}, (0, angular_rspack_compiler_1.maxWorkers)()), "f");
|
|
40
|
+
}
|
|
41
|
+
apply(compiler) {
|
|
42
|
+
const root = tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").root;
|
|
43
|
+
// Both of these are exclusive to each other - only one of them can be used at a time
|
|
44
|
+
// But they will happen before the compiler is created - so we can use them to set up the parallel compilation once
|
|
45
|
+
compiler.hooks.beforeRun.tapAsync(PLUGIN_NAME, async (compiler, callback) => {
|
|
46
|
+
await this.setupCompilation(root, compiler.options.resolve.tsConfig);
|
|
47
|
+
compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, async (params, callback) => {
|
|
48
|
+
await (0, angular_rspack_compiler_1.buildAndAnalyze)(tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_angularCompilation, "f"), tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_sourceFileCache, "f").typeScriptFileCache, tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_javascriptTransformer, "f"));
|
|
49
|
+
callback();
|
|
50
|
+
});
|
|
51
|
+
callback();
|
|
52
|
+
});
|
|
53
|
+
compiler.hooks.watchRun.tapAsync(PLUGIN_NAME, async (compiler, callback) => {
|
|
54
|
+
if (!compiler.hooks.beforeCompile.taps.some((tap) => tap.name === PLUGIN_NAME)) {
|
|
55
|
+
compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, async (params, callback) => {
|
|
56
|
+
const watchingModifiedFiles = compiler.watching?.compiler
|
|
57
|
+
?.modifiedFiles
|
|
58
|
+
? new Set(compiler.watching.compiler.modifiedFiles)
|
|
59
|
+
: new Set();
|
|
60
|
+
if (tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_angularCompilation, "f")) {
|
|
61
|
+
tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_sourceFileCache, "f").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)(tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_angularCompilation, "f"), tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_sourceFileCache, "f").typeScriptFileCache, tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_javascriptTransformer, "f"));
|
|
67
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
68
|
+
watchingModifiedFiles.forEach((file) => {
|
|
69
|
+
compilation.fileDependencies.add(file);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
callback();
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
callback();
|
|
76
|
+
});
|
|
77
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
78
|
+
compilation.hooks.processAssets.tap({
|
|
79
|
+
name: PLUGIN_NAME,
|
|
80
|
+
stage: compiler.rspack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
|
|
81
|
+
}, (assets) => {
|
|
82
|
+
for (const assetName in assets) {
|
|
83
|
+
const asset = compilation.getAsset(assetName);
|
|
84
|
+
if (!asset) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const assetHash = asset.info?.contenthash?.[0] ?? '';
|
|
88
|
+
const assetNameWithoutHash = assetName.replace(`.${assetHash}`, '');
|
|
89
|
+
if (assetNameWithoutHash !== 'main.js') {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const originalSource = asset.source;
|
|
93
|
+
let setLocaleContent = '';
|
|
94
|
+
if (tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_i18n, "f")?.shouldInline) {
|
|
95
|
+
// When inlining, a placeholder is used to allow the post-processing step to inject the $localize locale identifier.
|
|
96
|
+
setLocaleContent +=
|
|
97
|
+
'(globalThis.$localize ??= {}).locale = "___NG_LOCALE_INSERT___";\n';
|
|
98
|
+
}
|
|
99
|
+
else if (tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_i18n, "f")?.hasDefinedSourceLocale) {
|
|
100
|
+
// If not inlining translations and source locale is defined, inject the locale specifier.
|
|
101
|
+
setLocaleContent += `(globalThis.$localize ??= {}).locale = "${tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_i18n, "f").sourceLocale}";\n`;
|
|
102
|
+
}
|
|
103
|
+
const concatLocaleSource = new core_1.sources.ConcatSource(setLocaleContent, originalSource);
|
|
104
|
+
compilation.updateAsset(assetName, concatLocaleSource, (assetInfo) => assetInfo);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
compiler.hooks.emit.tapAsync(PLUGIN_NAME, async (compilation, callback) => {
|
|
109
|
+
if (!tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").skipTypeChecking) {
|
|
110
|
+
const { errors, warnings } = await tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_angularCompilation, "f").diagnoseFiles(angular_rspack_compiler_1.DiagnosticModes.All);
|
|
111
|
+
for (const error of errors ?? []) {
|
|
112
|
+
compilation.errors.push({
|
|
113
|
+
name: PLUGIN_NAME,
|
|
114
|
+
message: error.text || '',
|
|
115
|
+
file: error.location?.file,
|
|
116
|
+
loc: `${error.location?.line}:${error.location?.column}`,
|
|
117
|
+
moduleIdentifier: error.location?.file,
|
|
118
|
+
stack: error.text,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
for (const warning of warnings ?? []) {
|
|
122
|
+
compilation.warnings.push({
|
|
123
|
+
name: PLUGIN_NAME,
|
|
124
|
+
message: warning.text || '',
|
|
125
|
+
file: warning.location?.file,
|
|
126
|
+
loc: `${warning.location?.line}:${warning.location?.column}`,
|
|
127
|
+
stack: warning.text,
|
|
128
|
+
moduleIdentifier: warning.location?.file,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
await tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_javascriptTransformer, "f").close();
|
|
133
|
+
callback();
|
|
134
|
+
});
|
|
135
|
+
compiler.hooks.afterEmit.tap(PLUGIN_NAME, (compilation) => {
|
|
136
|
+
// Check for budget errors and display them to the user.
|
|
137
|
+
const budgets = tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").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)(tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").verbose));
|
|
167
|
+
if (stats.hasErrors()) {
|
|
168
|
+
process.exit(1);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
compiler.hooks.normalModuleFactory.tap(PLUGIN_NAME, (normalModuleFactory) => {
|
|
173
|
+
normalModuleFactory.hooks.beforeResolve.tap(PLUGIN_NAME, (data) => {
|
|
174
|
+
if (data.request.startsWith('angular:jit:')) {
|
|
175
|
+
const path = data.request.split(';')[1];
|
|
176
|
+
data.request = `${(0, node_path_1.normalize)((0, node_path_1.resolve)((0, node_path_1.dirname)(data.contextInfo.issuer), path))}?raw`;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
181
|
+
compilation[models_1.NG_RSPACK_SYMBOL_NAME] = () => ({
|
|
182
|
+
javascriptTransformer: tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_javascriptTransformer, "f"),
|
|
183
|
+
typescriptFileCache: tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_sourceFileCache, "f").typeScriptFileCache,
|
|
184
|
+
i18n: tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_i18n, "f"),
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
if (tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").serviceWorker) {
|
|
188
|
+
compiler.hooks.done.tapAsync(PLUGIN_NAME, async (compilation, callback) => {
|
|
189
|
+
let providedLocales = tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").localize;
|
|
190
|
+
if (!providedLocales) {
|
|
191
|
+
await (0, private_1.augmentAppWithServiceWorker)(tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").root, devkit_1.workspaceRoot, tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").outputPath.browser, tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").baseHref ?? '/', tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").ngswConfigPath);
|
|
192
|
+
}
|
|
193
|
+
else if (providedLocales && tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_i18n, "f")) {
|
|
194
|
+
if (typeof providedLocales === 'string') {
|
|
195
|
+
providedLocales = [providedLocales];
|
|
196
|
+
}
|
|
197
|
+
else if (typeof providedLocales === 'boolean') {
|
|
198
|
+
providedLocales = Array.from(tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_i18n, "f").inlineLocales);
|
|
199
|
+
}
|
|
200
|
+
for (const locale of providedLocales) {
|
|
201
|
+
await (0, private_1.augmentAppWithServiceWorker)(tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").root, devkit_1.workspaceRoot, (0, node_path_1.join)(tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").outputPath.browser, tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_i18n, "f").locales[locale]?.subPath ?? locale), (0, get_locale_base_href_1.getLocaleBaseHref)(tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_i18n, "f"), locale, tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").baseHref) ??
|
|
202
|
+
tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").baseHref ??
|
|
203
|
+
'/', tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").ngswConfigPath);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
callback();
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async setupCompilation(root, tsConfig, modifiedFiles) {
|
|
211
|
+
const tsconfigPath = tsConfig
|
|
212
|
+
? typeof tsConfig === 'string'
|
|
213
|
+
? tsConfig
|
|
214
|
+
: tsConfig.configFile
|
|
215
|
+
: tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").tsConfig;
|
|
216
|
+
tslib_1.__classPrivateFieldSet(this, _AngularRspackPlugin_angularCompilation, await (0, angular_rspack_compiler_1.setupCompilationWithAngularCompilation)({
|
|
217
|
+
source: {
|
|
218
|
+
tsconfigPath: tsconfigPath,
|
|
219
|
+
},
|
|
220
|
+
}, {
|
|
221
|
+
root,
|
|
222
|
+
aot: tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").aot,
|
|
223
|
+
tsConfig: tsconfigPath,
|
|
224
|
+
inlineStyleLanguage: tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").inlineStyleLanguage,
|
|
225
|
+
fileReplacements: tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").fileReplacements,
|
|
226
|
+
useTsProjectReferences: tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").useTsProjectReferences,
|
|
227
|
+
hasServer: tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").hasServer,
|
|
228
|
+
includePaths: tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").stylePreprocessorOptions?.includePaths,
|
|
229
|
+
sass: tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin__options, "f").stylePreprocessorOptions?.sass,
|
|
230
|
+
}, tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_sourceFileCache, "f"), tslib_1.__classPrivateFieldGet(this, _AngularRspackPlugin_angularCompilation, "f"), modifiedFiles), "f");
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
exports.AngularRspackPlugin = AngularRspackPlugin;
|
|
234
|
+
_AngularRspackPlugin__options = new WeakMap(), _AngularRspackPlugin_i18n = new WeakMap(), _AngularRspackPlugin_sourceFileCache = new WeakMap(), _AngularRspackPlugin_javascriptTransformer = new WeakMap(), _AngularRspackPlugin_angularCompilation = new WeakMap();
|