fix(react): do not set a module federation remote project as the default project (#11128)
This commit is contained in:
parent
c088dd7851
commit
2163c54b85
@ -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": [],
|
||||
|
||||
@ -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' });
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -26,6 +26,7 @@ export interface Schema {
|
||||
compiler?: 'babel' | 'swc';
|
||||
remotes?: string[];
|
||||
devServerPort?: number;
|
||||
skipDefaultProject?: boolean;
|
||||
}
|
||||
|
||||
export interface NormalizedSchema extends Schema {
|
||||
|
||||
@ -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": []
|
||||
|
||||
23
packages/react/src/generators/remote/remote.spec.ts
Normal file
23
packages/react/src/generators/remote/remote.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user