Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react): Error when invalid path is provided to federate-module generator #19720

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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