-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fails on Node shebang (#!/usr/bin/env node) #235
Comments
Since it isn't standard JS, I'm not sure what our official standpoint is. We could probably support it at some point in time. If you want to make it work now, consider removing |
Personally, I've been supporting shebang lines in any tools I've written I'll submit a PR for this. On Wed, Oct 28, 2015 at 4:25 AM Oskar Segersvärd notifications@github.com
|
Thinking about this a bit more after trying to build support for it as a plugin, I'm not sure it's possible to do yet. It should be done as a |
I'm probably missing something but why would the plugin need to know about the bundle or entry module in this case? Couldn't it just provide a |
My two cents: I didn't know about Here's what browserify did when this question came up: browserify/browserify#297 (tl;dr: they decided to support it since it is also supported by |
One good reason not to support it: when generating a CommonJS bundle (which is presumably what we're talking about), the shebang would appear below the 'use strict' pragma... 'use strict';
#!/usr/bin/env node
console.log('Hello, World!'); ...and that assumes that there's only one module (if anything is imported, it will generally appear before the entry module). The |
0.20.3 allows plugins to supply a banner/footer option |
I know this is old but for anyone interested you can do something like this: const writeFile = require('fs').writeFile;
const rollup = require('rollup');
rollup.rollup({
entry: 'source.js',
acorn: {
//Let the hashbang be
allowHashBang: true
}
}).then(bundle=>{
let code = bundle.generate({
format: 'cjs'
}).code;
let bangReg = /\n(#[!][^\n]+?\n)/;
//remove the hashbang from somewhere below 'use strict';
let hashBang = code.match(bangReg);
if(hashBang){
code = code.replace(bangReg, '');
//put the hashbang where it belongs
code = hashBang[1] + code;
}
writeFile('dist.js', code, (error)=>{
throw error;
});
}) This would be just for executable files you create yourself. It might break something else. |
Here's a workaround you can use from within the config only: import replace from 'rollup-plugin-replace';
export default {
banner: '#!/usr/bin/env node',
plugins: [
replace({
'#!/usr/bin/env node': ''
}),
// ... This will remove the shebang before feeding it to rollup plugins and then put it back at the end. |
@vjeux Does this solution still work for you? I've tried here but the problem persist. I am using |
@paulocoghi if you use the delimiter option it should resolve your issue. import replace from 'rollup-plugin-replace';
export default {
banner: '#!/usr/bin/env node',
plugins: [
replace({
delimiters: ['', ''],
'#!/usr/bin/env node': ''
}),
// ... The above was tested with:
|
Has anyone had success in using https://github.com/developit/rollup-plugin-preserve-shebang, from what I can see it will only do stuff if it finds a shebang in the source, but shebang in the source breaks rollup and I get a
Seems like the banner approach is the way to go. |
I noticed this issue is closed, I had the same problem and I ended up writing a plugin myself, I published it under rollup-plugin-strip-shebang in case someone is interested. |
just published a package that preserves shebangs - reads what shebangs are in the files, strips them so rollup can continue compiling, and then brings them back in the output file. https://github.com/elado/rollup-plugin-preserve-shebangs |
Thank you, that works for me😆 |
There's also https://github.com/developit/rollup-plugin-preserve-shebang Edit: nvm it's outdated, didn't work. https://github.com/elado/rollup-plugin-preserve-shebangs did! Thanks |
Workaround for - babel/babel#11216 - rollup/rollup#235
Workaround for - babel/babel#11216 - rollup/rollup#235
It's probably simplest to use output: {
file: 'bin/migrate.js',
banner: '#!/usr/bin/env node',
}, The |
I'm trying to use Rollup on a CLI, but it doesn't seem to like shebangs.
Here's a file that reproduces the issue:
I'm using rollup version
0.20.2
. Not sure if you'll want to support this as this is not standard JS. Browserify does (by removing the line). Webpack doesn't. Babel does (by leaving the line as is).The text was updated successfully, but these errors were encountered: