Skip to content

Commit

Permalink
Publish runtime and runtime-corejs2 when helpers are changed
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Dec 21, 2018
1 parent 49861d3 commit ef2f1fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
3 changes: 3 additions & 0 deletions collect-updates.js
Expand Up @@ -68,6 +68,9 @@ function collectUpdates(filteredPackages, packageGraph, execOpts, commandOptions
});
}

const dependents = collectDependents(candidates);
dependents.forEach(node => candidates.add(node));

// The result should always be in the same order as the input
const updates = [];

Expand Down
36 changes: 12 additions & 24 deletions lib/collect-dependents.js
Expand Up @@ -2,35 +2,23 @@

module.exports = collectDependents;

const has = Function.call.bind(Object.hasOwnProperty);

const forceDirectDependentUpdate = {
"@babel/helpers": ["@babel/runtime", "@babel/runtime-corejs2"]
};

function collectDependents(nodes) {
const collected = new Set();

nodes.forEach(currentNode => {
if (currentNode.localDependents.size === 0) {
// no point diving into a non-existent tree
return;
}

// depth-first search
const seen = new Set();
const visit = (dependentNode, dependentName, siblingDependents) => {
if (seen.has(dependentNode)) {
return;
}

seen.add(dependentNode);
if (has(forceDirectDependentUpdate, currentNode.name)) {
const forced = forceDirectDependentUpdate[currentNode.name];

if (dependentNode === currentNode || siblingDependents.has(currentNode.name)) {
// a direct or transitive cycle, skip it
return;
}

collected.add(dependentNode);

dependentNode.localDependents.forEach(visit);
};

currentNode.localDependents.forEach(visit);
currentNode.localDependents.forEach((dependentNode, dependentName) => {
if (forced.includes(dependentName)) collected.add(dependentNode);
});
}
});

return collected;
Expand Down

0 comments on commit ef2f1fc

Please sign in to comment.