- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2
 
Clean up Utils #150
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
base: main
Are you sure you want to change the base?
Clean up Utils #150
Conversation
        
          
                test/test_plugins.js
              
                Outdated
          
        
      | bucket: "static", | ||
| plugin: "faucet-pipeline-static" | ||
| }, | ||
| assets: { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this file is also the place where we would mark the old name as deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not currently sure how exactly we'd do that, especially because plugins can override these defaults? I guess we'll have to put on our hazmat suits and wade into the implementation eventually...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable to me, though I've kinda run out of brainspace for the moment; let's conclude faucet-pipeline/faucet-pipeline-static#71 first.
| } | ||
| 
               | 
          ||
| // exported for testing | ||
| exports.generateFingerprint = generateFingerprint; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| exports.generateFingerprint = generateFingerprint; | |
| exports._generateFingerprint = generateFingerprint; | 
That makes it explicit; cf. _determinePlugins.
| 
               | 
          ||
| function generateFingerprint(filepath, data) { | ||
| let filename = path.basename(filepath); | ||
| let ext = filename.indexOf(".") === -1 ? "" : "." + filename.split(".").pop(); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we not using path.extname here? (See potentially related discussion for faucet-static/static-images.)
(Though we might reasonably opt not to risk changing the implementation here, due to backwards-compatibility concerns.)
| exports.generateFingerprint = generateFingerprint; | ||
| 
               | 
          ||
| function generateHash(str) { | ||
| let hash = crypto.createHash("md5"); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we perhaps change this to SHA-256? I realize that might be a backwards-compatibility concern though...
My results suggest that you should probably not be using MD5. MD5 is slower than SHA-256 and not as safe.
| let fs = require("fs"); | ||
| let path = require("path"); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well do this while we're at it:
| let fs = require("fs"); | |
| let path = require("path"); | |
| let fs = require("node:fs"); | |
| let path = require("node:path"); | 
| let crypto = require("crypto"); | ||
| 
               | 
          ||
| exports.abort = abort; | ||
| exports.repr = repr; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I had intentionally moved exports to the top (yay hoisting) so you don't have to go searching for them in the middle of random implementation details. 🤷
        
          
                test/test_plugins.js
              
                Outdated
          
        
      | bucket: "static", | ||
| plugin: "faucet-pipeline-static" | ||
| }, | ||
| assets: { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not currently sure how exactly we'd do that, especially because plugins can override these defaults? I guess we'll have to put on our hazmat suits and wade into the implementation eventually...
| 
           Thanks for the feedback! I plan to incorporate that this week. I worked on two things we discussed in a chat: 
  | 
    
This is a breaking change. * FileFinder is removed (pending based on the static/images work) * resolvePath is moved into util/index.js (this is a breaking change for aiur) * generateFingerprint is moved into lib/manager.js as it is the only place where it is used (the test is moved accordingly) * SerializedRunner is moved to lib, as it is only used in core
3bf9b98    to
    1174e8a      
    Compare
  
    | 
           I rebased this branch on main-revised, and pulled out the parts into separate PRs to make it easier to discuss. This is the "all the other stuff" PR. I don't think it makes sense in its current form - it is more a reminder for things to look at a bit later.  | 
    
Clean up utils
Looking into static, I noticed that we use the
utilsless than I thought.This is a breaking change.