Skip to content

Commit

Permalink
fix(module-federation): ensure shared packages can be shared from host
Browse files Browse the repository at this point in the history
…#27162 (#27513)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
The host application is never set as a candidate to share packages from.
Particularly in angular, this causes issues with the injection context

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Host application should be a valid option for sharing packages

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #27162

(cherry picked from commit 8137708)
  • Loading branch information
Coly010 authored and FrozenPandaz committed Aug 21, 2024
1 parent dfa3441 commit d179bcd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,12 @@ export async function* moduleFederationDevServerExecutor(
options.staticRemotesPort ??= remotes.staticRemotePort;

// Set NX_MF_DEV_REMOTES for the Nx Runtime Library Control Plugin
process.env.NX_MF_DEV_REMOTES = JSON.stringify(
remotes.devRemotes.map((r) => (typeof r === 'string' ? r : r.remoteName))
);
process.env.NX_MF_DEV_REMOTES = JSON.stringify([
...(remotes.devRemotes.map((r) =>
typeof r === 'string' ? r : r.remoteName
) ?? []),
project.name,
]);

const staticRemotesConfig = parseStaticRemotesConfig(
[...remotes.staticRemotes, ...remotes.dynamicRemotes],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ export async function* moduleFederationSsrDevServerExecutor(
);

// Set NX_MF_DEV_REMOTES for the Nx Runtime Library Control Plugin
process.env.NX_MF_DEV_REMOTES = JSON.stringify(options.devRemotes);
process.env.NX_MF_DEV_REMOTES = JSON.stringify([
...(options.devRemotes ?? []),
project.name,
]);

const devRemotes = await startRemotes(
remotes.devRemotes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,12 @@ export default async function* moduleFederationDevServer(
options.staticRemotesPort ??= remotes.staticRemotePort;

// Set NX_MF_DEV_REMOTES for the Nx Runtime Library Control Plugin
process.env.NX_MF_DEV_REMOTES = JSON.stringify(
remotes.devRemotes.map((r) => (typeof r === 'string' ? r : r.remoteName))
);
process.env.NX_MF_DEV_REMOTES = JSON.stringify([
...(remotes.devRemotes.map((r) =>
typeof r === 'string' ? r : r.remoteName
) ?? []),
p.name,
]);

const staticRemotesConfig = parseStaticRemotesConfig(
[...remotes.staticRemotes, ...remotes.dynamicRemotes],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,12 @@ export default async function* moduleFederationSsrDevServer(

options.staticRemotesPort ??= remotes.staticRemotePort;

process.env.NX_MF_DEV_REMOTES = JSON.stringify(
remotes.devRemotes.map((r) => (typeof r === 'string' ? r : r.remoteName))
);
process.env.NX_MF_DEV_REMOTES = JSON.stringify([
...(remotes.devRemotes.map((r) =>
typeof r === 'string' ? r : r.remoteName
) ?? []),
projectConfig.name,
]);

const staticRemotesConfig = parseStaticSsrRemotesConfig(
[...remotes.staticRemotes, ...remotes.dynamicRemotes],
Expand Down

0 comments on commit d179bcd

Please sign in to comment.