Skip to content

Commit

Permalink
fix(core): fix plugin exclude option
Browse files Browse the repository at this point in the history
Closes #22737
  • Loading branch information
yjaaidi committed Apr 9, 2024
1 parent 32144bb commit 6fa09fe
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
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 { CreateNodes, NxPluginV2 } from 'nx/src/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) =>
minimatch(file, excludedPattern, { dot: true })
);
if (excluded) {
Expand Down

0 comments on commit 6fa09fe

Please sign in to comment.