Insert bin prefix for script packages
See original GitHub issueCurrent Behavior
The output of index.js
begins with use 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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Can I install an executable in $PREFIX/bin using Pkg?
The installed script can keep the path to Julia project and julia executable. Users would run ScriptInstaller.add("PACKAGE") which creates a dedicated project, ...
Read more >scripts - npm Docs
To create "pre" or "post" scripts for any scripts defined in the "scripts" section of the package.json , simply create another script with...
Read more >2. Writing the Setup Script — Python 3.11.1 documentation
The Distutils' own setup script, shown here, is used to install the package into Python 1.5.2.) #!/usr/bin/env python from distutils.core import setup ...
Read more >Installing and running Node.js bin scripts - 2ality
Locally installing a package with bin scripts means installing it as a dependency inside a package. The scripts are only accessible within that ......
Read more >npm install not working with --prefix - node.js - Stack Overflow
"Main" package.json contains all scripts (for Heroku and for me) and dependiencies for server. client is Angular2 app that's why it has own ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
bin
folder, similar to the code below (although ours uses ES Modules):This is also how Prettier handles it - see also their
package.json
Maybe this should be the recommendation from TSDX until there are other viable options?
So I’m working on a fix to this by making the dev/prod entry an actual Rollup plugin per https://github.com/formium/tsdx/issues/793#issuecomment-673952338 (it being out-of-band causes some issues like https://github.com/formium/tsdx/issues/351#issuecomment-657284291, 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
rollup-plugin-typescript2
like https://github.com/ezolenko/rollup-plugin-typescript2/pull/221 anyway). I feel pretty close but still need to do some testing, particularly against #367In the meantime, here’s a one-liner workaround in Bash for this that one can use in a post-build script: