feat(module-federation): add continuous tasks support to react rspack (#30644)
## Current Behavior Continuous tasks are not set up for React Rspack Module Federation Remote projects. This is important because `--dev-remotes` is no longer supported with Crystal Module Federation usage. ## Expected Behavior Add Continuous Tasks support for React Rspack Module Federation Remote Projects. This replaces the need for `nx serve shell --dev-remotes=remote1`. Instead, the command is simply `nx serve remote1` and continuous tasks means that the `shell:serve` task is executed correctly.
This commit is contained in:
parent
c5fb467118
commit
5f26c6811e
@ -1,9 +1,15 @@
|
|||||||
import 'nx/src/internal-testing-utils/mock-project-graph';
|
import 'nx/src/internal-testing-utils/mock-project-graph';
|
||||||
|
|
||||||
import { ProjectGraph, readJson, readNxJson } from '@nx/devkit';
|
import {
|
||||||
|
ProjectGraph,
|
||||||
|
readJson,
|
||||||
|
readNxJson,
|
||||||
|
readProjectConfiguration,
|
||||||
|
} from '@nx/devkit';
|
||||||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
||||||
import { Linter } from '@nx/eslint';
|
import { Linter } from '@nx/eslint';
|
||||||
import remote from './remote';
|
import remote from './remote';
|
||||||
|
import host from '../host/host';
|
||||||
import { getRootTsConfigPathInTree } from '@nx/js';
|
import { getRootTsConfigPathInTree } from '@nx/js';
|
||||||
|
|
||||||
jest.mock('@nx/devkit', () => {
|
jest.mock('@nx/devkit', () => {
|
||||||
@ -100,6 +106,37 @@ describe('remote generator', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('bundler=rspack', () => {
|
describe('bundler=rspack', () => {
|
||||||
|
it('should set up continuous tasks when host is provided', async () => {
|
||||||
|
const tree = createTreeWithEmptyWorkspace();
|
||||||
|
await host(tree, {
|
||||||
|
directory: 'test/host',
|
||||||
|
name: 'host',
|
||||||
|
skipFormat: true,
|
||||||
|
bundler: 'rspack',
|
||||||
|
e2eTestRunner: 'cypress',
|
||||||
|
linter: Linter.EsLint,
|
||||||
|
unitTestRunner: 'jest',
|
||||||
|
style: 'css',
|
||||||
|
});
|
||||||
|
|
||||||
|
await remote(tree, {
|
||||||
|
directory: 'test/remote',
|
||||||
|
name: 'remote',
|
||||||
|
devServerPort: 4201,
|
||||||
|
e2eTestRunner: 'cypress',
|
||||||
|
linter: Linter.EsLint,
|
||||||
|
skipFormat: true,
|
||||||
|
style: 'css',
|
||||||
|
unitTestRunner: 'jest',
|
||||||
|
typescriptConfiguration: false,
|
||||||
|
bundler: 'rspack',
|
||||||
|
host: 'host',
|
||||||
|
});
|
||||||
|
|
||||||
|
const remoteProject = readProjectConfiguration(tree, 'remote');
|
||||||
|
expect(remoteProject.targets.serve.dependsOn).toEqual(['host:serve']);
|
||||||
|
});
|
||||||
|
|
||||||
it('should create the remote with the correct config files', async () => {
|
it('should create the remote with the correct config files', async () => {
|
||||||
const tree = createTreeWithEmptyWorkspace();
|
const tree = createTreeWithEmptyWorkspace();
|
||||||
await remote(tree, {
|
await remote(tree, {
|
||||||
|
|||||||
@ -220,6 +220,14 @@ export async function remoteGenerator(host: Tree, schema: Schema) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.host && options.bundler === 'rspack') {
|
||||||
|
const projectConfig = readProjectConfiguration(host, options.projectName);
|
||||||
|
projectConfig.targets.serve ??= {};
|
||||||
|
projectConfig.targets.serve.dependsOn ??= [];
|
||||||
|
projectConfig.targets.serve.dependsOn.push(`${options.host}:serve`);
|
||||||
|
updateProjectConfiguration(host, options.projectName, projectConfig);
|
||||||
|
}
|
||||||
|
|
||||||
if (options.host && options.dynamic) {
|
if (options.host && options.dynamic) {
|
||||||
const hostConfig = readProjectConfiguration(host, schema.host);
|
const hostConfig = readProjectConfiguration(host, schema.host);
|
||||||
const pathToMFManifest = joinPathFragments(
|
const pathToMFManifest = joinPathFragments(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user