-
Notifications
You must be signed in to change notification settings - Fork 507
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
Insert bin prefix for script packages #338
Comments
thanks for your idea! i'd say this is beyond project goals - if you're making a CLI, you'll know to make those two changes. |
Is it possible to allow us to modify the index file using rollup in that case? Currently the rollup extensions do not allow for modifications to the index.js file generated in |
ah you’re right. i see. will leave this one to @jaredpalmer |
@jaredpalmer I'm happy to contribute to this if you have any ideas on how you think this should be configured from the end users perspective. |
Ahh. My preserve shebang Rollup hack is totally undone by dev/prod entry. Shoot! I wonder if we can sniff it out somehow. I also wonder if we have a flag to turn off Dev/prod since a cli can’t really run in DEV |
So I'm working on a fix to this by making the dev/prod entry an actual Rollup plugin per #793 (comment) (it being out-of-band causes some issues like #351 (comment), also other folks could potentially use it) and recently had a breakthrough on how to make it work with multiple inputs (mostly by heavily reading the Rollup docs again, which I've been doing for upstream fixes in In the meantime, here's a one-liner workaround in Bash for this that one can use in a post-build script: echo -e '#!/usr/bin/env node\n' "$(cat dist/index.js)" > dist/index.js |
We currently use TSDX to build Preflight, a command-line tool for the @upleveled students to check their project work before submitting. The way that we're dealing with it is to have a separate file in a #!/usr/bin/env node
'use strict';
require('../src/cli').run(process.argv.slice(2)); This is also how Prettier handles it - see also their Maybe this should be the recommendation from TSDX until there are other viable options? |
I used also filed a PR #957 with the similar approach, trying to resolve this issue. |
Current Behavior
The output of
index.js
begins withuse strict
which if the package is intended to be a script, an error outputs.Desired Behavior
When a package.json includes a bin parameter, prefix the
index.js
file with#!/usr/bin/env node
Who does this impact? Who is this for?
This is for users who wish to use tsdx for creating packages that are intended to be used in the command line.
Additional context
If it doesn't make sense to base the behavior on the bin parameter in the package.json, it might make sense instead to make this a new template type, but it's so similar to node, that this might be more effort than necessary.
The text was updated successfully, but these errors were encountered: