Skip to content

Merge mozilla/dispensary into this project#4006

Merged
willdurand merged 9 commits intomasterfrom
merge-dispensary
Nov 9, 2021
Merged

Merge mozilla/dispensary into this project#4006
willdurand merged 9 commits intomasterfrom
merge-dispensary

Conversation

@willdurand
Copy link
Member

@willdurand willdurand commented Nov 1, 2021

Fixes #869
Closes mozilla/dispensary#864
Closes #3601


First commit: This is an almost 1:1 import of mozilla/dispensary, with tests, docs and the CLI (scripts/dispensary). Except one test case in dispensary/test.index.js (for the cached libraries, rewritten using async/await and jest spyOn), only Prettier has been applied and paths have been adjusted. There is no other code change.

Second commit: Split the logic of the dispensary so that we have a "runtime" piece for addons-linter and another piece (updater) to update the dispensary hashes using scripts/dispensary.

Third commit: Simplify the dispensary updater to only do one thing: compute the hashes for the libraries in the json file, and output that to stdout.

Fourth commit: Removes request dep, replaced by node-fetch.

Fifth commit: Improves test coverage. Should be good now.

Last commit: add npm script to update the hashes.txt file

@codecov
Copy link

codecov bot commented Nov 1, 2021

Codecov Report

Merging #4006 (17713d8) into master (05a2c14) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4006      +/-   ##
==========================================
+ Coverage   98.72%   98.73%   +0.01%     
==========================================
  Files          52       55       +3     
  Lines        2658     2683      +25     
  Branches      802      808       +6     
==========================================
+ Hits         2624     2649      +25     
  Misses         34       34              
Impacted Files Coverage Δ
src/linter.js 99.15% <ø> (ø)
src/dispensary/hasher.js 100.00% <100.00%> (ø)
src/dispensary/index.js 100.00% <100.00%> (ø)
src/dispensary/utils.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 05a2c14...17713d8. Read the comment docs.

@fregante
Copy link
Contributor

fregante commented Nov 1, 2021

On second thought, I think this is great and makes mozilla/dispensary#864 much easier. In fact I think you can just move those dependencies to devDependencies instead and be done. Edit: It looks like _getCachedHashes needs to be extracted too, which I can do separately.

The problem in that issue was how to deal with the change of package type on npm (from generator to data-only). This PR kills the dispensary package on npm so that issue no longer exists.

@willdurand willdurand requested review from rpl and wagnerand November 2, 2021 08:33
@willdurand
Copy link
Member Author

Requesting pre-reviews to answer a few questions:

  • does that approach sound good?
  • do we want to update this patch to reduce its size (e.g., by dropping the command stuff in the Dispensary class)?

@wagnerand
Copy link
Contributor

This looks good to me overall. I'm all for simplifying things, the command stuff was a bit hard to read if you aren't familiar with the code. Let's also try and keep this low effort.

@willdurand
Copy link
Member Author

This looks good to me overall. I'm all for simplifying things, the command stuff was a bit hard to read if you aren't familiar with the code. Let's also try and keep this low effort.

Thanks. Yeah, I am not sure we need to keep the existing CLI stuff. We might not even need yargs. We could just have a Updater class or something that reads the libraries.json and updates hashes.txt. This would be called by the new script and nothing more. This would allow us to move most of the dependencies as dev deps too.

@willdurand
Copy link
Member Author

On second thought, I think this is great and makes mozilla/dispensary#864 much easier. In fact I think you can just move those dependencies to devDependencies instead and be done. Edit: It looks like _getCachedHashes needs to be extracted too, which I can do separately.

The problem in that issue was how to deal with the change of package type on npm (from generator to data-only). This PR kills the dispensary package on npm so that issue no longer exists.

The second commit should do what you're describing here.

@willdurand willdurand force-pushed the merge-dispensary branch 2 times, most recently from 0591c80 to c0a2f9a Compare November 2, 2021 13:08
@wagnerand
Copy link
Contributor

wagnerand commented Nov 2, 2021

This looks good to me overall. I'm all for simplifying things, the command stuff was a bit hard to read if you aren't familiar with the code. Let's also try and keep this low effort.

Thanks. Yeah, I am not sure we need to keep the existing CLI stuff. We might not even need yargs. We could just have a Updater class or something that reads the libraries.json and updates hashes.txt. This would be called by the new script and nothing more. This would allow us to move most of the dependencies as dev deps too.

Ah I see, that makes sense to me. There are only two commands, of which the update one is the most important, I think I never used the output one. Also, I don't recall ever using one of the arguments.

Copy link
Contributor

@fregante fregante left a comment

Choose a reason for hiding this comment

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

The second commit should do what you're describing here.

Yessss, LGTM. If merged, it would close:

@willdurand
Copy link
Member Author

The third commit simplifies the dispensary "updater".

@willdurand
Copy link
Member Author

The diff coverage is 95.77%.

I can probably write some more tests to reach 100%.

@willdurand willdurand marked this pull request as ready for review November 2, 2021 17:13
@willdurand
Copy link
Member Author

willdurand commented Nov 2, 2021

@wagnerand @rpl this is now ready for a review. Each commit should be self-contained, which should help understand which changes have been made (the first one being almost 1:1 as mentioned in the PR description). The subsequent changes were actually useful to reduce the overall diff.

Copy link
Contributor

@wagnerand wagnerand left a comment

Choose a reason for hiding this comment

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

Looks great to me overall, got a few questions here and there.

Great job! 👏 🏆

@willdurand willdurand force-pushed the merge-dispensary branch 2 times, most recently from 85bedb0 to eab90bb Compare November 3, 2021 12:37
@willdurand
Copy link
Member Author

(rebased)

Copy link
Member

@rpl rpl left a comment

Choose a reason for hiding this comment

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

@willdurand Thank you so much for having looked into this, I'm looking forward to the reductions of the node_modules/ size in web-ext too as a side effect of this changes 🥳

This looks pretty great to me, I do have only two small changes to request described below (the one related to the list of urls in the README does not really matter that much, the other two are the ones I mainly care about, they should both require only some small tweaks to what is already in this PR).

@willdurand willdurand requested a review from rpl November 8, 2021 21:31
@willdurand
Copy link
Member Author

I think I addressed all the comments (correctly). The command continues to work, tests pass, all other checks seem OK too.

r?

Copy link
Member

@rpl rpl left a comment

Choose a reason for hiding this comment

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

Lgtm. Thank you!

@willdurand willdurand merged commit 819adb3 into master Nov 9, 2021
@willdurand willdurand deleted the merge-dispensary branch November 9, 2021 11:10
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.

Reduce dependencies Split updater from data and matcher Move dispensary into the linter

4 participants