fix(react): do not set a module federation remote project as the default project (#11128)

This commit is contained in:
Leosvel Pérez Espinosa 2022-07-13 20:32:03 +01:00 committed by GitHub
parent c088dd7851
commit 2163c54b85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 62 additions and 2 deletions

View File

@ -212,6 +212,11 @@
"description": "The compiler to use.",
"enum": ["babel", "swc"],
"default": "babel"
},
"skipDefaultProject": {
"description": "Skip setting the project as the default project. When `false` (the default), the project is set as the default project only if there is no default project already set.",
"type": "boolean",
"default": false
}
},
"required": [],

View File

@ -4,6 +4,7 @@ import {
readJson,
readWorkspaceConfiguration,
Tree,
updateWorkspaceConfiguration,
} from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { Linter } from '@nrwl/linter';
@ -45,6 +46,28 @@ describe('app', () => {
expect(workspaceJson.defaultProject).toEqual('my-app');
});
it('should not overwrite default project if already set', async () => {
const workspace = readWorkspaceConfiguration(appTree);
workspace.defaultProject = 'some-awesome-project';
updateWorkspaceConfiguration(appTree, workspace);
await applicationGenerator(appTree, schema);
const { defaultProject } = readWorkspaceConfiguration(appTree);
expect(defaultProject).toBe('some-awesome-project');
});
it('should not set defaultProject when "--skip-default-project=true"', async () => {
await applicationGenerator(appTree, {
...schema,
skipDefaultProject: true,
});
const { defaultProject } = readWorkspaceConfiguration(appTree);
expect(defaultProject).toBeUndefined();
});
it('should update tags and implicit dependencies', async () => {
await applicationGenerator(appTree, { ...schema, tags: 'one,two' });

View File

@ -12,7 +12,7 @@ export function setDefaults(host: Tree, options: NormalizedSchema) {
const workspace = readWorkspaceConfiguration(host);
if (!workspace.defaultProject) {
if (!options.skipDefaultProject && !workspace.defaultProject) {
workspace.defaultProject = options.projectName;
}

View File

@ -26,6 +26,7 @@ export interface Schema {
compiler?: 'babel' | 'swc';
remotes?: string[];
devServerPort?: number;
skipDefaultProject?: boolean;
}
export interface NormalizedSchema extends Schema {

View File

@ -159,6 +159,11 @@
"description": "The compiler to use.",
"enum": ["babel", "swc"],
"default": "babel"
},
"skipDefaultProject": {
"description": "Skip setting the project as the default project. When `false` (the default), the project is set as the default project only if there is no default project already set.",
"type": "boolean",
"default": false
}
},
"required": []

View File

@ -0,0 +1,23 @@
import { readWorkspaceConfiguration } from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { Linter } from '@nrwl/linter';
import remote from './remote';
describe('remote generator', () => {
it('should not set the remote as the default project', async () => {
const tree = createTreeWithEmptyWorkspace(2);
await remote(tree, {
name: 'test',
devServerPort: 4201,
e2eTestRunner: 'cypress',
linter: Linter.EsLint,
skipFormat: false,
style: 'css',
unitTestRunner: 'jest',
});
const { defaultProject } = readWorkspaceConfiguration(tree);
expect(defaultProject).toBeUndefined();
});
});

View File

@ -29,7 +29,10 @@ export function addModuleFederationFiles(
export async function remoteGenerator(host: Tree, schema: Schema) {
const options = normalizeOptions(host, schema);
const initApp = await applicationGenerator(host, options);
const initApp = await applicationGenerator(host, {
...options,
skipDefaultProject: true,
});
if (schema.host) {
updateHostWithRemote(host, schema.host, options.name);