@nx/rspack 20.2.0-beta.1 → 20.2.0-beta.3
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/lib/config.d.ts +6 -0
- package/src/executors/rspack/lib/config.js +39 -0
- package/src/executors/rspack/rspack.impl.js +11 -12
- package/src/executors/rspack/schema.d.ts +39 -18
- package/src/executors/rspack/schema.json +191 -0
- 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/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 +2 -5
- package/src/plugins/utils/apply-web-config.d.ts +2 -2
- package/src/plugins/utils/apply-web-config.js +1 -8
- package/src/plugins/utils/models.d.ts +2 -2
- 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.d.ts +2 -2
- package/src/utils/create-compiler.js +12 -49
- 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 -55
- 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
|
@@ -119,14 +119,14 @@ function transformModuleFederationConfig(tree, configPath, scope) {
|
|
|
119
119
|
if (configContents.charAt(endIndex) === ',') {
|
|
120
120
|
endIndex++;
|
|
121
121
|
}
|
|
122
|
-
const newContents = `const { ModuleFederationConfig } = require('@nx/
|
|
122
|
+
const newContents = `const { ModuleFederationConfig } = require('@nx/module-federation');
|
|
123
123
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
124
124
|
tree.write(configPath, newContents);
|
|
125
125
|
}
|
|
126
126
|
function transformWithModuleFederation(tree, configPath, scope) {
|
|
127
127
|
const configContents = tree.read(configPath, 'utf-8');
|
|
128
128
|
const ast = tsquery_1.tsquery.ast(configContents);
|
|
129
|
-
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withModuleFederation]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/
|
|
129
|
+
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withModuleFederation]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/module-federation/webpack]`;
|
|
130
130
|
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
131
131
|
if (nodes.length === 0) {
|
|
132
132
|
return;
|
|
@@ -141,14 +141,14 @@ function transformWithModuleFederation(tree, configPath, scope) {
|
|
|
141
141
|
if (configContents.charAt(endIndex) === ',') {
|
|
142
142
|
endIndex++;
|
|
143
143
|
}
|
|
144
|
-
const newContents = `const { withModuleFederation } = require('@nx/
|
|
144
|
+
const newContents = `const { withModuleFederation } = require('@nx/module-federation/rspack');
|
|
145
145
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
146
146
|
tree.write(configPath, newContents);
|
|
147
147
|
}
|
|
148
148
|
function transformWithModuleFederationSSR(tree, configPath, scope) {
|
|
149
149
|
const configContents = tree.read(configPath, 'utf-8');
|
|
150
150
|
const ast = tsquery_1.tsquery.ast(configContents);
|
|
151
|
-
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withModuleFederationForSSR]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/
|
|
151
|
+
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withModuleFederationForSSR]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/module-federation/webpack]`;
|
|
152
152
|
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
153
153
|
if (nodes.length === 0) {
|
|
154
154
|
return;
|
|
@@ -163,7 +163,7 @@ function transformWithModuleFederationSSR(tree, configPath, scope) {
|
|
|
163
163
|
if (configContents.charAt(endIndex) === ',') {
|
|
164
164
|
endIndex++;
|
|
165
165
|
}
|
|
166
|
-
const newContents = `const { withModuleFederationForSSR } = require('@nx/
|
|
166
|
+
const newContents = `const { withModuleFederationForSSR } = require('@nx/module-federation/rspack');
|
|
167
167
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
168
168
|
tree.write(configPath, newContents);
|
|
169
169
|
}
|
|
@@ -104,7 +104,7 @@ function transformWithReact(tree, configPath, scope) {
|
|
|
104
104
|
function transformWithModuleFederation(tree, configPath, scope) {
|
|
105
105
|
const configContents = tree.read(configPath, 'utf-8');
|
|
106
106
|
const ast = tsquery_1.tsquery.ast(configContents);
|
|
107
|
-
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `ImportDeclaration:has(Identifier[name=withModuleFederation]) > StringLiteral[value=${scope}/
|
|
107
|
+
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `ImportDeclaration:has(Identifier[name=withModuleFederation]) > StringLiteral[value=${scope}/module-federation/webpack]`;
|
|
108
108
|
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
109
109
|
if (nodes.length === 0) {
|
|
110
110
|
return;
|
|
@@ -119,7 +119,7 @@ function transformWithModuleFederation(tree, configPath, scope) {
|
|
|
119
119
|
if (configContents.charAt(endIndex) === ',') {
|
|
120
120
|
endIndex++;
|
|
121
121
|
}
|
|
122
|
-
const newContents = `import { withModuleFederation } from '@nx/
|
|
122
|
+
const newContents = `import { withModuleFederation } from '@nx/module-federation/rspack';
|
|
123
123
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
124
124
|
tree.write(configPath, newContents);
|
|
125
125
|
}
|
|
@@ -141,14 +141,14 @@ function transformModuleFederationConfig(tree, configPath, scope) {
|
|
|
141
141
|
if (configContents.charAt(endIndex) === ',') {
|
|
142
142
|
endIndex++;
|
|
143
143
|
}
|
|
144
|
-
const newContents = `import { ModuleFederationConfig } from '@nx/
|
|
144
|
+
const newContents = `import { ModuleFederationConfig } from '@nx/module-federation';
|
|
145
145
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
146
146
|
tree.write(configPath, newContents);
|
|
147
147
|
}
|
|
148
148
|
function transformWithModuleFederationSSR(tree, configPath, scope) {
|
|
149
149
|
const configContents = tree.read(configPath, 'utf-8');
|
|
150
150
|
const ast = tsquery_1.tsquery.ast(configContents);
|
|
151
|
-
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `ImportDeclaration:has(Identifier[name=withModuleFederationForSSR]) > StringLiteral[value=${scope}/
|
|
151
|
+
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `ImportDeclaration:has(Identifier[name=withModuleFederationForSSR]) > StringLiteral[value=${scope}/module-federation/webpack]`;
|
|
152
152
|
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
153
153
|
if (nodes.length === 0) {
|
|
154
154
|
return;
|
|
@@ -163,7 +163,7 @@ function transformWithModuleFederationSSR(tree, configPath, scope) {
|
|
|
163
163
|
if (configContents.charAt(endIndex) === ',') {
|
|
164
164
|
endIndex++;
|
|
165
165
|
}
|
|
166
|
-
const newContents = `import { withModuleFederationForSSR } from '@nx/
|
|
166
|
+
const newContents = `import { withModuleFederationForSSR } from '@nx/module-federation/rspack';
|
|
167
167
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
168
168
|
tree.write(configPath, newContents);
|
|
169
169
|
}
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -7,3 +7,4 @@ tslib_1.__exportStar(require("./utils/config"), exports);
|
|
|
7
7
|
tslib_1.__exportStar(require("./utils/with-nx"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./utils/with-react"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./utils/with-web"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./plugins/use-legacy-nx-plugin/use-legacy-nx-plugin"), exports);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = migrateWithMfImport;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
6
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
7
|
+
const NX_RSPACK_MODULE_FEDERATION_IMPORT_SELECTOR = 'ImportDeclaration > StringLiteral[value=@nx/rspack/module-federation], VariableStatement CallExpression:has(Identifier[name=require]) > StringLiteral[value=@nx/rspack/module-federation]';
|
|
8
|
+
const NEW_IMPORT_PATH = `'@nx/module-federation/rspack'`;
|
|
9
|
+
async function migrateWithMfImport(tree) {
|
|
10
|
+
const projects = new Set();
|
|
11
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/rspack:module-federation-dev-server', (options, project, target) => {
|
|
12
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
13
|
+
projects.add(projectConfig.root);
|
|
14
|
+
});
|
|
15
|
+
for (const projectRoot of projects) {
|
|
16
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, projectRoot, (filePath) => {
|
|
17
|
+
if (!filePath.endsWith('.ts') && !filePath.endsWith('.js')) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
let contents = tree.read(filePath, 'utf-8');
|
|
21
|
+
if (!contents.includes('@nx/rspack/module-federation')) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const ast = tsquery_1.tsquery.ast(contents);
|
|
25
|
+
const importNodes = (0, tsquery_1.tsquery)(ast, NX_RSPACK_MODULE_FEDERATION_IMPORT_SELECTOR);
|
|
26
|
+
if (importNodes.length === 0) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const importPathNode = importNodes[0];
|
|
30
|
+
contents = `${contents.slice(0, importPathNode.getStart())}${NEW_IMPORT_PATH}${contents.slice(importPathNode.getEnd())}`;
|
|
31
|
+
tree.write(filePath, contents);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
35
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Compiler } from '@rspack/core';
|
|
2
|
+
import type { NxAppRspackPluginOptions } from '../utils/models';
|
|
3
|
+
/**
|
|
4
|
+
* This plugin provides features to build Node and Web applications.
|
|
5
|
+
* - TS Support (including tsconfig paths
|
|
6
|
+
* - Assets handling
|
|
7
|
+
* - Stylesheets handling
|
|
8
|
+
* - index.html and package.json generation
|
|
9
|
+
*
|
|
10
|
+
* Web-only features, such as stylesheets and images, are only supported when `target` is `web` or `webworker`.
|
|
11
|
+
*/
|
|
12
|
+
export declare class NxAppRspackPlugin {
|
|
13
|
+
private readonly options;
|
|
14
|
+
constructor(options?: NxAppRspackPluginOptions);
|
|
15
|
+
apply(compiler: Compiler): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NxAppRspackPlugin = void 0;
|
|
4
|
+
const normalize_options_1 = require("../utils/plugins/normalize-options");
|
|
5
|
+
const apply_base_config_1 = require("../utils/apply-base-config");
|
|
6
|
+
const apply_web_config_1 = require("../utils/apply-web-config");
|
|
7
|
+
/**
|
|
8
|
+
* This plugin provides features to build Node and Web applications.
|
|
9
|
+
* - TS Support (including tsconfig paths
|
|
10
|
+
* - Assets handling
|
|
11
|
+
* - Stylesheets handling
|
|
12
|
+
* - index.html and package.json generation
|
|
13
|
+
*
|
|
14
|
+
* Web-only features, such as stylesheets and images, are only supported when `target` is `web` or `webworker`.
|
|
15
|
+
*/
|
|
16
|
+
class NxAppRspackPlugin {
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
// If we're building inferred targets, skip normalizing the build options
|
|
19
|
+
if (!global.NX_GRAPH_CREATION) {
|
|
20
|
+
this.options = (0, normalize_options_1.normalizeOptions)(options);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
apply(compiler) {
|
|
24
|
+
// Default's to web
|
|
25
|
+
const target = this.options.target ?? compiler.options.target;
|
|
26
|
+
this.options.outputPath ??= compiler.options.output?.path;
|
|
27
|
+
if (typeof target === 'string') {
|
|
28
|
+
this.options.target = target;
|
|
29
|
+
}
|
|
30
|
+
(0, apply_base_config_1.applyBaseConfig)(this.options, compiler.options, {
|
|
31
|
+
useNormalizedEntry: true,
|
|
32
|
+
});
|
|
33
|
+
if (compiler.options.target) {
|
|
34
|
+
this.options.target = compiler.options.target;
|
|
35
|
+
}
|
|
36
|
+
if (this.options.target === 'web' || this.options.target === 'webworker') {
|
|
37
|
+
(0, apply_web_config_1.applyWebConfig)(this.options, compiler.options, {
|
|
38
|
+
useNormalizedEntry: true,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.NxAppRspackPlugin = NxAppRspackPlugin;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NxReactRspackPlugin = void 0;
|
|
4
|
+
const apply_react_config_1 = require("../utils/apply-react-config");
|
|
5
|
+
class NxReactRspackPlugin {
|
|
6
|
+
constructor(options = {}) {
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
apply(compiler) {
|
|
10
|
+
(0, apply_react_config_1.applyReactConfig)(this.options, compiler.options);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.NxReactRspackPlugin = NxReactRspackPlugin;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { NxRspackExecutionContext } from '../../utils/config';
|
|
2
|
+
import type { NxAppRspackPluginOptions } from '../utils/models';
|
|
3
|
+
import type { Compiler, Configuration } from '@rspack/core';
|
|
4
|
+
/**
|
|
5
|
+
* This function is used to wrap the legacy plugin function to be used with the `composePlugins` function.
|
|
6
|
+
* Initially the rspack config would be passed to the legacy plugin function and the options would be passed as a second argument.
|
|
7
|
+
* example:
|
|
8
|
+
* module.exports = composePlugins(
|
|
9
|
+
withNx(),
|
|
10
|
+
(config) => {
|
|
11
|
+
return config;
|
|
12
|
+
}
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
Since composePlugins is async, this function is used to wrap the legacy plugin function to be async.
|
|
16
|
+
Using the nxUseLegacyPlugin function, the first argument is the legacy plugin function and the second argument is the options.
|
|
17
|
+
The context options are created and passed to the legacy plugin function.
|
|
18
|
+
|
|
19
|
+
module.exports = async () => ({
|
|
20
|
+
plugins: [
|
|
21
|
+
...otherPlugins,
|
|
22
|
+
await nxUseLegacyPlugin(require({path}), options),
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
* @param fn The legacy plugin function usually from `combinedPlugins`
|
|
26
|
+
* @param executorOptions The options passed usually inside the executor or the config file
|
|
27
|
+
* @returns Rspack configuration
|
|
28
|
+
*/
|
|
29
|
+
export declare function useLegacyNxPlugin(fn: (config: Configuration, ctx: NxRspackExecutionContext) => Promise<Configuration>, executorOptions: NxAppRspackPluginOptions): Promise<{
|
|
30
|
+
apply(compiler: Compiler): void;
|
|
31
|
+
}>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLegacyNxPlugin = useLegacyNxPlugin;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const normalize_options_1 = require("../utils/plugins/normalize-options");
|
|
6
|
+
const configuration_1 = require("nx/src/config/configuration");
|
|
7
|
+
/**
|
|
8
|
+
* This function is used to wrap the legacy plugin function to be used with the `composePlugins` function.
|
|
9
|
+
* Initially the rspack config would be passed to the legacy plugin function and the options would be passed as a second argument.
|
|
10
|
+
* example:
|
|
11
|
+
* module.exports = composePlugins(
|
|
12
|
+
withNx(),
|
|
13
|
+
(config) => {
|
|
14
|
+
return config;
|
|
15
|
+
}
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
Since composePlugins is async, this function is used to wrap the legacy plugin function to be async.
|
|
19
|
+
Using the nxUseLegacyPlugin function, the first argument is the legacy plugin function and the second argument is the options.
|
|
20
|
+
The context options are created and passed to the legacy plugin function.
|
|
21
|
+
|
|
22
|
+
module.exports = async () => ({
|
|
23
|
+
plugins: [
|
|
24
|
+
...otherPlugins,
|
|
25
|
+
await nxUseLegacyPlugin(require({path}), options),
|
|
26
|
+
],
|
|
27
|
+
});
|
|
28
|
+
* @param fn The legacy plugin function usually from `combinedPlugins`
|
|
29
|
+
* @param executorOptions The options passed usually inside the executor or the config file
|
|
30
|
+
* @returns Rspack configuration
|
|
31
|
+
*/
|
|
32
|
+
async function useLegacyNxPlugin(fn, executorOptions) {
|
|
33
|
+
if (global.NX_GRAPH_CREATION) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const options = (0, normalize_options_1.normalizeOptions)(executorOptions);
|
|
37
|
+
const projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
38
|
+
const projectName = process.env.NX_TASK_TARGET_PROJECT;
|
|
39
|
+
const project = projectGraph.nodes[projectName];
|
|
40
|
+
const targetName = process.env.NX_TASK_TARGET_TARGET;
|
|
41
|
+
const context = {
|
|
42
|
+
cwd: process.cwd(),
|
|
43
|
+
isVerbose: process.env.NX_VERBOSE_LOGGING === 'true',
|
|
44
|
+
root: devkit_1.workspaceRoot,
|
|
45
|
+
projectGraph,
|
|
46
|
+
projectsConfigurations: (0, devkit_1.readProjectsConfigurationFromProjectGraph)(projectGraph),
|
|
47
|
+
nxJsonConfiguration: (0, configuration_1.readNxJson)(devkit_1.workspaceRoot),
|
|
48
|
+
target: project.data.targets[targetName],
|
|
49
|
+
targetName: targetName,
|
|
50
|
+
projectName: projectName,
|
|
51
|
+
};
|
|
52
|
+
const configuration = process.env.NX_TASK_TARGET_CONFIGURATION;
|
|
53
|
+
const ctx = {
|
|
54
|
+
context,
|
|
55
|
+
options: options,
|
|
56
|
+
configuration,
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
apply(compiler) {
|
|
60
|
+
compiler.hooks.beforeCompile.tapPromise('NxLegacyAsyncPlugin', () => {
|
|
61
|
+
return new Promise((resolve) => {
|
|
62
|
+
fn(compiler.options, ctx).then((updated) => {
|
|
63
|
+
// Merge options back shallowly since it's a fully functional configuration.
|
|
64
|
+
// Most likely, the user modified the config in place, but this guarantees that updates are applied if users did something like:
|
|
65
|
+
// `return { ...config, plugins: [...config.plugins, new MyPlugin()] }`
|
|
66
|
+
Object.assign(compiler.options, updated);
|
|
67
|
+
resolve();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -59,11 +59,7 @@ function applyNxIndependentConfig(options, config) {
|
|
|
59
59
|
// So to mitigate this we enable in memory caching when target is Node and in watch mode.
|
|
60
60
|
config.cache = options.target === 'node' && options.watch ? true : undefined;
|
|
61
61
|
config.devtool =
|
|
62
|
-
options.sourceMap === '
|
|
63
|
-
? 'hidden-source-map'
|
|
64
|
-
: options.sourceMap
|
|
65
|
-
? 'source-map'
|
|
66
|
-
: false;
|
|
62
|
+
options.sourceMap === true ? 'source-map' : options.sourceMap;
|
|
67
63
|
config.output = {
|
|
68
64
|
...(config.output ?? {}),
|
|
69
65
|
libraryTarget: config.output?.libraryTarget ??
|
|
@@ -83,6 +79,7 @@ function applyNxIndependentConfig(options, config) {
|
|
|
83
79
|
hashFunction: config.output?.hashFunction ?? 'xxhash64',
|
|
84
80
|
// Disabled for performance
|
|
85
81
|
pathinfo: config.output?.pathinfo ?? false,
|
|
82
|
+
clean: options.deleteOutputPath,
|
|
86
83
|
};
|
|
87
84
|
config.watch = options.watch;
|
|
88
85
|
config.watchOptions = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type Configuration } from '@rspack/core';
|
|
1
|
+
import { type Configuration, RspackOptionsNormalized } from '@rspack/core';
|
|
2
2
|
import { NormalizedNxAppRspackPluginOptions } from './models';
|
|
3
|
-
export declare function applyWebConfig(options: NormalizedNxAppRspackPluginOptions, config?: Configuration
|
|
3
|
+
export declare function applyWebConfig(options: NormalizedNxAppRspackPluginOptions, config?: Partial<RspackOptionsNormalized | Configuration>, { useNormalizedEntry, }?: {
|
|
4
4
|
useNormalizedEntry?: boolean;
|
|
5
5
|
}): void;
|
|
@@ -70,13 +70,6 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
|
|
|
70
70
|
const resolvedPath = style.input.startsWith('.')
|
|
71
71
|
? style.input
|
|
72
72
|
: (0, path_1.resolve)(options.root, style.input);
|
|
73
|
-
// Add style entry points.
|
|
74
|
-
if (entries[style.bundleName]) {
|
|
75
|
-
entries[style.bundleName].import.push(resolvedPath);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
entries[style.bundleName] = { import: [resolvedPath] };
|
|
79
|
-
}
|
|
80
73
|
// Add global css paths.
|
|
81
74
|
globalStylePaths.push(resolvedPath);
|
|
82
75
|
});
|
|
@@ -290,7 +283,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
|
|
|
290
283
|
}
|
|
291
284
|
});
|
|
292
285
|
config.optimization = !isProd
|
|
293
|
-
?
|
|
286
|
+
? {}
|
|
294
287
|
: {
|
|
295
288
|
...(config.optimization ?? {}),
|
|
296
289
|
minimizer: [...(config.optimization?.minimizer ?? []), ...minimizer],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Mode } from '@rspack/core';
|
|
1
|
+
import type { DevTool, Mode } from '@rspack/core';
|
|
2
2
|
import type { ProjectGraph } from '@nx/devkit';
|
|
3
3
|
import type { AssetGlob } from '@nx/js/src/utils/assets/assets';
|
|
4
4
|
export interface SvgrOptions {
|
|
@@ -171,7 +171,7 @@ export interface NxAppRspackPluginOptions {
|
|
|
171
171
|
/**
|
|
172
172
|
* Generate source maps.
|
|
173
173
|
*/
|
|
174
|
-
sourceMap?: boolean |
|
|
174
|
+
sourceMap?: boolean | DevTool;
|
|
175
175
|
/**
|
|
176
176
|
* When `true`, `process.env.NODE_ENV` will be excluded from the bundle. Useful for building a web application to run in a Node environment.
|
|
177
177
|
*/
|
|
@@ -81,7 +81,7 @@ function normalizeOptions(options) {
|
|
|
81
81
|
sourceMap: combinedPluginAndMaybeExecutorOptions.sourceMap ?? !isProd,
|
|
82
82
|
sourceRoot,
|
|
83
83
|
styles: combinedPluginAndMaybeExecutorOptions.styles ?? [],
|
|
84
|
-
target: combinedPluginAndMaybeExecutorOptions.target,
|
|
84
|
+
target: combinedPluginAndMaybeExecutorOptions.target ?? 'web',
|
|
85
85
|
targetName,
|
|
86
86
|
vendorChunk: combinedPluginAndMaybeExecutorOptions.vendorChunk ?? !isProd,
|
|
87
87
|
};
|
|
@@ -16,7 +16,7 @@ class NxTsconfigPathsRspackPlugin {
|
|
|
16
16
|
apply(compiler) {
|
|
17
17
|
// TODO(Colum): Investigate the best way to handle this, currently it is not working and affecting HMR
|
|
18
18
|
// // If we are not building libs from source, we need to remap paths so tsconfig may be updated.
|
|
19
|
-
|
|
19
|
+
this.handleBuildLibsFromSource(compiler.options, this.options);
|
|
20
20
|
const pathToTsconfig = !path.isAbsolute(this.options.tsConfig)
|
|
21
21
|
? path.join(devkit_1.workspaceRoot, this.options.tsConfig)
|
|
22
22
|
: this.options.tsConfig;
|
|
@@ -44,7 +44,8 @@ class NxTsconfigPathsRspackPlugin {
|
|
|
44
44
|
if (!options.buildLibsFromSource && options.targetName) {
|
|
45
45
|
const remappedTarget = options.targetName === 'serve' ? 'build' : options.targetName;
|
|
46
46
|
const { target, dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(undefined, options.projectGraph, options.root, options.projectName, remappedTarget, options.configurationName);
|
|
47
|
-
options.tsConfig = (0, buildable_libs_utils_1.createTmpTsConfig)(options.tsConfig, options.root, target.data.root, dependencies
|
|
47
|
+
options.tsConfig = (0, buildable_libs_utils_1.createTmpTsConfig)(options.tsConfig, options.root, target.data.root, dependencies, true // There is an issue with Rspack that requires the baseUrl to be set in the generated tsconfig
|
|
48
|
+
);
|
|
48
49
|
this.tmpTsConfigPath = options.tsConfig;
|
|
49
50
|
if (options.targetName === 'serve') {
|
|
50
51
|
const buildableDependencies = dependencies
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ExecutorContext } from '@nx/devkit';
|
|
2
2
|
import { Compiler, MultiCompiler } from '@rspack/core';
|
|
3
|
-
import {
|
|
4
|
-
export declare function createCompiler(options:
|
|
3
|
+
import { NormalizedRspackExecutorSchema } from '../executors/rspack/schema';
|
|
4
|
+
export declare function createCompiler(options: NormalizedRspackExecutorSchema & {
|
|
5
5
|
devServer?: any;
|
|
6
6
|
}, context: ExecutorContext): Promise<Compiler | MultiCompiler>;
|
|
7
7
|
export declare function isMultiCompiler(compiler: Compiler | MultiCompiler): compiler is MultiCompiler;
|
|
@@ -1,63 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.createCompiler = createCompiler;
|
|
27
4
|
exports.isMultiCompiler = isMultiCompiler;
|
|
28
5
|
const core_1 = require("@rspack/core");
|
|
29
|
-
const
|
|
6
|
+
const config_1 = require("../executors/rspack/lib/config");
|
|
30
7
|
async function createCompiler(options, context) {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
userDefinedConfig = (0, resolve_user_defined_rspack_config_1.resolveUserDefinedRspackConfig)(pathToConfig, options.tsConfig);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
userDefinedConfig = await Promise.resolve(`${pathToConfig}`).then(s => __importStar(require(s))).then((x) => x.default || x);
|
|
38
|
-
}
|
|
39
|
-
if (typeof userDefinedConfig.then === 'function') {
|
|
40
|
-
userDefinedConfig = await userDefinedConfig;
|
|
41
|
-
}
|
|
42
|
-
let config = {};
|
|
43
|
-
if (typeof userDefinedConfig === 'function') {
|
|
44
|
-
config = await userDefinedConfig({ devServer: options.devServer }, { options, context });
|
|
8
|
+
const config = await (0, config_1.getRspackConfigs)(options, context);
|
|
9
|
+
if (!options.standardRspackConfigFunction) {
|
|
10
|
+
validateConfig(config);
|
|
45
11
|
}
|
|
46
|
-
else {
|
|
47
|
-
config = userDefinedConfig;
|
|
48
|
-
config.devServer ??= options.devServer;
|
|
49
|
-
}
|
|
50
|
-
validateConfig(config);
|
|
51
12
|
return (0, core_1.rspack)(config);
|
|
52
13
|
}
|
|
53
14
|
function isMultiCompiler(compiler) {
|
|
54
15
|
return 'compilers' in compiler;
|
|
55
16
|
}
|
|
56
17
|
function validateConfig(config) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
18
|
+
[config].flat().forEach((config) => {
|
|
19
|
+
if (!config.entry) {
|
|
20
|
+
throw new Error('Entry is required. Please set the `main` option in the executor or the `entry` property in the rspack config.');
|
|
21
|
+
}
|
|
22
|
+
if (!config.output) {
|
|
23
|
+
throw new Error('Output is required. Please set the `outputPath` option in the executor or the `output` property in the rspack config.');
|
|
24
|
+
}
|
|
25
|
+
});
|
|
63
26
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TargetConfiguration, Tree } from '@nx/devkit';
|
|
2
|
-
import { ConfigurationSchema } from '../generators/configuration/schema';
|
|
3
|
-
import { Framework } from '../generators/init/schema';
|
|
2
|
+
import { type ConfigurationSchema } from '../generators/configuration/schema';
|
|
3
|
+
import { type Framework } from '../generators/init/schema';
|
|
4
4
|
export type Target = 'build' | 'serve';
|
|
5
5
|
export type TargetFlags = Partial<Record<Target, boolean>>;
|
|
6
6
|
export type UserProvidedTargetName = Partial<Record<Target, string>>;
|