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

Provide output content Hash #3293

Closed
Inqnuam opened this issue Aug 6, 2023 · 7 comments
Closed

Provide output content Hash #3293

Inqnuam opened this issue Aug 6, 2023 · 7 comments
Labels

Comments

@Inqnuam
Copy link

Inqnuam commented Aug 6, 2023

Could you please provide output content Hash in metafile?
This will allow us to avoid computing it again as I guess you already compute it during bundle process

@evanw
Copy link
Owner

evanw commented Aug 6, 2023

Why do you want this? What are you using it for?

@evanw evanw added the metafile label Aug 6, 2023
@Inqnuam
Copy link
Author

Inqnuam commented Aug 6, 2023

There's at least 2 use cases where I compute the hash manually

  • during local dev when I need to notify the browser which file (css, js) to update, currently my script is based on files modified date, but with the hash I can avoid this additional action
  • the second one is more important when we have query string based cache system instead of file path.
    Using entryNames: "[dir]/[name]-[hash]" produces different file names. Uploading theses new files to a remote server we also have to remove previously generated files as they will never be used again

@evanw
Copy link
Owner

evanw commented Aug 6, 2023

Thank you for your reply. I'm asking because there are different kinds of hashes for different uses. The two uses you mentioned use different hashes.

  • A few other people have also requested the ability to detect which files have changed (how to get changed file info on watch mode #1369, The onRebuild hook didn't pass the meta of changed files #2700, Feature request: Entry point should contain information whether it has changed #3084). I think it could make sense to expose esbuild's internal output file content hash to make this use case more convenient (which is what you're proposing here). This doesn't make anything possible that wasn't possible before because you could always have calculated one yourself, but it could make it easier to write little build scripts without external dependencies. However, I think it makes more sense to add it to the output file objects themselves instead of to the metafile since that's where the data that is being hashed lives.

  • The hash in the output file name is not a content hash, although it is often mistaken as one. So exposing this hash would likely introduce a lot of confusion. The hash includes a lot of things including all of the referenced dependencies of that output file and even sometimes the content of any related source maps. This is because the file name of the source map is equal to the JS/CSS file name with .map appended to it, so if the source map changes then the source map's hash must change, so the JS/CSS file's name must change too. The hash is also calculated in a roundabout way because of how esbuild assembles the output file in parallel from various pieces of source code so it's not any particular hashing algorithm (just "whatever esbuild happens to do"). I don't think it makes sense to expose this particular hash outside of the file name. I'm not exactly sure what you'd be using the hash for in your example with server uploads, but I'd recommend saving the file names from the previous build so you know what files to remove from the server.

@Inqnuam
Copy link
Author

Inqnuam commented Aug 8, 2023

Thanks for the release which now includes hash inside outputFiles.

However outputFiles being available only with write:false option I don't know how can i get the hashes when I want to delegate esbuild to write contents to filesystem, any suggestion?

@arthurmelobh
Copy link

@Inqnuam have you figured out how to do that? I also need the hash and wanted to delegate esbuild to write

@Inqnuam
Copy link
Author

Inqnuam commented Sep 26, 2023

Hello @arthurmelobh,
Unfortunately I don't use this hash feature as I can not get it without write: false

@arthurmelobh
Copy link

@Inqnuam I've figured out that if you use metafile: true the build result contains information about the output files, including the names with the hashes

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

No branches or pull requests

3 participants