bundle-collapser icon indicating copy to clipboard operation
bundle-collapser copied to clipboard

two different relative paths have same ID

Open bradleyretterer opened this issue 7 years ago • 7 comments

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.

bradleyretterer avatar Sep 16 '16 21:09 bradleyretterer

Just ran into this issue myself.

  • I have 2 directories with both index.js and component.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.

doxick avatar Jul 10 '17 09:07 doxick

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.

kgryte avatar Sep 21 '17 20:09 kgryte

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

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

rreusser avatar Oct 02 '17 18:10 rreusser

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

kgryte avatar Oct 02 '17 18:10 kgryte

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 avatar Oct 02 '17 22:10 rreusser

See also:

  • https://github.com/browserify/browserify/issues/1450
  • https://github.com/browserify/browserify/issues/1027
  • https://github.com/browserify/browserify/issues/1007

rreusser avatar Oct 02 '17 23:10 rreusser

@rreusser Thanks for the code archaeology!

kgryte avatar Oct 02 '17 23:10 kgryte