-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Configure from package.json #32830
Comments
Actually |
I feel like this feature is pretty standard already. Babel, ESLint, Vue and Browserslist support it, so that's 4 files that I can save from cluttering my repo. Would be great to be able to do that with |
Definitely, cosmiconfig is usually a good choice to simplify config resolution for tools. |
Don't wanna add too much noise here. It was kinda mentioned by @dmnsgn with cosmiconfig, but I would love to see support for CommonJS configuration file support (ex. I see the value in separating out these configurations away from the Would be more than happy to help contribute to making this happen if at all possible (would need a bit of guidance maybe since I haven't contributed to TS before). |
Yes, this would be perfect for small projects, online env's or boilerplates/templates. I've tried to this through, webpack plugins or Maybe it is possible to mock file so Sorry for duplicate issue |
Cleaned out half a dozen config files from my project... the only one remaining is |
With shareable configs, this will be awesome ❤️ |
@RyanCavanaugh are we still awaiting more feedback or is that tag no longer accurate? As far as implementation, it looks like this might be straightforward with cosmiconfig and it looks like some people may be willing to contribute code to get this feature if it is accepted. (Myself included) |
You should note that the TypeScript compiler has no dependencies. :-) So using something like cosmiconfig is pretty surely a no-go. |
@MartinJohns That's a good point! I can't speak for anyone else, but I would still be willing to contribute to get this feature. |
A few people in my organization have been somewhat offended by the number of configuration files required in a skeleton project, compared to other language ecosystems. Being able to get rid of a physical tsconfig.json file would help us out a little bit. |
It would be nice to be able to at least specify a shared config as |
This would be a great addition, as others have stated, I have all my other configs in my package.json (prettier, eslint, jest, babel...). This would be the last of my config file clutter to knock on the head |
I'm looking forward for this feature. |
This would help for multi-repo cases, where I can easily share a configuration file. Right now i can use extends, but why clutter every project with additional file.. Other configuration files (eslint, prettier) already have this |
It would be nice to have this feature! |
@RyanCavanaugh Any update on this? It doesn't seem too hard to implement, and it would be a great feature! Many of us are willing to contribute as well. |
Asked differently: are there counter-arguments as to why this would be a bad thing? Perhaps just pending a PR? One thing I can think of is that it would change assumptions made from third party tooling about where to look for said config (perhaps to the point of a "breaking feature"). Sounds manageable though. |
In my case this would help maintain monorepos where the config is stored in a single place and then new "child repos" extend it. Currently all the child repos have a "tsconfig.json" that extends "node.tsconfig.json" or "react.tsconfig.json". So it is pretty much a dummy file. If it was in the |
I don't know if I'm speaking for anyone else when I say this, but I am working on a really tiny package right now (like less than 4 kb) and so it would be nice if I didn't have to add an extra file with boilerplate that would add to the repo size. I already have a |
@William-McGonagle an extra file can be npmignored; putting it in package.json forces that weight to be part of your package. In other words, “an extra file” is the only way to minimize package size. |
@ljharb I get that the extra file can be npmignored, but I would just like the github repo itself to have fewer files. The only property I need is I know that it would add to the size of the npm package, but I have calculated it, and it would only add 54 bytes (unminified + unzipped), which is really an acceptable amount. For me, it would be useful. |
In addition, it shouldn't be too hard to auto filter out extra package.json keys during build |
@RedGuy12 it wouldn’t be, but precisely zero build tools do that that I’m aware of. |
@ljharb but babel, or similar build tools have this as an option, you choose to have extra file and gitignore it, OR you can have an extra config file |
A) Not all repos have downstream users. B) The time lost by developers trying to navigate a cluttered root structure is infinitely more important than the millisecond it takes for your modem to download an extra byte. |
I think you’re massively underestimating download counts and massively overestimating the cost of “clutter”. Repos without downstream users should be using a separate file anyways for CODEOWNERS-style code review control. |
What if it's a small project that you're working on by yourself, as most projects are? You don't need special CODEOWNERS for tsconfig then. |
Nor do you need to worry much about a small handful of config files. (also, it’s never by yourself; there’s always “you” and “you in 6 months”, and that guy thinks you’re a jerk already, might as well keep things more maintainable and separate) |
I think you're massively underestimating how many projects don't have millions of weekly downloads while massively underestimating how many users would prefer to not have you dictate their file structure. People and repos are different and needlessly trying to enforce a one-size-fits-all doesn't work. Especially if the one-size-fit is aimed at the top 1%. |
And TypeScript wonders why people complain about ramp up time... Having a configuration file in the first place is annoying. But being SO rigid and strict about that configuration file is just frustrating. Do you know how easy it is to run a JavaScript file? 'node index.js'. No configuration. Nothing. Yet TypeScript not only insists on having configuration files, but also not allowing for the flexibility that all these developers are asking for. It's a VERY simple and reasonable request... I'll say it again. Just use cosmiconfig. |
As the original poster of this issue, let me clarify a few things:
|
To get the consensus of those who are interested in this feature, please use the emojis on this comment to vote on which scenario you think the TS team should implement as the resolution to this feature request:
|
The fact that the JS ecosystem relies heavily on an unmaintainable dependency mess is annoying. TypeScript has zero dependencies. Adding "cosmiconfig" will add 24 dependencies. That's a maintainability and security risk. |
I agree. Reading a config from package.json or a .js file would require very little code. No dependency needed. |
I am in favour of integrating every dot config files into package.json, but I see a downside, this would break compatibility with
How would this be managed? |
@ottodevs Well it would need to be adjusted to use an offset like "tsconfig" in a JSON file instead of just a whole JSON file. But given it is parsing it anyway, that should be relatively easy. Also, I should mention that just like any other new feature, the expectation is not to make this the new default, but just to provide it as an option. That would take time to catch on, the integration would notifications from its users and would have ample opportunity to implement it before the larger community adopts it. |
Cannot wait for this feature, I am running a framework of modules and have .tsconfig files all over the place. Centralising them into one package and referencing it from package.json would be great. We are already doing this for .eslint .prettier .jest etc.
Would be fab! |
Please add this feature! |
Any news on this? |
+1 |
Shared configs can already be done with base configs. If you are truly passionate in your crusade against files in root, consider "scripts": {
"build": "tsc -p .config/tsconfig.json"
} or pull it out of package.json at build-time. "scripts": {
- "build": "tsc"
+ "build": "cat package.json | jq .typescriptConfig > tsconfig.json && tsc && rm tsconfig.json"
} or "scripts": {
+ "prebuild": "cat package.json | jq .typescriptConfig > tsconfig.json",
"build": "tsc",
+ "postbuild": "rm tsconfig.json",
}
I'm with @ljharb, and I do not want to relive the madness which was how every snowflake package built with webpack/babel wanted to configure it in some different way. |
@philihp IDEs (e.g. IntelliJ) use tsconfig.json (e.g. compilerOptions.baseUrl from it for source code navigation). |
IDEs can update plugins to support it if they want to. I would be surprised if they don’t already read data from package.json for other things (scripts, for example). If the feature isn’t even optionally there, this is just circular. |
@ZeroVa IDEs (at least jetbrains' ones) obviously read all the data from package.json, including scripts (and everything else, dependencies, jest configuration, eslint configuration etc). There is no |
@philihp I appreciate your suggestion, but this is at its core a crusade against accidental complexity, which your build steps only add to.
Consolidating dependency configs in We already use it for configuring I can configure |
Sorry I’m not a library maintainer but I just want to say this: please enable tsconfig.json in package.json. Js ecosystem has to stop writing config files at the root. It has to be in one place: package.json. That’s it |
@jakobrosenberg
idiomatic convention across projects makes it easier to context switch between them, and speeds up new developer onboarding. additional thought: you probably want to avoid too much in package.json because your CI's node_modules cache often keys off of a hash of it. This can be be really annoying in large monorepos. |
I endorse your comment @philihp BTW, but still when you don't have a large monorepo but a humble little project you want to give the developer options to still stick the tsConfig in the package.json. For now I can think of the following workarounds/ideas until tsconfig.json is supported in package.json. I'm sharing these so maybe an actually working life hack may spin off of this.
"scripts": {
"start": "tsc -p config/tsconfig.json && node .",
// other scripts...
}
// package.json
"scripts": {
"postinstall": "node config/createSymlink.js",
// other scripts...
} // config/createSymlink.js
const fs = require('fs');
const path = require('path');
const os = require('os');
const tsConfigPath = path.join(__dirname, 'config', 'tsconfig.json');
const symlinkPath = path.join(__dirname, 'tsconfig.json');
if (fs.existsSync(symlinkPath)) {
fs.unlinkSync(symlinkPath);
}
if (os.platform() === 'win32') {
// On Windows, use a junction.
fs.symlinkSync(tsConfigPath, symlinkPath, 'junction');
} else {
// On Unix, use a symbolic link.
fs.symlinkSync(tsConfigPath, symlinkPath);
} |
A humble little project would still be impacted by slower install times by having a larger packument because tsconfig (a large file) is inlined within it. |
Then don’t use it if that’s your concern but don’t force others to follow
your style. Maybe that is less of a concern for others. I could see the
objection if it was that you were forced to do it that way. But all that is
being requested is the option to do so.
…On Fri, 14 Jun 2024 at 16:16, Jordan Harband ***@***.***> wrote:
A humble little project would still be impacted by slower install times by
having a larger packument because tsconfig (a large file) is inlined within
it.
—
Reply to this email directly, view it on GitHub
<#32830 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ARUILX4VSJUZE3THYUCI44LZHMCOJAVCNFSM4ILFXYSKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMJWHAZDKMZWHE4A>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
If you author a package in my dep graph, I'm forced to download your tsconfig twice - once as part of the initial packument fetching to build the graph, and another inside the package tarball. Config in package.json for a library can't be used without forcing consumers to suffer from it. |
tbf, if you really wanted a concise package.json, you would pass it though a build step to remove all extra keys and minify it
tsconfig would just be one more thing that could go in there
…________________________________
From: Jordan Harband ***@***.***>
Sent: Friday, June 14, 2024 3:47:03 PM
To: microsoft/TypeScript ***@***.***>
Cc: Paul Reid ***@***.***>; Mention ***@***.***>
Subject: Re: [microsoft/TypeScript] Configure from package.json (#32830)
If you author a package in my dep graph, I'm forced to download your tsconfig twice - once as part of the initial packument fetching to build the graph, and another inside the package tarball. Config in package.json for a library can't be used without forcing consumers to suffer from it.
—
Reply to this email directly, view it on GitHub<#32830 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AOT5DERUS56VN5ZBAQZL4DTZHNJEPAVCNFSM4ILFXYSKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMJWHA3TIMJVGQ2Q>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Search Terms
package.json, config, configuration, tsconfig
Suggestion
Allow
package.json
as an alternate source fortsconfig.json
options. To be clear, I am requesting that you please re-evaluate #6590 - it has been 2 years since that issue was posted, so interests may have changed and I believe this feature holds good value.UPDATE: 2022-04-28
Please vote how you would like to see this feature implemented here: #32830 (comment)
Use Cases
Provide a broader configuration support and decluttering the project root of configuration files that can easily be moved to
package.json
.Some users prefer to store their all their configuration files in 1 larger file. Right now, that is not an option.
Examples
Example of what the
package.json
would look like.Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: