Skip to content

Commit

Permalink
feat(core): add implicitDependencies: '*'
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Nov 11, 2022
1 parent c18ec6c commit e49243d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ProjectConfiguration } from 'nx/src/config/workspace-json-project-json';
import { normalizeImplicitDependencies } from './workspace-projects';

describe('workspace-projects', () => {
describe('normalizeImplicitDependencies', () => {
it('should expand "*" implicit dependencies', () => {
expect(
normalizeImplicitDependencies('test-project', ['*'], {
fileMap: {},
filesToProcess: {},
workspace: {
version: 2,
projects: {
...makeProject('test-project'),
...makeProject('a'),
...makeProject('b'),
...makeProject('c'),
},
},
})
).toEqual(['a', 'b', 'c']);
});
});
});

function makeProject(name: string): Record<string, ProjectConfiguration> {
return {
[name]: {
root: `packages/${name}`,
},
};
}
32 changes: 27 additions & 5 deletions packages/nx/src/project-graph/build-nodes/workspace-projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import { ProjectGraphBuilder } from '../project-graph-builder';
import { PackageJson } from 'nx/src/utils/package-json';
import { readJsonFile } from 'nx/src/utils/fileutils';
import { NxJsonConfiguration } from 'nx/src/config/nx-json';
import { TargetConfiguration } from 'nx/src/config/workspace-json-project-json';
import {
ProjectConfiguration,
TargetConfiguration,
} from 'nx/src/config/workspace-json-project-json';

export function buildWorkspaceProjectNodes(
ctx: ProjectGraphProcessorContext,
Expand All @@ -22,6 +25,7 @@ export function buildWorkspaceProjectNodes(
Object.keys(ctx.workspace.projects).forEach((key) => {
const p = ctx.workspace.projects[key];
const projectRoot = join(workspaceRoot, p.root);

if (existsSync(join(projectRoot, 'package.json'))) {
p.targets = mergeNpmScriptsWithTargets(projectRoot, p.targets);

Expand All @@ -42,6 +46,12 @@ export function buildWorkspaceProjectNodes(
}
}

p.implicitDependencies = normalizeImplicitDependencies(
key,
p.implicitDependencies,
ctx
);

p.targets = mergeNxDefaultTargetsWithNxTargets(
p.targets,
nxJson.targetDefaults
Expand All @@ -59,10 +69,7 @@ export function buildWorkspaceProjectNodes(
? 'e2e'
: 'app'
: 'lib';
const tags =
ctx.workspace.projects && ctx.workspace.projects[key]
? ctx.workspace.projects[key].tags || []
: [];
const tags = ctx.workspace.projects?.[key]?.tags || [];

toAdd.push({
name: key,
Expand Down Expand Up @@ -112,3 +119,18 @@ function mergeNxDefaultTargetsWithNxTargets(
}
return targets;
}

export function normalizeImplicitDependencies(
source: string,
implicitDependencies: ProjectConfiguration['implicitDependencies'],
context: ProjectGraphProcessorContext
) {
return implicitDependencies?.flatMap((target) => {
if (target === '*') {
return Object.keys(context.workspace.projects).filter(
(projectName) => projectName !== source
);
}
return target;
});
}
18 changes: 9 additions & 9 deletions packages/nx/src/project-graph/build-project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { getRootTsConfigPath } from '../utils/typescript';
import {
ProjectFileMap,
ProjectGraph,
ProjectGraphExternalNode,
ProjectGraphProcessorContext,
} from '../config/project-graph';
import { readJsonFile } from '../utils/fileutils';
Expand Down Expand Up @@ -415,14 +414,15 @@ function createContext(
fileMap: ProjectFileMap,
filesToProcess: ProjectFileMap
): ProjectGraphProcessorContext {
const projects: Record<string, ProjectConfiguration> = Object.keys(
projectsConfigurations.projects
).reduce((map, projectName) => {
map[projectName] = {
...projectsConfigurations.projects[projectName],
};
return map;
}, {});
const projects = Object.keys(projectsConfigurations.projects).reduce(
(map, projectName) => {
map[projectName] = {
...projectsConfigurations.projects[projectName],
};
return map;
},
{} as Record<string, ProjectConfiguration>
);
return {
workspace: {
...projectsConfigurations,
Expand Down

0 comments on commit e49243d

Please sign in to comment.