Webpack plugin that runs typescript type checker on a separate process.
Installations
npm install fork-ts-checker-webpack-plugin
Developer
TypeStrong
Developer Guide
Module System
CommonJS
Min. Node Version
>=12.13.0
Typescript Support
Yes
Node Version
16.20.2
NPM Version
7.24.2
Statistics
1,958 Stars
642 Commits
244 Forks
20 Watching
9 Branches
113 Contributors
Updated on 23 Nov 2024
Languages
TypeScript (94.44%)
JavaScript (4.59%)
Dockerfile (0.91%)
Shell (0.07%)
Total Downloads
Cumulative downloads
Total Downloads
2,904,048,718
Last day
-2.9%
2,830,790
Compared to previous day
Last week
3%
14,670,556
Compared to previous week
Last month
12.1%
61,458,150
Compared to previous month
Last year
-11.1%
701,311,448
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
12
Peer Dependencies
2
Dev Dependencies
40
Fork TS Checker Webpack Plugin
Webpack plugin that runs TypeScript type checker on a separate process.
Features
- Speeds up TypeScript type checking (by moving it to a separate process) 🏎
- Supports modern TypeScript features like project references and incremental mode ✨
- Displays nice error messages with the code frame formatter 🌈
Installation
This plugin requires Node.js >=14.0.0+, Webpack ^5.11.0, TypeScript ^3.6.0
- If you depend on TypeScript 2.1 - 2.6.2, please use version 4 of the plugin.
- If you depend on Webpack 4, TypeScript 2.7 - 3.5.3 or ESLint feature, please use version 6 of the plugin.
- If you depend on Node.js 12, please use version 8 of the plugin.
- If you need Vue.js support, please use version 6 of ths plugin
1# with npm 2npm install --save-dev fork-ts-checker-webpack-plugin 3 4# with yarn 5yarn add --dev fork-ts-checker-webpack-plugin 6 7# with pnpm 8pnpm add -D fork-ts-checker-webpack-plugin
The minimal webpack config (with ts-loader)
1// webpack.config.js 2const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); 3 4module.exports = { 5 context: __dirname, // to automatically find tsconfig.json 6 entry: './src/index.ts', 7 resolve: { 8 extensions: [".ts", ".tsx", ".js"], 9 }, 10 module: { 11 rules: [ 12 { 13 test: /\.tsx?$/, 14 loader: 'ts-loader', 15 // add transpileOnly option if you use ts-loader < 9.3.0 16 // options: { 17 // transpileOnly: true 18 // } 19 } 20 ] 21 }, 22 plugins: [new ForkTsCheckerWebpackPlugin()], 23 watchOptions: { 24 // for some systems, watching many files can result in a lot of CPU or memory usage 25 // https://webpack.js.org/configuration/watch/#watchoptionsignored 26 // don't use this pattern, if you have a monorepo with linked packages 27 ignored: /node_modules/, 28 }, 29};
Examples how to configure it with babel-loader, ts-loader and Visual Studio Code are in the examples directory.
Modules resolution
It's very important to be aware that this plugin uses TypeScript's, not
webpack's modules resolution. It means that you have to setup tsconfig.json
correctly.
It's because of the performance - with TypeScript's module resolution we don't have to wait for webpack to compile files.
To debug TypeScript's modules resolution, you can use
tsc --traceResolution
command.
Options
This plugin uses cosmiconfig
. This means that besides the plugin constructor,
you can place your configuration in the:
"fork-ts-checker"
field in thepackage.json
.fork-ts-checkerrc
file in JSON or YAML formatfork-ts-checker.config.js
file exporting a JS object
Options passed to the plugin constructor will overwrite options from the cosmiconfig (using deepmerge).
Name | Type | Default value | Description |
---|---|---|---|
async | boolean | compiler.options.mode === 'development' | If true , reports issues after webpack's compilation is done. Thanks to that it doesn't block the compilation. Used only in the watch mode. |
typescript | object | {} | See TypeScript options. |
issue | object | {} | See Issues options. |
formatter | string or object or function | codeframe | Available formatters are basic , codeframe and a custom function . To configure codeframe formatter, pass: { type: 'codeframe', options: { <coderame options> } } . To use absolute file path, pass: { type: 'codeframe', pathType: 'absolute' } . |
logger | { log: function, error: function } or webpack-infrastructure | console | Console-like object to print issues in async mode. |
devServer | boolean | true | If set to false , errors will not be reported to Webpack Dev Server. |
TypeScript options
Options for the TypeScript checker (typescript
option object).
Name | Type | Default value | Description |
---|---|---|---|
memoryLimit | number | 2048 | Memory limit for the checker process in MB. If the process exits with the allocation failed error, try to increase this number. |
configFile | string | 'tsconfig.json' | Path to the tsconfig.json file (path relative to the compiler.options.context or absolute path) |
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 . |
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. 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 fork-ts-checker-webpack-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 . |
build | boolean | false | The equivalent of the --build flag for the tsc command. |
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 ). |
diagnosticOptions | object | { syntactic: false, semantic: true, declaration: false, global: false } | Settings to select which diagnostics do we want to perform. |
profile | boolean | false | Measures and prints timings related to the TypeScript performance. |
typescriptPath | string | require.resolve('typescript') | If supplied this is a custom path where TypeScript can be found. |
Issues options
Options for the issues filtering (issue
option object).
I could write some plain text explanation of these options but I think code will explain it better:
1interface Issue { 2 severity: 'error' | 'warning'; 3 code: string; 4 file?: string; 5} 6 7type IssueMatch = Partial<Issue>; // file field supports glob matching 8type IssuePredicate = (issue: Issue) => boolean; 9type IssueFilter = IssueMatch | IssuePredicate | (IssueMatch | IssuePredicate)[];
Name | Type | Default value | Description |
---|---|---|---|
include | IssueFilter | undefined | If object , defines issue properties that should be matched. If function , acts as a predicate where issue is an argument. |
exclude | IssueFilter | undefined | Same as include but issues that match this predicate will be excluded. |
Expand example
Include issues from the src
directory, exclude issues from .spec.ts
files:
1module.exports = { 2 // ...the webpack configuration 3 plugins: [ 4 new ForkTsCheckerWebpackPlugin({ 5 issue: { 6 include: [ 7 { file: '**/src/**/*' } 8 ], 9 exclude: [ 10 { file: '**/*.spec.ts' } 11 ] 12 } 13 }) 14 ] 15};
Plugin hooks
This plugin provides some custom webpack hooks:
Hook key | Type | Params | Description |
---|---|---|---|
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. |
waiting | SyncHook | compilation | Waiting for the issues checking. |
canceled | SyncHook | compilation | Issues checking for the compilation has been canceled. |
error | SyncHook | compilation | An error occurred during issues checking. |
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. |
To access plugin hooks and tap into the event, we need to use the getCompilerHooks
static method.
When we call this method with a webpack compiler instance, it returns the object with
tapable hooks where you can pass in your callbacks.
1// ./src/webpack/MyWebpackPlugin.js 2const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); 3 4class MyWebpackPlugin { 5 apply(compiler) { 6 const hooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(compiler); 7 8 // log some message on waiting 9 hooks.waiting.tap('MyPlugin', () => { 10 console.log('waiting for issues'); 11 }); 12 // don't show warnings 13 hooks.issues.tap('MyPlugin', (issues) => 14 issues.filter((issue) => issue.severity === 'error') 15 ); 16 } 17} 18 19module.exports = MyWebpackPlugin; 20 21// webpack.config.js 22const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); 23const MyWebpackPlugin = require('./src/webpack/MyWebpackPlugin'); 24 25module.exports = { 26 /* ... */ 27 plugins: [ 28 new ForkTsCheckerWebpackPlugin(), 29 new MyWebpackPlugin() 30 ] 31};
Profiling types resolution
When using TypeScript 4.3.0 or newer you can profile long type checks by setting "generateTrace" compiler option. This is an instruction from microsoft/TypeScript#40063:
- Set "generateTrace": "{folderName}" in your
tsconfig.json
(undercompilerOptions
) - Look in the resulting folder. If you used build mode, there will be a
legend.json
telling you what went where. Otherwise, there will betrace.json
file andtypes.json
files. - Navigate to edge://tracing or chrome://tracing and load
trace.json
- Expand Process 1 with the little triangle in the left sidebar
- Click on different blocks to see their payloads in the bottom pane
- Open
types.json
in an editor - When you see a type ID in the tracing output, go-to-line {id} to find data about that type
Enabling incremental mode
You must both set "incremental": true in your tsconfig.json
(under compilerOptions
) and also specify mode: 'write-references' in ForkTsCheckerWebpackPlugin
settings.
Related projects
ts-loader
- TypeScript loader for webpack.babel-loader
- Alternative TypeScript loader for webpack.fork-ts-checker-notifier-webpack-plugin
- Notifies about build status using system notifications (similar to the webpack-notifier).
Credits
This plugin was created in Realytics in 2017. Thank you for supporting Open Source.
License
MIT License
No vulnerabilities found.
Reason
GitHub workflow tokens follow principle of least privilege
Details
- Warn: jobLevel 'deployments' permission set to 'write': .github/workflows/main.yml:95
- Info: topLevel 'contents' permission set to 'read': .github/workflows/main.yml:4
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 8/13 approved changesets -- score normalized to 6
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:9: update your workflow using https://app.stepsecurity.io/secureworkflow/TypeStrong/fork-ts-checker-webpack-plugin/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/TypeStrong/fork-ts-checker-webpack-plugin/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/TypeStrong/fork-ts-checker-webpack-plugin/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:35: update your workflow using https://app.stepsecurity.io/secureworkflow/TypeStrong/fork-ts-checker-webpack-plugin/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:49: update your workflow using https://app.stepsecurity.io/secureworkflow/TypeStrong/fork-ts-checker-webpack-plugin/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:52: update your workflow using https://app.stepsecurity.io/secureworkflow/TypeStrong/fork-ts-checker-webpack-plugin/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:61: update your workflow using https://app.stepsecurity.io/secureworkflow/TypeStrong/fork-ts-checker-webpack-plugin/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:69: update your workflow using https://app.stepsecurity.io/secureworkflow/TypeStrong/fork-ts-checker-webpack-plugin/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:78: update your workflow using https://app.stepsecurity.io/secureworkflow/TypeStrong/fork-ts-checker-webpack-plugin/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:99: update your workflow using https://app.stepsecurity.io/secureworkflow/TypeStrong/fork-ts-checker-webpack-plugin/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:102: update your workflow using https://app.stepsecurity.io/secureworkflow/TypeStrong/fork-ts-checker-webpack-plugin/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:110: update your workflow using https://app.stepsecurity.io/secureworkflow/TypeStrong/fork-ts-checker-webpack-plugin/main.yml/main?enable=pin
- Warn: containerImage not pinned by hash: .devcontainer/Dockerfile:1: pin your Docker image by updating node:12 to node:12@sha256:01627afeb110b3054ba4a1405541ca095c8bfca1cb6f2be9479c767a2711879e
- Warn: npmCommand not pinned by hash: .devcontainer/Dockerfile:14-45
- Info: 0 out of 12 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 containerImage dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 29 are checked with a SAST tool
Reason
20 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-5v2h-r2cx-5xgj
- Warn: Project is vulnerable to: GHSA-rrrm-qjm4-v8hf
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-hj9c-8jmm-8c52
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-x2pg-mjhr-2m5x
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-4vvj-4cpr-p986
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
4.4
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to fork-ts-checker-webpack-plugin
fork-ts-checker-notifier-webpack-plugin
a notifier for users of fork-ts-checker-webpack-plugin
@k88/typescript-compile-error-formatter
Formats Typescript error messages from Fork TS Checker Webpack Plugin
gatsby-plugin-ts
Typescript support via ts-loader & fork-ts-checker-webpack-plugin + automate codegen
fork-ts-checker-webpack-plugin-alt
Runs typescript type checker and linter on separate process.