Skip to content
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

FR: Configure tsx in tsconfig.json #36

Closed
mikestopcontinues opened this issue Jun 18, 2022 · 4 comments
Closed

FR: Configure tsx in tsconfig.json #36

mikestopcontinues opened this issue Jun 18, 2022 · 4 comments
Labels

Comments

@mikestopcontinues
Copy link

ts-node supports the following:

{
  "compilerOptions": {...},
  "ts-node": {
    "compilerOptions": {...},
    "require": [
      "dotenv-flow/config"
    ]
  }
}

In my monorepo, this makes it really easy to keep config out of CLI args. In particular, having access to require makes all my scripts draw env-vars properly with minimum fuss.

I'd like to be able to do the same thing with tsx. I saw a previous ticket where you expose --require, though it's undocumented in the CLI help text. I'm not against using it for the time being, but for dozens of scripts, it's overkill to insert it everywhere.

Thanks for such an awesome project!

@privatenumber
Copy link
Owner

privatenumber commented Jun 19, 2022

tsx is a wrapper around Node.js, so it doesn't actually expose --require. It just passes all arguments through to Node.js.

Seeing as dotenv-flow/config is a runtime requirement, why not just import it at the top of the entry-files?

You can also add it via NODE_OPTIONS env var by creating a caller script entry:

{
	"scripts": {
		"dotenv-run": "NODE_OPTIONS='--require dotenv-flow/config' npm run",
		...
	}
}

and run scripts via:

npm run dotenv-run -- <script name>

In terms of configuration, I would like to align more closely with Node.js than ts-node. I'm also very hesitant to add a configuration file as it sets a precedent to justify further configuration to be added (and therefore more complexity).

@mikestopcontinues
Copy link
Author

The main benefit to me is that all scripts I write across my monorepo automatically benefit from the config, rather than requiring boilerplate in the form of import statements or cli args.

That said, I do understand wanting to keep your surface area small. So I'd consider this issue resolved.

Perhaps I should write a script that merely wraps tsx with my preferred args, and use that across my repo. At present, I just updated all my npm scripts with tsx --require etc. Doesn't help with running arbitrary scripts, but it's good enough for now.

@NishargShah
Copy link

This feature is required for my situation. I am detecting my .env based on branch/function so I need to require one ts file every time in my script and that is not good. I hope this feature will release soon...

@privatenumber
Copy link
Owner

If you think of tsx as an alias to node, you'll realize there's plenty of other solutions. Try investigation solutions that are designed for Node.js.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants