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(angular): failing tests related to mfe #9491

Merged
merged 1 commit into from Mar 24, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -13,7 +13,7 @@ import {
} from './lib';

export default async function convertToWithMF(tree: Tree, schema: Schema) {
const projects = new Set(getMfeProjects(tree));
const projects = new Set(getMfeProjects(tree, { legacy: true }));

if (!projects.has(schema.project)) {
throw new Error(
Expand Down
10 changes: 8 additions & 2 deletions packages/angular/src/utils/get-mfe-projects.ts
Expand Up @@ -2,9 +2,15 @@ import type { Tree } from '@nrwl/devkit';
import { tsquery } from '@phenomnomnominal/tsquery';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';

export function getMfeProjects(tree: Tree) {
export function getMfeProjects(
tree: Tree,
{ legacy }: { legacy: boolean } = { legacy: false }
) {
const NRWL_WEBPACK_BROWSER_BUILDER = '@nrwl/angular:webpack-browser';
const CUSTOM_WEBPACK_OPTION = 'customWebpackConfig';
const MODULE_FEDERATION_IDENTIFIER = legacy
? 'Identifier[name=ModuleFederationPlugin]'
: 'Identifier[name=withModuleFederation]';

const projects: string[] = [];
forEachExecutorOptions(
Expand All @@ -19,7 +25,7 @@ export function getMfeProjects(tree: Tree) {
const ast = tsquery.ast(webpackConfig);
const moduleFederationWebpackConfig = tsquery(
ast,
'Identifier[name=withModuleFederation]',
MODULE_FEDERATION_IDENTIFIER,
{
visitAllChildren: true,
}
Expand Down
Expand Up @@ -48,7 +48,7 @@ Array [
},
"name": "host",
"remotes": Object {
"remote1": "http:/localhost:4201/remoteEntry.mjs",
"remote1": "http://localhost:4201/remoteEntry.mjs",
},
"shared": Object {
"@angular/core": Object {
Expand Down
Expand Up @@ -10,7 +10,7 @@ import * as fs from 'fs';

import { withModuleFederation } from './with-module-federation';

xdescribe('withModuleFederation', () => {
describe('withModuleFederation', () => {
afterEach(() => jest.clearAllMocks());
it('should create a host config correctly', async () => {
// ARRANGE
Expand Down
11 changes: 7 additions & 4 deletions packages/angular/src/utils/mfe/with-module-federation.ts
Expand Up @@ -4,9 +4,8 @@ import {
shareWorkspaceLibraries,
} from './mfe-webpack';
import {
appRootPath,
workspaceRoot,
createProjectGraphAsync,
joinPathFragments,
ProjectGraph,
readCachedProjectGraph,
Workspaces,
Expand Down Expand Up @@ -62,7 +61,9 @@ function recursivelyResolveWorkspaceDependents(
}

function mapWorkspaceLibrariesToTsConfigImport(workspaceLibraries: string[]) {
const { projects } = new Workspaces(appRootPath).readWorkspaceConfiguration();
const { projects } = new Workspaces(
workspaceRoot
).readWorkspaceConfiguration();

const tsConfigPath = process.env.NX_TSCONFIG_PATH ?? getRootTsConfigPath();
const tsConfig: ParsedCommandLine = readTsConfig(tsConfigPath);
Expand Down Expand Up @@ -150,7 +151,9 @@ function determineRemoteUrl(remote: string) {
You can also use the tuple syntax in your webpack config to configure your remotes. e.g. \`remotes: [['remote1', 'http://localhost:4201']]\``
);
}
return joinPathFragments(publicHost, 'remoteEntry.mjs');
return `${
publicHost.endsWith('/') ? publicHost.slice(0, -1) : publicHost
}/remoteEntry.mjs`;
}

function mapRemotes(remotes: MFERemotes) {
Expand Down