@nx/rspack 20.2.0-beta.2 → 20.2.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app-plugin.d.ts +2 -0
- package/app-plugin.js +5 -0
- package/generators.json +10 -0
- package/migrations.json +21 -1
- package/module-federation.d.ts +4 -1
- package/module-federation.js +7 -2
- package/package.json +10 -8
- package/react-plugin.d.ts +1 -0
- package/react-plugin.js +5 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +5 -7
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +5 -7
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +1 -1
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +4 -5
- package/src/executors/rspack/schema.d.ts +1 -1
- package/src/executors/rspack/schema.json +1 -1
- package/src/generators/application/application.js +0 -2
- package/src/generators/configuration/configuration.js +0 -2
- package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.d.ts +7 -0
- package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.js +92 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.d.ts +6 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.js +106 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/normalize-path-options.d.ts +2 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/normalize-path-options.js +73 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/utils.d.ts +1 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/utils.js +13 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/validate-project.d.ts +9 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/validate-project.js +40 -0
- package/src/generators/convert-config-to-rspack-plugin/schema.json +19 -0
- package/src/generators/convert-to-inferred/__snapshots__/convert-to-inferred.spec.ts.snap +268 -0
- package/src/generators/convert-to-inferred/convert-to-inferred.d.ts +12 -0
- package/src/generators/convert-to-inferred/convert-to-inferred.js +114 -0
- package/src/generators/convert-to-inferred/schema.json +19 -0
- package/src/generators/convert-to-inferred/utils/ast.d.ts +3 -0
- package/src/generators/convert-to-inferred/utils/ast.js +40 -0
- package/src/generators/convert-to-inferred/utils/build-post-target-transformer.d.ts +6 -0
- package/src/generators/convert-to-inferred/utils/build-post-target-transformer.js +210 -0
- package/src/generators/convert-to-inferred/utils/index.d.ts +3 -0
- package/src/generators/convert-to-inferred/utils/index.js +6 -0
- package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.d.ts +6 -0
- package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.js +207 -0
- package/src/generators/convert-to-inferred/utils/types.d.ts +11 -0
- package/src/generators/convert-webpack/lib/transform-cjs.js +5 -5
- package/src/generators/convert-webpack/lib/transform-esm.js +5 -5
- package/src/generators/init/init.js +0 -2
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts +2 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +35 -0
- package/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.d.ts +16 -0
- package/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.js +43 -0
- package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.d.ts +8 -0
- package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.js +13 -0
- package/src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin.d.ts +31 -0
- package/src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin.js +73 -0
- package/src/plugins/utils/apply-base-config.js +3 -0
- package/src/plugins/utils/apply-web-config.d.ts +2 -2
- package/src/plugins/utils/apply-web-config.js +1 -1
- package/src/plugins/utils/plugins/normalize-options.js +1 -1
- package/src/plugins/utils/plugins/nx-tsconfig-paths-rspack-plugin.js +3 -2
- package/src/utils/create-compiler.js +3 -1
- package/src/utils/generator-utils.d.ts +2 -2
- package/src/utils/generator-utils.js +134 -67
- package/src/utils/has-plugin.d.ts +2 -0
- package/src/utils/has-plugin.js +10 -0
- package/src/utils/module-federation/build-static.remotes.d.ts +1 -1
- package/src/utils/versions.d.ts +2 -2
- package/src/utils/versions.js +2 -2
- package/src/utils/module-federation/dependencies.d.ts +0 -6
- package/src/utils/module-federation/dependencies.js +0 -56
- package/src/utils/module-federation/get-remotes-for-host.d.ts +0 -16
- package/src/utils/module-federation/get-remotes-for-host.js +0 -99
- package/src/utils/module-federation/index.d.ts +0 -6
- package/src/utils/module-federation/index.js +0 -9
- package/src/utils/module-federation/models/index.d.ts +0 -47
- package/src/utils/module-federation/package-json.d.ts +0 -8
- package/src/utils/module-federation/package-json.js +0 -12
- package/src/utils/module-federation/parse-static-remotes-config.d.ts +0 -13
- package/src/utils/module-federation/parse-static-remotes-config.js +0 -34
- package/src/utils/module-federation/plugins/runtime-library-control.plugin.d.ts +0 -3
- package/src/utils/module-federation/plugins/runtime-library-control.plugin.js +0 -54
- package/src/utils/module-federation/public-api.d.ts +0 -8
- package/src/utils/module-federation/public-api.js +0 -20
- package/src/utils/module-federation/remotes.d.ts +0 -19
- package/src/utils/module-federation/remotes.js +0 -85
- package/src/utils/module-federation/secondary-entry-points.d.ts +0 -12
- package/src/utils/module-federation/secondary-entry-points.js +0 -104
- package/src/utils/module-federation/share.d.ts +0 -48
- package/src/utils/module-federation/share.js +0 -235
- package/src/utils/module-federation/start-remote-proxies.d.ts +0 -5
- package/src/utils/module-federation/start-remote-proxies.js +0 -45
- package/src/utils/module-federation/start-ssr-remote-proxies.d.ts +0 -5
- package/src/utils/module-federation/start-ssr-remote-proxies.js +0 -59
- package/src/utils/module-federation/typescript.d.ts +0 -4
- package/src/utils/module-federation/typescript.js +0 -53
- package/src/utils/module-federation/with-module-federation/package-json.d.ts +0 -8
- package/src/utils/module-federation/with-module-federation/package-json.js +0 -12
- package/src/utils/module-federation/with-module-federation/utils.d.ts +0 -12
- package/src/utils/module-federation/with-module-federation/utils.js +0 -76
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.d.ts +0 -3
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js +0 -62
- package/src/utils/module-federation/with-module-federation/with-module-federation.d.ts +0 -8
- package/src/utils/module-federation/with-module-federation/with-module-federation.js +0 -70
- /package/src/{utils/module-federation/models/index.js → generators/convert-to-inferred/utils/types.js} +0 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateProject = validateProject;
|
|
4
|
+
function hasAnotherRspackConfig(tree, projectRoot) {
|
|
5
|
+
const files = tree.children(projectRoot);
|
|
6
|
+
const projectJsonString = tree.read(`${projectRoot}/project.json`, 'utf-8');
|
|
7
|
+
for (const file of files) {
|
|
8
|
+
if (file !== 'rspack.config.js' &&
|
|
9
|
+
file.endsWith('.js') &&
|
|
10
|
+
file.includes('rspack.config') &&
|
|
11
|
+
projectJsonString.includes(file) &&
|
|
12
|
+
tree.exists(`${projectRoot}/rspack.config.js`)) {
|
|
13
|
+
return 'Cannot convert a project with multiple rspack config files. Please consolidate them into a single rspack.config.js file.';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function isNestProject(project) {
|
|
18
|
+
for (const target in project.targets) {
|
|
19
|
+
if (project.targets[target].executor === '@nx/js:node') {
|
|
20
|
+
return `The project ${project.name} is using the '@nx/js:node' executor. At the moment, we do not support migrating such projects.`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validates the project to ensure it can be migrated
|
|
26
|
+
*
|
|
27
|
+
* @param tree The virtual file system
|
|
28
|
+
* @param project the project configuration object for the project
|
|
29
|
+
* @returns A string if there is an error, otherwise undefined
|
|
30
|
+
*/
|
|
31
|
+
function validateProject(tree, project) {
|
|
32
|
+
const containsMfeExecutor = Object.keys(project.targets).some((target) => {
|
|
33
|
+
return ['@nx/rspack:module-federation-dev-server'].includes(project.targets[target].executor);
|
|
34
|
+
});
|
|
35
|
+
if (containsMfeExecutor) {
|
|
36
|
+
return `The project ${project.name} is using Module Federation. At the moment, we don't support migrating projects that use Module Federation.`;
|
|
37
|
+
}
|
|
38
|
+
const hasAnotherConfig = hasAnotherRspackConfig(tree, project.root);
|
|
39
|
+
return hasAnotherConfig || isNestProject(project);
|
|
40
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "NxRspackConvertConfigToRspackPlugin",
|
|
4
|
+
"description": "Convert existing Rspack project(s) using `@nx/rspack:rspack` executor that uses `withNx` to use `NxAppRspackPlugin`. Defaults to migrating all projects. Pass '--project' to migrate only one target.",
|
|
5
|
+
"title": "Convert Rspack project using withNx to NxAppRspackPlugin",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"project": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The project to convert from using the `@nx/rspack:rspack` executor and `withNx` plugin to use `NxAppRspackPlugin`.",
|
|
11
|
+
"x-priority": "important"
|
|
12
|
+
},
|
|
13
|
+
"skipFormat": {
|
|
14
|
+
"type": "boolean",
|
|
15
|
+
"description": "Whether to format files at the end of the migration.",
|
|
16
|
+
"default": false
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`convert-to-inferred all projects should migrate all projects using the rspack executors 1`] = `
|
|
4
|
+
"const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
|
|
5
|
+
const { NxReactRspackPlugin } = require('@nx/rspack/react-plugin');
|
|
6
|
+
const { useLegacyNxPlugin } = require('@nx/rspack');
|
|
7
|
+
|
|
8
|
+
// These options were migrated by @nx/rspack:convert-to-inferred from
|
|
9
|
+
// the project.json file and merged with the options in this file
|
|
10
|
+
const configValues = {
|
|
11
|
+
build: {
|
|
12
|
+
default: {
|
|
13
|
+
outputPath: '../../dist/apps/app1',
|
|
14
|
+
index: './src/index.html',
|
|
15
|
+
main: './src/main.tsx',
|
|
16
|
+
tsConfig: './tsconfig.app.json',
|
|
17
|
+
assets: ['./src/favicon.ico', './src/assets'],
|
|
18
|
+
styles: ['./src/styles.scss'],
|
|
19
|
+
},
|
|
20
|
+
development: {
|
|
21
|
+
extractLicenses: false,
|
|
22
|
+
optimization: false,
|
|
23
|
+
sourceMap: true,
|
|
24
|
+
vendorChunk: true,
|
|
25
|
+
},
|
|
26
|
+
production: {
|
|
27
|
+
fileReplacements: [
|
|
28
|
+
{
|
|
29
|
+
replace: './src/environments/environment.ts',
|
|
30
|
+
with: './src/environments/environment.prod.ts',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
optimization: true,
|
|
34
|
+
outputHashing: 'all',
|
|
35
|
+
sourceMap: false,
|
|
36
|
+
namedChunks: false,
|
|
37
|
+
extractLicenses: true,
|
|
38
|
+
vendorChunk: false,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
serve: {
|
|
42
|
+
default: {
|
|
43
|
+
hmr: true,
|
|
44
|
+
server: {
|
|
45
|
+
type: 'https',
|
|
46
|
+
options: { cert: './server.crt', key: './server.key' },
|
|
47
|
+
},
|
|
48
|
+
port: 4200,
|
|
49
|
+
headers: { 'Access-Control-Allow-Origin': '*' },
|
|
50
|
+
historyApiFallback: {
|
|
51
|
+
index: '/index.html',
|
|
52
|
+
disableDotRule: true,
|
|
53
|
+
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
development: { open: true },
|
|
57
|
+
production: { hmr: false },
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Determine the correct configValue to use based on the configuration
|
|
62
|
+
const configuration = process.env.NX_TASK_TARGET_CONFIGURATION || 'default';
|
|
63
|
+
|
|
64
|
+
const buildOptions = {
|
|
65
|
+
...configValues.build.default,
|
|
66
|
+
...configValues.build[configuration],
|
|
67
|
+
};
|
|
68
|
+
const devServerOptions = {
|
|
69
|
+
...configValues.serve.default,
|
|
70
|
+
...configValues.serve[configuration],
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @type{import('@rspack/core').RspackOptionsNormalized}
|
|
75
|
+
*/
|
|
76
|
+
module.exports = async () => ({
|
|
77
|
+
devServer: devServerOptions,
|
|
78
|
+
plugins: [
|
|
79
|
+
new NxAppRspackPlugin(buildOptions),
|
|
80
|
+
new NxReactRspackPlugin({
|
|
81
|
+
// Uncomment this line if you don't want to use SVGR
|
|
82
|
+
// See: https://react-svgr.com/
|
|
83
|
+
// svgr: false
|
|
84
|
+
}),
|
|
85
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
86
|
+
await useLegacyNxPlugin(require('./rspack.config.old'), buildOptions),
|
|
87
|
+
],
|
|
88
|
+
});
|
|
89
|
+
"
|
|
90
|
+
`;
|
|
91
|
+
|
|
92
|
+
exports[`convert-to-inferred all projects should migrate all projects using the rspack executors 2`] = `
|
|
93
|
+
"const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
|
|
94
|
+
const { NxReactRspackPlugin } = require('@nx/rspack/react-plugin');
|
|
95
|
+
const { useLegacyNxPlugin } = require('@nx/rspack');
|
|
96
|
+
|
|
97
|
+
// These options were migrated by @nx/rspack:convert-to-inferred from
|
|
98
|
+
// the project.json file and merged with the options in this file
|
|
99
|
+
const configValues = {
|
|
100
|
+
build: {
|
|
101
|
+
default: {
|
|
102
|
+
outputPath: '../../dist/apps/app2',
|
|
103
|
+
index: './src/index.html',
|
|
104
|
+
main: './src/main.tsx',
|
|
105
|
+
tsConfig: './tsconfig.app.json',
|
|
106
|
+
assets: ['./src/favicon.ico', './src/assets'],
|
|
107
|
+
styles: ['./src/styles.scss'],
|
|
108
|
+
},
|
|
109
|
+
development: {
|
|
110
|
+
extractLicenses: false,
|
|
111
|
+
optimization: false,
|
|
112
|
+
sourceMap: true,
|
|
113
|
+
vendorChunk: true,
|
|
114
|
+
},
|
|
115
|
+
production: {
|
|
116
|
+
fileReplacements: [
|
|
117
|
+
{
|
|
118
|
+
replace: './src/environments/environment.ts',
|
|
119
|
+
with: './src/environments/environment.prod.ts',
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
optimization: true,
|
|
123
|
+
outputHashing: 'all',
|
|
124
|
+
sourceMap: false,
|
|
125
|
+
namedChunks: false,
|
|
126
|
+
extractLicenses: true,
|
|
127
|
+
vendorChunk: false,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
serve: {
|
|
131
|
+
default: {
|
|
132
|
+
hmr: true,
|
|
133
|
+
server: {
|
|
134
|
+
type: 'https',
|
|
135
|
+
options: { cert: './server.crt', key: './server.key' },
|
|
136
|
+
},
|
|
137
|
+
port: 4200,
|
|
138
|
+
headers: { 'Access-Control-Allow-Origin': '*' },
|
|
139
|
+
historyApiFallback: {
|
|
140
|
+
index: '/index.html',
|
|
141
|
+
disableDotRule: true,
|
|
142
|
+
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
development: { open: true },
|
|
146
|
+
production: { hmr: false },
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// Determine the correct configValue to use based on the configuration
|
|
151
|
+
const configuration = process.env.NX_TASK_TARGET_CONFIGURATION || 'default';
|
|
152
|
+
|
|
153
|
+
const buildOptions = {
|
|
154
|
+
...configValues.build.default,
|
|
155
|
+
...configValues.build[configuration],
|
|
156
|
+
};
|
|
157
|
+
const devServerOptions = {
|
|
158
|
+
...configValues.serve.default,
|
|
159
|
+
...configValues.serve[configuration],
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @type{import('@rspack/core').RspackOptionsNormalized}
|
|
164
|
+
*/
|
|
165
|
+
module.exports = async () => ({
|
|
166
|
+
devServer: devServerOptions,
|
|
167
|
+
plugins: [
|
|
168
|
+
new NxAppRspackPlugin(buildOptions),
|
|
169
|
+
new NxReactRspackPlugin({
|
|
170
|
+
// Uncomment this line if you don't want to use SVGR
|
|
171
|
+
// See: https://react-svgr.com/
|
|
172
|
+
// svgr: false
|
|
173
|
+
}),
|
|
174
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
175
|
+
await useLegacyNxPlugin(require('./rspack.config.old'), buildOptions),
|
|
176
|
+
],
|
|
177
|
+
});
|
|
178
|
+
"
|
|
179
|
+
`;
|
|
180
|
+
|
|
181
|
+
exports[`convert-to-inferred all projects should migrate all projects using the rspack executors 3`] = `
|
|
182
|
+
"const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
|
|
183
|
+
const { NxReactRspackPlugin } = require('@nx/rspack/react-plugin');
|
|
184
|
+
const { useLegacyNxPlugin } = require('@nx/rspack');
|
|
185
|
+
|
|
186
|
+
// These options were migrated by @nx/rspack:convert-to-inferred from
|
|
187
|
+
// the project.json file and merged with the options in this file
|
|
188
|
+
const configValues = {
|
|
189
|
+
build: {
|
|
190
|
+
default: {
|
|
191
|
+
outputPath: '../../dist/apps/app3',
|
|
192
|
+
index: './src/index.html',
|
|
193
|
+
main: './src/main.tsx',
|
|
194
|
+
tsConfig: './tsconfig.app.json',
|
|
195
|
+
assets: ['./src/favicon.ico', './src/assets'],
|
|
196
|
+
styles: ['./src/styles.scss'],
|
|
197
|
+
},
|
|
198
|
+
development: {
|
|
199
|
+
extractLicenses: false,
|
|
200
|
+
optimization: false,
|
|
201
|
+
sourceMap: true,
|
|
202
|
+
vendorChunk: true,
|
|
203
|
+
},
|
|
204
|
+
production: {
|
|
205
|
+
fileReplacements: [
|
|
206
|
+
{
|
|
207
|
+
replace: './src/environments/environment.ts',
|
|
208
|
+
with: './src/environments/environment.prod.ts',
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
optimization: true,
|
|
212
|
+
outputHashing: 'all',
|
|
213
|
+
sourceMap: false,
|
|
214
|
+
namedChunks: false,
|
|
215
|
+
extractLicenses: true,
|
|
216
|
+
vendorChunk: false,
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
serve: {
|
|
220
|
+
default: {
|
|
221
|
+
hmr: true,
|
|
222
|
+
server: {
|
|
223
|
+
type: 'https',
|
|
224
|
+
options: { cert: './server.crt', key: './server.key' },
|
|
225
|
+
},
|
|
226
|
+
port: 4200,
|
|
227
|
+
headers: { 'Access-Control-Allow-Origin': '*' },
|
|
228
|
+
historyApiFallback: {
|
|
229
|
+
index: '/index.html',
|
|
230
|
+
disableDotRule: true,
|
|
231
|
+
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
development: { open: true },
|
|
235
|
+
production: { hmr: false },
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
// Determine the correct configValue to use based on the configuration
|
|
240
|
+
const configuration = process.env.NX_TASK_TARGET_CONFIGURATION || 'default';
|
|
241
|
+
|
|
242
|
+
const buildOptions = {
|
|
243
|
+
...configValues.build.default,
|
|
244
|
+
...configValues.build[configuration],
|
|
245
|
+
};
|
|
246
|
+
const devServerOptions = {
|
|
247
|
+
...configValues.serve.default,
|
|
248
|
+
...configValues.serve[configuration],
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* @type{import('@rspack/core').RspackOptionsNormalized}
|
|
253
|
+
*/
|
|
254
|
+
module.exports = async () => ({
|
|
255
|
+
devServer: devServerOptions,
|
|
256
|
+
plugins: [
|
|
257
|
+
new NxAppRspackPlugin(buildOptions),
|
|
258
|
+
new NxReactRspackPlugin({
|
|
259
|
+
// Uncomment this line if you don't want to use SVGR
|
|
260
|
+
// See: https://react-svgr.com/
|
|
261
|
+
// svgr: false
|
|
262
|
+
}),
|
|
263
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
264
|
+
await useLegacyNxPlugin(require('./rspack.config.old'), buildOptions),
|
|
265
|
+
],
|
|
266
|
+
});
|
|
267
|
+
"
|
|
268
|
+
`;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
|
+
import { logger as devkitLogger } from 'nx/src/devkit-exports';
|
|
3
|
+
interface Schema {
|
|
4
|
+
project?: string;
|
|
5
|
+
skipFormat?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function convertToInferred(tree: Tree, options: Schema): Promise<import("@nx/devkit").GeneratorCallback>;
|
|
8
|
+
export declare function createCollectingLogger(): typeof devkitLogger & {
|
|
9
|
+
loggedMessages: Map<string, string[]>;
|
|
10
|
+
flushLogs: (filter?: (message: string) => boolean) => void;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToInferred = convertToInferred;
|
|
4
|
+
exports.createCollectingLogger = createCollectingLogger;
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const aggregate_log_util_1 = require("@nx/devkit/src/generators/plugin-migrations/aggregate-log-util");
|
|
7
|
+
const executor_to_plugin_migrator_1 = require("@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator");
|
|
8
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
9
|
+
const plugin_1 = require("../../plugins/plugin");
|
|
10
|
+
const versions_1 = require("../../utils/versions");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
13
|
+
async function convertToInferred(tree, options) {
|
|
14
|
+
const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
15
|
+
const migrationContext = {
|
|
16
|
+
logger: new aggregate_log_util_1.AggregatedLog(),
|
|
17
|
+
projectGraph,
|
|
18
|
+
workspaceRoot: tree.root,
|
|
19
|
+
};
|
|
20
|
+
const logger = createCollectingLogger();
|
|
21
|
+
const migratedProjects = await (0, executor_to_plugin_migrator_1.migrateProjectExecutorsToPlugin)(tree, projectGraph, '@nx/rspack/plugin', plugin_1.createNodesV2, {
|
|
22
|
+
buildTargetName: 'build',
|
|
23
|
+
previewTargetName: 'preview',
|
|
24
|
+
serveStaticTargetName: 'serve-static',
|
|
25
|
+
serveTargetName: 'serve',
|
|
26
|
+
}, [
|
|
27
|
+
{
|
|
28
|
+
executors: ['@nx/rspack:rspack', '@nrwl/rspack:rspack'],
|
|
29
|
+
postTargetTransformer: (0, utils_1.buildPostTargetTransformerFactory)(migrationContext),
|
|
30
|
+
targetPluginOptionMapper: (target) => ({ buildTargetName: target }),
|
|
31
|
+
skipProjectFilter: skipProjectFilterFactory(tree),
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
executors: ['@nx/rspack:dev-server', '@nrwl/rspack:dev-server'],
|
|
35
|
+
postTargetTransformer: (0, utils_1.servePostTargetTransformerFactory)(migrationContext),
|
|
36
|
+
targetPluginOptionMapper: (target) => ({ serveTargetName: target }),
|
|
37
|
+
skipProjectFilter: skipProjectFilterFactory(tree),
|
|
38
|
+
},
|
|
39
|
+
], options.project, logger);
|
|
40
|
+
if (migratedProjects.size === 0) {
|
|
41
|
+
const convertMessage = [...logger.loggedMessages.values()]
|
|
42
|
+
.flat()
|
|
43
|
+
.find((v) => v.includes('@nx/rspack:convert-config-to-rspack-plugin'));
|
|
44
|
+
if (convertMessage.length > 0) {
|
|
45
|
+
logger.flushLogs((message) => !convertMessage.includes(message));
|
|
46
|
+
throw new Error(convertMessage);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
logger.flushLogs();
|
|
50
|
+
throw new executor_to_plugin_migrator_1.NoTargetsToMigrateError();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
logger.flushLogs();
|
|
55
|
+
}
|
|
56
|
+
const installCallback = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@rspack/core': versions_1.rspackCoreVersion }, undefined, true);
|
|
57
|
+
if (!options.skipFormat) {
|
|
58
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
59
|
+
}
|
|
60
|
+
return (0, devkit_1.runTasksInSerial)(installCallback, () => {
|
|
61
|
+
migrationContext.logger.flushLogs();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function skipProjectFilterFactory(tree) {
|
|
65
|
+
return function skipProjectFilter(projectConfiguration) {
|
|
66
|
+
const buildTarget = Object.values(projectConfiguration.targets).find((target) => target.executor === '@nx/rspack:rspack' ||
|
|
67
|
+
target.executor === '@nrwl/rspack:rspack');
|
|
68
|
+
// the projects for which this is called are guaranteed to have a build target
|
|
69
|
+
const rspackConfigPath = buildTarget.options.rspackConfig;
|
|
70
|
+
if (!rspackConfigPath) {
|
|
71
|
+
return `The rspack config path is missing in the project configuration (${projectConfiguration.root}).`;
|
|
72
|
+
}
|
|
73
|
+
const sourceFile = tsquery_1.tsquery.ast(tree.read(rspackConfigPath, 'utf-8'));
|
|
74
|
+
const composePluginsSelector = 'CallExpression:has(Identifier[name=composePlugins])';
|
|
75
|
+
const composePlugins = (0, tsquery_1.tsquery)(sourceFile, composePluginsSelector)[0];
|
|
76
|
+
if (composePlugins) {
|
|
77
|
+
return `The rspack config (${rspackConfigPath}) can only work with the "@nx/rspack:rspack" executor. Run the "@nx/rspack:convert-config-to-rspack-plugin" generator first.`;
|
|
78
|
+
}
|
|
79
|
+
const nxAppRspackPluginSelector = 'PropertyAssignment:has(Identifier[name=plugins]) NewExpression:has(Identifier[name=NxAppRspackPlugin])';
|
|
80
|
+
const nxAppRspackPlugin = (0, tsquery_1.tsquery)(sourceFile, nxAppRspackPluginSelector)[0];
|
|
81
|
+
if (!nxAppRspackPlugin) {
|
|
82
|
+
return `No "NxAppRspackPlugin" found in the rspack config (${rspackConfigPath}). Its usage is required for the migration to work.`;
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function createCollectingLogger() {
|
|
88
|
+
const loggedMessages = new Map();
|
|
89
|
+
const flushLogs = (filter) => {
|
|
90
|
+
loggedMessages.forEach((messages, method) => {
|
|
91
|
+
messages.forEach((message) => {
|
|
92
|
+
if (!filter || filter(message)) {
|
|
93
|
+
devkit_exports_1.logger[method](message);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
return new Proxy({ ...devkit_exports_1.logger, loggedMessages, flushLogs }, {
|
|
99
|
+
get(target, property) {
|
|
100
|
+
const originalMethod = target[property];
|
|
101
|
+
if (typeof originalMethod === 'function') {
|
|
102
|
+
return (...args) => {
|
|
103
|
+
const message = args.join(' ');
|
|
104
|
+
const propertyString = String(property);
|
|
105
|
+
if (!loggedMessages.has(message)) {
|
|
106
|
+
loggedMessages.set(propertyString, []);
|
|
107
|
+
}
|
|
108
|
+
loggedMessages.get(propertyString).push(message);
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return originalMethod;
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "NxWebpackConvertToInferred",
|
|
4
|
+
"description": "Convert existing Webpack project(s) using `@nx/webpack:wepack` executor to use `@nx/webpack/plugin`.",
|
|
5
|
+
"title": "Convert a Webpack project from executor to plugin",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"project": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The project to convert from using the `@nx/webpack:webpack` executor to use `@nx/webpack/plugin`. If not provided, all projects using the `@nx/webpack:webpack` executor will be converted.",
|
|
11
|
+
"x-priority": "important"
|
|
12
|
+
},
|
|
13
|
+
"skipFormat": {
|
|
14
|
+
"type": "boolean",
|
|
15
|
+
"description": "Whether to format files.",
|
|
16
|
+
"default": false
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toPropertyAssignment = toPropertyAssignment;
|
|
4
|
+
exports.toExpression = toExpression;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const ts = tslib_1.__importStar(require("typescript"));
|
|
7
|
+
function toPropertyAssignment(key, value) {
|
|
8
|
+
if (typeof value === 'string') {
|
|
9
|
+
return ts.factory.createPropertyAssignment(ts.factory.createStringLiteral(key), ts.factory.createStringLiteral(value));
|
|
10
|
+
}
|
|
11
|
+
else if (typeof value === 'number') {
|
|
12
|
+
return ts.factory.createPropertyAssignment(ts.factory.createStringLiteral(key), ts.factory.createNumericLiteral(value));
|
|
13
|
+
}
|
|
14
|
+
else if (typeof value === 'boolean') {
|
|
15
|
+
return ts.factory.createPropertyAssignment(ts.factory.createStringLiteral(key), value ? ts.factory.createTrue() : ts.factory.createFalse());
|
|
16
|
+
}
|
|
17
|
+
else if (Array.isArray(value)) {
|
|
18
|
+
return ts.factory.createPropertyAssignment(ts.factory.createStringLiteral(key), ts.factory.createArrayLiteralExpression(value.map((item) => toExpression(item))));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return ts.factory.createPropertyAssignment(ts.factory.createStringLiteral(key), ts.factory.createObjectLiteralExpression(Object.entries(value).map(([key, value]) => toPropertyAssignment(key, value))));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function toExpression(value) {
|
|
25
|
+
if (typeof value === 'string') {
|
|
26
|
+
return ts.factory.createStringLiteral(value);
|
|
27
|
+
}
|
|
28
|
+
else if (typeof value === 'number') {
|
|
29
|
+
return ts.factory.createNumericLiteral(value);
|
|
30
|
+
}
|
|
31
|
+
else if (typeof value === 'boolean') {
|
|
32
|
+
return value ? ts.factory.createTrue() : ts.factory.createFalse();
|
|
33
|
+
}
|
|
34
|
+
else if (Array.isArray(value)) {
|
|
35
|
+
return ts.factory.createArrayLiteralExpression(value.map((item) => toExpression(item)));
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return ts.factory.createObjectLiteralExpression(Object.entries(value).map(([key, value]) => toPropertyAssignment(key, value)));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TargetConfiguration, Tree } from '@nx/devkit';
|
|
2
|
+
import type { MigrationContext } from './types';
|
|
3
|
+
export declare function buildPostTargetTransformerFactory(migrationContext: MigrationContext): (target: TargetConfiguration, tree: Tree, projectDetails: {
|
|
4
|
+
projectName: string;
|
|
5
|
+
root: string;
|
|
6
|
+
}, inferredTarget: TargetConfiguration) => TargetConfiguration;
|