-
-
Notifications
You must be signed in to change notification settings - Fork 752
Allow overriding tsconfig options from within tsconfig.json #1891
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
Conversation
- In anticipation of TypeStrong/typedoc#1891
|
I'm not entirely against this, though I'd say said library is bad.. shouldn't be shipping TS. Putting compiler options in This should also be configurable within typedoc.json, which is another reason for using a separate name. |
|
Thank You for Your reply and insights .. and I do concur. Furthermore, I've noticed, that the I'm currently also investigating the possibility of implementing such overrides via a plugin, but this seems a little off, as configuration parsing should be (IMO) implemented within the core of an application. Do You have any thoughts on this? 🤔 |
|
I've looked through the sources again and I think I may have found a quite minimal, yet better way of implementing the discussed feature. Furthermore, I thought it might be desirable to let users also pass such overrides via CLI, so I went ahead and implemented JSON parsing, iff the I also thought of implementing some test case(s) for this feature, but I wasn't sure where to put such a test case, as the If You have any issues with the code style, logic or missing test cases, please let me know! |
|
I think I'd rather not do the JSON parsing - it makes the logic more complicated and I don't see anyone ever using it. None of the other complex objects do it either. (Also, if keeping it, the validate function isn't sufficient since it doesn't actually do checks on the parsed value) Other than that, I like it! The default-options.ts file is actually the appropriate place to add tests - it's meant to test validation for our default options (e.g. those not added by plugins) |
|
Hey, sorry for not getting back to You sooner. As You suggested, I threw out the JSON parsing and kept the remaining changes as simple and small as possible. Regarding the test case, it's currently just a duplication of the As always, if You have any issues with the code(style), please let me know and I'll try to address these. Thank You and kind regards! |
Gerrit0
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
What this pull request contains
What this pull request does
This pull request implements a new TypeDoc option:
compilerOptions. By employing this option, one may selectively override some fields of thetsconfig.jsonused by TypeDoc.An example
Let's take the following (trimmed-down)
tsconfig.json:{ "compilerOptions": { // Enforce strictness "noUnusedLocals": true, "noUnusedParameters": true, "strict": true, }, "typedocOptions": { // Abandon strictness "compilerOptions": { "noUnusedLocals": false, "noUnusedParameters": false, "strict": false } } }With this configuration, TypeScript
strictness will be enforced throughout the codebase. But when runningtypedoc, the strictness will be dropped by patching the originalcompilerOptionswith the providedtypedocOptions.compilerOptions.Motivation
When working with abstracted TypeScript tooling (e.g. not using
tscdirectly, butrollup-plugin-typescript2), the handling and transpilation of source code within a project may differ between those abstracted tools andtsc(and therefore TypeDoc). Allowing the user to override parts of thetsconfig.jsonfor TypeDoc from within the sametsconfig.jsonseems to be a quite well scoped way to tackle these differences (without throwing yet anothertsconfig.typedoc.jsoninto the project and polluting the scene further).Real world motivation
As an anecdotic example, I recently added a library to a project I'm currently working on and everything went well. Until I tried to build the documentation for said project. ... Because the libary distributes TypeScript source files instead of declaration files (
.tsinstead of.d.ts) the--skipLibCheckoption of TypeScript does not catch those files andtsckeeps insisting on type-checking those sources within thenode_modulesfolder, which throw errors. And as the library was built without having the TypeScriptstrict-mode enabled, I now cannot gettscto run on my project anymore, whilerollup-plugin-typescript2happily transpiles my codebase and creates valid TypeScript definitions. To stress this, there are many, many examples of other people having the same issue and trying to get the TypeScript maintainers to implement a way around such behavior:skipLibCheck: trueis ignored when package'stypesfield points to a.tsfile (not a.d.tsdeclaration file) microsoft/TypeScript#41883Meanwhile, Deno even implemented a CLI flag for exactly this.
Full disclosure
I know, I know, I could just create something like
tsconfig.typedoc.jsonand manually override my desired preferences within this extending TypeScript configuration file. But, as stated above, I really don't like to clutter up my repository with "unnecessary" files. And to me it feels like a good practice to have the TypeScript configuration, thetypedocOptionsand thecompilerOptionsoverrides all in one place: A singletsconfig.json! 😄