Description
- Rollup Version: 2.28.2
- Operating System (or Browser): MacOS, repl.it
- Node Version (if applicable): v12.19.0
- Link to reproduction (IMPORTANT, read below): https://repl.it/repls/PricklyBuzzingCode#package.json
Expected Behavior
All commonjsRegister
calls should be at the top.
The commonjs
plugin generates them at the top, and it should stay that way.
In cases of import from 'whatever'
, the import is clearly meant for causing a side effect, and thus it's order of execution matters.
(Of course it could be also in normal imports, but this case is very explicit and well known).
Actual Behavior
The order of imports generated by the commonjs
plugin is not preserved, and other modules appear in between.
The result in some cases is that there's a call to commonjsRequire
before the dynamic modules have been registered, so they it can't find/generate the module during the commonjsRequire
call.
In this specific REPL you can see that between the commonjsRegister(...internal/wrapAsync)
and commonjsRegister(...asyncify)
, there's one piece of code var setImmediate_1 = createCommonjsModule(...)
, which is extra weird since this variable is not in use yet, so why bump it to that position on top?
I know that rollup tends to manage the order of things by itself for the sake of optimization,
but we need to think of a way to at least specify cases where the user (or a plugin) requires a steady order of imports.
And perhaps detect those "side effect" imports and handle those automatically.