Parcel: When entry file has a shebang, output it in the first line of the bundle

Created on 9 Dec 2018  路  8Comments  路  Source: parcel-bundler/parcel

馃檵 feature request

In UNIX systems, the first line of a script can be a shebang with the path to the interpreter. When the main entry file has this shebang (and optionally when target: node), this shebang line could be taken _out of the bundled modules_ and outputted in the first line of the bundle.

馃 Expected Behavior

hello-world.js:

#!/usr/bin/env node

console.log("Hello, world!");
$ parcel build -t node hello-world.js

dist/hello-world.js:

#!/usr/bin/env node

// parcel bundle prologue ...function(require,module,exports) {
console.log("Hello, world!");
// }... parcel bundle epilogue

馃槸 Current Behavior

dist/hello-world.js:

// parcel bundle prologue ...function(require,module,exports) {
#!/usr/bin/env node
console.log("Hello, world!");
// }... parcel bundle epilogue

(which is actually a SyntaxError)

馃敠 Context

I run into this when trying to make executable scripts for node which have all their files already bundled.

Good First Issue Feature

Most helpful comment

@sintloer That's great, I'll start using it! Maybe you could copy the shebang of the entry file instead of having to define it in the package.json?

However, I still think parcel should have native support for this, especially as the input is a valid node script but the output is as SyntaxError.

All 8 comments

@cprecioso, I created a plugin for this.
See: https://github.com/sintloer/parcel-plugin-shebang

@sintloer That's great, I'll start using it! Maybe you could copy the shebang of the entry file instead of having to define it in the package.json?

However, I still think parcel should have native support for this, especially as the input is a valid node script but the output is as SyntaxError.

@cprecioso, Yes, I think Parcel should support shebang natively.
As for my plugin - your idea is really good. I will want to implement it.

@cprecioso, new version of my plugin (1.2.0) supports copy the shebang of the entry file :)

@sintloer why didn't you contribute this directly to parcel core?
This seems like something that should be in core if detected?

@DeMoorJasper, it should be. It's a good idea.
I'll do it.

@sintloer any updates?

No progress still?

Was this page helpful?
0 / 5 - 0 ratings