Skip to content

refactor Greenwood hashing utils to use crypto.createHash #1534

@thescientist13

Description

@thescientist13

Current State

Currently Greenwood has a bit of an ad-hoc solution for generating hashes for filenames in hashing-utils.js
https://github.com/ProjectEvergreen/greenwood/blob/master/packages/cli/src/lib/hashing-utils.js

But as seen in #1523 this can cause different results across operating systems.

However, NodeJS has had a createHash function available in the standard library for a while which would probably a lot more of a stable option
https://nodejs.org/docs/latest-v18.x/api/crypto.html#cryptocreatehashalgorithm-options
Image

Desired State

The desired state would be to refactor that hashing implementation to use createHash instead.

This may likely break some test cases that are expecting certain hash files for validating bundling took place, so for those test cases, we should probably move to using expect.match with a Regex instead, like we can see here

So instead of hardcoding the filename

expect(scriptContents).to.contain(
  `import r from"/styles/theme.${themeFileHash}.css"with{type:"css"};`,
);

We would use a Regex

expect(scriptContents).to.match(
  /import r from"\/styles\/theme\.([a-zA-Z0-9]{8}.)\.css"with{type:"css"};/,
);

Additional Context

No response

Metadata

Metadata

Assignees

Labels

CLIenhancementImprove something existing (e.g. no docs, new APIs, etc)good first issueGood for newcomers

Type

Projects

Status

👀 In review

Relationships

None yet

Development

No branches or pull requests

Issue actions