Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse lockfile recursively #5

Merged
merged 9 commits into from
Aug 9, 2018
Merged

Conversation

miiila
Copy link
Contributor

@miiila miiila commented Aug 3, 2018

  • 💥 Tests written and linted ℹ︎
  • Documentation written ℹ︎
  • Commit history is tidy ℹ︎

What this does

Introduces a recursive algorithm for creation of dependency tree from package-lock.json and package.json.

Notes for the reviewer

I did my best to comment the algorithm, but feel free to suggest any naming or other structural improvements.

More information

@miiila miiila self-assigned this Aug 3, 2018
@miiila miiila requested a review from lili2311 August 3, 2018 12:10
lib/index.ts Outdated
return depSubTree;
} else {
// no more deps, return tree
return depSubTree;
Copy link
Contributor

Choose a reason for hiding this comment

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

don't think you need an else here since you return in the statement above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, I'll move return to the separate statement.

lib/index.ts Outdated
} else {
// tree was walked to the root and dependency was not found
if (!depKeys.length) {
throw new Error(`Dependency ${dep} was not found in package-lock.json.`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this message more verbose and let the user know that it looks like their package.json and their lockfile are out of sync and give them some advice how to sync them up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will try :-)

lib/index.ts Outdated
if (deps[dep].requires) {
Object.keys(deps[dep].requires).forEach(async (subDep) => {
depSubTree.dependencies[subDep] = await buildSubTreeRecursive(subDep, [...depKeys, subDep]);

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you run the linter on this, looks like they might be some linting fixes to add.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tslint doesn't complain.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hah strange!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't complain :-D It does now.

package.json Outdated
@@ -25,11 +25,12 @@
"devDependencies": {
"@types/node": "10.5.5",
"@types/sinon": "5.0.1",
"semantic-release": "^8.2.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove :)

@miiila miiila force-pushed the feat/parse-lockfile-recursively branch 2 times, most recently from c1b2b33 to df0a59e Compare August 3, 2018 17:44
@miiila miiila requested a review from darscan August 3, 2018 17:45
@miiila miiila dismissed lili2311’s stale review August 3, 2018 17:45

All comments addressed, thank you for them.

@miiila miiila force-pushed the feat/parse-lockfile-recursively branch from df0a59e to 3181788 Compare August 9, 2018 10:54
@miiila miiila force-pushed the feat/parse-lockfile-recursively branch from 3181788 to 69290b1 Compare August 9, 2018 11:01
@miiila miiila force-pushed the feat/parse-lockfile-recursively branch from f10b991 to e48b713 Compare August 9, 2018 15:26
bin/index.js Outdated
.then((tree) => {
console.log(JSON.stringify(tree));
})
.catch((e) => {
Copy link

Choose a reason for hiding this comment

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

.catch(console.error); might be better here

package.json Outdated
@@ -2,6 +2,9 @@
"name": "snyk-nodejs-lockfile-parser",
"description": "Generate a dep tree given a lockfile",
"main": "dist/lib/index.js",
"bin": {
"parse": "./bin/index.js"
Copy link

Choose a reason for hiding this comment

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

I think "parse" is probably too generic for a bin that will be installed globally

Copy link

Choose a reason for hiding this comment

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

Not sure what a better name might be.. maybe "parse-npm-lockfile"??

lib/index.ts Outdated
if (!root || !lockFilePath || !lockFilePath) {
throw new Error('Missing required parameters for parseLockFile()');
}
// TODO: validate only valid options were passed in
Copy link

Choose a reason for hiding this comment

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

I might drop this TODO.. just noise

@miiila miiila force-pushed the feat/parse-lockfile-recursively branch from 2eb170c to c04aeee Compare August 9, 2018 15:50
@miiila miiila merged commit 5ae268f into master Aug 9, 2018
@miiila miiila deleted the feat/parse-lockfile-recursively branch August 9, 2018 16:07
@snyksec
Copy link

snyksec commented Aug 9, 2018

🎉 This PR is included in version 1.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants