{"id":21687827,"url":"https://github.com/rspack-contrib/ts-checker-rspack-plugin","last_synced_at":"2025-04-14T10:13:23.728Z","repository":{"id":264453150,"uuid":"893353413","full_name":"rspack-contrib/ts-checker-rspack-plugin","owner":"rspack-contrib","description":"Rspack plugin that runs typescript type checker on a separate process.","archived":false,"fork":false,"pushed_at":"2025-02-08T07:32:15.000Z","size":4392,"stargazers_count":9,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-14T10:13:18.911Z","etag":null,"topics":["rspack","types","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rspack-contrib.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-24T07:58:26.000Z","updated_at":"2025-04-11T11:55:22.000Z","dependencies_parsed_at":"2024-11-24T13:08:11.641Z","dependency_job_id":"7d368699-799e-4570-88ae-d278e5152416","html_url":"https://github.com/rspack-contrib/ts-checker-rspack-plugin","commit_stats":null,"previous_names":["rspack-contrib/ts-checker-rspack-plugin"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rspack-contrib%2Fts-checker-rspack-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rspack-contrib%2Fts-checker-rspack-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rspack-contrib%2Fts-checker-rspack-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rspack-contrib%2Fts-checker-rspack-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rspack-contrib","download_url":"https://codeload.github.com/rspack-contrib/ts-checker-rspack-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248860167,"owners_count":21173342,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rspack","types","typescript"],"created_at":"2024-11-25T17:01:19.127Z","updated_at":"2025-04-14T10:13:23.718Z","avatar_url":"https://github.com/rspack-contrib.png","language":"TypeScript","funding_links":[],"categories":["Plugins"],"sub_categories":["Rspack Plugins"],"readme":"# ts-checker-rspack-plugin\n\nRspack plugin that runs TypeScript type checker on a separate process.\n\n\u003cp\u003e\n  \u003ca href=\"https://npmjs.com/package/ts-checker-rspack-plugin\"\u003e\n   \u003cimg src=\"https://img.shields.io/npm/v/ts-checker-rspack-plugin?style=flat-square\u0026colorA=564341\u0026colorB=EDED91\" alt=\"npm version\" /\u003e\n  \u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square\u0026colorA=564341\u0026colorB=EDED91\" alt=\"license\" /\u003e\n  \u003ca href=\"https://npmcharts.com/compare/ts-checker-rspack-plugin?minimal=true\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/ts-checker-rspack-plugin.svg?style=flat-square\u0026colorA=564341\u0026colorB=EDED91\" alt=\"downloads\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Credits\n\nThis plugin is forked from [TypeStrong/fork-ts-checker-webpack-plugin](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin), which is created by [Piotr Oleś](https://github.com/piotr-oles). See the original project's [LICENSE](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/blob/main/LICENSE).\n\nBig thanks to `fork-ts-checker-webpack-plugin` creators and contributors for their great work. ❤️\n\n## Features\n\n- Speeds up [TypeScript](https://github.com/Microsoft/TypeScript) type checking (by moving it to a separate process) 🏎\n- Supports modern TypeScript features like [project references](https://www.typescriptlang.org/docs/handbook/project-references.html) and [incremental mode](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#faster-subsequent-builds-with-the---incremental-flag) ✨\n- Displays nice error messages with the [code frame](https://babeljs.io/docs/en/next/babel-code-frame.html) formatter 🌈\n\n💡 For Rsbuild projects, use [@rsbuild/plugin-type-check](https://github.com/rspack-contrib/rsbuild-plugin-type-check) to get out-of-the-box experience.\n\n## Installation\n\nThis plugin requires **Node.js \u003e=16.0.0+**, **Rspack ^1.0.0**, **TypeScript ^3.8.0**\n\n```sh\n# with npm\nnpm install -D ts-checker-rspack-plugin\n\n# with yarn\nyarn add -D ts-checker-rspack-plugin\n\n# with pnpm\npnpm add -D ts-checker-rspack-plugin\n```\n\nThe minimal Rspack config with [builtin:swc-loader](https://rspack.dev/guide/features/builtin-swc-loader).\n\n```js\n// rspack.config.js\nconst { TsCheckerRspackPlugin } = require('ts-checker-rspack-plugin');\n\nmodule.exports = {\n  context: __dirname, // to automatically find tsconfig.json\n  entry: './src/index.ts',\n  resolve: {\n    extensions: ['.ts', '.tsx', '.js'],\n  },\n  module: {\n    rules: [\n      {\n        test: /\\.tsx?$/,\n        loader: 'builtin:swc-loader',\n        options: {\n          jsc: {\n            parser: {\n              syntax: 'typescript',\n            },\n          },\n        },\n      },\n    ],\n  },\n  plugins: [new TsCheckerRspackPlugin()],\n  watchOptions: {\n    // for some systems, watching many files can result in a lot of CPU or memory usage\n    // https://rspack.dev/config/watch#watchoptionsignored\n    // don't use this pattern, if you have a monorepo with linked packages\n    ignored: /node_modules/,\n  },\n};\n```\n\n## Modules resolution\n\nIt's very important to be aware that **this plugin uses [TypeScript](https://github.com/Microsoft/TypeScript)'s, not\nRspack's modules resolution**. It means that you have to setup `tsconfig.json` correctly.\n\n\u003e It's because of the performance - with TypeScript's module resolution we don't have to wait for Rspack to compile files.\n\u003e\n\u003e To debug TypeScript's modules resolution, you can use `tsc --traceResolution` command.\n\n## Options\n\n| Name         | Type                                                             | Default value                             | Description                                                                                                                                                                                                                                                                                                       |\n| ------------ | ---------------------------------------------------------------- | ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `async`      | `boolean`                                                        | `compiler.options.mode === 'development'` | If `true`, reports issues **after** Rspack's compilation is done. Thanks to that it doesn't block the compilation. Used only in the `watch` mode.                                                                                                                                                                 |\n| `typescript` | `object`                                                         | `{}`                                      | See [TypeScript options](#typescript-options).                                                                                                                                                                                                                                                                    |\n| `issue`      | `object`                                                         | `{}`                                      | See [Issues options](#issues-options).                                                                                                                                                                                                                                                                            |\n| `formatter`  | `string` or `object` or `function`                               | `codeframe`                               | Available formatters are `basic`, `codeframe` and a custom `function`. To [configure](https://babeljs.io/docs/en/babel-code-frame#options) `codeframe` formatter, pass: `{ type: 'codeframe', options: { \u003ccoderame options\u003e } }`. To use absolute file path, pass: `{ type: 'codeframe', pathType: 'absolute' }`. |\n| `logger`     | `{ log: function, error: function }` or `webpack-infrastructure` | `console`                                 | Console-like object to print issues in `async` mode.                                                                                                                                                                                                                                                              |\n| `devServer`  | `boolean`                                                        | `true`                                    | If set to `false`, errors will not be reported to Dev Server and displayed in the error overlay.                                                                                                                                                                                                                                                     |\n\n### TypeScript options\n\nOptions for the TypeScript checker (`typescript` option object).\n\n| Name                | Type                                                                           | Default value                                                                                                  | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |\n| ------------------- | ------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `memoryLimit`       | `number`                                                                       | `8192`                                                                                                         | Memory limit for the checker process in MB. If the process exits with the allocation failed error, try to increase this number.                                                                                                                                                                                                                                                                                                                                                                                                                                          |\n| `configFile`        | `string`                                                                       | `'tsconfig.json'`                                                                                              | Path to the `tsconfig.json` file (path relative to the `compiler.options.context` or absolute path)                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |\n| `configOverwrite`   | `object`                                                                       | `{ compilerOptions: { skipLibCheck: true, sourceMap: false, inlineSourceMap: false, declarationMap: false } }` | This configuration will overwrite configuration from the `tsconfig.json` file. Supported fields are: `extends`, `compilerOptions`, `include`, `exclude`, `files`, and `references`.                                                                                                                                                                                                                                                                                                                                                                                      |\n| `context`           | `string`                                                                       | `dirname(configuration.configFile)`                                                                            | The base path for finding files specified in the `tsconfig.json`. Same as the `context` option from the [ts-loader](https://github.com/TypeStrong/ts-loader#context). Useful if you want to keep your `tsconfig.json` in an external package. Keep in mind that **not** having a `tsconfig.json` in your project root can cause different behaviour between `ts-checker-rspack-plugin` and `tsc`. When using editors like `VS Code` it is advised to add a `tsconfig.json` file to the root of the project and extend the config file referenced in option `configFile`. |\n| `build`             | `boolean`                                                                      | `false`                                                                                                        | The equivalent of the `--build` flag for the `tsc` command.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |\n| `mode`              | `'readonly'` or `'write-dts'` or `'write-tsbuildinfo'` or `'write-references'` | `build === true ? 'write-tsbuildinfo' ? 'readonly'`                                                            | Use `readonly` if you don't want to write anything on the disk, `write-dts` to write only `.d.ts` files, `write-tsbuildinfo` to write only `.tsbuildinfo` files, `write-references` to write both `.js` and `.d.ts` files of project references (last 2 modes requires `build: true`).                                                                                                                                                                                                                                                                                   |\n| `diagnosticOptions` | `object`                                                                       | `{ syntactic: false, semantic: true, declaration: false, global: false }`                                      | Settings to select which diagnostics do we want to perform.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |\n| `profile`           | `boolean`                                                                      | `false`                                                                                                        | Measures and prints timings related to the TypeScript performance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |\n| `typescriptPath`    | `string`                                                                       | `require.resolve('typescript')`                                                                                | If supplied this is a custom path where TypeScript can be found.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |\n\n### Issues options\n\nOptions for the issues filtering (`issue` option object).\nI could write some plain text explanation of these options but I think code will explain it better:\n\n```typescript\ninterface Issue {\n  severity: 'error' | 'warning';\n  code: string;\n  file?: string;\n}\n\ntype IssueMatch = Partial\u003cIssue\u003e; // file field supports glob matching\ntype IssuePredicate = (issue: Issue) =\u003e boolean;\ntype IssueFilter = IssueMatch | IssuePredicate | (IssueMatch | IssuePredicate)[];\n```\n\n| Name      | Type          | Default value | Description                                                                                                                                                |\n| --------- | ------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `include` | `IssueFilter` | `undefined`   | If `object`, defines issue properties that should be [matched](src/issue/issue-match.ts). If `function`, acts as a predicate where `issue` is an argument. |\n| `exclude` | `IssueFilter` | `undefined`   | Same as `include` but issues that match this predicate will be excluded.                                                                                   |\n\n\u003cdetails\u003e\n\u003csummary\u003eExpand example\u003c/summary\u003e\n\nInclude issues from the `src` directory, exclude issues from `.spec.ts` files:\n\n```js\nmodule.exports = {\n  // ...the Rspack configuration\n  plugins: [\n    new TsCheckerRspackPlugin({\n      issue: {\n        include: [{ file: '**/src/**/*' }],\n        exclude: [{ file: '**/*.spec.ts' }],\n      },\n    }),\n  ],\n};\n```\n\n\u003c/details\u003e\n\n## Plugin hooks\n\nThis plugin provides some custom Rspack hooks:\n\n| Hook key   | Type                       | Params                | Description                                                                                                                                                        |\n| ---------- | -------------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `start`    | `AsyncSeriesWaterfallHook` | `change, compilation` | Starts issues checking for a compilation. It's an async waterfall hook, so you can modify the list of changed and removed files or delay the start of the service. |\n| `waiting`  | `SyncHook`                 | `compilation`         | Waiting for the issues checking.                                                                                                                                   |\n| `canceled` | `SyncHook`                 | `compilation`         | Issues checking for the compilation has been canceled.                                                                                                             |\n| `error`    | `SyncHook`                 | `compilation`         | An error occurred during issues checking.                                                                                                                          |\n| `issues`   | `SyncWaterfallHook`        | `issues, compilation` | Issues have been received and will be reported. It's a waterfall hook, so you can modify the list of received issues.                                              |\n\nTo access plugin hooks and tap into the event, we need to use the `getCompilerHooks` static method.\nWhen we call this method with a [Rspack compiler instance](https://rspack.dev/api/javascript-api/compiler), it returns the object with\n[tapable](https://github.com/webpack/tapable) hooks where you can pass in your callbacks.\n\n```js\n// ./src/rspack/MyRspackPlugin.js\nconst { TsCheckerRspackPlugin } = require('ts-checker-rspack-plugin');\n\nclass MyRspackPlugin {\n  apply(compiler) {\n    const hooks = TsCheckerRspackPlugin.getCompilerHooks(compiler);\n\n    // log some message on waiting\n    hooks.waiting.tap('MyPlugin', () =\u003e {\n      console.log('waiting for issues');\n    });\n    // don't show warnings\n    hooks.issues.tap('MyPlugin', (issues) =\u003e issues.filter((issue) =\u003e issue.severity === 'error'));\n  }\n}\n\nmodule.exports = MyRspackPlugin;\n\n// rspack.config.js\nconst { TsCheckerRspackPlugin } = require('ts-checker-rspack-plugin');\nconst MyRspackPlugin = require('./src/rspack/MyRspackPlugin');\n\nmodule.exports = {\n  /* ... */\n  plugins: [new TsCheckerRspackPlugin(), new MyRspackPlugin()],\n};\n```\n\n## Profiling types resolution\n\nWhen using TypeScript 4.3.0 or newer you can profile long type checks by\nsetting \"generateTrace\" compiler option. This is an instruction from [microsoft/TypeScript#40063](https://github.com/microsoft/TypeScript/pull/40063):\n\n1. Set \"generateTrace\": \"{folderName}\" in your `tsconfig.json` (under `compilerOptions`)\n2. Look in the resulting folder. If you used build mode, there will be a `legend.json` telling you what went where.\n   Otherwise, there will be `trace.json` file and `types.json` files.\n3. Navigate to [edge://tracing](edge://tracing) or [chrome://tracing](chrome://tracing) and load `trace.json`\n4. Expand Process 1 with the little triangle in the left sidebar\n5. Click on different blocks to see their payloads in the bottom pane\n6. Open `types.json` in an editor\n7. When you see a type ID in the tracing output, go-to-line {id} to find data about that type\n\n## Enabling incremental mode\n\nYou must both set \"incremental\": true in your `tsconfig.json` (under `compilerOptions`) and also specify mode: 'write-references' in `TsCheckerRspackPlugin` settings.\n\n## License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frspack-contrib%2Fts-checker-rspack-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frspack-contrib%2Fts-checker-rspack-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frspack-contrib%2Fts-checker-rspack-plugin/lists"}