browserify / bundle-collapser

convert bundle paths to IDs to save bytes in browserify bundles
Other
194 stars 21 forks source link

two different relative paths have same ID #20

Open bradleyretterer opened 8 years ago

bradleyretterer commented 8 years ago

Say I have a node module a that has require("../compiled/templates"); along with a node module b that has its own require("../compiled/templates"); - both pointing to their own respective templates.js file. When I use this on bundle-collapser, I get the same ID for both files, even though they're different files (i.e. they should have two different IDs). This leads me to believe that the ID generated is based off the uniqueness of the string, and not the full absolute path of the file that is required.

doxick commented 7 years ago

Just ran into this issue myself.

In the second index.js, the first component.js gets referred. So indeed, it generates IDs based on string.

kgryte commented 7 years ago

Can anyone confirm whether this affects both the CLI and the plugin? I can imagine that, when piped a bundle, the CLI may not have access to absolute path information (as default browserify behavior is to resolve everything relative to a common directory). This may not be true for the plugin which would potentially have access to absolute file paths during bundling.

rreusser commented 7 years ago

I'm able to reproduce it. It seems it's an issue for all api usages.

https://github.com/rreusser/bundle-collapser-uniqueness-failure

kgryte commented 7 years ago

@substack Perhaps you can move this repo to the browserify org. :)

rreusser commented 7 years ago

They key seems to be identical file contents. If two files have the same contents, they seem to get flagged as dedupable. Bundle-collapsed browserify output's require function then grabs one or the other and gets it wrong.

rreusser commented 7 years ago

See also:

kgryte commented 7 years ago

@rreusser Thanks for the code archaeology!