Skip to content

Commit

Permalink
fix(react): do not set a module federation remote project as the defa…
Browse files Browse the repository at this point in the history
…ult project (nrwl#11128)
  • Loading branch information
leosvelperez authored Jul 13, 2022
1 parent c088dd7 commit 2163c54
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/generated/packages/react.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
23 changes: 23 additions & 0 deletions packages/react/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
readJson,
readWorkspaceConfiguration,
Tree,
updateWorkspaceConfiguration,
} from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { Linter } from '@nrwl/linter';
Expand Down Expand Up @@ -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' });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions packages/react/src/generators/application/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface Schema {
compiler?: 'babel' | 'swc';
remotes?: string[];
devServerPort?: number;
skipDefaultProject?: boolean;
}

export interface NormalizedSchema extends Schema {
Expand Down
5 changes: 5 additions & 0 deletions packages/react/src/generators/application/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
Expand Down
23 changes: 23 additions & 0 deletions packages/react/src/generators/remote/remote.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
5 changes: 4 additions & 1 deletion packages/react/src/generators/remote/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2163c54

Please sign in to comment.