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 8, 2023
1 parent a9f8cc6 commit c5daee1
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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 +51,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) {
console.log(
`Not automatically serving remotes: ${[...remotesToSkip.values()].join(
', '
)}`
);
}
const staticRemotes = getStaticRemotes(
project,
context,
Expand Down
13 changes: 12 additions & 1 deletion packages/nx/src/utils/find-matching-projects.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
findMatchingProjects,
getMatchingStringsWithCache,
parseStringPattern,
} 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 Expand Up @@ -158,6 +159,16 @@ describe('findMatchingProjects', () => {
'nested',
]);
});

it('should do something when pattern is not matched', () => {
expect(parseStringPattern('john', projectGraph)).toMatchInlineSnapshot(`
{
"exclude": false,
"type": "unlabeled",
"value": "john",
}
`);
});
});

const projects = [
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) {
console.log(
`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 c5daee1

Please sign in to comment.