Skip to content

Allow specifying exclude as a command line optionΒ #46005

@remcohaszing

Description

@remcohaszing

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.:

{
  "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'"
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions