TypeScript
TypeScript copied to clipboard
Allow specifying exclude as a command line option
Suggestion
🔍 Search Terms
List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.
exclude cli
✅ Viability Checklist
My suggestion meets these guidelines:
- [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
- [x] This wouldn't change the runtime behavior of existing JavaScript code
- [x] This could be implemented without emitting different JS based on the types of the expressions
- [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- [x] This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
I would like to be able to specify the exclude option which exists in tsconfig.json as a command line option.
📃 Motivating Example
The tsc command line tool now supports the --exclude option. This option behaves the same as the "exclude": [] option in tsconfig.json.
💻 Use Cases
In my experienct a TypeScript project currently typically needs 3 files (excluding actual code);
tsconfig.json for type checking, including tests etc.:
{
"compilerOptions": {
"declaration": true,
"noEmit": true,
// … Add more options as desired
}
}
tsconfig.build.json for building a project, excluding tests etc. (this can be named however you like)
{
"extends": "./tsconfig.json",
// The real exclude patterns are project specific.
"exclude": ["__tests__", "*.test.ts", "*.spec.js"],
"compilerOptions": {
// Actually do emit when building.
"noEmit": false
}
}
package.json including a prepack script for building the project:
{
"scripts": {
"prepack": "tsc -P tsconfig.build.json"
}
}
Introducing the --exclude command line option removes the need for a custom build tsconfig. This unclutters the project root by removing the need for a specific tsconfig file only for building. So basically the following changes can be made:
tsconfig.build.json is deleted:
- {
- "extends": "./tsconfig.json",
- // The real exclude patterns are project specific.
- "exclude": ["__tests__", "*.test.ts", "*.spec.js"],
- "compilerOptions": {
- // Actually do emit when building.
- "noEmit": false
- }
- }
package.json now uses the tsconfig.json file, but specifies the exclude pattern:
{
"scripts": {
- "prepack": "tsc -P tsconfig.build.json"
+ "prepack": "tsc --noEmit false --exclude '__tests__' --exclude '*.test.ts' --exclude '*.spec.js'"
}
}
I just ran into this issue. It was a little surprising that CLI has so many params but not the exclude. My case is the same: type checking of all ts files and building without tests.
i would love an exclude option too. there are too many configs in a monorepo with all the toolings (prettier, tsconfig, ...). it would make things easier
Absolutely agree with this. I was surprised there's no way to do this as it is. I'm also trying to keep to one tsconfig.json file and being allowed to specify an --exclude parameter would make that possible.
Just hopping on, agreed that a --exclude flag in the CLI would be a good addition.
Would like this too! I have a use case for using the tsconfig.json file for most of my tsc use, and then with a different configuration using the cli flags in a different part of the project.
I also want this. My client and server code is in a flatter directory structure than a complete "client" & "server" separation (as there is some shared model code), and I'm currently building server code with tsc and bundling client and React code with Parcel. tsconfig includes the entire source folder i.e. the client and server code.
Currently I cannot have the flexibility of node scripts:
- Building all the code
- Building only the server code
I either have to change the tsconfig each time or use a CLI exclude flag that can be added to another node script. Of course there are solutions but I prefer the flexibility of an exclude flag on the CLI
I also have this exact same usecase. I would like to compile my code without tests so that I can quickly prototype something and then fix the tests at the end.
#54410 is somewhat related.
is there an option to do this?
It seems natural to expect parity between the command line flags of the tsc cli and tsconfig.json. For instance, webpack supports a cli where "Any parameters sent to the CLI will map to a corresponding parameter in the configuration file."
My use case is that I'd like to download a github repo by tag with the degit tool, make no changes to the repository (Not create an additional tsconfig.declaration.ts), and generate declaration files for the repo simply by executing.
tsc --declaration --emitDeclarationOnly --declarationDir ./myDeclarations --exclude "src/**/*.spec.ts"
I want this to be a helper npm script in my project root as "postinstall":, where I would rather not need to invoke touch to create the custom tsconfig as it would break platform compatibility.
Have we heard any comment from anyone on the TypeScript team? This has been open for almost 3 years with many folks having similar needs and no response? I would greatly appreciate it if the TypeScript team could at least acknowledge the "issue", maybe provide a recommended "workaround" and if the TypeScript team down not feel this is a good thing to add to the CLI then it would be wonderful to have an explanation. Thanks!
Why has this not been done? This is a no-brainer.