Skip to content

Commit 4b13fd3

Browse files
authored
feat: simplify logger options (#695)
Currently, the logger options are overcomplicated. To simplify them, we are removing logger.infrastructure option. BREAKING CHANGE: 🧨 Changes in options: `logger.issues` becomes `logger`, `logger.devServer` becomes `devServer`, `logger.infrastructure` has been removed
1 parent 39ebae6 commit 4b13fd3

14 files changed

+33
-170
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,14 @@ you can place your configuration in the:
8585

8686
Options passed to the plugin constructor will overwrite options from the cosmiconfig (using [deepmerge](https://github.com/TehShrike/deepmerge)).
8787

88-
| Name | Type | Default value | Description |
89-
| ----------------- | ---------------------------------- | ------------------------------------------------------------------ | ----------- |
90-
| `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. |
91-
| `typescript` | `object` | `{}` | See [TypeScript options](#typescript-options). |
92-
| `issue` | `object` | `{}` | See [Issues options](#issues-options). |
93-
| `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> } }`. |
94-
| `logger` | `object` | `{ infrastructure: 'silent', issues: 'console', devServer: true }` | Available loggers are `silent`, `console`, and `webpack-infrastructure`. Infrastructure logger prints additional information, issue logger prints `issues` in the `async` mode. If `devServer` is set to `false`, errors will not be reported to Webpack Dev Server. |
88+
| Name | Type | Default value | Description |
89+
| ----------------- | ------------------------------------ | ----------------------------------------- | ----------- |
90+
| `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. |
91+
| `typescript` | `object` | `{}` | See [TypeScript options](#typescript-options). |
92+
| `issue` | `object` | `{}` | See [Issues options](#issues-options). |
93+
| `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> } }`. |
94+
| `logger` | `{ log: function, error: function }` | `console` | Console-like object to print issues in `async` mode. |
95+
| `devServer` | `boolean` | `true` | If set to `false`, errors will not be reported to Webpack Dev Server. |
9596

9697
### TypeScript options
9798

@@ -105,7 +106,7 @@ Options for the TypeScript checker (`typescript` option object).
105106
| `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 `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`. |
106107
| `build` | `boolean` | `false` | The equivalent of the `--build` flag for the `tsc` command. |
107108
| `mode` | `'readonly'` or `'write-tsbuildinfo'` or `'write-references'` | `'write-tsbuildinfo'` | If you use the `babel-loader`, it's recommended to use `write-references` mode to improve initial compilation time. If you use `ts-loader`, it's recommended to use `write-tsbuildinfo` mode to not overwrite files emitted by the `ts-loader`. |
108-
| `diagnosticOptions` | `object` | `{ syntactic: false, semantic: true, declaration: false, global: false }` | Settings to select which diagnostics do we want to perform. |
109+
| `diagnosticOptions` | `object` | `{ syntactic: false, semantic: true, declaration: false, global: false }` | Settings to select which diagnostics do we want to perform. |
109110
| `extensions` | `object` | `{}` | See [TypeScript extensions options](#typescript-extensions-options). |
110111
| `profile` | `boolean` | `false` | Measures and prints timings related to the TypeScript performance. |
111112
| `typescriptPath` | `string` | `require.resolve('typescript')` | If supplied this is a custom path where TypeScript can be found. |

src/hooks/intercept-done-to-get-dev-server-tap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function interceptDoneToGetDevServerTap(
1414
// inspired by https://github.com/ypresto/fork-ts-checker-async-overlay-webpack-plugin
1515
compiler.hooks.done.intercept({
1616
register: (tap) => {
17-
if (tap.name === 'webpack-dev-server' && tap.type === 'sync' && config.logger.devServer) {
17+
if (tap.name === 'webpack-dev-server' && tap.type === 'sync' && config.devServer) {
1818
debug('Intercepting webpack-dev-server tap.');
1919
state.webpackDevServerDoneTap = tap;
2020
}

src/hooks/tap-done-to-async-get-issues.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function tapDoneToAsyncGetIssues(
3131
try {
3232
if (await isPending(issuesPromise)) {
3333
hooks.waiting.call(stats.compilation);
34-
config.logger.issues.log(chalk.cyan('Issues checking in progress...'));
34+
config.logger.log(chalk.cyan('Issues checking in progress...'));
3535
} else {
3636
// wait 10ms to log issues after webpack stats
3737
await wait(10);
@@ -59,9 +59,9 @@ function tapDoneToAsyncGetIssues(
5959

6060
if (issues.length) {
6161
// follow webpack's approach - one process.write to stderr with all errors and warnings
62-
config.logger.issues.error(issues.map((issue) => formatter(issue)).join('\n'));
62+
config.logger.error(issues.map((issue) => formatter(issue)).join('\n'));
6363
} else {
64-
config.logger.issues.log(chalk.green('No issues found.'));
64+
config.logger.log(chalk.green('No issues found.'));
6565
}
6666

6767
// report issues to webpack-dev-server, if it's listening

src/hooks/tap-error-to-log-message.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ function tapErrorToLogMessage(
1212
const hooks = getPluginHooks(compiler);
1313

1414
hooks.error.tap('ForkTsCheckerWebpackPlugin', (error) => {
15-
config.logger.issues.error(String(error));
15+
config.logger.error(String(error));
1616

1717
if (error instanceof RpcExitError) {
1818
if (error.signal === 'SIGINT') {
19-
config.logger.issues.error(
19+
config.logger.error(
2020
chalk.red(
2121
'Issues checking service interrupted - If running in a docker container, this may be caused ' +
2222
"by the container running out of memory. If so, try increasing the container's memory limit " +
2323
'or lowering the `memoryLimit` value in the ForkTsCheckerWebpackPlugin configuration.'
2424
)
2525
);
2626
} else {
27-
config.logger.issues.error(
27+
config.logger.error(
2828
chalk.red(
2929
'Issues checking service aborted - probably out of memory. ' +
3030
'Check the `memoryLimit` option in the ForkTsCheckerWebpackPlugin configuration.\n' +
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
interface Logger {
2-
info: (message: string) => void;
32
log: (message: string) => void;
43
error: (message: string) => void;
54
}
65

7-
export default Logger;
6+
export { Logger };

src/logger/logger-config.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/logger/logger-factory.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/logger/logger-options.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/logger/partial-logger.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/logger/webpack-infrastructure-logger.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)