Skip to content

Commit

Permalink
fix(core): additional null check when hashing lockfile (#13803)
Browse files Browse the repository at this point in the history
Fixes #13776
Fixes #13777
  • Loading branch information
AgentEnder committed Dec 14, 2022
1 parent 2883f17 commit efa6ef0
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions packages/nx/src/lock-file/utils/hashing.ts
Expand Up @@ -34,29 +34,39 @@ function hashExternalNode(node: ProjectGraphExternalNode, graph: ProjectGraph) {
if (!graph.dependencies[node.name]) {
node.data.hash = hashString(hashKey);
} else {
const hashingInput = [hashKey];

// collect all dependencies' hashes
traverseExternalNodesDependencies(node.name, graph, hashingInput);
node.data.hash = defaultHashing.hashArray(hashingInput.sort());
const externalDependencies = traverseExternalNodesDependencies(
node.name,
graph,
new Set([hashKey])
);
node.data.hash = defaultHashing.hashArray(
Array.from(externalDependencies).sort()
);
}
}

function traverseExternalNodesDependencies(
projectName: string,
graph: ProjectGraph,
visited: string[]
) {
visited: Set<string>
): Set<string> {
graph.dependencies[projectName].forEach((d) => {
const target = graph.externalNodes[d.target];
if (!target) {
return;
}

const targetKey = `${target.data.packageName}@${target.data.version}`;
if (visited.indexOf(targetKey) === -1) {
visited.push(targetKey);

if (!visited.has(targetKey)) {
visited.add(targetKey);
if (graph.dependencies[d.target]) {
traverseExternalNodesDependencies(d.target, graph, visited);
}
}
});
return visited;
}

/**
Expand Down

1 comment on commit efa6ef0

@vercel
Copy link

@vercel vercel bot commented on efa6ef0 Dec 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx.dev
nx-dev-nrwl.vercel.app

Please sign in to comment.