From abf9bc7eef0a64c82fb310c5786632a3c253cc1c Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Thu, 21 Nov 2024 22:43:49 -0500 Subject: [PATCH] feat(rspack): fix tests --- .../application/application.spec.ts | 81 ------------------- .../rules/update-module-federation-project.ts | 12 ++- 2 files changed, 8 insertions(+), 85 deletions(-) diff --git a/packages/react/src/generators/application/application.spec.ts b/packages/react/src/generators/application/application.spec.ts index 75b6f01a2dc78..d94a8268388e7 100644 --- a/packages/react/src/generators/application/application.spec.ts +++ b/packages/react/src/generators/application/application.spec.ts @@ -1241,85 +1241,4 @@ describe('app', () => { } `); }); - - it('should add project to excludes when @nx/rspack/plugin is setup as object and --bundler=rspack', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace(); - let nxJson = readNxJson(tree); - delete nxJson.targetDefaults; - nxJson.plugins ??= []; - nxJson.plugins.push({ - plugin: '@nx/rspack/plugin', - options: { - buildTargetName: 'build-base', - }, - }); - updateNxJson(tree, nxJson); - - // ACT - await applicationGenerator(tree, { - directory: 'myapp', - addPlugin: true, - linter: Linter.None, - style: 'none', - bundler: 'rspack', - e2eTestRunner: 'none', - }); - - // ASSERT - nxJson = readNxJson(tree); - expect( - nxJson.plugins.find((p) => - typeof p === 'string' - ? p === '@nx/rspack/plugin' - : p.plugin === '@nx/rspack/plugin' - ) - ).toMatchInlineSnapshot(` - { - "exclude": [ - "myapp/**", - ], - "options": { - "buildTargetName": "build-base", - }, - "plugin": "@nx/rspack/plugin", - } - `); - }); - it('should add project to excludes when @nx/rspack/plugin is setup as string and --bundler=rspack', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace(); - let nxJson = readNxJson(tree); - delete nxJson.targetDefaults; - nxJson.plugins ??= []; - nxJson.plugins.push('@nx/rspack/plugin'); - updateNxJson(tree, nxJson); - - // ACT - await applicationGenerator(tree, { - directory: 'myapp', - addPlugin: true, - linter: Linter.None, - style: 'none', - bundler: 'rspack', - e2eTestRunner: 'none', - }); - - // ASSERT - nxJson = readNxJson(tree); - expect( - nxJson.plugins.find((p) => - typeof p === 'string' - ? p === '@nx/rspack/plugin' - : p.plugin === '@nx/rspack/plugin' - ) - ).toMatchInlineSnapshot(` - { - "exclude": [ - "myapp/**", - ], - "plugin": "@nx/rspack/plugin", - } - `); - }); }); diff --git a/packages/react/src/rules/update-module-federation-project.ts b/packages/react/src/rules/update-module-federation-project.ts index f42e7f3e9b6cf..350d047506d03 100644 --- a/packages/react/src/rules/update-module-federation-project.ts +++ b/packages/react/src/rules/update-module-federation-project.ts @@ -26,7 +26,7 @@ export function updateModuleFederationProject( if (options.bundler === 'rspack') { projectConfig.targets.build.executor = '@nx/rspack:rspack'; projectConfig.targets.build.options = { - ...projectConfig.targets.build.options, + ...(projectConfig.targets.build.options ?? {}), main: maybeJs( { js: options.js, useJsx: true }, `${options.appProjectRoot}/src/main.ts` @@ -37,23 +37,27 @@ export function updateModuleFederationProject( target: 'web', }; + projectConfig.targets.build.configurations ??= {}; + projectConfig.targets.build.configurations.production = { - ...projectConfig.targets.build.configurations.production, + ...(projectConfig.targets.build.configurations?.production ?? {}), rspackConfig: `${options.appProjectRoot}/rspack.config.prod.${ options.typescriptConfiguration && !options.js ? 'ts' : 'js' }`, }; } else { projectConfig.targets.build.options = { - ...projectConfig.targets.build.options, + ...(projectConfig.targets.build.options ?? {}), main: maybeJs(options, `${options.appProjectRoot}/src/main.ts`), webpackConfig: `${options.appProjectRoot}/webpack.config.${ options.typescriptConfiguration && !options.js ? 'ts' : 'js' }`, }; + projectConfig.targets.build.configurations ??= {}; + projectConfig.targets.build.configurations.production = { - ...projectConfig.targets.build.configurations.production, + ...(projectConfig.targets.build.configurations?.production ?? {}), webpackConfig: `${options.appProjectRoot}/webpack.config.prod.${ options.typescriptConfiguration && !options.js ? 'ts' : 'js' }`,