goto-bus-stop/browser-pack-flat

Import order is not preserved

edsrzf opened this issue · 2 comments

The order of imports is not preserved when using this plugin. Ideally, imports would not have side effects that are visible to each other and this wouldn't matter, but in practice this isn't always the case. 😢

I know there can be differences in execution vs. Node (as noted in the README), but it seems like if all require calls are at the top of all files, it would be possible for execution order to be preserved.

Example

I have this index.js:

require('./one')
require('./two')
require('./three')

one.js, two.js, and three.js each contain a console.log line that logs the name of the file.

Node gives the expected output:

$ node index.js
one.js
two.js
three.js

Browserify with browser-pack-flat outputs:

$ browserify -p browser-pack-flat index.js|node
one.js
three.js
two.js

(Note that running Browserify without -p browser-pack-flat yields the same output as plain Node, with the import order preserved.)

node version: 10.15.3
browserify version: 16.2.3
browser-pack-flat version: 3.3.0

hmm yeah, it maintains the order that browserify lists the dependencies in, but that's not the same as the order in the source! if we sort the dependencies by their location in the source code it should help a lot here (there will still be a separate remaining ordering issue for lazy requires)

Fantastic, the issues I was having with my project are fixed! Thank you for the fast turnaround on this!