Skip to content

Commit

Permalink
fix(angular): skipping remotes should not only look at the current wo…
Browse files Browse the repository at this point in the history
…rkspace #17473
  • Loading branch information
Coly010 committed Jun 9, 2023
1 parent a9f8cc6 commit c17e256
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { Schema } from './schema';
import { readCachedProjectGraph, workspaceRoot, Workspaces } from '@nx/devkit';
import {
logger,
readCachedProjectGraph,
workspaceRoot,
Workspaces,
} from '@nx/devkit';
import { scheduleTarget } from 'nx/src/adapter/ngcli-adapter';
import { executeWebpackDevServerBuilder } from '../webpack-dev-server/webpack-dev-server.impl';
import { readProjectsConfigurationFromProjectGraph } from 'nx/src/project-graph/project-graph';
Expand All @@ -10,7 +15,10 @@ import {
} from '../utilities/module-federation';
import { existsSync } from 'fs';
import { extname, join } from 'path';
import { findMatchingProjects } from 'nx/src/utils/find-matching-projects';
import {
findMatchingProjects,
parseStringPattern,
} from 'nx/src/utils/find-matching-projects';

export function executeModuleFederationDevServerBuilder(
schema: Schema,
Expand Down Expand Up @@ -48,9 +56,24 @@ export function executeModuleFederationDevServerBuilder(

validateDevRemotes(options, workspaceProjects);

const patternMatchedRemotesToSkip = new Set(
findMatchingProjects(options.skipRemotes, projectGraph.nodes)
);
const remotesNotInGraph = options.skipRemotes.filter((r) => {
const { exclude, type } = parseStringPattern(r, projectGraph.nodes);
return exclude === false && type === 'unlabeled';
});
const remotesToSkip = new Set(
findMatchingProjects(options.skipRemotes, projectGraph.nodes) ?? []
[...patternMatchedRemotesToSkip, ...remotesNotInGraph] ?? []
);

if (remotesToSkip.size > 0) {
logger.info(
`Not automatically serving remotes: ${[...remotesToSkip.values()].join(
', '
)}`
);
}
const staticRemotes = getStaticRemotes(
project,
context,
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/utils/find-matching-projects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
findMatchingProjects,
getMatchingStringsWithCache,
} from './find-matching-projects';
import minimatch = require('minimatch');
import type { ProjectGraphProjectNode } from '../config/project-graph';
import minimatch = require('minimatch');

describe('findMatchingProjects', () => {
let projectGraph: Record<string, ProjectGraphProjectNode> = {
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/utils/find-matching-projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function addMatchingProjectsByTag(
}
}

function parseStringPattern(
export function parseStringPattern(
pattern: string,
projects: Record<string, ProjectGraphProjectNode>
): ProjectPattern {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {
} from '@nx/devkit/src/utils/async-iterable';
import * as chalk from 'chalk';
import { waitForPortOpen } from '@nx/web/src/utils/wait-for-port-open';
import { findMatchingProjects } from 'nx/src/utils/find-matching-projects';
import {
findMatchingProjects,
parseStringPattern,
} from 'nx/src/utils/find-matching-projects';
import { fork } from 'child_process';

type ModuleFederationDevServerOptions = WebDevServerOptions & {
Expand Down Expand Up @@ -38,9 +41,24 @@ export default async function* moduleFederationDevServer(
);
}

const patternMatchedRemotesToSkip = new Set(
findMatchingProjects(options.skipRemotes, context.projectGraph.nodes)
);
const remotesNotInGraph = options.skipRemotes.filter((r) => {
const { exclude, type } = parseStringPattern(r, context.projectGraph.nodes);
return exclude === false && type === 'unlabeled';
});
const remotesToSkip = new Set(
findMatchingProjects(options.skipRemotes ?? [], context.projectGraph.nodes)
[...patternMatchedRemotesToSkip, ...remotesNotInGraph] ?? []
);

if (remotesToSkip.size > 0) {
logger.info(
`Not automatically serving remotes: ${[...remotesToSkip.values()].join(
', '
)}`
);
}
const knownRemotes = (moduleFederationConfig.remotes ?? []).filter((r) => {
const validRemote = Array.isArray(r) ? r[0] : r;
return !remotesToSkip.has(validRemote);
Expand Down

0 comments on commit c17e256

Please sign in to comment.