Skip to content

Commit

Permalink
fix(react): Error when invalid path is provided to federate-module ge…
Browse files Browse the repository at this point in the history
…nerator
  • Loading branch information
ndcunningham committed Oct 18, 2023
1 parent 4ee2916 commit cee3c1c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"path": {
"type": "string",
"description": "The path to locate the federated module.",
"description": "The path to locate the federated module. This path should be relative to the workspace root and the file should exist.",
"x-prompt": "What is the path to the module to be federated?"
},
"remote": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {

export async function federateModuleGenerator(tree: Tree, schema: Schema) {
if (!tree.exists(schema.path)) {
throw new Error(stripIndents`The "path" provided does not exist. Please verify the path is correct and pointing to a file that exists in the workspace.
throw new Error(stripIndents`The "path" provided does not exist. Please verify the path is correct and pointing to a file that exists in the workspace.
Path: ${schema.path}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('federate-module', () => {

beforeAll(() => {
tree = createTreeWithEmptyWorkspace();
tree.write('my-remote/src/my-federated-module.ts', ''); // Ensure that the file exists
});
describe('no remote', () => {
it('should generate a remote and e2e', async () => {
Expand Down Expand Up @@ -46,6 +47,17 @@ describe('federate-module', () => {
tsconfig.compilerOptions.paths['my-remote/my-federated-module']
).toEqual(['my-remote/src/my-federated-module.ts']);
});

it('should error when invalid path is provided', async () => {
await federateModuleGenerator(tree, {
...schema,
path: 'invalid/path',
}).catch((e) => {
expect(e.message).toContain(
'The "path" provided does not exist. Please verify the path is correct and pointing to a file that exists in the workspace.'
);
});
});
});

describe('with remote', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
logger,
readJson,
runTasksInSerial,
stripIndents,
} from '@nx/devkit';
import { Schema } from './schema';

Expand All @@ -14,6 +15,12 @@ import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/pr
import { addTsConfigPath, getRootTsConfigPathInTree } from '@nx/js';

export async function federateModuleGenerator(tree: Tree, schema: Schema) {
// Check if the file exists
if (!tree.exists(schema.path)) {
throw new Error(stripIndents`The "path" provided does not exist. Please verify the path is correct and pointing to a file that exists in the workspace.
Path: ${schema.path}`);
}
const tasks: GeneratorCallback[] = [];
// Check remote exists
const remote = checkRemoteExists(tree, schema.remote);
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/generators/federate-module/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"path": {
"type": "string",
"description": "The path to locate the federated module.",
"description": "The path to locate the federated module. This path should be relative to the workspace root and the file should exist.",
"x-prompt": "What is the path to the module to be federated?"
},
"remote": {
Expand Down

0 comments on commit cee3c1c

Please sign in to comment.