Skip to content

Clean up Utils#150

Draft
moonglum wants to merge 1 commit into
mainfrom
util-cleanup
Draft

Clean up Utils#150
moonglum wants to merge 1 commit into
mainfrom
util-cleanup

Conversation

@moonglum

@moonglum moonglum commented Mar 9, 2025

Copy link
Copy Markdown
Member

Clean up utils

Looking into static, I noticed that we use the utils less than I thought.

  • FileFinder is removed - note this is also done in removed support for faucet-pipeline-static and FileFinder #166
  • resolvePath is moved into util/index.js (this is a breaking change for aiur, but aiur will depend on 3 anyway)
  • 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

This is a breaking change.

Comment thread test/test_plugins.js Outdated
bucket: "static",
plugin: "faucet-pipeline-static"
},
assets: {

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Contributor

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...

@FND FND left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread lib/manager.js
}

// exported for testing
exports.generateFingerprint = generateFingerprint;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
exports.generateFingerprint = generateFingerprint;
exports._generateFingerprint = generateFingerprint;

That makes it explicit; cf. _determinePlugins.

Comment thread lib/manager.js

function generateFingerprint(filepath, data) {
let filename = path.basename(filepath);
let ext = filename.indexOf(".") === -1 ? "" : "." + filename.split(".").pop();

Copy link
Copy Markdown
Contributor

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.)

Comment thread lib/manager.js
exports.generateFingerprint = generateFingerprint;

function generateHash(str) {
let hash = crypto.createHash("md5");

Copy link
Copy Markdown
Contributor

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.

JavaScript hashing speed comparison: MD5 versus SHA-256

Comment thread lib/util/index.js
Comment on lines +3 to 4
let fs = require("fs");
let path = require("path");

Copy link
Copy Markdown
Contributor

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:

Suggested change
let fs = require("fs");
let path = require("path");
let fs = require("node:fs");
let path = require("node:path");

Comment thread lib/util/index.js
let crypto = require("crypto");

exports.abort = abort;
exports.repr = repr;

Copy link
Copy Markdown
Contributor

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. 🤷

Comment thread test/test_plugins.js Outdated
bucket: "static",
plugin: "faucet-pipeline-static"
},
assets: {

Copy link
Copy Markdown
Contributor

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...

@moonglum

Copy link
Copy Markdown
Member Author

Thanks for the feedback! I plan to incorporate that this week.

I worked on two things we discussed in a chat:

  1. I removed browserslist. The setup is really weird: We determine the browsers in core, and pass them to the plugin. But most of the handling is done by the plugin anyway. This doesn't make a lot of sense to me. I created this PR for faucet-pipeline-sass to show how I think it should work instead. This change in -sass, -css and -js would make it dual-compatible with 2.x and 3.x. See Implement browserslist handling outside of core faucet-pipeline-sass#210
  2. I made nite-owl optional. I would like to take that opportunity to rename it to faucet-pipeline-watch (or -watcher), as that is what nite-owl really is. That makes it more consistent with other additional libraries you need to install.

@FND FND mentioned this pull request Oct 29, 2025
@moonglum moonglum changed the title v3.1.0 v4.0.0 Oct 31, 2025
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
@moonglum moonglum changed the title v4.0.0 Clean up Utils Nov 2, 2025
@moonglum
moonglum changed the base branch from main to main-revised November 2, 2025 11:15
@moonglum

moonglum commented Nov 2, 2025

Copy link
Copy Markdown
Member Author

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.

@moonglum
moonglum changed the base branch from main-revised to main November 3, 2025 12:14
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.

2 participants