Skip to content

Commit

Permalink
feat: port changes from main branch (#649)
Browse files Browse the repository at this point in the history
This commit contains fixes from the main branch
  • Loading branch information
piotr-oles committed Aug 26, 2021
1 parent 82e8448 commit ad466df
Show file tree
Hide file tree
Showing 22 changed files with 259 additions and 178 deletions.
23 changes: 16 additions & 7 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
# Configuration for probot-stale - https://github.com/probot/stale

# Number of days of inactivity before an Issue or Pull Request becomes stale
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 60

# Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
daysUntilClose: 14
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- pinned
- security
# Label to use when marking an issue as stale
staleLabel: wontfix
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,17 @@ Options passed to the plugin constructor will overwrite options from the cosmico
| 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` or `boolean` | `true` | If a `boolean`, it enables/disables TypeScript checker. If an `object`, see [TypeScript options](#typescript-options). |
| `typescript` | `object` | `{}` | See [TypeScript options](#typescript-options). |
| `issue` | `object` | `{}` | See [Issues options](#issues-options). |
| `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> } }`. |
| `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. |
| `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. |

### TypeScript options

Options for the TypeScript checker (`typescript` option object).

| Name | Type | Default value | Description |
| -------------------- | --------- | -------------------------------------------------------------------------------------------------------------- | ----------- |
| `enabled` | `boolean` | `true` | If `true`, it enables TypeScript checker. |
| `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`. |
Expand Down
46 changes: 25 additions & 21 deletions src/ForkTsCheckerWebpackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import schema from './ForkTsCheckerWebpackPluginOptions.json';
import { ForkTsCheckerWebpackPluginOptions } from './ForkTsCheckerWebpackPluginOptions';
import { createForkTsCheckerWebpackPluginConfiguration } from './ForkTsCheckerWebpackPluginConfiguration';
import { createForkTsCheckerWebpackPluginState } from './ForkTsCheckerWebpackPluginState';
import { composeReporterRpcClients, createAggregatedReporter, ReporterRpcClient } from './reporter';
import { assertTypeScriptSupport } from './typescript-reporter/TypeScriptSupport';
import { createTypeScriptReporterRpcClient } from './typescript-reporter/reporter/TypeScriptReporterRpcClient';
import { tapStartToConnectAndRunReporter } from './hooks/tapStartToConnectAndRunReporter';
Expand All @@ -27,9 +26,18 @@ class ForkTsCheckerWebpackPlugin {
*/
static readonly version: string = '{{VERSION}}'; // will be replaced by the @semantic-release/exec
/**
* Default pool for the plugin concurrency limit
* Default pools for the plugin concurrency limit
*/
static readonly pool: Pool = createPool(Math.max(1, os.cpus().length));
static readonly issuesPool: Pool = createPool(Math.max(1, os.cpus().length));
static readonly dependenciesPool: Pool = createPool(Math.max(1, os.cpus().length));

/**
* @deprecated Use ForkTsCheckerWebpackPlugin.issuesPool instead
*/
static get pool(): Pool {
// for backward compatibility
return ForkTsCheckerWebpackPlugin.issuesPool;
}

private readonly options: ForkTsCheckerWebpackPluginOptions;

Expand All @@ -54,26 +62,22 @@ class ForkTsCheckerWebpackPlugin {
apply(compiler: webpack.Compiler) {
const configuration = createForkTsCheckerWebpackPluginConfiguration(compiler, this.options);
const state = createForkTsCheckerWebpackPluginState();
const reporters: ReporterRpcClient[] = [];

if (configuration.typescript.enabled) {
assertTypeScriptSupport(configuration.typescript);
reporters.push(createTypeScriptReporterRpcClient(configuration.typescript));
}

if (reporters.length) {
const reporter = createAggregatedReporter(composeReporterRpcClients(reporters));
assertTypeScriptSupport(configuration.typescript);
const issuesReporter = createTypeScriptReporterRpcClient(configuration.typescript);
const dependenciesReporter = createTypeScriptReporterRpcClient(configuration.typescript);

tapAfterEnvironmentToPatchWatching(compiler, state);
tapStartToConnectAndRunReporter(compiler, reporter, configuration, state);
tapAfterCompileToAddDependencies(compiler, configuration, state);
tapStopToDisconnectReporter(compiler, reporter, state);
tapErrorToLogMessage(compiler, configuration);
} else {
throw new Error(
`ForkTsCheckerWebpackPlugin is configured to not use any issue reporter. It's probably a configuration issue.`
);
}
tapAfterEnvironmentToPatchWatching(compiler, state);
tapStartToConnectAndRunReporter(
compiler,
issuesReporter,
dependenciesReporter,
configuration,
state
);
tapAfterCompileToAddDependencies(compiler, configuration, state);
tapStopToDisconnectReporter(compiler, issuesReporter, dependenciesReporter, state);
tapErrorToLogMessage(compiler, configuration);
}
}

Expand Down
144 changes: 74 additions & 70 deletions src/ForkTsCheckerWebpackPluginOptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,26 @@
"additionalProperties": true
}
},
"required": ["type"]
"required": [
"type"
]
},
"FormatterType": {
"FormatterType": {
"type": "string",
"enum": ["basic", "codeframe"]
"enum": [
"basic",
"codeframe"
]
},
"IssueMatch": {
"type": "object",
"properties": {
"severity": {
"type": "string",
"enum": ["error", "warning"]
"enum": [
"error",
"warning"
]
},
"code": {
"type": "string"
Expand Down Expand Up @@ -84,7 +92,11 @@
},
"LoggerType": {
"type": "string",
"enum": ["console", "webpack-infrastructure", "silent"]
"enum": [
"console",
"webpack-infrastructure",
"silent"
]
},
"Logger": {
"type": "object",
Expand All @@ -101,81 +113,73 @@
}
},
"TypeScriptReporterOptions": {
"oneOf": [
{
"type": "object",
"properties": {
"memoryLimit": {
"type": "number",
"description": "Memory limit for TypeScript reporter process."
},
"configFile": {
"type": "string",
"description": "Path to tsconfig.json. By default plugin uses context or process.cwd() to localize tsconfig.json file."
},
"context": {
"type": "string",
"description": "The base path for finding files specified in the tsconfig.json. Same as context option from the ts-loader."
},
"build": {
"type": "boolean",
"description": "Enable TypeScript reporter."
"description": "The equivalent of the `--build` flag from the `tsc`."
},
{
"mode": {
"type": "string",
"enum": [
"readonly",
"write-tsbuildinfo",
"write-references"
],
"description": "`readonly` keeps all emitted files in memory, `write-tsbuildinfo` which writes only .tsbuildinfo files and `write-references` which writes both .tsbuildinfo and referenced projects output"
},
"compilerOptions": {
"type": "object",
"description": "Custom compilerOptions to be passed to the TypeScript compiler.",
"additionalProperties": true
},
"diagnosticOptions": {
"type": "object",
"description": "Types of diagnostics to be reported.",
"properties": {
"enabled": {
"type": "boolean",
"description": "Enable TypeScript reporter."
"syntactic": {
"type": "boolean"
},
"memoryLimit": {
"type": "number",
"description": "Memory limit for TypeScript reporter process."
"semantic": {
"type": "boolean"
},
"configFile": {
"type": "string",
"description": "Path to tsconfig.json. By default plugin uses context or process.cwd() to localize tsconfig.json file."
},
"context": {
"type": "string",
"description": "The base path for finding files specified in the tsconfig.json. Same as context option from the ts-loader."
"declaration": {
"type": "boolean"
},
"build": {
"type": "boolean",
"description": "The equivalent of the `--build` flag from the `tsc`."
},
"mode": {
"type": "string",
"enum": ["readonly", "write-tsbuildinfo", "write-references"],
"description": "`readonly` keeps all emitted files in memory, `write-tsbuildinfo` which writes only .tsbuildinfo files and `write-references` which writes both .tsbuildinfo and referenced projects output"
},
"compilerOptions": {
"type": "object",
"description": "Custom compilerOptions to be passed to the TypeScript compiler.",
"additionalProperties": true
},
"diagnosticOptions": {
"type": "object",
"description": "Types of diagnostics to be reported.",
"properties": {
"syntactic": {
"type": "boolean"
},
"semantic": {
"type": "boolean"
},
"declaration": {
"type": "boolean"
},
"global": {
"type": "boolean"
}
}
},
"extensions": {
"type": "object",
"properties": {
"vue": {
"$ref": "#/definitions/TypeScriptVueExtensionOptions"
}
}
},
"profile": {
"type": "boolean",
"description": "Measures and prints timings related to the TypeScript performance."
},
"typescriptPath": {
"type": "string",
"description": "If supplied this is a custom path where TypeScript can be found."
"global": {
"type": "boolean"
}
}
},
"extensions": {
"type": "object",
"properties": {
"vue": {
"$ref": "#/definitions/TypeScriptVueExtensionOptions"
}
}
},
"profile": {
"type": "boolean",
"description": "Measures and prints timings related to the TypeScript performance."
},
"typescriptPath": {
"type": "string",
"description": "If supplied this is a custom path where TypeScript can be found."
}
]
}
},
"TypeScriptVueExtensionOptions": {
"oneOf": [
Expand Down
6 changes: 4 additions & 2 deletions src/ForkTsCheckerWebpackPluginState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { FilesMatch, Report } from './reporter';
import { Issue } from './issue';

interface ForkTsCheckerWebpackPluginState {
reportPromise: Promise<Report | undefined>;
issuesReportPromise: Promise<Report | undefined>;
dependenciesReportPromise: Promise<Report | undefined>;
issuesPromise: Promise<Issue[] | undefined>;
dependenciesPromise: Promise<FilesMatch | undefined>;
lastDependencies: FilesMatch | undefined;
Expand All @@ -14,7 +15,8 @@ interface ForkTsCheckerWebpackPluginState {

function createForkTsCheckerWebpackPluginState(): ForkTsCheckerWebpackPluginState {
return {
reportPromise: Promise.resolve(undefined),
issuesReportPromise: Promise.resolve(undefined),
dependenciesReportPromise: Promise.resolve(undefined),
issuesPromise: Promise.resolve(undefined),
dependenciesPromise: Promise.resolve(undefined),
lastDependencies: undefined,
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/tapDoneToAsyncGetIssues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function tapDoneToAsyncGetIssues(
return;
}

const reportPromise = state.reportPromise;
const reportPromise = state.issuesReportPromise;
const issuesPromise = state.issuesPromise;
let issues: Issue[] | undefined;

Expand All @@ -46,7 +46,7 @@ function tapDoneToAsyncGetIssues(
return;
}

if (reportPromise !== state.reportPromise) {
if (reportPromise !== state.issuesReportPromise) {
// there is a newer report - ignore this one
return;
}
Expand Down

0 comments on commit ad466df

Please sign in to comment.