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

Stable names when minifyIdentifiers enabled #1846

Closed
yumauri opened this issue Dec 13, 2021 · 8 comments
Closed

Stable names when minifyIdentifiers enabled #1846

yumauri opened this issue Dec 13, 2021 · 8 comments

Comments

@yumauri
Copy link

yumauri commented Dec 13, 2021

Looks like with option minifyIdentifiers esbuild choose names randomly OR it somehow depends on operating system.

This causes different gzip compression rate for my local machine (macOS) and CI (GitHub action), thus failing build (when using size-limit tool, see this issue).

Is it possible to make short names generation stable over different machines?
Screenshot 2021-12-13 at 12 17 34

@ai
Copy link

ai commented Dec 13, 2021

Random names will also generate different hash on different machines, which could be painful in some environments.

@yumauri
Copy link
Author

yumauri commented Dec 13, 2021

Unfortunately I tried and failed to create minimal reproduce, even on my files... Maybe there are deeper roots, than I thought.
Maybe @evanw will know better, or at least have a notion, why short names could be different after minification.

@evanw
Copy link
Owner

evanw commented Dec 13, 2021

They should be stable assuming the inputs to esbuild are the same. Name generation is intended to be completely deterministic.

One think to know is that to improve gzip compression the identifiers are derived from a character frequency analysis of the input source code, so any difference in input source code between two environments can potentially result in different identifiers, even if the overall structure of the resulting code is the same. So that's one thing to check for (e.g. make sure that plugins aren't the problem).

If you can provide a way to reproduce this and it's a bug in esbuild after all, then I can find a way to fix it.

@yumauri
Copy link
Author

yumauri commented Dec 13, 2021

@evanw Thank you! Issue is exactly this — to test file size with tree-shaking, size-limit generates fake entry point, where imports original file by the full file name. On different environments this path is different, thus causing one small difference in source code.

Not sure if it is bug or no, because when esbuild creates a bundle — there are no any filepathes inside it, so, depending on paths of imported files is a bit strange, what do you think?

@evanw
Copy link
Owner

evanw commented Dec 13, 2021

I would not consider this a bug with esbuild since esbuild only guarantees that the output will be the same if the input is the same. I can try to adjust the character frequencies to avoid this particular case but the only 100% sure way to guarantee the same output is to have the same input.

Note that even when file paths don't appear in the output directly, the relative paths of input files are still included in hash calculations for output file names. One reason is because different files with the same contents must retain separate module identity for correctness (e.g. #928). Another reason is because source maps contain the relative path to the input file and esbuild currently locks the name of the source map to the name of the output file plus .map at the end (so if the source map contents change, the output file name must change too).

fake entry point, where imports original file by the full file name

By "full file name" do you mean the absolute path to the file? One simple fix could be to use the relative path to the file instead, which would be platform-independent.

@yumauri
Copy link
Author

yumauri commented Dec 13, 2021

By "full file name" do you mean the absolute path to the file?

Yeah, I mean absolute path :)
I guess your commit should fix this particular case, thank you!

@evanw
Copy link
Owner

evanw commented Dec 14, 2021

The mitigation was just released in version 0.14.4 so I'm going to close this. Hopefully it works but you should also be able to just use a relative path instead to avoid this.

@evanw evanw closed this as completed Dec 14, 2021
@yumauri
Copy link
Author

yumauri commented Dec 14, 2021

Version 0.14.5 has fixed the issue, thank you!

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

No branches or pull requests

3 participants