Skip to content

Commit a6b66eb

Browse files
piecykpiotr-oles
authored andcommitted
feat: allow to use webpack infrastructure logger
1 parent 78b6090 commit a6b66eb

File tree

4 files changed

+42
-36
lines changed

4 files changed

+42
-36
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module.exports = {
7070
## Modules resolution
7171

7272
It's very important to be aware that **this plugin uses [TypeScript](https://github.com/Microsoft/TypeScript)'s, not
73-
[webpack](https://github.com/webpack/webpack)'s modules resolution**. It means that you have to setup `tsconfig.json` correctly.
73+
[webpack](https://github.com/webpack/webpack)'s modules resolution**. It means that you have to setup `tsconfig.json` correctly.
7474

7575
> It's because of the performance - with TypeScript's module resolution we don't have to wait for webpack to compile files.
7676
>
@@ -83,7 +83,7 @@ you can place your configuration in the:
8383
* `"fork-ts-checker"` field in the `package.json`
8484
* `.fork-ts-checkerrc` file in JSON or YAML format
8585
* `fork-ts-checker.config.js` file exporting a JS object
86-
86+
8787
Options passed to the plugin constructor will overwrite options from the cosmiconfig (using [deepmerge](https://github.com/TehShrike/deepmerge)).
8888

8989
| Name | Type | Default value | Description |
@@ -92,7 +92,7 @@ Options passed to the plugin constructor will overwrite options from the cosmico
9292
| `typescript` | `object` | `{}` | See [TypeScript options](#typescript-options). |
9393
| `issue` | `object` | `{}` | See [Issues options](#issues-options). |
9494
| `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 object: `{ type: 'codeframe', options: { <coderame options> } }`. |
95-
| `logger` | `{ log: function, error: function }` | `console` | Console-like object to print issues in `async` mode. |
95+
| `logger` | `{ log: function, error: function }` or `webpack-infrastructure` | `console` | Console-like object to print issues in `async` mode. |
9696
| `devServer` | `boolean` | `true` | If set to `false`, errors will not be reported to Webpack Dev Server. |
9797

9898
### TypeScript options
@@ -120,7 +120,7 @@ Options for the TypeScript checker extensions (`typescript.extensions` option ob
120120
|----------------|-----------------------|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
121121
| `vue` | `object` or `boolean` | `false` | If `true`, it enables Vue [Single File Component](https://vuejs.org/v2/guide/single-file-components.html) support. |
122122
| `vue.enabled` | `boolean` | `false` | Same as the `vue` option |
123-
| `vue.compiler` | `string` | `'vue-template-compiler'` | The package name of the compiler that will be used to parse `.vue` files. You can use `'nativescript-vue-template-compiler'` if you use [nativescript-vue](https://github.com/nativescript-vue/nativescript-vue) |
123+
| `vue.compiler` | `string` | `'vue-template-compiler'` | The package name of the compiler that will be used to parse `.vue` files. You can use `'nativescript-vue-template-compiler'` if you use [nativescript-vue](https://github.com/nativescript-vue/nativescript-vue) |
124124

125125
### Issues options
126126

@@ -184,11 +184,11 @@ To enable Vue.js support, follow these steps:
184184
```sh
185185
# with npm
186186
npm install --save vue vue-class-component
187-
npm install --save-dev vue-loader ts-loader css-loader vue-template-compiler
187+
npm install --save-dev vue-loader ts-loader css-loader vue-template-compiler
188188

189189
# with yarn
190190
yarn add vue vue-class-component
191-
yarn add --dev vue-loader ts-loader css-loader vue-template-compiler
191+
yarn add --dev vue-loader ts-loader css-loader vue-template-compiler
192192
```
193193

194194
2. Add `tsconfig.json` configuration:
@@ -311,7 +311,7 @@ class MyWebpackPlugin {
311311
console.log('waiting for issues');
312312
});
313313
// don't show warnings
314-
hooks.issues.tap('MyPlugin', (issues) =>
314+
hooks.issues.tap('MyPlugin', (issues) =>
315315
issues.filter((issue) => issue.severity === 'error')
316316
);
317317
}
@@ -335,7 +335,7 @@ module.exports = {
335335
## Typings
336336

337337
To use the plugin typings, you have to install `@types/webpack`. It's not included by default to not collide with your
338-
existing typings (`@types/webpack` imports `@types/node`). [It's an old TypeScript issue](https://github.com/microsoft/TypeScript/issues/18588),
338+
existing typings (`@types/webpack` imports `@types/node`). [It's an old TypeScript issue](https://github.com/microsoft/TypeScript/issues/18588),
339339
the alternative is to set `skipLibCheck: true` in the `compilerOptions` 😉
340340
```sh
341341
# with npm
@@ -351,7 +351,7 @@ Starting from TypeScript 4.1.0, you can profile long type checks by
351351
setting "generateTrace" compiler option. This is an instruction from [microsoft/TypeScript#40063](https://github.com/microsoft/TypeScript/pull/40063):
352352

353353
1. Set "generateTrace": "{folderName}" in your `tsconfig.json`
354-
2. Look in the resulting folder. If you used build mode, there will be a `legend.json` telling you what went where.
354+
2. Look in the resulting folder. If you used build mode, there will be a `legend.json` telling you what went where.
355355
Otherwise, there will be `trace.json` file and `types.json` files.
356356
3. Navigate to [edge://tracing](edge://tracing) or [chrome://tracing](chrome://tracing) and load `trace.json`
357357
4. Expand Process 1 with the little triangle in the left sidebar
@@ -361,7 +361,7 @@ setting "generateTrace" compiler option. This is an instruction from [microsoft/
361361

362362

363363
## Related projects
364-
364+
365365
* [`ts-loader`](https://github.com/TypeStrong/ts-loader) - TypeScript loader for webpack.
366366
* [`babel-loader`](https://github.com/babel/babel-loader) - Alternative TypeScript loader for webpack.
367367
* [`fork-ts-checker-notifier-webpack-plugin`](https://github.com/johnnyreilly/fork-ts-checker-notifier-webpack-plugin) - Notifies about build status using system notifications (similar to the [webpack-notifier](https://github.com/Turbo87/webpack-notifier)).

src/plugin-config.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type webpack from 'webpack';
22

33
import type { FormatterConfig } from './formatter';
44
import { createFormatterConfig } from './formatter';
5+
import { getInfrastructureLogger } from './infrastructure-logger';
56
import type { IssueConfig } from './issue/issue-config';
67
import { createIssueConfig } from './issue/issue-config';
78
import type { Logger } from './logger';
@@ -27,7 +28,17 @@ function createPluginConfig(
2728
typescript: createTypeScriptWorkerConfig(compiler, options.typescript),
2829
issue: createIssueConfig(compiler, options.issue),
2930
formatter: createFormatterConfig(options.formatter),
30-
logger: options.logger || console,
31+
logger:
32+
options.logger === 'webpack-infrastructure'
33+
? (() => {
34+
const { info, error } = getInfrastructureLogger(compiler);
35+
36+
return {
37+
log: info,
38+
error,
39+
};
40+
})()
41+
: options.logger || console,
3142
devServer: options.devServer !== false,
3243
};
3344
}

src/plugin-options.json

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,18 @@
3939
"additionalProperties": true
4040
}
4141
},
42-
"required": [
43-
"type"
44-
]
42+
"required": ["type"]
4543
},
4644
"FormatterType": {
4745
"type": "string",
48-
"enum": [
49-
"basic",
50-
"codeframe"
51-
]
46+
"enum": ["basic", "codeframe"]
5247
},
5348
"IssueMatch": {
5449
"type": "object",
5550
"properties": {
5651
"severity": {
5752
"type": "string",
58-
"enum": [
59-
"error",
60-
"warning"
61-
]
53+
"enum": ["error", "warning"]
6254
},
6355
"code": {
6456
"type": "string"
@@ -95,15 +87,23 @@
9587
]
9688
},
9789
"Logger": {
98-
"type": "object",
99-
"properties": {
100-
"error": {
101-
"instanceof": "Function"
90+
"oneOf": [
91+
{
92+
"type": "object",
93+
"properties": {
94+
"error": {
95+
"instanceof": "Function"
96+
},
97+
"log": {
98+
"instanceof": "Function"
99+
}
100+
}
102101
},
103-
"log": {
104-
"instanceof": "Function"
102+
{
103+
"type": "string",
104+
"enum": ["webpack-infrastructure"]
105105
}
106-
}
106+
]
107107
},
108108
"TypeScriptOptions": {
109109
"type": "object",
@@ -126,12 +126,7 @@
126126
},
127127
"mode": {
128128
"type": "string",
129-
"enum": [
130-
"readonly",
131-
"write-tsbuildinfo",
132-
"write-dts",
133-
"write-references"
134-
],
129+
"enum": ["readonly", "write-tsbuildinfo", "write-dts", "write-references"],
135130
"description": "`readonly` keeps all emitted files in memory, `write-tsbuildinfo` which writes only .tsbuildinfo files, `write-dts` writes .tsbuildinfo and type definition files, and `write-references` which writes both .tsbuildinfo and referenced projects output"
136131
},
137132
"compilerOptions": {

src/plugin-options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface ForkTsCheckerWebpackPluginOptions {
88
typescript?: TypeScriptWorkerOptions;
99
formatter?: FormatterOptions;
1010
issue?: IssueOptions;
11-
logger?: Logger;
11+
logger?: Logger | 'webpack-infrastructure';
1212
devServer?: boolean;
1313
}
1414

0 commit comments

Comments
 (0)