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(core): fix plugin exclude option #22738

Merged
merged 2 commits into from
Apr 9, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {
} from '../../config/workspace-json-project-json';
import {
ConfigurationSourceMaps,
createProjectConfigurations,
isCompatibleTarget,
mergeProjectConfigurationIntoRootMap,
mergeTargetConfigurations,
readProjectConfigurationsFromRootMap,
readTargetDefaultsForTarget,
} from './project-configuration-utils';
import { NxPluginV2 } from '../../utils/nx-plugin';

describe('project-configuration-utils', () => {
describe('target merging', () => {
Expand Down Expand Up @@ -1525,6 +1527,98 @@ describe('project-configuration-utils', () => {
).toBe(false);
});
});

describe('createProjectConfigurations', () => {
/* A fake plugin that sets `fake-lib` tag to libs. */
const fakeTagPlugin: NxPluginV2 = {
name: 'fake-tag-plugin',
createNodes: [
'libs/*/project.json',
(vitestConfigPath) => {
const [_libs, name, _config] = vitestConfigPath.split('/');
return {
projects: {
[name]: {
name: name,
root: `libs/${name}`,
tags: ['fake-lib'],
},
},
};
},
],
};

it('should create nodes for files matching included patterns only', async () => {
const projectConfigurations = await createProjectConfigurations(
undefined,
{},
['libs/a/project.json', 'libs/b/project.json'],
[
{
plugin: fakeTagPlugin,
},
]
);

expect(projectConfigurations.projects).toEqual({
a: {
name: 'a',
root: 'libs/a',
tags: ['fake-lib'],
},
b: {
name: 'b',
root: 'libs/b',
tags: ['fake-lib'],
},
});
});

it('should create nodes for files matching included patterns only', async () => {
const projectConfigurations = await createProjectConfigurations(
undefined,
{},
['libs/a/project.json', 'libs/b/project.json'],
[
{
plugin: fakeTagPlugin,
include: ['libs/a/**'],
},
]
);

expect(projectConfigurations.projects).toEqual({
a: {
name: 'a',
root: 'libs/a',
tags: ['fake-lib'],
},
});
});

it('should not create nodes for files matching excluded patterns', async () => {
const projectConfigurations = await createProjectConfigurations(
undefined,
{},
['libs/a/project.json', 'libs/b/project.json'],
[
{
plugin: fakeTagPlugin,
exclude: ['libs/b/**'],
},
]
);

expect(projectConfigurations.projects).toEqual({
a: {
name: 'a',
root: 'libs/a',
tags: ['fake-lib'],
},
});
});
});
});

class RootMapBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export function createProjectConfigurations(
}

if (exclude) {
const excluded = include.some((excludedPattern) =>
const excluded = exclude.some((excludedPattern) =>
yjaaidi marked this conversation as resolved.
Show resolved Hide resolved
minimatch(file, excludedPattern, { dot: true })
);
if (excluded) {
Expand Down