@nx/rspack 20.4.3 → 20.5.0-beta.0
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/package.json +5 -5
- package/src/executors/rspack/lib/config.js +1 -6
- package/src/generators/application/application.js +3 -0
- package/src/generators/configuration/configuration.js +3 -0
- package/src/plugins/plugin.js +3 -14
- package/src/utils/generator-utils.js +3 -7
- package/src/utils/resolve-user-defined-rspack-config.d.ts +1 -1
- package/src/utils/resolve-user-defined-rspack-config.js +31 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/rspack",
|
|
3
3
|
"description": "The Nx Plugin for Rspack contains executors and generators that support building applications using Rspack.",
|
|
4
|
-
"version": "20.
|
|
4
|
+
"version": "20.5.0-beta.0",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"generators": "./generators.json",
|
|
25
25
|
"executors": "./executors.json",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@nx/js": "20.
|
|
28
|
-
"@nx/devkit": "20.
|
|
29
|
-
"@nx/web": "20.
|
|
30
|
-
"@nx/module-federation": "20.
|
|
27
|
+
"@nx/js": "20.5.0-beta.0",
|
|
28
|
+
"@nx/devkit": "20.5.0-beta.0",
|
|
29
|
+
"@nx/web": "20.5.0-beta.0",
|
|
30
|
+
"@nx/module-federation": "20.5.0-beta.0",
|
|
31
31
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
32
32
|
"@rspack/core": "^1.1.5",
|
|
33
33
|
"@rspack/dev-server": "^1.0.9",
|
|
@@ -6,12 +6,7 @@ const resolve_user_defined_rspack_config_1 = require("../../../utils/resolve-use
|
|
|
6
6
|
const with_nx_1 = require("../../../utils/with-nx");
|
|
7
7
|
const with_web_1 = require("../../../utils/with-web");
|
|
8
8
|
async function getRspackConfigs(options, context) {
|
|
9
|
-
let
|
|
10
|
-
let userDefinedConfig = 'default' in maybeUserDefinedConfig
|
|
11
|
-
? 'default' in maybeUserDefinedConfig.default
|
|
12
|
-
? maybeUserDefinedConfig.default.default
|
|
13
|
-
: maybeUserDefinedConfig.default
|
|
14
|
-
: maybeUserDefinedConfig;
|
|
9
|
+
let userDefinedConfig = (0, resolve_user_defined_rspack_config_1.resolveUserDefinedRspackConfig)(options.rspackConfig, options.tsConfig);
|
|
15
10
|
if (typeof userDefinedConfig.then === 'function') {
|
|
16
11
|
userDefinedConfig = await userDefinedConfig;
|
|
17
12
|
}
|
|
@@ -11,6 +11,9 @@ async function default_1(tree, _options) {
|
|
|
11
11
|
const tasks = [];
|
|
12
12
|
const initTask = await (0, init_1.default)(tree, {
|
|
13
13
|
..._options,
|
|
14
|
+
// TODO: Crystalize the default rspack.config.js file.
|
|
15
|
+
// The default setup isn't crystalized so don't add plugin.
|
|
16
|
+
addPlugin: false,
|
|
14
17
|
});
|
|
15
18
|
tasks.push(initTask);
|
|
16
19
|
const options = await (0, normalize_options_1.normalizeOptions)(tree, _options);
|
|
@@ -10,6 +10,9 @@ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-set
|
|
|
10
10
|
async function configurationGenerator(tree, options) {
|
|
11
11
|
const task = await (0, init_1.default)(tree, {
|
|
12
12
|
...options,
|
|
13
|
+
// TODO: Crystalize the default rspack.config.js file.
|
|
14
|
+
// The default setup isn't crystalized so don't add plugin.
|
|
15
|
+
addPlugin: false,
|
|
13
16
|
});
|
|
14
17
|
const { targets, root, projectType } = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
15
18
|
const { target, framework } = (0, generator_utils_1.determineFrameworkAndTarget)(tree, options, root, targets);
|
package/src/plugins/plugin.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createNodesV2 = exports.createDependencies = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
5
6
|
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
6
7
|
const js_1 = require("@nx/js");
|
|
7
8
|
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
@@ -47,22 +48,10 @@ async function createNodesInternal(configFilePath, options, context, targetsCach
|
|
|
47
48
|
!siblingFiles.includes('project.json')) {
|
|
48
49
|
return {};
|
|
49
50
|
}
|
|
50
|
-
let packageJson = {};
|
|
51
|
-
if (siblingFiles.includes('package.json')) {
|
|
52
|
-
packageJson = (0, devkit_1.readJsonFile)((0, path_1.join)(context.workspaceRoot, projectRoot, 'package.json'));
|
|
53
|
-
}
|
|
54
51
|
const normalizedOptions = normalizeOptions(options);
|
|
55
52
|
// We do not want to alter how the hash is calculated, so appending the config file path to the hash
|
|
56
53
|
// to prevent vite/vitest files overwriting the target cache created by the other
|
|
57
|
-
const
|
|
58
|
-
...[
|
|
59
|
-
(0, path_1.join)(context.workspaceRoot, configFilePath),
|
|
60
|
-
(0, path_1.join)(context.workspaceRoot, (0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))),
|
|
61
|
-
].map(file_hasher_1.hashFile),
|
|
62
|
-
(0, file_hasher_1.hashObject)(options),
|
|
63
|
-
(0, file_hasher_1.hashObject)(packageJson),
|
|
64
|
-
]);
|
|
65
|
-
const hash = `${nodeHash}_${configFilePath}`;
|
|
54
|
+
const hash = (await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, normalizedOptions, context, [(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))])) + configFilePath;
|
|
66
55
|
targetsCache[hash] ??= await createRspackTargets(configFilePath, projectRoot, normalizedOptions, context, isTsSolutionSetup);
|
|
67
56
|
const { targets, metadata } = targetsCache[hash];
|
|
68
57
|
return {
|
|
@@ -77,7 +66,7 @@ async function createNodesInternal(configFilePath, options, context, targetsCach
|
|
|
77
66
|
}
|
|
78
67
|
async function createRspackTargets(configFilePath, projectRoot, options, context, isTsSolutionSetup) {
|
|
79
68
|
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
80
|
-
const rspackConfig =
|
|
69
|
+
const rspackConfig = (0, resolve_user_defined_rspack_config_1.resolveUserDefinedRspackConfig)((0, path_1.join)(context.workspaceRoot, configFilePath), (0, js_1.getRootTsConfigPath)(), true);
|
|
81
70
|
const rspackOptions = await (0, read_rspack_options_1.readRspackOptions)(rspackConfig);
|
|
82
71
|
const outputs = [];
|
|
83
72
|
for (const config of rspackOptions) {
|
|
@@ -15,7 +15,6 @@ 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 ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
19
18
|
const has_plugin_1 = require("./has-plugin");
|
|
20
19
|
function findExistingTargetsInProject(targets, userProvidedTargets) {
|
|
21
20
|
const output = {
|
|
@@ -130,14 +129,11 @@ function addOrChangeBuildTarget(tree, options, target) {
|
|
|
130
129
|
if (tree.exists((0, devkit_1.joinPathFragments)(project.root, 'src/assets'))) {
|
|
131
130
|
assets.push((0, devkit_1.joinPathFragments)(project.root, 'src/assets'));
|
|
132
131
|
}
|
|
133
|
-
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
|
|
134
132
|
const buildOptions = {
|
|
135
133
|
target: options.target ?? 'web',
|
|
136
|
-
outputPath:
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
// If standalone project then use the project's name in dist.
|
|
140
|
-
project.root === '.' ? project.name : project.root),
|
|
134
|
+
outputPath: (0, devkit_1.joinPathFragments)('dist',
|
|
135
|
+
// If standalone project then use the project's name in dist.
|
|
136
|
+
project.root === '.' ? project.name : project.root),
|
|
141
137
|
index: (0, devkit_1.joinPathFragments)(project.root, 'src/index.html'),
|
|
142
138
|
main: determineMain(tree, options),
|
|
143
139
|
tsConfig: determineTsConfig(tree, options),
|
|
@@ -2,8 +2,37 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveUserDefinedRspackConfig = resolveUserDefinedRspackConfig;
|
|
4
4
|
const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
|
|
5
|
-
|
|
5
|
+
const internal_1 = require("@nx/js/src/internal");
|
|
6
|
+
function resolveUserDefinedRspackConfig(path, tsConfig,
|
|
6
7
|
/** Skip require cache and return latest content */
|
|
7
8
|
reload = false) {
|
|
8
|
-
|
|
9
|
+
if (reload) {
|
|
10
|
+
// Clear cache if the path is in the cache
|
|
11
|
+
if (require.cache[path]) {
|
|
12
|
+
// Clear all entries because config may import other modules
|
|
13
|
+
(0, config_utils_1.clearRequireCache)();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Don't transpile non-TS files. This prevents workspaces libs from being registered via tsconfig-paths.
|
|
17
|
+
// There's an issue here with Nx workspace where loading plugins from source (via tsconfig-paths) can lead to errors.
|
|
18
|
+
if (!/\.(ts|mts|cts)$/.test(path)) {
|
|
19
|
+
return require(path);
|
|
20
|
+
}
|
|
21
|
+
const cleanupTranspiler = (0, internal_1.registerTsProject)(tsConfig);
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
23
|
+
const maybeCustomRspackConfig = require(path);
|
|
24
|
+
cleanupTranspiler();
|
|
25
|
+
// If the user provides a configuration in TS file
|
|
26
|
+
// then there are 3 cases for exploring an object. The first one is:
|
|
27
|
+
// `module.exports = { ... }`. And the second one is:
|
|
28
|
+
// `export default { ... }`. The ESM format is compiled into:
|
|
29
|
+
// `{ default: { ... } }`
|
|
30
|
+
// There is also a case of
|
|
31
|
+
// `{ default: { default: { ... } }`
|
|
32
|
+
const customRspackConfig = 'default' in maybeCustomRspackConfig
|
|
33
|
+
? 'default' in maybeCustomRspackConfig.default
|
|
34
|
+
? maybeCustomRspackConfig.default.default
|
|
35
|
+
: maybeCustomRspackConfig.default
|
|
36
|
+
: maybeCustomRspackConfig;
|
|
37
|
+
return customRspackConfig;
|
|
9
38
|
}
|