Skip to content

Commit

Permalink
fix: correct async cycle and provide good_enough fixture for test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mila Votradovec committed Aug 9, 2018
1 parent 3cf3bbe commit 69290b1
Show file tree
Hide file tree
Showing 4 changed files with 4,937 additions and 20 deletions.
23 changes: 9 additions & 14 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default function parseLockFile(root, targetFilePath, lockFilePath, option
throw new Error(`LockFile package-lock.json not found at location: ${lockFileFullPath}`);
}

const targetFile = fs.readFileSync(targetFilePath);
const lockFile = fs.readFileSync(lockFilePath);
const targetFile = fs.readFileSync(targetFileFullPath);
const lockFile = fs.readFileSync(lockFileFullPath);

return buildDepTree(targetFile, lockFile, options);
}
Expand All @@ -46,9 +46,9 @@ async function buildDepTree(targetFileRaw, lockFileRaw, options) {
const fullDepList = lockFile.dependencies;
const topLevelDeps = Object.keys(targetFile.dependencies);

for (const dep of topLevelDeps) {
await Promise.all(topLevelDeps.map(async (dep) => {
depTree.dependencies[dep] = await buildSubTreeRecursive(dep, []);
}
}));

return depTree;

Expand All @@ -71,16 +71,11 @@ async function buildDepTree(targetFileRaw, lockFileRaw, options) {
// update the tree
depSubTree.version = deps[dep].version;
// repeat the process for dependencies of looked-up dep
if (deps[dep].requires) {
Object.keys(deps[dep].requires).forEach(async (subDep) => {
depSubTree.dependencies[subDep] = await buildSubTreeRecursive(subDep, [...depKeys, subDep]);

});
return depSubTree;
} else {
// no more deps, return tree
return depSubTree;
}
const newDeps = deps[dep].requires && Object.keys(deps[dep].requires) || [];
await Promise.all(newDeps.map(async (subDep) => {
depSubTree.dependencies[subDep] = await buildSubTreeRecursive(subDep, [...depKeys, dep]);
}));
return depSubTree;
} else {
// tree was walked to the root and dependency was not found
if (!depKeys.length) {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"devDependencies": {
"@types/node": "10.5.5",
"@types/sinon": "5.0.1",
"semantic-release": "^8.2.0",
"sinon": "6.1.4",
"source-map-support": "^0.5.6",
"tap": "github:snyk/node-tap#alternative-runtimes",
Expand Down
Loading

0 comments on commit 69290b1

Please sign in to comment.