Skip to content

Commit

Permalink
fix(core): ensure graph creation keeps dep type in worker mode
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Jul 18, 2023
1 parent cd8c61d commit d2780bd
Showing 1 changed file with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ProjectGraphBuilder } from '../../../../project-graph/project-graph-bui
import { join } from 'path';
import { buildExplicitTypescriptAndPackageJsonDependencies } from './build-explicit-typescript-and-package-json-dependencies';
import * as os from 'os';
import { ExplicitDependency } from './explicit-project-dependencies';

export function buildExplicitDependencies(
jsPluginConfig: {
Expand Down Expand Up @@ -93,6 +94,25 @@ function createWorkerPool(numberOfWorkers: number) {
return res;
}

function addDependency(
builder: ProjectGraphBuilder,
dependency: ExplicitDependency
) {
if (dependency.type === DependencyType.static) {
builder.addStaticDependency(
dependency.sourceProjectName,
dependency.targetProjectName,
dependency.sourceProjectFile
);
} else {
builder.addDynamicDependency(
dependency.sourceProjectName,
dependency.targetProjectName,
dependency.sourceProjectFile
);
}
}

function buildExplicitDependenciesWithoutWorkers(
jsPluginConfig: {
analyzeSourceFiles?: boolean;
Expand All @@ -107,21 +127,7 @@ function buildExplicitDependenciesWithoutWorkers(
ctx.projectsConfigurations,
builder.graph,
ctx.filesToProcess
).forEach((r) => {
if (r.type === DependencyType.static) {
builder.addStaticDependency(
r.sourceProjectName,
r.targetProjectName,
r.sourceProjectFile
);
} else {
builder.addDynamicDependency(
r.sourceProjectName,
r.targetProjectName,
r.sourceProjectFile
);
}
});
).forEach((r) => addDependency(builder, r));
}

function buildExplicitDependenciesUsingWorkers(
Expand All @@ -148,13 +154,7 @@ function buildExplicitDependenciesUsingWorkers(
return new Promise((res, reject) => {
for (let w of workers) {
w.on('message', (explicitDependencies) => {
explicitDependencies.forEach((r) => {
builder.addExplicitDependency(
r.sourceProjectName,
r.sourceProjectFile,
r.targetProjectName
);
});
explicitDependencies.forEach((r) => addDependency(builder, r));
if (bins.length > 0) {
w.postMessage({ filesToProcess: bins.shift() });
}
Expand Down

0 comments on commit d2780bd

Please sign in to comment.