diff --git a/docs/generated/packages/react/generators/federate-module.json b/docs/generated/packages/react/generators/federate-module.json index 0fe80424ead411..bd916aeb29955a 100644 --- a/docs/generated/packages/react/generators/federate-module.json +++ b/docs/generated/packages/react/generators/federate-module.json @@ -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": { diff --git a/packages/angular/src/generators/federate-module/federate-module.ts b/packages/angular/src/generators/federate-module/federate-module.ts index e8637789ed92b8..b03f567c3b8d49 100644 --- a/packages/angular/src/generators/federate-module/federate-module.ts +++ b/packages/angular/src/generators/federate-module/federate-module.ts @@ -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}`); } diff --git a/packages/react/src/generators/federate-module/federate-module.spec.ts b/packages/react/src/generators/federate-module/federate-module.spec.ts index 12ce7b19b87472..ac9be2b4c741c7 100644 --- a/packages/react/src/generators/federate-module/federate-module.spec.ts +++ b/packages/react/src/generators/federate-module/federate-module.spec.ts @@ -1,4 +1,4 @@ -import { Tree, getProjects } from '@nx/devkit'; +import { Tree, getProjects, logger } from '@nx/devkit'; import { Schema } from './schema'; import { Schema as remoteSchma } from '../remote/schema'; import { federateModuleGenerator } from './federate-module'; @@ -46,6 +46,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', () => { diff --git a/packages/react/src/generators/federate-module/federate-module.ts b/packages/react/src/generators/federate-module/federate-module.ts index 627a0047274bdf..e9fe3740c5db80 100644 --- a/packages/react/src/generators/federate-module/federate-module.ts +++ b/packages/react/src/generators/federate-module/federate-module.ts @@ -5,6 +5,7 @@ import { logger, readJson, runTasksInSerial, + stripIndents, } from '@nx/devkit'; import { Schema } from './schema'; @@ -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); diff --git a/packages/react/src/generators/federate-module/schema.json b/packages/react/src/generators/federate-module/schema.json index ebeda7758cc609..e74868b47fb36c 100644 --- a/packages/react/src/generators/federate-module/schema.json +++ b/packages/react/src/generators/federate-module/schema.json @@ -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": {