@nx/angular 20.6.0-canary.20250314-beb1784 → 20.6.1
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/generators.json +5 -0
- package/package.json +10 -8
- package/src/generators/convert-to-rspack/convert-to-rspack.d.ts +4 -0
- package/src/generators/convert-to-rspack/convert-to-rspack.js +318 -0
- package/src/generators/convert-to-rspack/lib/create-config.d.ts +2 -0
- package/src/generators/convert-to-rspack/lib/create-config.js +48 -0
- package/src/generators/convert-to-rspack/lib/get-custom-webpack-config.d.ts +6 -0
- package/src/generators/convert-to-rspack/lib/get-custom-webpack-config.js +75 -0
- package/src/generators/convert-to-rspack/lib/update-tsconfig.d.ts +2 -0
- package/src/generators/convert-to-rspack/lib/update-tsconfig.js +14 -0
- package/src/generators/convert-to-rspack/lib/validate-supported-executor.d.ts +2 -0
- package/src/generators/convert-to-rspack/lib/validate-supported-executor.js +14 -0
- package/src/generators/convert-to-rspack/schema.d.ts +5 -0
- package/src/generators/convert-to-rspack/schema.json +30 -0
- package/src/utils/backward-compatible-versions.js +2 -0
- package/src/utils/versions.d.ts +1 -0
- package/src/utils/versions.js +2 -1
package/generators.json
CHANGED
|
@@ -38,6 +38,11 @@
|
|
|
38
38
|
"schema": "./src/generators/convert-to-application-executor/schema.json",
|
|
39
39
|
"description": "Converts projects to use the `@nx/angular:application` executor or the `@angular-devkit/build-angular:application` builder."
|
|
40
40
|
},
|
|
41
|
+
"convert-to-rspack": {
|
|
42
|
+
"factory": "./src/generators/convert-to-rspack/convert-to-rspack",
|
|
43
|
+
"schema": "./src/generators/convert-to-rspack/schema.json",
|
|
44
|
+
"description": "Converts Angular Webpack projects to use Rspack."
|
|
45
|
+
},
|
|
41
46
|
"directive": {
|
|
42
47
|
"factory": "./src/generators/directive/directive",
|
|
43
48
|
"schema": "./src/generators/directive/schema.json",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/angular",
|
|
3
|
-
"version": "20.6.
|
|
3
|
+
"version": "20.6.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Playwright and Cypress. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
|
6
6
|
"repository": {
|
|
@@ -65,19 +65,21 @@
|
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
67
67
|
"@typescript-eslint/type-utils": "^8.0.0",
|
|
68
|
+
"enquirer": "~2.3.6",
|
|
68
69
|
"picocolors": "^1.1.0",
|
|
69
70
|
"magic-string": "~0.30.2",
|
|
70
71
|
"minimatch": "9.0.3",
|
|
71
72
|
"semver": "^7.5.3",
|
|
72
73
|
"tslib": "^2.3.0",
|
|
73
74
|
"webpack-merge": "^5.8.0",
|
|
74
|
-
"@nx/devkit": "20.6.
|
|
75
|
-
"@nx/js": "20.6.
|
|
76
|
-
"@nx/eslint": "20.6.
|
|
77
|
-
"@nx/webpack": "20.6.
|
|
78
|
-
"@nx/
|
|
79
|
-
"@nx/
|
|
80
|
-
"@nx/
|
|
75
|
+
"@nx/devkit": "20.6.1",
|
|
76
|
+
"@nx/js": "20.6.1",
|
|
77
|
+
"@nx/eslint": "20.6.1",
|
|
78
|
+
"@nx/webpack": "20.6.1",
|
|
79
|
+
"@nx/rspack": "20.6.1",
|
|
80
|
+
"@nx/module-federation": "20.6.1",
|
|
81
|
+
"@nx/web": "20.6.1",
|
|
82
|
+
"@nx/workspace": "20.6.1",
|
|
81
83
|
"piscina": "^4.4.0"
|
|
82
84
|
},
|
|
83
85
|
"peerDependencies": {
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToRspack = convertToRspack;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const versions_1 = require("../../utils/versions");
|
|
6
|
+
const create_config_1 = require("./lib/create-config");
|
|
7
|
+
const get_custom_webpack_config_1 = require("./lib/get-custom-webpack-config");
|
|
8
|
+
const update_tsconfig_1 = require("./lib/update-tsconfig");
|
|
9
|
+
const validate_supported_executor_1 = require("./lib/validate-supported-executor");
|
|
10
|
+
const posix_1 = require("path/posix");
|
|
11
|
+
const path_1 = require("path");
|
|
12
|
+
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
13
|
+
const enquirer_1 = require("enquirer");
|
|
14
|
+
const SUPPORTED_EXECUTORS = [
|
|
15
|
+
'@angular-devkit/build-angular:browser',
|
|
16
|
+
'@angular-devkit/build-angular:dev-server',
|
|
17
|
+
'@nx/angular:webpack-browser',
|
|
18
|
+
'@nx/angular:dev-server',
|
|
19
|
+
'@nx/angular:module-federation-dev-server',
|
|
20
|
+
];
|
|
21
|
+
const RENAMED_OPTIONS = {
|
|
22
|
+
main: 'browser',
|
|
23
|
+
ngswConfigPath: 'serviceWorker',
|
|
24
|
+
};
|
|
25
|
+
const REMOVED_OPTIONS = [
|
|
26
|
+
'publicHost',
|
|
27
|
+
'disableHostCheck',
|
|
28
|
+
'resourcesOutputPath',
|
|
29
|
+
'routesFile',
|
|
30
|
+
'routes',
|
|
31
|
+
'discoverRoutes',
|
|
32
|
+
'appModuleBundle',
|
|
33
|
+
'inputIndexPath',
|
|
34
|
+
'outputIndexPath',
|
|
35
|
+
'buildOptimizer',
|
|
36
|
+
'deployUrl',
|
|
37
|
+
'buildTarget',
|
|
38
|
+
'browserTarget',
|
|
39
|
+
];
|
|
40
|
+
function normalizeFromProjectRoot(tree, path, projectRoot) {
|
|
41
|
+
if (projectRoot === '.') {
|
|
42
|
+
if (!path.startsWith('./')) {
|
|
43
|
+
return `./${path}`;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return path;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else if (path.startsWith(projectRoot)) {
|
|
50
|
+
return path.replace(projectRoot, '.');
|
|
51
|
+
}
|
|
52
|
+
else if (!path.startsWith('./')) {
|
|
53
|
+
if (tree.exists(path)) {
|
|
54
|
+
const pathWithWorkspaceRoot = (0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, path);
|
|
55
|
+
const projectRootWithWorkspaceRoot = (0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, projectRoot);
|
|
56
|
+
return (0, path_1.relative)(projectRootWithWorkspaceRoot, pathWithWorkspaceRoot);
|
|
57
|
+
}
|
|
58
|
+
return `./${path}`;
|
|
59
|
+
}
|
|
60
|
+
return path;
|
|
61
|
+
}
|
|
62
|
+
const defaultNormalizer = (tree, path, root) => normalizeFromProjectRoot(tree, path, root);
|
|
63
|
+
const PATH_NORMALIZER = {
|
|
64
|
+
index: (tree, path, root) => {
|
|
65
|
+
if (typeof path === 'string') {
|
|
66
|
+
return normalizeFromProjectRoot(tree, path, root);
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
input: normalizeFromProjectRoot(tree, path.input, root),
|
|
70
|
+
output: path.output ?? 'index.html',
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
indexHtmlTransformer: defaultNormalizer,
|
|
74
|
+
main: defaultNormalizer,
|
|
75
|
+
server: defaultNormalizer,
|
|
76
|
+
tsConfig: defaultNormalizer,
|
|
77
|
+
outputPath: (tree, path, root) => {
|
|
78
|
+
const relativePathFromWorkspaceRoot = (0, path_1.relative)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, root), devkit_1.workspaceRoot);
|
|
79
|
+
return (0, devkit_1.joinPathFragments)(relativePathFromWorkspaceRoot, path);
|
|
80
|
+
},
|
|
81
|
+
proxyConfig: defaultNormalizer,
|
|
82
|
+
polyfills: (tree, paths, root) => {
|
|
83
|
+
const normalizedPaths = [];
|
|
84
|
+
const normalizeFn = (path) => {
|
|
85
|
+
try {
|
|
86
|
+
const resolvedPath = require.resolve(path, {
|
|
87
|
+
paths: [(0, posix_1.join)(devkit_1.workspaceRoot, 'node_modules')],
|
|
88
|
+
});
|
|
89
|
+
normalizedPaths.push(path);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
normalizedPaths.push(normalizeFromProjectRoot(tree, path, root));
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
if (typeof paths === 'string') {
|
|
96
|
+
normalizeFn(paths);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
for (const path of paths) {
|
|
100
|
+
normalizeFn(path);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return normalizedPaths;
|
|
104
|
+
},
|
|
105
|
+
styles: (tree, paths, root) => {
|
|
106
|
+
const normalizedPaths = [];
|
|
107
|
+
for (const path of paths) {
|
|
108
|
+
if (typeof path === 'string') {
|
|
109
|
+
normalizedPaths.push(normalizeFromProjectRoot(tree, path, root));
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
normalizedPaths.push({
|
|
113
|
+
input: normalizeFromProjectRoot(tree, path.input, root),
|
|
114
|
+
bundleName: path.bundleName,
|
|
115
|
+
inject: path.inject ?? true,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return normalizedPaths;
|
|
120
|
+
},
|
|
121
|
+
scripts: (tree, paths, root) => {
|
|
122
|
+
const normalizedPaths = [];
|
|
123
|
+
for (const path of paths) {
|
|
124
|
+
if (typeof path === 'string') {
|
|
125
|
+
normalizedPaths.push(normalizeFromProjectRoot(tree, path, root));
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
normalizedPaths.push({
|
|
129
|
+
input: normalizeFromProjectRoot(tree, path.input, root),
|
|
130
|
+
bundleName: path.bundleName,
|
|
131
|
+
inject: path.inject ?? true,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return normalizedPaths;
|
|
136
|
+
},
|
|
137
|
+
assets: (tree, paths, root) => {
|
|
138
|
+
const normalizedPaths = [];
|
|
139
|
+
for (const path of paths) {
|
|
140
|
+
if (typeof path === 'string') {
|
|
141
|
+
normalizedPaths.push(normalizeFromProjectRoot(tree, path, root));
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
normalizedPaths.push({
|
|
145
|
+
...path,
|
|
146
|
+
input: normalizeFromProjectRoot(tree, path.input, root),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return normalizedPaths;
|
|
151
|
+
},
|
|
152
|
+
fileReplacements: (tree, paths, root) => {
|
|
153
|
+
const normalizedPaths = [];
|
|
154
|
+
for (const path of paths) {
|
|
155
|
+
normalizedPaths.push({
|
|
156
|
+
replace: normalizeFromProjectRoot(tree, 'src' in path ? path.src : path.replace, root),
|
|
157
|
+
with: normalizeFromProjectRoot(tree, 'replaceWith' in path ? path.replaceWith : path.with, root),
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return normalizedPaths;
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
function handleBuildTargetOptions(tree, options, newConfigurationOptions, root) {
|
|
164
|
+
let customWebpackConfigPath;
|
|
165
|
+
if (!options || Object.keys(options).length === 0) {
|
|
166
|
+
return customWebpackConfigPath;
|
|
167
|
+
}
|
|
168
|
+
if (options.customWebpackConfig) {
|
|
169
|
+
customWebpackConfigPath = options.customWebpackConfig.path;
|
|
170
|
+
delete options.customWebpackConfig;
|
|
171
|
+
}
|
|
172
|
+
if (options.outputs) {
|
|
173
|
+
// handled by the Rspack inference plugin
|
|
174
|
+
delete options.outputs;
|
|
175
|
+
}
|
|
176
|
+
for (const [key, value] of Object.entries(options)) {
|
|
177
|
+
let optionName = key;
|
|
178
|
+
let optionValue = key in PATH_NORMALIZER ? PATH_NORMALIZER[key](tree, value, root) : value;
|
|
179
|
+
if (REMOVED_OPTIONS.includes(key)) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (key in RENAMED_OPTIONS) {
|
|
183
|
+
optionName = RENAMED_OPTIONS[key];
|
|
184
|
+
}
|
|
185
|
+
newConfigurationOptions[optionName] = optionValue;
|
|
186
|
+
}
|
|
187
|
+
if (typeof newConfigurationOptions.polyfills === 'string') {
|
|
188
|
+
newConfigurationOptions.polyfills = [newConfigurationOptions.polyfills];
|
|
189
|
+
}
|
|
190
|
+
let outputPath = newConfigurationOptions.outputPath;
|
|
191
|
+
if (typeof outputPath === 'string') {
|
|
192
|
+
if (!/\/browser\/?$/.test(outputPath)) {
|
|
193
|
+
console.warn(`The output location of the browser build has been updated from "${outputPath}" to ` +
|
|
194
|
+
`"${(0, posix_1.join)(outputPath, 'browser')}". ` +
|
|
195
|
+
'You might need to adjust your deployment pipeline or, as an alternative, ' +
|
|
196
|
+
'set outputPath.browser to "" in order to maintain the previous functionality.');
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
outputPath = outputPath.replace(/\/browser\/?$/, '');
|
|
200
|
+
}
|
|
201
|
+
newConfigurationOptions['outputPath'] = {
|
|
202
|
+
base: outputPath,
|
|
203
|
+
};
|
|
204
|
+
if (typeof newConfigurationOptions.resourcesOutputPath === 'string') {
|
|
205
|
+
const media = newConfigurationOptions.resourcesOutputPath.replaceAll('/', '');
|
|
206
|
+
if (media && media !== 'media') {
|
|
207
|
+
newConfigurationOptions['outputPath'] = {
|
|
208
|
+
base: outputPath,
|
|
209
|
+
media,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return customWebpackConfigPath;
|
|
215
|
+
}
|
|
216
|
+
function handleDevServerTargetOptions(tree, options, newConfigurationOptions, root) {
|
|
217
|
+
for (const [key, value] of Object.entries(options)) {
|
|
218
|
+
let optionName = key;
|
|
219
|
+
let optionValue = key in PATH_NORMALIZER ? PATH_NORMALIZER[key](tree, value, root) : value;
|
|
220
|
+
if (REMOVED_OPTIONS.includes(key)) {
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (key in RENAMED_OPTIONS) {
|
|
224
|
+
optionName = RENAMED_OPTIONS[key];
|
|
225
|
+
}
|
|
226
|
+
newConfigurationOptions[optionName] = optionValue;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
async function getProjectToConvert(tree) {
|
|
230
|
+
const projects = new Set();
|
|
231
|
+
for (const executor of SUPPORTED_EXECUTORS) {
|
|
232
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, executor, (_, project) => {
|
|
233
|
+
projects.add(project);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
const { project } = await (0, enquirer_1.prompt)({
|
|
237
|
+
type: 'select',
|
|
238
|
+
name: 'project',
|
|
239
|
+
message: 'Which project would you like to convert to rspack?',
|
|
240
|
+
choices: Array.from(projects),
|
|
241
|
+
});
|
|
242
|
+
return project;
|
|
243
|
+
}
|
|
244
|
+
async function convertToRspack(tree, schema) {
|
|
245
|
+
let { project: projectName } = schema;
|
|
246
|
+
if (!projectName) {
|
|
247
|
+
projectName = await getProjectToConvert(tree);
|
|
248
|
+
}
|
|
249
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
250
|
+
const tasks = [];
|
|
251
|
+
const createConfigOptions = {
|
|
252
|
+
root: project.root,
|
|
253
|
+
};
|
|
254
|
+
const configurationOptions = {};
|
|
255
|
+
const buildTargetNames = [];
|
|
256
|
+
const serveTargetNames = [];
|
|
257
|
+
let customWebpackConfigPath;
|
|
258
|
+
(0, validate_supported_executor_1.validateSupportedBuildExecutor)(Object.values(project.targets));
|
|
259
|
+
for (const [targetName, target] of Object.entries(project.targets)) {
|
|
260
|
+
if (target.executor === '@angular-devkit/build-angular:browser' ||
|
|
261
|
+
target.executor === '@nx/angular:webpack-browser') {
|
|
262
|
+
customWebpackConfigPath = handleBuildTargetOptions(tree, target.options, createConfigOptions, project.root);
|
|
263
|
+
if (target.configurations) {
|
|
264
|
+
for (const [configurationName, configuration] of Object.entries(target.configurations)) {
|
|
265
|
+
configurationOptions[configurationName] = {};
|
|
266
|
+
handleBuildTargetOptions(tree, configuration, configurationOptions[configurationName], project.root);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
buildTargetNames.push(targetName);
|
|
270
|
+
}
|
|
271
|
+
else if (target.executor === '@angular-devkit/build-angular:dev-server' ||
|
|
272
|
+
target.executor === '@nx/angular:dev-server' ||
|
|
273
|
+
target.executor === '@nx/angular:module-federation-dev-server') {
|
|
274
|
+
createConfigOptions.devServer = {};
|
|
275
|
+
if (target.options) {
|
|
276
|
+
handleDevServerTargetOptions(tree, target.options, createConfigOptions.devServer, project.root);
|
|
277
|
+
}
|
|
278
|
+
if (target.configurations) {
|
|
279
|
+
for (const [configurationName, configuration] of Object.entries(target.configurations)) {
|
|
280
|
+
configurationOptions[configurationName] ??= {};
|
|
281
|
+
configurationOptions[configurationName].devServer ??= {};
|
|
282
|
+
handleDevServerTargetOptions(tree, configuration, configurationOptions[configurationName].devServer, project.root);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
serveTargetNames.push(targetName);
|
|
287
|
+
}
|
|
288
|
+
const customWebpackConfigInfo = customWebpackConfigPath
|
|
289
|
+
? await (0, get_custom_webpack_config_1.getCustomWebpackConfig)(tree, project.root, customWebpackConfigPath)
|
|
290
|
+
: undefined;
|
|
291
|
+
(0, create_config_1.createConfig)(tree, createConfigOptions, configurationOptions, customWebpackConfigInfo?.normalizedPathToCustomWebpackConfig, customWebpackConfigInfo?.isWebpackConfigFunction);
|
|
292
|
+
(0, update_tsconfig_1.updateTsconfig)(tree, project.root);
|
|
293
|
+
for (const targetName of [...buildTargetNames, ...serveTargetNames]) {
|
|
294
|
+
delete project.targets[targetName];
|
|
295
|
+
}
|
|
296
|
+
(0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
|
|
297
|
+
const { rspackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxVersion);
|
|
298
|
+
await rspackInitGenerator(tree, {
|
|
299
|
+
addPlugin: true,
|
|
300
|
+
});
|
|
301
|
+
// This is needed to prevent a circular execution of the build target
|
|
302
|
+
const rootPkgJson = (0, devkit_1.readJson)(tree, 'package.json');
|
|
303
|
+
if (rootPkgJson.scripts?.build === 'nx build') {
|
|
304
|
+
delete rootPkgJson.scripts.build;
|
|
305
|
+
(0, devkit_1.writeJson)(tree, 'package.json', rootPkgJson);
|
|
306
|
+
}
|
|
307
|
+
if (!schema.skipInstall) {
|
|
308
|
+
const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
309
|
+
'@nx/angular-rspack': versions_1.angularRspackVersion,
|
|
310
|
+
});
|
|
311
|
+
tasks.push(installTask);
|
|
312
|
+
}
|
|
313
|
+
if (!schema.skipFormat) {
|
|
314
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
315
|
+
}
|
|
316
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
317
|
+
}
|
|
318
|
+
exports.default = convertToRspack;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createConfig = createConfig;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function createConfig(tree, opts, configurationOptions = {}, existingWebpackConfigPath, isExistingWebpackConfigFunction) {
|
|
6
|
+
const { root, ...createConfigOptions } = opts;
|
|
7
|
+
const hasConfigurations = Object.keys(configurationOptions).length > 0;
|
|
8
|
+
const expandedConfigurationOptions = hasConfigurations
|
|
9
|
+
? Object.entries(configurationOptions)
|
|
10
|
+
.map(([configurationName, configurationOptions]) => {
|
|
11
|
+
return `
|
|
12
|
+
${configurationName}: {
|
|
13
|
+
options: {
|
|
14
|
+
${JSON.stringify(configurationOptions, undefined, 2).slice(1, -1)}
|
|
15
|
+
}
|
|
16
|
+
}`;
|
|
17
|
+
})
|
|
18
|
+
.join(',\n')
|
|
19
|
+
: '';
|
|
20
|
+
const configContents = `
|
|
21
|
+
import { createConfig }from '@nx/angular-rspack';
|
|
22
|
+
${existingWebpackConfigPath
|
|
23
|
+
? `import baseWebpackConfig from '${existingWebpackConfigPath}';
|
|
24
|
+
${isExistingWebpackConfigFunction
|
|
25
|
+
? ''
|
|
26
|
+
: `import webpackMerge from 'webpack-merge';`}`
|
|
27
|
+
: ''}
|
|
28
|
+
|
|
29
|
+
${existingWebpackConfigPath ? 'const baseConfig = ' : 'export default '}createConfig({
|
|
30
|
+
options: {
|
|
31
|
+
root: __dirname,
|
|
32
|
+
${JSON.stringify(createConfigOptions, undefined, 2).slice(1, -1)}
|
|
33
|
+
}
|
|
34
|
+
}${hasConfigurations ? `, {${expandedConfigurationOptions}}` : ''});
|
|
35
|
+
${existingWebpackConfigPath
|
|
36
|
+
? `
|
|
37
|
+
export default ${isExistingWebpackConfigFunction
|
|
38
|
+
? `async function (env, argv) {
|
|
39
|
+
const oldConfig = await baseWebpackConfig;
|
|
40
|
+
const browserConfig = baseConfig[0];
|
|
41
|
+
return oldConfig(browserConfig);
|
|
42
|
+
}`
|
|
43
|
+
: 'webpackMerge(baseConfig[0], baseWebpackConfig);'}
|
|
44
|
+
`
|
|
45
|
+
: ''}
|
|
46
|
+
`;
|
|
47
|
+
tree.write((0, devkit_1.joinPathFragments)(root, 'rspack.config.ts'), configContents);
|
|
48
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
export declare function getCustomWebpackConfig(tree: Tree, projectRoot: string, pathToCustomWebpackConfig: string): Promise<{
|
|
3
|
+
isWebpackConfigFunction: boolean;
|
|
4
|
+
normalizedPathToCustomWebpackConfig: string;
|
|
5
|
+
}>;
|
|
6
|
+
export declare function convertWebpackConfigToUseNxModuleFederationPlugin(webpackConfigContents: string): string;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCustomWebpackConfig = getCustomWebpackConfig;
|
|
4
|
+
exports.convertWebpackConfigToUseNxModuleFederationPlugin = convertWebpackConfigToUseNxModuleFederationPlugin;
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
9
|
+
const FILE_EXTENSION_REGEX = /\.[^.]+$/;
|
|
10
|
+
async function getCustomWebpackConfig(tree, projectRoot, pathToCustomWebpackConfig) {
|
|
11
|
+
const webpackConfigContents = tree.read(pathToCustomWebpackConfig, 'utf-8');
|
|
12
|
+
if (webpackConfigContents.includes('@nx/module-federation/angular') &&
|
|
13
|
+
webpackConfigContents.includes('withModuleFederation')) {
|
|
14
|
+
tree.write(pathToCustomWebpackConfig, convertWebpackConfigToUseNxModuleFederationPlugin(webpackConfigContents));
|
|
15
|
+
return {
|
|
16
|
+
isWebpackConfigFunction: false,
|
|
17
|
+
normalizedPathToCustomWebpackConfig: `./${(0, path_1.relative)(projectRoot, pathToCustomWebpackConfig).replace(FILE_EXTENSION_REGEX, '')}`,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const configFile = await (0, config_utils_1.loadConfigFile)((0, path_1.join)(tree.root, pathToCustomWebpackConfig));
|
|
21
|
+
const webpackConfig = 'default' in configFile ? configFile.default : configFile;
|
|
22
|
+
return {
|
|
23
|
+
isWebpackConfigFunction: typeof webpackConfig === 'function',
|
|
24
|
+
normalizedPathToCustomWebpackConfig: `./${(0, path_1.relative)(projectRoot, pathToCustomWebpackConfig).replace(FILE_EXTENSION_REGEX, '')}`,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function convertWebpackConfigToUseNxModuleFederationPlugin(webpackConfigContents) {
|
|
28
|
+
let newWebpackConfigContents = webpackConfigContents;
|
|
29
|
+
let ast = tsquery_1.tsquery.ast(webpackConfigContents);
|
|
30
|
+
const withModuleFederationImportNodes = (0, tsquery_1.tsquery)(ast, 'ImportDeclaration:has(StringLiteral[value=@nx/module-federation/angular])');
|
|
31
|
+
if (withModuleFederationImportNodes.length > 0) {
|
|
32
|
+
const withModuleFederationImportNode = withModuleFederationImportNodes[0];
|
|
33
|
+
newWebpackConfigContents = `${webpackConfigContents.slice(0, withModuleFederationImportNode.getStart())}import { NxModuleFederationPlugin } from '@nx/module-federation/rspack';${webpackConfigContents.slice(withModuleFederationImportNode.getEnd())}`;
|
|
34
|
+
ast = tsquery_1.tsquery.ast(newWebpackConfigContents);
|
|
35
|
+
const exportedWithModuleFederationNodes = (0, tsquery_1.tsquery)(ast, 'ExportAssignment:has(CallExpression > Identifier[name=withModuleFederation])');
|
|
36
|
+
if (exportedWithModuleFederationNodes.length > 0) {
|
|
37
|
+
const exportedWithModuleFederationNode = exportedWithModuleFederationNodes[0];
|
|
38
|
+
newWebpackConfigContents = `${newWebpackConfigContents.slice(0, exportedWithModuleFederationNode.getStart())}${newWebpackConfigContents.slice(exportedWithModuleFederationNode.getEnd())}
|
|
39
|
+
export default {
|
|
40
|
+
plugins: [
|
|
41
|
+
new NxModuleFederationPlugin(config, {
|
|
42
|
+
dts: false,
|
|
43
|
+
}),
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
devkit_1.logger.warn("Could not find 'export default withModuleFederation' in the webpack config file. Skipping conversion.");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const withModuleFederationRequireNodes = (0, tsquery_1.tsquery)(ast, 'VariableStatement:has(CallExpression > Identifier[name=withModuleFederation], StringLiteral[value=@nx/module-federation/angular])');
|
|
53
|
+
if (withModuleFederationRequireNodes.length > 0) {
|
|
54
|
+
const withModuleFederationRequireNode = withModuleFederationRequireNodes[0];
|
|
55
|
+
newWebpackConfigContents = `${webpackConfigContents.slice(0, withModuleFederationRequireNode.getStart())}const { NxModuleFederationPlugin } = require('@nx/module-federation/rspack');${webpackConfigContents.slice(withModuleFederationRequireNode.getEnd())}`;
|
|
56
|
+
ast = tsquery_1.tsquery.ast(newWebpackConfigContents);
|
|
57
|
+
const exportedWithModuleFederationNodes = (0, tsquery_1.tsquery)(ast, 'ExpressionStatement:has(BinaryExpression > PropertyAccessExpression:has(Identifier[name=module], Identifier[name=exports]), CallExpression:has(Identifier[name=withModuleFederation]))');
|
|
58
|
+
if (exportedWithModuleFederationNodes.length > 0) {
|
|
59
|
+
const exportedWithModuleFederationNode = exportedWithModuleFederationNodes[0];
|
|
60
|
+
newWebpackConfigContents = `${newWebpackConfigContents.slice(0, exportedWithModuleFederationNode.getStart())}${newWebpackConfigContents.slice(exportedWithModuleFederationNode.getEnd())}
|
|
61
|
+
module.exports = {
|
|
62
|
+
plugins: [
|
|
63
|
+
new NxModuleFederationPlugin({ config }, {
|
|
64
|
+
dts: false,
|
|
65
|
+
}),
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
`;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
devkit_1.logger.warn("Could not find 'module.exports = withModuleFederation' in the webpack config file. Skipping conversion.");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return newWebpackConfigContents;
|
|
75
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateTsconfig = updateTsconfig;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function updateTsconfig(tree, projectRoot) {
|
|
6
|
+
const tsconfigPath = (0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.json');
|
|
7
|
+
const tsconfig = (0, devkit_1.readJson)(tree, tsconfigPath);
|
|
8
|
+
tsconfig['ts-node'] = {
|
|
9
|
+
compilerOptions: {
|
|
10
|
+
module: 'CommonJS',
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
(0, devkit_1.writeJson)(tree, tsconfigPath, tsconfig);
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateSupportedBuildExecutor = validateSupportedBuildExecutor;
|
|
4
|
+
const SUPPORTED_BUILD_EXECUTORS = [
|
|
5
|
+
'@angular-devkit/build-angular:browser',
|
|
6
|
+
'@nx/angular:webpack-browser',
|
|
7
|
+
];
|
|
8
|
+
function validateSupportedBuildExecutor(targets) {
|
|
9
|
+
const executorsUsedByProject = targets.map((target) => target.executor);
|
|
10
|
+
if (!executorsUsedByProject.some((executor) => SUPPORTED_BUILD_EXECUTORS.includes(executor))) {
|
|
11
|
+
throw new Error('The project does not use a supported build executor. Please use one of the following executors: ' +
|
|
12
|
+
SUPPORTED_BUILD_EXECUTORS.join(', '));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "GeneratorNxApp",
|
|
4
|
+
"title": "Creates an Angular application.",
|
|
5
|
+
"description": "Creates an Angular application.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"cli": "nx",
|
|
8
|
+
"properties": {
|
|
9
|
+
"project": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"aliases": ["name", "projectName"],
|
|
12
|
+
"description": "Project for which to convert to rspack.",
|
|
13
|
+
"$default": {
|
|
14
|
+
"$source": "argv",
|
|
15
|
+
"index": 0
|
|
16
|
+
},
|
|
17
|
+
"x-priority": "important"
|
|
18
|
+
},
|
|
19
|
+
"skipFormat": {
|
|
20
|
+
"description": "Skip formatting files.",
|
|
21
|
+
"type": "boolean",
|
|
22
|
+
"default": false
|
|
23
|
+
},
|
|
24
|
+
"skipInstall": {
|
|
25
|
+
"description": "Skip installing dependencies.",
|
|
26
|
+
"type": "boolean",
|
|
27
|
+
"default": false
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -6,6 +6,7 @@ exports.backwardCompatibleVersions = {
|
|
|
6
6
|
angularVersion: '~17.3.0',
|
|
7
7
|
angularDevkitVersion: '~17.3.0',
|
|
8
8
|
ngPackagrVersion: '~17.3.0',
|
|
9
|
+
angularRspackVersion: '~20.6.1',
|
|
9
10
|
ngrxVersion: '~17.0.0',
|
|
10
11
|
rxjsVersion: '~7.8.0',
|
|
11
12
|
zoneJsVersion: '~0.14.3',
|
|
@@ -33,6 +34,7 @@ exports.backwardCompatibleVersions = {
|
|
|
33
34
|
angularVersion: '~18.2.0',
|
|
34
35
|
angularDevkitVersion: '~18.2.0',
|
|
35
36
|
ngPackagrVersion: '~18.2.0',
|
|
37
|
+
angularRspackVersion: '~20.6.1',
|
|
36
38
|
ngrxVersion: '~18.0.2',
|
|
37
39
|
rxjsVersion: '~7.8.0',
|
|
38
40
|
zoneJsVersion: '~0.14.3',
|
package/src/utils/versions.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export declare const nxVersion: any;
|
|
|
2
2
|
export declare const angularVersion = "~19.2.0";
|
|
3
3
|
export declare const angularDevkitVersion = "~19.2.0";
|
|
4
4
|
export declare const ngPackagrVersion = "~19.2.0";
|
|
5
|
+
export declare const angularRspackVersion = "~20.6.1";
|
|
5
6
|
export declare const ngrxVersion = "^19.0.0";
|
|
6
7
|
export declare const rxjsVersion = "~7.8.0";
|
|
7
8
|
export declare const zoneJsVersion = "~0.15.0";
|
package/src/utils/versions.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.jsoncEslintParserVersion = exports.jasmineMarblesVersion = exports.typesNodeVersion = exports.jestPresetAngularVersion = exports.tsNodeVersion = exports.autoprefixerVersion = exports.postcssUrlVersion = exports.postcssVersion = exports.tailwindVersion = exports.typescriptEslintVersion = exports.angularEslintVersion = exports.moduleFederationEnhancedVersion = exports.moduleFederationNodeVersion = exports.browserSyncVersion = exports.typesExpressVersion = exports.expressVersion = exports.typesCorsVersion = exports.corsVersion = exports.tsLibVersion = exports.angularJsVersion = exports.zoneJsVersion = exports.rxjsVersion = exports.ngrxVersion = exports.ngPackagrVersion = exports.angularDevkitVersion = exports.angularVersion = exports.nxVersion = void 0;
|
|
3
|
+
exports.jsoncEslintParserVersion = exports.jasmineMarblesVersion = exports.typesNodeVersion = exports.jestPresetAngularVersion = exports.tsNodeVersion = exports.autoprefixerVersion = exports.postcssUrlVersion = exports.postcssVersion = exports.tailwindVersion = exports.typescriptEslintVersion = exports.angularEslintVersion = exports.moduleFederationEnhancedVersion = exports.moduleFederationNodeVersion = exports.browserSyncVersion = exports.typesExpressVersion = exports.expressVersion = exports.typesCorsVersion = exports.corsVersion = exports.tsLibVersion = exports.angularJsVersion = exports.zoneJsVersion = exports.rxjsVersion = exports.ngrxVersion = exports.angularRspackVersion = exports.ngPackagrVersion = exports.angularDevkitVersion = exports.angularVersion = exports.nxVersion = void 0;
|
|
4
4
|
exports.nxVersion = require('../../package.json').version;
|
|
5
5
|
exports.angularVersion = '~19.2.0';
|
|
6
6
|
exports.angularDevkitVersion = '~19.2.0';
|
|
7
7
|
exports.ngPackagrVersion = '~19.2.0';
|
|
8
|
+
exports.angularRspackVersion = '~20.6.1';
|
|
8
9
|
exports.ngrxVersion = '^19.0.0';
|
|
9
10
|
exports.rxjsVersion = '~7.8.0';
|
|
10
11
|
exports.zoneJsVersion = '~0.15.0';
|