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): normalizing project names for module federation correctly #27901 #27990

Merged
merged 1 commit into from
Sep 19, 2024
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
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