@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,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
|
+
}
|
|
@@ -26,6 +26,7 @@ function applyBaseConfig(options, config = {}, { useNormalizedEntry, } = {}) {
|
|
|
26
26
|
options.memoryLimit ??= 2048;
|
|
27
27
|
options.transformers ??= [];
|
|
28
28
|
options.progress ??= true;
|
|
29
|
+
options.outputHashing ??= 'all';
|
|
29
30
|
applyNxIndependentConfig(options, config);
|
|
30
31
|
// Some of the options only work during actual tasks, not when reading the rspack config during CreateNodes.
|
|
31
32
|
if (global.NX_GRAPH_CREATION)
|
|
@@ -79,6 +80,7 @@ function applyNxIndependentConfig(options, config) {
|
|
|
79
80
|
hashFunction: config.output?.hashFunction ?? 'xxhash64',
|
|
80
81
|
// Disabled for performance
|
|
81
82
|
pathinfo: config.output?.pathinfo ?? false,
|
|
83
|
+
clean: options.deleteOutputPath,
|
|
82
84
|
};
|
|
83
85
|
config.watch = options.watch;
|
|
84
86
|
config.watchOptions = {
|
|
@@ -91,6 +93,7 @@ function applyNxIndependentConfig(options, config) {
|
|
|
91
93
|
};
|
|
92
94
|
config.ignoreWarnings = [
|
|
93
95
|
(x) => IGNORED_RSPACK_WARNINGS.some((r) => typeof x === 'string' ? r.test(x) : r.test(x.message)),
|
|
96
|
+
...(config.ignoreWarnings ?? []),
|
|
94
97
|
];
|
|
95
98
|
config.optimization = !isProd
|
|
96
99
|
? undefined
|
|
@@ -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;
|
|
@@ -283,7 +283,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
|
|
|
283
283
|
}
|
|
284
284
|
});
|
|
285
285
|
config.optimization = !isProd
|
|
286
|
-
?
|
|
286
|
+
? {}
|
|
287
287
|
: {
|
|
288
288
|
...(config.optimization ?? {}),
|
|
289
289
|
minimizer: [...(config.optimization?.minimizer ?? []), ...minimizer],
|
|
@@ -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
|
|
@@ -6,7 +6,9 @@ const core_1 = require("@rspack/core");
|
|
|
6
6
|
const config_1 = require("../executors/rspack/lib/config");
|
|
7
7
|
async function createCompiler(options, context) {
|
|
8
8
|
const config = await (0, config_1.getRspackConfigs)(options, context);
|
|
9
|
-
|
|
9
|
+
if (!options.standardRspackConfigFunction) {
|
|
10
|
+
validateConfig(config);
|
|
11
|
+
}
|
|
10
12
|
return (0, core_1.rspack)(config);
|
|
11
13
|
}
|
|
12
14
|
function isMultiCompiler(compiler) {
|
|
@@ -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>>;
|
|
@@ -15,6 +15,7 @@ exports.determineMain = determineMain;
|
|
|
15
15
|
exports.determineTsConfig = determineTsConfig;
|
|
16
16
|
const devkit_1 = require("@nx/devkit");
|
|
17
17
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
18
|
+
const has_plugin_1 = require("./has-plugin");
|
|
18
19
|
function findExistingTargetsInProject(targets, userProvidedTargets) {
|
|
19
20
|
const output = {
|
|
20
21
|
validFoundTargetName: {},
|
|
@@ -177,82 +178,148 @@ function addOrChangeServeTarget(tree, options, target) {
|
|
|
177
178
|
}
|
|
178
179
|
function writeRspackConfigFile(tree, options, stylePreprocessorOptions) {
|
|
179
180
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
180
|
-
tree.write((0, devkit_1.joinPathFragments)(project.root, 'rspack.config.js'), createConfig(options, stylePreprocessorOptions));
|
|
181
|
+
tree.write((0, devkit_1.joinPathFragments)(project.root, 'rspack.config.js'), createConfig(tree, { ...options, stylePreprocessorOptions }));
|
|
181
182
|
}
|
|
182
|
-
function createConfig(
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
? `
|
|
189
|
-
{
|
|
190
|
-
stylePreprocessorOptions: ${JSON.stringify(stylePreprocessorOptions)},
|
|
191
|
-
}
|
|
192
|
-
`
|
|
193
|
-
: ''}), (config) => {
|
|
194
|
-
return config;
|
|
195
|
-
});
|
|
196
|
-
`;
|
|
183
|
+
function createConfig(tree, options) {
|
|
184
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
185
|
+
const buildOptions = createBuildOptions(tree, options, project);
|
|
186
|
+
const defaultConfig = generateDefaultConfig(project, buildOptions);
|
|
187
|
+
if (isWebFramework(options)) {
|
|
188
|
+
return generateWebConfig(tree, options, defaultConfig);
|
|
197
189
|
}
|
|
198
|
-
else if (options.framework === '
|
|
199
|
-
return
|
|
200
|
-
|
|
190
|
+
else if (options.framework === 'nest') {
|
|
191
|
+
return generateNestConfig(tree, options, project, buildOptions);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
return generateGenericConfig(tree, options, defaultConfig);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function createBuildOptions(tree, options, project) {
|
|
198
|
+
return {
|
|
199
|
+
target: options.target ?? 'web',
|
|
200
|
+
outputPath: (0, devkit_1.joinPathFragments)('dist', project.root === '.' ? project.name : project.root),
|
|
201
|
+
main: determineMain(tree, options),
|
|
202
|
+
tsConfig: determineTsConfig(tree, options),
|
|
203
|
+
rspackConfig: (0, devkit_1.joinPathFragments)(project.root, 'rspack.config.js'),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function generateDefaultConfig(project, buildOptions) {
|
|
207
|
+
return `
|
|
208
|
+
const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
|
|
209
|
+
const { join } = require('path');
|
|
201
210
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
211
|
+
module.exports = {
|
|
212
|
+
output: {
|
|
213
|
+
path: join(__dirname, '${(0, devkit_1.offsetFromRoot)(project.root)}${buildOptions.outputPath}'),
|
|
214
|
+
},
|
|
215
|
+
plugins: [
|
|
216
|
+
new NxAppRspackPlugin({
|
|
217
|
+
target: '${buildOptions.target}',
|
|
218
|
+
tsConfig: '${buildOptions.tsConfig}',
|
|
219
|
+
main: '${buildOptions.main}',
|
|
220
|
+
outputHashing: '${buildOptions.target !== 'web' ? 'none' : 'all'}',
|
|
221
|
+
})
|
|
222
|
+
]
|
|
223
|
+
}`;
|
|
224
|
+
}
|
|
225
|
+
function isWebFramework(options) {
|
|
226
|
+
return options.framework === 'web' || options.target === 'web';
|
|
227
|
+
}
|
|
228
|
+
function generateWebConfig(tree, options, defaultConfig) {
|
|
229
|
+
if ((0, has_plugin_1.hasPlugin)(tree)) {
|
|
230
|
+
return defaultConfig;
|
|
212
231
|
}
|
|
213
|
-
|
|
232
|
+
return `
|
|
233
|
+
const { composePlugins, withNx, withWeb } = require('@nx/rspack');
|
|
234
|
+
module.exports = composePlugins(withNx(), withWeb(${options.stylePreprocessorOptions
|
|
235
|
+
? `
|
|
236
|
+
{
|
|
237
|
+
stylePreprocessorOptions: ${JSON.stringify(options.stylePreprocessorOptions)},
|
|
238
|
+
}
|
|
239
|
+
`
|
|
240
|
+
: ''}), (config) => {
|
|
241
|
+
return config;
|
|
242
|
+
});
|
|
243
|
+
`;
|
|
244
|
+
}
|
|
245
|
+
function generateNestConfig(tree, options, project, buildOptions) {
|
|
246
|
+
if ((0, has_plugin_1.hasPlugin)(tree)) {
|
|
214
247
|
return `
|
|
215
|
-
|
|
216
|
-
|
|
248
|
+
const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
|
|
249
|
+
const rspack = require('@rspack/core');
|
|
250
|
+
const { join } = require('path');
|
|
217
251
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
252
|
+
module.exports = {
|
|
253
|
+
output: {
|
|
254
|
+
path: join(__dirname, '${(0, devkit_1.offsetFromRoot)(project.root)}${buildOptions.outputPath}'),
|
|
255
|
+
},
|
|
256
|
+
optimization: {
|
|
257
|
+
minimizer: [
|
|
258
|
+
new rspack.SwcJsMinimizerRspackPlugin({
|
|
259
|
+
minimizerOptions: {
|
|
260
|
+
compress: {
|
|
261
|
+
keep_classnames: true,
|
|
262
|
+
keep_fnames: true,
|
|
263
|
+
},
|
|
264
|
+
mangle: {
|
|
265
|
+
keep_classnames: true,
|
|
266
|
+
keep_fnames: true,
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
}),
|
|
270
|
+
],
|
|
271
|
+
},
|
|
272
|
+
plugins: [
|
|
273
|
+
new NxAppRspackPlugin({
|
|
274
|
+
target: '${buildOptions.target}',
|
|
275
|
+
tsConfig: '${buildOptions.tsConfig}',
|
|
276
|
+
main: '${buildOptions.main}',
|
|
277
|
+
outputHashing: '${buildOptions.target !== 'web' ? 'none' : 'all'}',
|
|
278
|
+
})
|
|
279
|
+
]
|
|
280
|
+
}`;
|
|
241
281
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
282
|
+
return `
|
|
283
|
+
const { composePlugins, withNx } = require('@nx/rspack');
|
|
284
|
+
const rspack = require('@rspack/core');
|
|
245
285
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
286
|
+
module.exports = composePlugins(withNx(), (config) => {
|
|
287
|
+
config.optimization = {
|
|
288
|
+
minimizer: [
|
|
289
|
+
new rspack.SwcJsMinimizerRspackPlugin({
|
|
290
|
+
minimizerOptions: {
|
|
291
|
+
compress: {
|
|
292
|
+
keep_classnames: true,
|
|
293
|
+
keep_fnames: true,
|
|
294
|
+
},
|
|
295
|
+
mangle: {
|
|
296
|
+
keep_classnames: true,
|
|
297
|
+
keep_fnames: true,
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
}),
|
|
301
|
+
],
|
|
302
|
+
};
|
|
303
|
+
return config;
|
|
304
|
+
});
|
|
305
|
+
`;
|
|
306
|
+
}
|
|
307
|
+
function generateGenericConfig(tree, options, defaultConfig) {
|
|
308
|
+
if ((0, has_plugin_1.hasPlugin)(tree)) {
|
|
309
|
+
return defaultConfig;
|
|
255
310
|
}
|
|
311
|
+
return `
|
|
312
|
+
const { composePlugins, withNx${options.stylePreprocessorOptions ? ', withWeb' : ''} } = require('@nx/rspack');
|
|
313
|
+
|
|
314
|
+
module.exports = composePlugins(withNx()${options.stylePreprocessorOptions
|
|
315
|
+
? `,
|
|
316
|
+
withWeb({
|
|
317
|
+
stylePreprocessorOptions: ${JSON.stringify(options.stylePreprocessorOptions)},
|
|
318
|
+
})`
|
|
319
|
+
: ''}, (config) => {
|
|
320
|
+
return config;
|
|
321
|
+
});
|
|
322
|
+
`;
|
|
256
323
|
}
|
|
257
324
|
function deleteWebpackConfig(tree, projectRoot, webpackConfigFilePath) {
|
|
258
325
|
const webpackConfigPath = webpackConfigFilePath && tree.exists(webpackConfigFilePath)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasPlugin = hasPlugin;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function hasPlugin(tree) {
|
|
6
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
7
|
+
return !!nxJson.plugins?.some((p) => typeof p === 'string'
|
|
8
|
+
? p === '@nx/rspack/plugin'
|
|
9
|
+
: p.plugin === '@nx/rspack/plugin');
|
|
10
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ExecutorContext } from '@nx/devkit';
|
|
2
2
|
import { ModuleFederationDevServerOptions } from '../../executors/module-federation-dev-server/schema';
|
|
3
|
-
import type { StaticRemotesConfig } from '
|
|
3
|
+
import type { StaticRemotesConfig } from '@nx/module-federation/src/utils';
|
|
4
4
|
export declare function buildStaticRemotes(staticRemotesConfig: StaticRemotesConfig, nxBin: any, context: ExecutorContext, options: ModuleFederationDevServerOptions): Promise<Record<string, string>>;
|
package/src/utils/versions.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const nxVersion: any;
|
|
2
|
-
export declare const rspackCoreVersion = "1.
|
|
3
|
-
export declare const rspackDevServerVersion = "1.0.
|
|
2
|
+
export declare const rspackCoreVersion = "1.1.2";
|
|
3
|
+
export declare const rspackDevServerVersion = "1.0.9";
|
|
4
4
|
export declare const rspackPluginMinifyVersion = "^0.7.5";
|
|
5
5
|
export declare const rspackPluginReactRefreshVersion = "^1.0.0";
|
|
6
6
|
export declare const lessLoaderVersion = "~11.1.3";
|
package/src/utils/versions.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.eslintPluginReactHooksVersion = exports.eslintPluginReactVersion = exports.eslintPluginJsxA11yVersion = exports.eslintPluginImportVersion = exports.stylusVersion = exports.sassVersion = exports.lessVersion = exports.nestjsMicroservicesVersion = exports.nestjsPlatformExpressVersion = exports.nestjsCoreVersion = exports.nestjsCommonVersion = exports.typesReactDomVersion = exports.typesReactVersion = exports.reactDomVersion = exports.reactRefreshVersion = exports.reactVersion = exports.lessLoaderVersion = exports.rspackPluginReactRefreshVersion = exports.rspackPluginMinifyVersion = exports.rspackDevServerVersion = exports.rspackCoreVersion = exports.nxVersion = void 0;
|
|
4
4
|
exports.nxVersion = require('../../package.json').version;
|
|
5
|
-
exports.rspackCoreVersion = '1.
|
|
6
|
-
exports.rspackDevServerVersion = '1.0.
|
|
5
|
+
exports.rspackCoreVersion = '1.1.2';
|
|
6
|
+
exports.rspackDevServerVersion = '1.0.9';
|
|
7
7
|
exports.rspackPluginMinifyVersion = '^0.7.5';
|
|
8
8
|
exports.rspackPluginReactRefreshVersion = '^1.0.0';
|
|
9
9
|
exports.lessLoaderVersion = '~11.1.3';
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { ProjectGraph } from '@nx/devkit';
|
|
2
|
-
import type { WorkspaceLibrary } from './models';
|
|
3
|
-
export declare function getDependentPackagesForProject(projectGraph: ProjectGraph, name: string): {
|
|
4
|
-
workspaceLibraries: WorkspaceLibrary[];
|
|
5
|
-
npmPackages: string[];
|
|
6
|
-
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDependentPackagesForProject = getDependentPackagesForProject;
|
|
4
|
-
const typescript_1 = require("./typescript");
|
|
5
|
-
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
function getDependentPackagesForProject(projectGraph, name) {
|
|
7
|
-
const { npmPackages, workspaceLibraries } = collectDependencies(projectGraph, name);
|
|
8
|
-
return {
|
|
9
|
-
workspaceLibraries: [...workspaceLibraries.values()],
|
|
10
|
-
npmPackages: [...npmPackages],
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function collectDependencies(projectGraph, name, dependencies = {
|
|
14
|
-
workspaceLibraries: new Map(),
|
|
15
|
-
npmPackages: new Set(),
|
|
16
|
-
}, seen = new Set()) {
|
|
17
|
-
if (seen.has(name)) {
|
|
18
|
-
return dependencies;
|
|
19
|
-
}
|
|
20
|
-
seen.add(name);
|
|
21
|
-
(projectGraph.dependencies[name] ?? []).forEach((dependency) => {
|
|
22
|
-
if (dependency.target.startsWith('npm:')) {
|
|
23
|
-
dependencies.npmPackages.add(dependency.target.replace('npm:', ''));
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
dependencies.workspaceLibraries.set(dependency.target, {
|
|
27
|
-
name: dependency.target,
|
|
28
|
-
root: projectGraph.nodes[dependency.target].data.root,
|
|
29
|
-
importKey: getLibraryImportPath(dependency.target, projectGraph),
|
|
30
|
-
});
|
|
31
|
-
collectDependencies(projectGraph, dependency.target, dependencies, seen);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
return dependencies;
|
|
35
|
-
}
|
|
36
|
-
function getLibraryImportPath(library, projectGraph) {
|
|
37
|
-
let buildLibsFromSource = true;
|
|
38
|
-
if (process.env.NX_BUILD_LIBS_FROM_SOURCE) {
|
|
39
|
-
buildLibsFromSource = process.env.NX_BUILD_LIBS_FROM_SOURCE === 'true';
|
|
40
|
-
}
|
|
41
|
-
const libraryNode = projectGraph.nodes[library];
|
|
42
|
-
let sourceRoots = [libraryNode.data.sourceRoot];
|
|
43
|
-
if (!buildLibsFromSource && process.env.NX_BUILD_TARGET) {
|
|
44
|
-
const buildTarget = (0, devkit_1.parseTargetString)(process.env.NX_BUILD_TARGET, projectGraph);
|
|
45
|
-
sourceRoots = (0, devkit_1.getOutputsForTargetAndConfiguration)(buildTarget, {}, libraryNode);
|
|
46
|
-
}
|
|
47
|
-
const tsConfigPathMappings = (0, typescript_1.readTsPathMappings)();
|
|
48
|
-
for (const [key, value] of Object.entries(tsConfigPathMappings)) {
|
|
49
|
-
for (const src of sourceRoots) {
|
|
50
|
-
if (value.find((path) => path.startsWith(src))) {
|
|
51
|
-
return key;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type ProjectGraph } from '@nx/devkit';
|
|
2
|
-
import { ModuleFederationConfig } from './models';
|
|
3
|
-
interface ModuleFederationExecutorContext {
|
|
4
|
-
projectName: string;
|
|
5
|
-
projectGraph: ProjectGraph;
|
|
6
|
-
root: string;
|
|
7
|
-
}
|
|
8
|
-
export declare function getRemotes(devRemotes: string[], skipRemotes: string[], config: ModuleFederationConfig, context: ModuleFederationExecutorContext, pathToManifestFile?: string): {
|
|
9
|
-
staticRemotes: string[];
|
|
10
|
-
devRemotes: any[];
|
|
11
|
-
dynamicRemotes: any[];
|
|
12
|
-
remotePorts: any[];
|
|
13
|
-
staticRemotePort: number;
|
|
14
|
-
};
|
|
15
|
-
export declare function getModuleFederationConfig(tsconfigPath: string, workspaceRoot: string, projectRoot: string, pluginName?: 'react' | 'angular'): any;
|
|
16
|
-
export {};
|