-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Load js config file #51613
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
Load js config file #51613
Conversation
|
Plenty of people want this feature, it's one of the reasons the issue was reopened
It's incredibly useful, please reconsider... As for the "can of worms" problem, there isn't any really.. typescript would only treat the import as a json object, if it fails at converting it to json it falls back, and reports an error to the user. A lot of other dev tools like Webpack, Rollup, Vite etc.. even support config plugins, which would be more "hazardous" than this implementation. |
It's up to the team, I just quoted them.
It executes the JavaScript. So what happens if there are imports in the js file? Or if someone accesses And the config is also used for tooling support, e.g. when you open a project in VS Code it reads your configuration. With this change it means you open your workspace and it executes JavaScript - that's a security no-go. What's the alternative? Only support .js in CLI? People will expect it to work, and not to have two configs. Try to blacklist/whitelist code in the file? That's never going to work safely. |
Imports in the js file will be executed as the developer wants, like in my latest example:
which would be read by typescript as: {
"compilerOptions":{
"outDir": "dist/dev",
}
} Imports and anything else, can't have a way into typescript's process, as the read output of the js file is a json string
Well yes, VS Code prompts the user a modal to check if the user trusts the content of the project already, Devs put only what's needed in config files, see how rollup & webpack configs have been used til now by the dev community. Denying this control to his configuration process, isn't gonna stop him from putting malicious code in his own project, if he wills to |
This could also solve #37884 |
The TypeScript team hasn't accepted the linked issue #30400. If you can get it accepted, this PR will have a better chance of being reviewed. |
I would much prefer to design this feature in an issue instead of a PR. The code is pretty simple, but the design is complicated. Since the original issue is still open, let's discuss there. Although I personally still agree with @RyanCavanaugh 's hesitation to have an executable config. In the meantime, to help with PR housekeeping, I'm going to close this PR. |
Fixes #30400 , #39441 and potentially #37884
I was coding a helper for Prebuilder like this one for Rollup,
It needs a javascript config file, in order to let Prebuilder control the compilation process with dynamic paths.
I was surprised to see that it's still not possible in typescript, so i dug in this repo this weekend, and came up with this solution, that apparently satisfies some of the points expressed in #30400:
Testing
I tried writing a test, but it has not been easy, i spent more time trying to do this, than the actual implementation...
I would leave this task to any willing person, as i couldn't figure where to put the .js config file
I have tested manually like this:
npm run build
npm run test
(✔)npx hereby LKG
And it worked perfectly, transpiling to the 'dist' folder.✔
Config extensibility (
extends: "./tsconfig.js",
) works with js config files too ✔Usage
tsconfig.js :
Also:
Dynamically adding a path ✔
And extending with a .js config ✔
SET NODE_ENV=dev&& tsc -p tsconfig-extended.js