ts-checker-rspack-plugin 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -119,45 +119,72 @@ Options for the TypeScript checker (`typescript` option object).
119
119
  ### Issues options
120
120
 
121
121
  Options for the issues filtering (`issue` option object).
122
- I could write some plain text explanation of these options but I think code will explain it better:
122
+
123
+ - **Type**:
123
124
 
124
125
  ```typescript
126
+ interface IssueOptions {
127
+ include?: IssuePredicateOption;
128
+ exclude?: IssuePredicateOption;
129
+ defaultSeverity?: 'auto' | 'warning' | 'error';
130
+ }
131
+
125
132
  interface Issue {
126
133
  severity: 'error' | 'warning';
127
134
  code: string;
135
+ // file field supports glob matching
128
136
  file?: string;
129
137
  }
130
138
 
131
- type IssueMatch = Partial<Issue>; // file field supports glob matching
139
+ type IssueMatch = Partial<Issue>;
132
140
  type IssuePredicate = (issue: Issue) => boolean;
133
- type IssueFilter = IssueMatch | IssuePredicate | (IssueMatch | IssuePredicate)[];
141
+ type IssuePredicateOption = IssuePredicate | IssueMatch | (IssuePredicate | IssueMatch)[];
134
142
  ```
135
143
 
136
- | Name | Type | Default value | Description |
137
- | --------- | ------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
138
- | `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. |
139
- | `exclude` | `IssueFilter` | `undefined` | Same as `include` but issues that match this predicate will be excluded. |
144
+ | Name | Type | Default value | Description |
145
+ | ----------------- | -------------------------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
146
+ | `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. |
147
+ | `exclude` | `IssueFilter` | `undefined` | Same as `include` but issues that match this predicate will be excluded. |
148
+ | `defaultSeverity` | `'auto' \| 'warning' \| 'error'` | `'auto'` | Controls how the plugin assigns the severity of emitted issues. |
149
+
150
+ `defaultSeverity` behavior:
151
+
152
+ - `auto`: Uses the default mapping based on the TypeScript diagnostic category (`Error` → `error`, `Warning` → `warning`).
153
+ - `warning`: Forces all issues to be emitted as warnings.
154
+ - `error`: Forces all issues to be emitted as errors.
140
155
 
141
- <details>
142
- <summary>Expand example</summary>
156
+ - **Example**:
143
157
 
144
158
  Include issues from the `src` directory, exclude issues from `.spec.ts` files:
145
159
 
146
160
  ```js
147
- module.exports = {
148
- // ...the Rspack configuration
149
- plugins: [
150
- new TsCheckerRspackPlugin({
151
- issue: {
152
- include: [{ file: '**/src/**/*' }],
153
- exclude: [{ file: '**/*.spec.ts' }],
154
- },
155
- }),
156
- ],
157
- };
161
+ new TsCheckerRspackPlugin({
162
+ issue: {
163
+ include: [{ file: '**/src/**/*' }],
164
+ exclude: [{ file: '**/*.spec.ts' }],
165
+ },
166
+ });
158
167
  ```
159
168
 
160
- </details>
169
+ Exclude files under `/node_modules/` using `file:`:
170
+
171
+ ```js
172
+ new TsCheckerRspackPlugin({
173
+ issue: {
174
+ exclude: [({ file = '' }) => /[\\/]some-folder[\\/]/.test(file)],
175
+ },
176
+ });
177
+ ```
178
+
179
+ Force all issues to be emitted as warnings and do not break the build:
180
+
181
+ ```js
182
+ new TsCheckerRspackPlugin({
183
+ issue: {
184
+ defaultSeverity: 'warning',
185
+ },
186
+ });
187
+ ```
161
188
 
162
189
  ## Plugin hooks
163
190
 
@@ -220,7 +247,27 @@ setting "generateTrace" compiler option. This is an instruction from [microsoft/
220
247
 
221
248
  ## Enabling incremental mode
222
249
 
223
- You must both set "incremental": true in your `tsconfig.json` (under `compilerOptions`) and also specify mode: 'write-references' in `TsCheckerRspackPlugin` settings.
250
+ You must both set `"compilerOptions.incremental": true` in your `tsconfig.json` and also specify `build: true` in `TsCheckerRspackPlugin` settings.
251
+
252
+ - `tsconfig.json`:
253
+
254
+ ```diff
255
+ {
256
+ "compilerOptions": {
257
+ + "incremental": true,
258
+ }
259
+ }
260
+ ```
261
+
262
+ - `TsCheckerRspackPlugin` settings:
263
+
264
+ ```js
265
+ new TsCheckerRspackPlugin({
266
+ typescript: {
267
+ build: true,
268
+ },
269
+ });
270
+ ```
224
271
 
225
272
  ## Vue components
226
273
 
@@ -125,12 +125,12 @@ const diagnosticsPerConfigFile = new Map();
125
125
  function updateDiagnostics(configFile, diagnostics) {
126
126
  diagnosticsPerConfigFile.set(configFile, diagnostics);
127
127
  }
128
- function getIssues() {
128
+ function getIssues(defaultSeverity) {
129
129
  const allDiagnostics = [];
130
130
  diagnosticsPerConfigFile.forEach((diagnostics)=>{
131
131
  allDiagnostics.push(...diagnostics);
132
132
  });
133
- return createIssuesFromDiagnostics(allDiagnostics);
133
+ return createIssuesFromDiagnostics(allDiagnostics, defaultSeverity);
134
134
  }
135
135
  function invalidateDiagnostics() {
136
136
  diagnosticsPerConfigFile.clear();
@@ -155,7 +155,7 @@ ${e.stack}`,
155
155
  }
156
156
  return programDiagnostics;
157
157
  }
158
- function createIssueFromDiagnostic(diagnostic) {
158
+ function createIssueFromDiagnostic(diagnostic, defaultSeverity) {
159
159
  let file;
160
160
  let location;
161
161
  if (diagnostic.file) {
@@ -175,16 +175,20 @@ function createIssueFromDiagnostic(diagnostic) {
175
175
  };
176
176
  }
177
177
  }
178
+ const getSeverity = ()=>{
179
+ if ('auto' === defaultSeverity) return 0 === diagnostic.category ? 'warning' : 'error';
180
+ return defaultSeverity;
181
+ };
178
182
  return {
179
183
  code: 'TS' + String(diagnostic.code),
180
- severity: 0 === diagnostic.category ? 'warning' : 'error',
184
+ severity: getSeverity(),
181
185
  message: typescript.flattenDiagnosticMessageText(diagnostic.messageText, external_os_namespaceObject.EOL),
182
186
  file,
183
187
  location
184
188
  };
185
189
  }
186
- function createIssuesFromDiagnostics(diagnostics) {
187
- return deduplicateAndSortIssues(diagnostics.map((diagnostic)=>createIssueFromDiagnostic(diagnostic)));
190
+ function createIssuesFromDiagnostics(diagnostics, defaultSeverity) {
191
+ return deduplicateAndSortIssues(diagnostics.map((diagnostic)=>createIssueFromDiagnostic(diagnostic, defaultSeverity)));
188
192
  }
189
193
  const external_memfs_namespaceObject = require("memfs");
190
194
  const external_node_fs_namespaceObject = require("node:fs");
@@ -679,8 +683,8 @@ function parseConfig(configFileName, configFileContext) {
679
683
  ] : parsedConfigFile.errors
680
684
  };
681
685
  }
682
- function getParseConfigIssues() {
683
- const issues = createIssuesFromDiagnostics(parseConfigDiagnostics);
686
+ function getParseConfigIssues(defaultSeverity) {
687
+ const issues = createIssuesFromDiagnostics(parseConfigDiagnostics, defaultSeverity);
684
688
  issues.forEach((issue)=>{
685
689
  if (!issue.file) issue.file = worker_config_config.configFile;
686
690
  });
@@ -1044,7 +1048,7 @@ function invalidateWatchProgram(withHost = false) {
1044
1048
  function invalidateWatchProgramRootFileNames() {
1045
1049
  shouldUpdateRootFiles = true;
1046
1050
  }
1047
- const getIssuesWorker = async (change, watching)=>{
1051
+ const getIssuesWorker = async (change, watching, defaultSeverity)=>{
1048
1052
  system.invalidateCache();
1049
1053
  if (didConfigFileChanged(change)) {
1050
1054
  invalidateConfig();
@@ -1066,7 +1070,7 @@ const getIssuesWorker = async (change, watching)=>{
1066
1070
  }
1067
1071
  registerArtifacts();
1068
1072
  enablePerformanceIfNeeded();
1069
- const parseConfigIssues = getParseConfigIssues();
1073
+ const parseConfigIssues = getParseConfigIssues(defaultSeverity);
1070
1074
  if (parseConfigIssues.length) return parseConfigIssues;
1071
1075
  if (worker_config_config.build) useSolutionBuilder();
1072
1076
  else if (watching) useWatchProgram();
@@ -1078,7 +1082,7 @@ const getIssuesWorker = async (change, watching)=>{
1078
1082
  system?.invokeFileDeleted(deletedFile);
1079
1083
  });
1080
1084
  await system.waitForQueued();
1081
- const issues = getIssues();
1085
+ const issues = getIssues(defaultSeverity);
1082
1086
  dumpTracingLegendIfNeeded();
1083
1087
  printPerformanceMeasuresIfNeeded();
1084
1088
  disablePerformanceIfNeeded();
package/lib/index.js CHANGED
@@ -744,7 +744,7 @@ function tapStartToRunWorkers(compiler, getIssuesWorker, getDependenciesWorker,
744
744
  return issuesPool.submit(async ()=>{
745
745
  try {
746
746
  debug(`Running the getIssuesWorker, iteration ${iteration}.`);
747
- const issues = await getIssuesWorker(aggregatedFilesChange, state.watching);
747
+ const issues = await getIssuesWorker(aggregatedFilesChange, state.watching, config.issue.defaultSeverity);
748
748
  if (state.aggregatedFilesChange === aggregatedFilesChange) state.aggregatedFilesChange = void 0;
749
749
  if (state.abortController === abortController) state.abortController = void 0;
750
750
  return issues;
@@ -854,8 +854,10 @@ function createIssueConfig(compiler, options) {
854
854
  if (!options) options = {};
855
855
  const include = options.include ? createIssuePredicateFromOption(context, options.include) : createTrivialIssuePredicate(true);
856
856
  const exclude = options.exclude ? createIssuePredicateFromOption(context, options.exclude) : createTrivialIssuePredicate(false);
857
+ const defaultSeverity = options.defaultSeverity ?? 'auto';
857
858
  return {
858
- predicate: (issue)=>include(issue) && !exclude(issue)
859
+ predicate: (issue)=>include(issue) && !exclude(issue),
860
+ defaultSeverity
859
861
  };
860
862
  }
861
863
  function createTypeScriptWorkerConfig(compiler, options) {
@@ -1,8 +1,10 @@
1
1
  import type * as rspack from '@rspack/core';
2
2
  import type { IssueOptions } from './issue-options';
3
3
  import type { IssuePredicate } from './issue-predicate';
4
+ import type { IssueDefaultSeverity } from './issue-severity';
4
5
  interface IssueConfig {
5
6
  predicate: IssuePredicate;
7
+ defaultSeverity: IssueDefaultSeverity;
6
8
  }
7
9
  declare function createIssueConfig(compiler: rspack.Compiler, options: IssueOptions | undefined): IssueConfig;
8
10
  export { IssueConfig, createIssueConfig };
@@ -1,8 +1,10 @@
1
1
  import type { IssueMatch } from './issue-match';
2
2
  import type { IssuePredicate } from './issue-predicate';
3
+ import type { IssueDefaultSeverity } from './issue-severity';
3
4
  type IssuePredicateOption = IssuePredicate | IssueMatch | (IssuePredicate | IssueMatch)[];
4
5
  interface IssueOptions {
5
6
  include?: IssuePredicateOption;
6
7
  exclude?: IssuePredicateOption;
8
+ defaultSeverity?: IssueDefaultSeverity;
7
9
  }
8
10
  export { IssueOptions, IssuePredicateOption };
@@ -1,4 +1,4 @@
1
- type IssueSeverity = 'error' | 'warning';
2
- declare function isIssueSeverity(value: unknown): value is IssueSeverity;
3
- declare function compareIssueSeverities(severityA: IssueSeverity, severityB: IssueSeverity): number;
4
- export { IssueSeverity, isIssueSeverity, compareIssueSeverities };
1
+ export type IssueSeverity = 'error' | 'warning';
2
+ export type IssueDefaultSeverity = IssueSeverity | 'auto';
3
+ export declare function isIssueSeverity(value: unknown): value is IssueSeverity;
4
+ export declare function compareIssueSeverities(severityA: IssueSeverity, severityB: IssueSeverity): number;
@@ -1,5 +1,5 @@
1
1
  import type { FilesChange } from '../../files-change';
2
- import type { Issue } from '../../issue';
3
- declare const getIssuesWorker: (change: FilesChange, watching: boolean) => Promise<Issue[]>;
2
+ import type { Issue, IssueDefaultSeverity } from '../../issue';
3
+ declare const getIssuesWorker: (change: FilesChange, watching: boolean, defaultSeverity: IssueDefaultSeverity) => Promise<Issue[]>;
4
4
  export type GetIssuesWorker = typeof getIssuesWorker;
5
5
  export {};
@@ -1,9 +1,9 @@
1
1
  import type * as ts from 'typescript';
2
2
  import type { FilesChange } from '../../../files-change';
3
3
  import type { FilesMatch } from '../../../files-match';
4
- import type { Issue } from '../../../issue';
4
+ import type { Issue, IssueDefaultSeverity } from '../../../issue';
5
5
  export declare function parseConfig(configFileName: string, configFileContext: string): ts.ParsedCommandLine;
6
- export declare function getParseConfigIssues(): Issue[];
6
+ export declare function getParseConfigIssues(defaultSeverity: IssueDefaultSeverity): Issue[];
7
7
  export declare function getParsedConfig(force?: boolean): ts.ParsedCommandLine;
8
8
  export declare function parseNextConfig(): readonly [ts.ParsedCommandLine | undefined, ts.ParsedCommandLine];
9
9
  export declare function invalidateConfig(): void;
@@ -1,7 +1,7 @@
1
1
  import type * as ts from 'typescript';
2
- import type { Issue } from '../../../issue';
2
+ import type { Issue, IssueDefaultSeverity } from '../../../issue';
3
3
  export declare function updateDiagnostics(configFile: string, diagnostics: ts.Diagnostic[]): void;
4
- export declare function getIssues(): Issue[];
4
+ export declare function getIssues(defaultSeverity: IssueDefaultSeverity): Issue[];
5
5
  export declare function invalidateDiagnostics(): void;
6
6
  export declare function getDiagnosticsOfProgram(program: ts.Program | ts.BuilderProgram): ts.Diagnostic[];
7
- export declare function createIssuesFromDiagnostics(diagnostics: ts.Diagnostic[]): Issue[];
7
+ export declare function createIssuesFromDiagnostics(diagnostics: ts.Diagnostic[], defaultSeverity: IssueDefaultSeverity): Issue[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-checker-rspack-plugin",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Runs typescript type checker and linter on separate process.",
5
5
  "keywords": [
6
6
  "rspack",
@@ -35,10 +35,10 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@babel/code-frame": "^7.27.1",
38
- "@rspack/lite-tapable": "^1.0.1",
38
+ "@rspack/lite-tapable": "^1.1.0",
39
39
  "chokidar": "^3.6.0",
40
40
  "is-glob": "^4.0.3",
41
- "memfs": "^4.50.0",
41
+ "memfs": "^4.51.1",
42
42
  "minimatch": "^9.0.5",
43
43
  "picocolors": "^1.1.1"
44
44
  },
@@ -53,8 +53,8 @@
53
53
  },
54
54
  "devDependencies": {
55
55
  "@jest/console": "^27.5.1",
56
- "@rslib/core": "^0.17.0",
57
- "@rspack/core": "^1.6.0",
56
+ "@rslib/core": "^0.18.2",
57
+ "@rspack/core": "^1.6.5",
58
58
  "@types/babel__code-frame": "^7.0.6",
59
59
  "@types/is-glob": "^4.0.4",
60
60
  "@types/jest": "^27.5.2",
@@ -67,7 +67,7 @@
67
67
  "jest-environment-node": "^27.5.1",
68
68
  "jest-runner": "^27.5.1",
69
69
  "mock-fs": "^5.5.0",
70
- "prettier": "^3.6.2",
70
+ "prettier": "^3.7.3",
71
71
  "strip-ansi": "^6.0.1",
72
72
  "ts-jest": "^27.1.5",
73
73
  "typescript": "^5.9.3"
@@ -76,5 +76,5 @@
76
76
  "access": "public",
77
77
  "registry": "https://registry.npmjs.org/"
78
78
  },
79
- "packageManager": "pnpm@10.20.0"
79
+ "packageManager": "pnpm@10.24.0"
80
80
  }