Skip to content

Commit

Permalink
chore(core): refactor implicit dependencies code (#18825)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored Sep 1, 2023
1 parent ed6d7f7 commit 83ebf0f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 29 deletions.
1 change: 0 additions & 1 deletion packages/nx/src/project-graph/build-dependencies/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/nx/src/project-graph/build-project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
shouldRecomputeWholeGraph,
writeCache,
} from './nx-deps-cache';
import { buildImplicitProjectDependencies } from './build-dependencies';
import { applyImplicitDependencies } from './utils/implicit-project-dependencies';
import { normalizeProjectNodes } from './utils/normalize-project-nodes';
import { isNxPluginV1, isNxPluginV2, loadNxPlugins } from '../utils/nx-plugin';
import { getRootTsConfigPath } from '../plugins/js/utils/typescript';
Expand Down Expand Up @@ -167,7 +167,7 @@ async function buildProjectGraphUsingContext(
}
}

buildImplicitProjectDependencies(ctx, updatedBuilder);
applyImplicitDependencies(ctx.projectsConfigurations, updatedBuilder);

const finalGraph = updatedBuilder.getUpdatedProjectGraph();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ProjectGraphProcessorContext } from '../../config/project-graph';
import { ProjectGraphBuilder } from '../project-graph-builder';
import { buildImplicitProjectDependencies } from './implicit-project-dependencies';
import { applyImplicitDependencies } from './implicit-project-dependencies';

jest.mock('fs', () => {
const memFs = require('memfs').fs;
Expand All @@ -13,7 +12,7 @@ jest.mock('nx/src/utils/workspace-root', () => ({
workspaceRoot: '/root',
}));

describe('explicit project dependencies', () => {
describe('implicit project dependencies', () => {
it(`should add implicit deps`, () => {
const builder = new ProjectGraphBuilder();
builder.addNode({
Expand All @@ -25,17 +24,13 @@ describe('explicit project dependencies', () => {
data: {},
} as any);

buildImplicitProjectDependencies(
applyImplicitDependencies(
{
filesToProcess: {},
fileMap: {},
projectsConfigurations: {
version: 2,
projects: {
proj1: { root: '', implicitDependencies: ['proj2'] },
},
version: 2,
projects: {
proj1: { root: '', implicitDependencies: ['proj2'] },
},
} as Partial<ProjectGraphProcessorContext> as ProjectGraphProcessorContext,
},
builder
);

Expand All @@ -60,17 +55,13 @@ describe('explicit project dependencies', () => {
} as any);
builder.addImplicitDependency('proj1', 'proj2');

buildImplicitProjectDependencies(
applyImplicitDependencies(
{
filesToProcess: {},
fileMap: {},
projectsConfigurations: {
version: 2,
projects: {
proj1: { root: '', implicitDependencies: ['!proj2'] },
},
version: 2,
projects: {
proj1: { root: '', implicitDependencies: ['!proj2'] },
},
} as Partial<ProjectGraphProcessorContext> as ProjectGraphProcessorContext,
},
builder
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ProjectGraphProcessorContext } from '../../config/project-graph';
import { ProjectsConfigurations } from '../../config/workspace-json-project-json';
import { ProjectGraphBuilder } from '../project-graph-builder';

export function buildImplicitProjectDependencies(
ctx: ProjectGraphProcessorContext,
export function applyImplicitDependencies(
projectsConfigurations: ProjectsConfigurations,
builder: ProjectGraphBuilder
) {
Object.keys(ctx.projectsConfigurations.projects).forEach((source) => {
const p = ctx.projectsConfigurations.projects[source];
Object.keys(projectsConfigurations.projects).forEach((source) => {
const p = projectsConfigurations.projects[source];
if (p.implicitDependencies && p.implicitDependencies.length > 0) {
p.implicitDependencies.forEach((target) => {
if (target.startsWith('!')) {
Expand Down

0 comments on commit 83ebf0f

Please sign in to comment.