-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Allow tsconfig to be a module, not only json #25271
Comments
As a hacky workaround now I can generate const config = {/*dynamically generated config*/};
require('fs').writeFileSync('tsconfig.json', JSON.stringify(config)); This works for compilation, but doesn't work for editors, because they do not see actual file. |
The config file is meant to be statically understood by different tools, some of them have no capability nor need to execute JavaScript. for more dynamic modifications we recommend using a build tool e.g. gulp/jake/grunt/broccoli/etc.., or directly using the compiler API. |
Got that, will have to stick with my workaround. At least there is an issue now, that someone can upvote. Thank you for taking your time! |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
@mhegazy Do you have examples of such tools that need to statically analyze I too am running into this problem, as I want to share my configuration across projects. This sort of stuff becomes easier when we get dynamic abilities. |
If I'm not using those such tools that statically analyze tsconfig, then why can't I choose to use a JS module instead? I don't care if some tool won't be able to statically analyze my tsconfig... because I'm not using those tools... |
When trying to share tsconfig (and other build scripts and configs) across projects, this gets in the way in some cases if I can't use
|
TypeScript itself, Visual Studio, Visual Studio Code, etc... |
Does these tools analyze js config files like webpack.config.js or babel.config.js? |
This seems to be a missed opportunity for flexibility for typescript. All those tools should be able to execute a bit of JS and have it report the config much like every other build tool config in the JS ecosystem like webpack.config.js, jest.config.js, gulp (gulpfile.js), babel (https://new.babeljs.io/docs/en/next/babelconfigjs.html). It seems like getting the config from a module is one |
For anybody still interested in this feature: https://www.npmjs.com/package/tsconfig.js |
Personally I'd like to see them use the node-interpret package to determine how to load the configuration file. I'd LOVE to be able to create a dynamic configuration file IN typescript by creating a tsconfig.ts (like webpack does webpack.config.js) and node-ts runs the module |
@dl748 I wanted to look into this just now. A quick search the mentioned node-interpret package yielded https://github.com/gulpjs/interpret, which doesn't seem right. Please include a useful reference if you open an issue. |
@rasenplanscher See https://webpack.js.org/configuration/configuration-languages/ Source for use https://github.com/webpack/webpack-cli/blob/next/packages/webpack-cli/lib/groups/ConfigGroup.js |
@dl748 |
You should add to the documentation though, that if loading other extensions like coffee or typescript, you need to make sure the required loader (e.g. coffeescript for .coffee and ts-node for .ts) is installed |
Good point, done 👍 |
I really see little harm in allowing dynamic configs and letting the editor decide which to use. No one is saying remove Right now, TS is literally the only tool I cannot configure dynamically, and it's quite frustrating, resorting to me having to use hacky methods like generating the file dynamically, which doesn't work well with editors. |
@ryall |
@rasenplanscher I have my own similar implementation, however that's not really the point. I think dynamic config should be part of the core architecture rather than an external library. |
Not only does this replace the magic strings for paths all across the config files, but it also results in a single source of truth to avoid confusion later for which path means what. Consequentially, this also makes the app more flexible for users because changing the names of these directories later on is substantially easier if they wish. Note: This doesn't work for tsconfig.json because [the TypeScript devs are stubborn](microsoft/TypeScript#25271), so those paths would have to be updated manually if they're changed in `Paths`.
Not only does this replace the magic strings for paths all across the config files, but it also results in a single source of truth to avoid confusion later for which path means what. Consequentially, this also makes the app more flexible for users because changing the names of these directories later on is substantially easier if they wish. Note: This doesn't work for tsconfig.json because [the TypeScript devs are stubborn](microsoft/TypeScript#25271), so those paths would have to be updated manually if they're changed in `Paths`.
Not only does this replace the magic strings for paths all across the config files, but it also results in a single source of truth to avoid confusion later for which path means what. Consequentially, this also makes the app more flexible for users because changing the names of these directories later on is substantially easier if they wish. Note: This doesn't work for tsconfig.json because [the TypeScript devs are stubborn](microsoft/TypeScript#25271), so those paths would have to be updated manually if they're changed in `Paths`.
Since it has been almost 4 year since this issue was brought up, can we reopen the issue ? When faced with more complex projects, the ability to define Can we please at least give it a shot? |
In my monorepo, I would like to be able to dynamically derive project references from the namespaced dependencies enumerated in my |
My |
Search Terms
I have found a related question here: #9876 (comment). But that was not anyhow replied or addressed. So I have opened this issue.
Suggestion
Allow
tsconfig
file to be an executable module, not only static JSONUse Cases
path.join(__dirname, 'path/to/file')
to generate dynamic pathsextends
property doesn't work. Same also was asked there: Configuration Inheritance #9876 (comment)Also there is similar features in other tools:
Examples
tsconfig.js
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: