-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Description
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:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- 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.:
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'"
}
}
{ "compilerOptions": { "declaration": true, "noEmit": true, // β¦ Add more options as desired } }