Skip to content

Commit

Permalink
fix(react): normalizing project names for module federation correctly #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Sep 19, 2024
1 parent 7f4a877 commit 3f19990
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/react/src/generators/host/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export async function hostGeneratorInternal(

const initTask = await applicationGenerator(host, {
...options,
name: options.projectName,
// The target use-case is loading remotes as child routes, thus always enable routing.
routing: true,
skipFormat: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function addModuleFederationFiles(
defaultRemoteManifest: { name: string; port: number }[]
) {
const templateVariables = {
...names(options.name),
...names(options.projectName),
...options,
static: !options?.dynamic,
tmpl: '',
Expand All @@ -26,7 +26,7 @@ export function addModuleFederationFiles(
}),
};

const projectConfig = readProjectConfiguration(host, options.name);
const projectConfig = readProjectConfiguration(host, options.projectName);
const pathToMFManifest = joinPathFragments(
projectConfig.sourceRoot,
'assets/module-federation.manifest.json'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import type { Tree } from '@nx/devkit';
import { joinPathFragments, readProjectConfiguration } from '@nx/devkit';
import { addTsConfigPath } from '@nx/js';
import { maybeJs } from '../../../utils/maybe-js';
import type { Schema } from '../schema';
import { NormalizedSchema } from '../../application/schema';

export function setupTspathForRemote(tree: Tree, options: Schema) {
const project = readProjectConfiguration(tree, options.name);
export function setupTspathForRemote(tree: Tree, options: NormalizedSchema) {
const project = readProjectConfiguration(tree, options.projectName);

const exportPath = maybeJs(options, './src/remote-entry.ts');

const exportName = 'Module';

addTsConfigPath(tree, `${options.name}/${exportName}`, [
addTsConfigPath(tree, `${options.projectName}/${exportName}`, [
joinPathFragments(project.root, exportPath),
]);
}
9 changes: 5 additions & 4 deletions packages/react/src/generators/remote/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function addModuleFederationFiles(
options: NormalizedSchema<Schema>
) {
const templateVariables = {
...names(options.name),
...names(options.projectName),
...options,
tmpl: '',
};
Expand Down Expand Up @@ -113,16 +113,17 @@ export async function remoteGeneratorInternal(host: Tree, schema: Schema) {
if (options.dynamic) {
// Dynamic remotes generate with library { type: 'var' } by default.
// We need to ensure that the remote name is a valid variable name.
const isValidRemote = isValidVariable(options.name);
const isValidRemote = isValidVariable(options.projectName);
if (!isValidRemote.isValid) {
throw new Error(
`Invalid remote name provided: ${options.name}. ${isValidRemote.message}`
`Invalid remote name provided: ${options.projectName}. ${isValidRemote.message}`
);
}
}

const initAppTask = await applicationGenerator(host, {
...options,
name: options.projectName,
skipFormat: true,
});
tasks.push(initAppTask);
Expand Down Expand Up @@ -201,7 +202,7 @@ export async function remoteGeneratorInternal(host: Tree, schema: Schema) {
);
addRemoteToDynamicHost(
host,
options.name,
options.projectName,
options.devServerPort,
pathToMFManifest
);
Expand Down

0 comments on commit 3f19990

Please sign in to comment.