-
-
Notifications
You must be signed in to change notification settings - Fork 533
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
Add ability to --transpile-only from a shebang #703
Comments
@cspotcode Do you have a quick and easy way to do this with node/npm? The easiest way to me seems to be, 1. write a proxy |
I just published "ts-node-to" that does this. https://www.npmjs.com/package/ts-node-to It splices '--transpile-only' into the argv array before https://github.com/cspotcode/personal-monorepo/blob/master/packages/ts-node-to/bin.js I've also been brainstorming a more robust solution to this shebang problem, but it's not specific to ts-node. I wrote a bash script "env2" that behaves like https://github.com/cspotcode/personal-monorepo/blob/master/packages/env2/README.md Unfortunately for good Windows support I'll need to implement it as a native binary in something like rust, so that's what I've been working on when I find time... EDIT: I went ahead and published a Posix shell implementation of my env2 idea: https://www.npmjs.com/package/env2-shebang |
@blakeembrey ^--- sorry for the double-post; I forgot to at-mention you. |
I have a more complex use-case today than I did when submitting this issue. I wound up creating https://www.npmjs.com/package/env2-shebang#env2rc-convention-based-shebangs For our project, I want to enable developers to run
However, Linux doesn't support extra args in a shebang, and this is a lot for people to remember. We need to use this style of invocation because Setting these options with environment variables has similar issues: you'd have to remember to set the variables in your shell session, and you can't set env vars in a shebang. env2rc takes care of this complexity. But for ts-node specifically, it'd be great if ts-node options were pulled from either |
Using |
I'm working on a PR that loads config flags from tsconfig.json. In the process, I'm generating a JSON schema from the TS types via typescript-json-schema. So far the experience is nice: The JSON schema generator can extract arbitrary @-tags into the schema, which means it could hypothetically drive the CLI parser or render the README, too. Not sure it's worth the effort, but it's cool that it's possible. EDIT: I should have posted this in #4, oops. |
You could just do this: #!/bin/sh
':' //; exec /usr/bin/env ts-node --transpile-only "$0" "$@"
console.log('This is TypeScript') No need for a seperate package. This works quite well because exec replaces the shell process so the environment, args, and exit codes of the script will be that of the |
@brandonkal Are you sure that works? |
@cspotcode You are right. Corrected my comment to keep |
@cspotcode #!/bin/sh
":" //; exec /usr/bin/env ts-node --transpile-only "$0" "$@"
.charAt(0);
console.log('This is TypeScript') |
Linux doesn't support passing args to a binary via shebang; only Mac as far as I know. Linux treats everything following the binary as a single arg. So, for example, this will not work:
On my project, we want to write shell scripts in .ts but run them with
--transpile-only
. The only way I can think to do this is creating a new binary, for examplets-node-transpile-only
, that behaves exactly likets-node
but with--transpile-only
enabled by default.Then we can do the following:
The text was updated successfully, but these errors were encountered: