|
1 | 1 | import { type Tree, readNxJson, updateNxJson } from '@nx/devkit';
|
2 | 2 |
|
3 |
| -export function addMfEnvToTargetDefaultInputs(tree: Tree) { |
| 3 | +export function addMfEnvToTargetDefaultInputs( |
| 4 | + tree: Tree, |
| 5 | + bundler: 'rspack' | 'webpack' |
| 6 | +) { |
4 | 7 | const nxJson = readNxJson(tree);
|
5 |
| - const webpackExecutor = '@nx/webpack:webpack'; |
| 8 | + const executor = |
| 9 | + bundler === 'rspack' ? '@nx/rspack:rspack' : '@nx/webpack:webpack'; |
6 | 10 | const mfEnvVar = 'NX_MF_DEV_REMOTES';
|
7 | 11 |
|
8 | 12 | nxJson.targetDefaults ??= {};
|
9 |
| - nxJson.targetDefaults[webpackExecutor] ??= {}; |
10 |
| - nxJson.targetDefaults[webpackExecutor].inputs ??= [ |
11 |
| - 'production', |
12 |
| - '^production', |
13 |
| - ]; |
14 |
| - nxJson.targetDefaults[webpackExecutor].dependsOn ??= ['^build']; |
| 13 | + nxJson.targetDefaults[executor] ??= {}; |
| 14 | + nxJson.targetDefaults[executor].inputs ??= ['production', '^production']; |
| 15 | + nxJson.targetDefaults[executor].dependsOn ??= ['^build']; |
15 | 16 |
|
16 | 17 | let mfEnvVarExists = false;
|
17 |
| - for (const input of nxJson.targetDefaults[webpackExecutor].inputs) { |
| 18 | + for (const input of nxJson.targetDefaults[executor].inputs) { |
18 | 19 | if (typeof input === 'object' && input['env'] === mfEnvVar) {
|
19 | 20 | mfEnvVarExists = true;
|
20 | 21 | break;
|
21 | 22 | }
|
22 | 23 | }
|
23 | 24 | if (!mfEnvVarExists) {
|
24 |
| - nxJson.targetDefaults[webpackExecutor].inputs.push({ env: mfEnvVar }); |
| 25 | + nxJson.targetDefaults[executor].inputs.push({ env: mfEnvVar }); |
25 | 26 | }
|
26 |
| - nxJson.targetDefaults[webpackExecutor].cache = true; |
| 27 | + nxJson.targetDefaults[executor].cache = true; |
27 | 28 | updateNxJson(tree, nxJson);
|
28 | 29 | }
|
0 commit comments