bundle-collapser
bundle-collapser copied to clipboard
two different relative paths have same ID
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.
Just ran into this issue myself.
- I have 2 directories with both
index.js
andcomponent.js
. - In both
index.js
files, i refer to./component.js
In the second index.js, the first component.js gets referred. So indeed, it generates IDs based on string.
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.
I'm able to reproduce it. It seems it's an issue for all api usages.
https://github.com/rreusser/bundle-collapser-uniqueness-failure
@substack Perhaps you can move this repo to the browserify
org. :)
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.
See also:
- https://github.com/browserify/browserify/issues/1450
- https://github.com/browserify/browserify/issues/1027
- https://github.com/browserify/browserify/issues/1007
@rreusser Thanks for the code archaeology!