Support .cjs files imported with `@rollup/plugin-commonjs`
Add support for CommonJS files loaded with @rollup/plugin-commonjs.
If try to run rollup-plugin-preserve-shebang on a CommonJS file
(e.g. one that uses const x = require("..."); syntax instead of
import),
@rollup/plugin-commonjs
will append ?commonjs-entry to the end of the id.
This means that renderChunk() will fail to add the shebang back to the file, since the moduleId is different.
E.g. in transform(code, modId), modId = "...example.js"
However, in renderChunk(),
chunk.facadeModuleId = "...example.js?commonjs-entry".
In order to get the original module id, you need to remove ?commonjs-entry.
I encountered exactly the same issue, would be helpful if this PR can be merged.
I am not sure this is true anymore. I don't know what has changed since this was opened two year ago, but I just tested the scenario this PR attempts to fix (alongside my PR that adds integration tests #16) and I can't reproduce this. Is it still valid?