0.2.0 - Mid migration

This commit is contained in:
Daniel Mason 2022-04-25 14:47:15 +12:00
parent 139e6a915e
commit 7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions

View file

@ -0,0 +1,318 @@
## ⚠️ Next versions are available only on the [GitHub Releases](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/releases) page ⚠️
# [1.3.0-beta.1](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/compare/v1.2.0...v1.3.0-beta.1@beta) (2019-04-30)
### Bug Fixes
- **tests:** fix linter tests that were doing nothing ([d078278](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/commit/d078278))
- **tests:** linter tests - useTypescriptIncrementalApi usage ([e0020d6](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/commit/e0020d6))
- **tests:** rework vue integration tests ([5ad2568](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/commit/5ad2568))
### Features
- **apiincrementalchecker:** improve generation of diagnostics ([ae80e5f](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/commit/ae80e5f)), closes [#257](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/issues/257)
# [1.2.0](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/compare/v1.1.1...v1.2.0) (2019-04-22)
### Bug Fixes
- semantic-release update `CHANGELOG.md` on the git repo ([8ad58af](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/commit/8ad58af))
### Features
- add semantic-release integration ([5fe0653](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/commit/5fe0653))
# [1.2.0-beta.4](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/compare/v1.2.0-beta.3@beta...v1.2.0-beta.4@beta) (2019-04-23)
### Bug Fixes
- **tests:** fix linter tests that were doing nothing ([d078278](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/commit/d078278))
- **tests:** linter tests - useTypescriptIncrementalApi usage ([e0020d6](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/commit/e0020d6))
### Features
- **apiincrementalchecker:** improve generation of diagnostics ([ae80e5f](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/commit/ae80e5f)), closes [#257](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/issues/257)
# [1.2.0-beta.3](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/compare/v1.2.0-beta.2@beta...v1.2.0-beta.3@beta) (2019-04-22)
### Bug Fixes
- **tests:** rework vue integration tests ([5ad2568](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/commit/5ad2568))
# [1.2.0-beta.2](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/compare/v1.2.0-beta.1@beta...v1.2.0-beta.2@beta) (2019-04-22)
### Bug Fixes
- semantic-release update `CHANGELOG.md` on the git repo ([8ad58af](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/commit/8ad58af))
# [1.2.0-beta.1](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/compare/v1.1.0...v1.2.0-beta.1@beta) (2019-04-22)
### Features
- add semantic-release integration ([5fe0653](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/commit/5fe0653))
## v1.1.1
- [Fix a regression w/ plugins like tsconfig-paths-webpack-plugin](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/260)
## v1.1.0
- [Add new custom resolution options](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/250)
## v1.0.4
- [gracefully handle error thrown from the service](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/249)
## v1.0.3
- [use worker-rpc library for inter-process communication](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/231)
## v1.0.2
- [Fix ignoreLintWarning mark warnings as errors](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/243)
## v1.0.1
- [Apply rounding to compilation time](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/235)
## v1.0.0
- [Going 1.0](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/218)
This is the first major version of `fork-ts-checker-webpack-plugin`. A long time coming :-)
There are actually no breaking changes that we're aware of; users of 0.x `fork-ts-checker-webpack-plugin` should be be able to upgrade without any drama. Users of TypeScript 3+ may notice a performance improvement as by default the plugin now uses the [incremental watch API](https://github.com/Microsoft/TypeScript/pull/20234) in TypeScript. Should this prove problematic you can opt out of using it by supplying `useTypescriptIncrementalApi: false`.
We are aware of an [issue with Vue and the incremental API](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/issues/219). We hope it will be fixed soon - a generous member of the community is taking a look. In the meantime, we will _not_ default to using the incremental watch API when in Vue mode.
The plugin supports webpack 2, 3, 4 and 5 alpha and TypeScript 2.1+ alongside tslint 4+.
See also: https://blog.johnnyreilly.com/2019/03/the-big-one-point-oh.html
## v1.0.0-alpha.10
- [Fix incremental api to work with TS 3+ by default](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/223)
## v1.0.0-alpha.9
- [Default to incremental api usage to true if TS 3+](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/217)
## v1.0.0-alpha.8
- [Respect tslint configs hierarchical order](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/214)
## v1.0.0-alpha.7
- [Add ignoreLintWarnings option](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/213)
## v1.0.0-alpha.6
- [don't directly depend upon typescript](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/208)
## v1.0.0-alpha.5
- [can now provide path where typescript can be found](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/204)
## v1.0.0-alpha.4
- [make node 6 compatible](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/202)
## v1.0.0-alpha.3
- [replace peerDeps with runtime checks](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/201)
## v1.0.0-alpha.2
- [Add `useTypescriptIncrementalApi`](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/198) (#196)
## v1.0.0-alpha.1
- [Use object-spread instead of `Object.assign`](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/194) (#194)
## v1.0.0-alpha.0
- [Add support for webpack 5](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/166)
### Breaking Changes
Version `1.x` additionally supports webpack 5 alongside webpack 4, whose hooks are now tapped differently:
```diff
- compiler.hooks.forkTsCheckerDone.tap(...args)
+ const forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(compiler)
+ forkTsCheckerHooks.done.tap(...args)
```
v1.0.0-alpha.0 drops support for node 6.
## v0.5.2
- [Fix erroneous error on diagnostics at 0 line; remove deprecated fs.existsSync](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/190) (#190)
## v0.5.1
- [Make the checker compile with TypeScript 3.2](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/189)
## 0.5.0
- Removed unused dependency `resolve`.
- Replace `lodash` usage with native calls.
- ** Breaking Changes**:
- Removed all getters from `NormalizedMessage`, use direct property access instead.
- **Internal**:
- Test against ts-loader v5
- Enable all strict type checks
- Update dev dependencies
## v0.4.15
- [Add `tslintAutoFix` option to be passed on to tslint to auto format typescript files](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/174) (#174)
## v0.4.14
- [Add support for `reportFiles` option](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/179) (#179)
## v0.4.13
- [Merge in `compilerOptions` prior to calling `parseJsonConfigFileContent`](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/176) (#176)
## v0.4.12
- [Add `compilerOptions` option](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/173) (#173)
## v0.4.11
- [Fix os.cpus is not a function](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/172) (#172)
## v0.4.10
- [Allow fork-ts-checker-webpack-plugin to be imported in .ts files using ESM import syntax](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/163) (#163)
## v0.4.9
- [Set "compilationDone" before resolving "forkTsCheckerServiceBeforeStart"](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/146) (#146)
## v0.4.8
- [Fix(types collision): update webpack](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/151) (#142)
## v0.4.7
- [Fix(types collision): update chalk and chokidar](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/147) (#142)
- [Fix(logger): Don't limit Options.logger to Console type](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/143)
## v0.4.6
- [Fix(types): Make options Partial<Options>](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/141) (#140)
## v0.4.5
- [Fix(types): Add types to the plugin](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/139) (#137)
- [Fix(vue): Avoid false positive of no-consecutive-blank-lines TSLint rule in Vue file](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/138) (#130)
## v0.4.4
- [Fix(vue): resolve src attribute on the script block on Vue files](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/130) (#111, #85)
- Add TypeScript ^3.0.0 to peerDependencies
## v0.4.3
- Fix "File system lag can cause Invalid source file errors to slip through" (#127)
## v0.4.2
- Format messages when `async` is false
## v0.4.1
- Fix webpack 4 hooks bug
## v0.4.0
- Support webpack 4
## v0.3.0
- Add `vue` support
## v0.2.10
- Fix #80 "Cannot read property 'getLineAndCharacterOfPosition' of undefined"
- Fix #76 "TypeError: Cannot read property '0' of undefined"
## v0.2.9
- Make errors formatting closer to `ts-loader` style
- Handle tslint exclude option
## v0.2.8
- Add `checkSyntacticErrors` option
- Fix `process.env` pass to the child process
- Add `fork-ts-checker-service-before-start` hook
## v0.2.7
- Fix service is not killed when webpack watch is done
## v0.2.6
- Add diagnostics/lints formatters - `formatter` and `formatterOptions` option
## v0.2.5
- Add `async` option - more information in `README.md`
## v0.2.4
- Fix `ESLint: "fork-ts-checker-webpack-plugin" is not published.` issue
## v0.2.3
- Add support for webpack 3 as peerDependency
## v0.2.2
- Force `isolatedModule: false` in checker compiler for better performance
## v0.2.1
- Fix for `tslint: true` option issue
## v0.2.0
- tsconfig.json and tslint.json path are not printed anymore.
- `watch` option is not used on 'build' mode
- Handle case with no options object (`new ForkTsCheckerWebpacPlugin()`)
- Basic integration tests (along units)
- **Breaking changes**:
- tslint is not enabled by default - you have to set `tslint: true` or `tslint: './path/to/tslint.json'` to enable it.
- `blockEmit` option is removed - it choose automatically - blocks always on 'build' mode, never on 'watch' mode.
## v0.1.5
- Disable tslint if module is not installed and no tslint path is passed
- Improve README.md
## v0.1.4
- Fix send to closed channel case
- Fix removed files case
- Add `fork-ts-checker-service-start-error` hook
## v0.1.3
- Fix "Cannot read property 'mtime' of undefined on OSX"
## v0.1.2
- Workers mode works correctly (fixed typo)
## v0.1.1
- Support memory limit in multi-process mode
- Handle already closed channel case on sending ipc message
## v0.1.0
- Initial release - not production ready.

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 TypeStrong
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,434 @@
<div align="center">
<h1>Fork TS Checker Webpack Plugin</h1>
<p>Webpack plugin that runs TypeScript type checker on a separate process.</p>
[![npm version](https://img.shields.io/npm/v/fork-ts-checker-webpack-plugin.svg)](https://www.npmjs.com/package/fork-ts-checker-webpack-plugin)
[![npm beta version](https://img.shields.io/npm/v/fork-ts-checker-webpack-plugin/beta.svg)](https://www.npmjs.com/package/fork-ts-checker-webpack-plugin)
[![build status](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/workflows/CI/CD/badge.svg?branch=master&event=push)](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/actions?query=branch%3Amaster+event%3Apush)
[![downloads](http://img.shields.io/npm/dm/fork-ts-checker-webpack-plugin.svg)](https://npmjs.org/package/fork-ts-checker-webpack-plugin)
[![commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
</div>
## Installation
This plugin requires minimum **Node.js 6.11.5**, **webpack 4**, **TypeScript 2.1** and optionally **ESLint 6** (which itself requires minimum **Node.js 8.10.0**)
If you depend on **webpack 2**, **webpack 3**, or **tslint 4**, please use [older version](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/tree/v3.1.1) of the plugin.
```sh
# with npm
npm install --save-dev fork-ts-checker-webpack-plugin
# with yarn
yarn add --dev fork-ts-checker-webpack-plugin
```
Basic webpack config (with [ts-loader](https://github.com/TypeStrong/ts-loader))
```js
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const webpackConfig = {
context: __dirname, // to automatically find tsconfig.json
entry: './src/index.ts',
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
// disable type checker - we will use it in fork plugin
transpileOnly: true
}
}
]
},
plugins: [new ForkTsCheckerWebpackPlugin()]
};
```
## Motivation
There was already similar solution - [awesome-typescript-loader](https://github.com/s-panferov/awesome-typescript-loader). You can
add `CheckerPlugin` and delegate checker to the separate process. The problem with `awesome-typescript-loader` was that, in our case,
it was a lot slower than [ts-loader](https://github.com/TypeStrong/ts-loader) on an incremental build (~20s vs ~3s).
Secondly, we used [tslint](https://palantir.github.io/tslint) and we wanted to run this, along with type checker, in a separate process.
This is why this plugin was created. To provide better performance, the plugin reuses Abstract Syntax Trees between compilations and shares
these trees with TSLint.
## Modules resolution
It's very important to be aware that **this plugin uses [TypeScript](https://github.com/Microsoft/TypeScript)'s, not
[webpack](https://github.com/webpack/webpack)'s modules resolution**. It means that you have to setup `tsconfig.json` correctly. For example
if you set `files: ['./src/someFile.ts']` in `tsconfig.json`, this plugin will check only `someFile.ts` for semantic errors. It's because
of performance. The goal of this plugin is to be _as fast as possible_. With TypeScript's module resolution we don't have to wait for webpack
to compile files (which traverses dependency graph during compilation) - we have a full list of files from the begin.
To debug TypeScript's modules resolution, you can use `tsc --traceResolution` command.
## ESLint
[ESLint is the future of linting in the TypeScript world.](https://eslint.org/blog/2019/01/future-typescript-eslint) If you'd like to use eslint with the plugin, supply this option: `eslint: true` and ensure you have the relevant dependencies installed:
`yarn add eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin --dev`
You should have an ESLint configuration file in your root project directory. Here is a sample `.eslintrc.js` configuration for a TypeScript project:
```js
const path = require('path');
module.exports = {
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
extends: [
'plugin:@typescript-eslint/recommended' // Uses the recommended rules from the @typescript-eslint/eslint-plugin
],
parserOptions: {
project: path.resolve(__dirname, './tsconfig.json'),
tsconfigRootDir: __dirname,
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
},
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
}
};
```
There's a good explanation on setting up TypeScript ESLint support by Robert Cooper [here](https://dev.to/robertcoopercode/using-eslint-and-prettier-in-a-typescript-project-53jb).
## Options
- **tsconfig** `string`:
Path to _tsconfig.json_ file. Default: `path.resolve(compiler.options.context, './tsconfig.json')`.
- **compilerOptions** `object`:
Allows overriding TypeScript options. Should be specified in the same format as you would do for the `compilerOptions` property in tsconfig.json. Default: `{}`.
- **eslint** `true | undefined`:
- If `true`, this activates eslint support.
- **eslintOptions** `object`:
- Options that can be used to initialise ESLint. See https://eslint.org/docs/developer-guide/nodejs-api#cliengine
- **async** `boolean`:
True by default - `async: false` can block webpack's emit to wait for type checker/linter and to add errors to the webpack's compilation.
We recommend to set this to `false` in projects where type checking is faster than webpack's build - it's better for integration with other plugins. Another scenario where you might want to set this to `false` is if you use the `overlay` functionality of `webpack-dev-server`.
- **ignoreDiagnostics** `number[]`:
List of TypeScript diagnostic codes to ignore.
- **ignoreLints** `string[]`:
List of eslint rule names to ignore.
- **ignoreLintWarnings** `boolean`:
If true, will ignore all lint warnings.
- **reportFiles** `string[]`:
Only report errors on files matching these glob patterns. This can be useful when certain types definitions have errors that are not fatal to your application. Default: `[]`. Please note that this may behave unexpectedly if using the incremental API as the incremental API doesn't look for global and semantic errors [if it has already found syntactic errors](https://github.com/Microsoft/TypeScript/blob/89386ddda7dafc63cb35560e05412487f47cc267/src/compiler/watch.ts#L141).
```js
// in webpack.config.js
new ForkTsCheckerWebpackPlugin({
reportFiles: ['src/**/*.{ts,tsx}', '!src/skip.ts']
});
```
- **logger** `object`:
Logger instance. It should be object that implements method: `error`, `warn`, `info`. Default: `console`.
- **formatter** `'default' | 'codeframe' | (issue: Issue) => string)`:
Formatter for issues and lints. By default uses `default` formatter. You can also pass your own formatter as a function
(see `src/issue/` and `src/formatter/` for API reference).
- **formatterOptions** `object`:
Options passed to formatters (currently only `codeframe` - see [available options](https://babeljs.io/docs/en/next/babel-code-frame.html#options))
- **silent** `boolean`:
If `true`, logger will not be used. Default: `false`.
- **checkSyntacticErrors** `boolean`:
This option is useful if you're using ts-loader in `happyPackMode` with [HappyPack](https://github.com/amireh/happypack) or [thread-loader](https://github.com/webpack-contrib/thread-loader) to parallelise your builds. If `true` it will ensure that the plugin checks for _both_ syntactic errors (eg `const array = [{} {}];`) and semantic errors (eg `const x: number = '1';`). By default the plugin only checks for semantic errors. This is because when ts-loader is used in `transpileOnly` mode, ts-loader will still report syntactic errors. When used in `happyPackMode` it does not. Default: `false`.
- **memoryLimit** `number`:
Memory limit for service process in MB. If service exits with allocation failed error, increase this number. Default: `2048`.
- **vue** `boolean | { enabled: boolean, compiler: string }`:
If `true` or `enabled: true`, the linter and compiler will process VueJs single-file-component (.vue) files. See the
[Vue section](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin#vue) further down for information on how to correctly setup your project.
- **useTypescriptIncrementalApi** `boolean`:
If true, the plugin will use incremental compilation API introduced in TypeScript 2.7. Defaults to `true` when working with TypeScript 3+ and `false` when below 3. The default can be overridden by directly specifying a value.
Don't use it together with VueJs enabled - it's not supported yet.
- **measureCompilationTime** `boolean`:
If true, the plugin will measure the time spent inside the compilation code. This may be useful to compare modes,
especially if there are other loaders/plugins involved in the compilation. **requires Node.js >= 8.5.0**
- **typescript** `string`:
If supplied this is a custom path where `typescript` can be found. Defaults to `require.resolve('typescript')`.
- **resolveModuleNameModule** and **resolveTypeReferenceDirectiveModule** `string`:
Both of those options refer to files on the disk that respectively export a `resolveModuleName` or a `resolveTypeReferenceDirectiveModule` function. These functions will be used to resolve the import statements and the `<reference types="...">` directives instead of the default TypeScript implementation. Check the following code for an example of what those functions should look like:
<details>
<summary>Code sample</summary>
```js
const { resolveModuleName } = require(`ts-pnp`);
exports.resolveModuleName = (
typescript,
moduleName,
containingFile,
compilerOptions,
resolutionHost
) => {
return resolveModuleName(
moduleName,
containingFile,
compilerOptions,
resolutionHost,
typescript.resolveModuleName
);
};
exports.resolveTypeReferenceDirective = (
typescript,
moduleName,
containingFile,
compilerOptions,
resolutionHost
) => {
return resolveModuleName(
moduleName,
containingFile,
compilerOptions,
resolutionHost,
typescript.resolveTypeReferenceDirective
);
};
```
</details>
## Different behaviour in watch mode
If you turn on [webpacks watch mode](https://webpack.js.org/configuration/watch/#watch) the `fork-ts-checker-notifier-webpack-plugin` will take care of logging type errors, _not_ webpack itself. That means if you set `silent: true` you won't see type errors in your console in watch mode.
You can either set `silent: false` to show the logging from `fork-ts-checker-notifier-webpack-plugin` _or_ set `async: false`. Now webpack itself will log type errors again, but note that this can slow down your builds depending on the size of your project.
## Notifier
You may already be using the excellent [webpack-notifier](https://github.com/Turbo87/webpack-notifier) plugin to make build failures more obvious in the form of system notifications. There's an equivalent notifier plugin designed to work with the `fork-ts-checker-webpack-plugin`. It is the `fork-ts-checker-notifier-webpack-plugin` and can be found [here](https://github.com/johnnyreilly/fork-ts-checker-notifier-webpack-plugin). This notifier deliberately has a similar API as the `webpack-notifier` plugin to make migration easier.
## Known Issue Watching Non-Emitting Files
At present there is an issue with the plugin regarding the triggering of type-checking when a change is made in a source file that will not emit js. If you have a file which contains only `interface`s and / or `type`s then changes to it will **not** trigger the type checker whilst in watch mode. Sorry about that.
We hope this will be resolved in future; the issue can be tracked [here](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/issues/36).
## Plugin Hooks
This plugin provides some custom webpack hooks (all are sync):
| Hook Access Key | Description | Params |
| -------------------- | ------------------------------------------------------------------------------ | --------------------------------- |
| `cancel` | Cancellation has been requested | `cancellationToken` |
| `waiting` | Waiting for results | - |
| `serviceBeforeStart` | Async plugin that can be used for delaying `fork-ts-checker-service-start` | - |
| `serviceStart` | Service will be started | `tsconfigPath`, `memoryLimit` |
| `serviceStartError` | Cannot start service | `error` |
| `serviceOutOfMemory` | Service is out of memory | - |
| `receive` | Plugin receives diagnostics and lints from service | `diagnostics`, `lints` |
| `emit` | Service will add errors and warnings to webpack compilation ('build' mode) | `diagnostics`, `lints`, `elapsed` |
| `done` | Service finished type checking and webpack finished compilation ('watch' mode) | `diagnostics`, `lints`, `elapsed` |
### Accessing plugin hooks
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](https://webpack.js.org/api/node/),
it returns the series of [tapable](https://github.com/webpack/tapable)
hooks where you can pass in your callbacks.
```js
// require the plugin
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
// setup compiler with the plugin
const compiler = webpack({
// .. webpack config
});
// Optionally add the plugin to the compiler
// **Don't do this if already added through configuration**
new ForkTsCheckerWebpackPlugin({
silent: true,
async: true
}).apply(compiler);
// Now get the plugin hooks from compiler
const tsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(compiler);
// These hooks provide access to different events
// =================================================== //
// The properties of tsCheckerHooks corresponds to the //
// Hook Access Key of the table above. //
// =================================================== //
// Example, if we want to run some code when plugin has received diagnostics
// and lint
tsCheckerHooks.receive.tap('yourListenerName', (diagnostics, lint) => {
// do something with diagnostics, perhaps show custom message
console.log(diagnostics);
});
// Say we want to show some message when plugin is waiting for typecheck results
tsCheckerHooks.waiting.tap('yourListenerName', () => {
console.log('waiting for typecheck results');
});
```
Calling `.tap()` on any hooks, requires two arguments.
##### `name` (`string`)
The first argument passed to `.tap` is the name of your listener callback (`yourListenerName`).
It doesn't need to correspond to anything special. It is intended to be used
[internally](https://github.com/webpack/tapable#interception) as the `name` of
the hook.
##### `callback` (`function`)
The second argument is the callback function. Depending on the hook you are
tapping into, several arguments are passed to the function. Do check the table
above to find out which arguments are passed to which hooks.
### Accessing hooks on Webpack Multi-Compiler instance
The above method will not work on webpack [multi compiler](https://webpack.js.org/api/node/#multicompiler)
instance. The reason is `getCompilerHooks` expects (at lease as of now) the same
compiler instance to be passed where the plugin was attached. So in case of
multi compiler, we need to access individual compiler instances.
```js
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
// setup multi compiler with the plugin
const compiler = webpack([
{
// .. webpack config
},
{
// .. webpack config
}
]);
// safely determine if instance is multi-compiler
if ('compilers' in compiler) {
compiler.compilers.forEach(singleCompiler => {
// get plugin hooks from the single compiler instance
const tsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(
singleCompiler
);
// now access hooks just like before
tsCheckerHooks.waiting.tap('yourListenerName', () => {
console.log('waiting for typecheck results');
});
});
}
```
## Vue
1. Turn on the vue option in the plugin in your webpack config:
```js
new ForkTsCheckerWebpackPlugin({
vue: true
});
```
Optionally change default [vue-template-compiler](https://github.com/vuejs/vue/tree/dev/packages/vue-template-compiler) to [nativescript-vue-template-compiler](https://github.com/nativescript-vue/nativescript-vue/tree/master/packages/nativescript-vue-template-compiler) if you use [nativescript-vue](https://github.com/nativescript-vue/nativescript-vue)
```
new ForkTsCheckerWebpackPlugin({
vue: { enabled: true, compiler: 'nativescript-vue-template-compiler' }
});
```
2. To activate TypeScript in your `.vue` files, you need to ensure your script tag's language attribute is set
to `ts` or `tsx` (also make sure you include the `.vue` extension in all your import statements as shown below):
```html
<script lang="ts">
import Hello from '@/components/hello.vue';
// ...
</script>
```
3. Ideally you are also using `ts-loader` (in transpileOnly mode). Your Webpack config rules may look something like this:
```js
{
test: /\.ts$/,
loader: 'ts-loader',
include: [resolve('src'), resolve('test')],
options: {
appendTsSuffixTo: [/\.vue$/],
transpileOnly: true
}
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},
```
4. Ensure your `tsconfig.json` includes .vue files:
```js
// tsconfig.json
{
"include": [
"src/**/*.ts",
"src/**/*.vue"
],
"exclude": [
"node_modules"
]
}
```
5. It accepts any wildcard in your TypeScript configuration:
```js
// tsconfig.json
{
"compilerOptions": {
// ...
"baseUrl": ".",
"paths": {
"@/*": [
"src/*"
],
"~/*": [
"src/*"
]
}
}
}
// In a .ts or .vue file...
import Hello from '@/components/hello.vue'
```
6. If you are working in **VSCode**, you can get the [Vetur](https://marketplace.visualstudio.com/items?itemName=octref.vetur) extension to complete the developer workflow.
## Credits
This plugin was created in [Realytics](https://www.realytics.io/) in 2017. Thank you for supporting Open Source.
## License
MIT License

View file

@ -0,0 +1,36 @@
module.exports = {
list: ['feat', 'fix', 'refactor', 'perf', 'test', 'chore', 'docs'],
maxMessageLength: 64,
minMessageLength: 3,
questions: ['type', 'subject', 'body', 'breaking', 'issues'],
types: {
feat: {
description: 'A new feature',
value: 'feat'
},
fix: {
description: 'A bug fix',
value: 'fix'
},
refactor: {
description: 'A code change that neither adds a feature or fixes a bug',
value: 'refactor'
},
perf: {
description: 'A code change that improves performance',
value: 'perf'
},
test: {
description: 'Adding missing tests',
value: 'test'
},
chore: {
description: 'Build process, CI or auxiliary tool changes',
value: 'chore'
},
docs: {
description: 'Documentation only changes',
value: 'docs'
}
}
};

View file

@ -0,0 +1,18 @@
import * as ts from 'typescript';
import { IncrementalCheckerInterface, IncrementalCheckerParams } from './IncrementalCheckerInterface';
import { CancellationToken } from './CancellationToken';
import { CompilerHost } from './CompilerHost';
export declare class ApiIncrementalChecker implements IncrementalCheckerInterface {
protected readonly tsIncrementalCompiler: CompilerHost;
protected readonly typescript: typeof ts;
private currentEsLintErrors;
private lastUpdatedFiles;
private lastRemovedFiles;
private readonly eslinter;
constructor({ typescript, programConfigFile, compilerOptions, eslinter, vue, checkSyntacticErrors, resolveModuleName, resolveTypeReferenceDirective }: IncrementalCheckerParams);
hasEsLinter(): boolean;
isFileExcluded(filePath: string): boolean;
nextIteration(): void;
getTypeScriptIssues(): Promise<import("./issue/Issue").Issue[]>;
getEsLintIssues(cancellationToken: CancellationToken): Promise<import("./issue/Issue").Issue[]>;
}

View file

@ -0,0 +1,107 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var CompilerHost_1 = require("./CompilerHost");
var issue_1 = require("./issue");
var ApiIncrementalChecker = /** @class */ (function () {
function ApiIncrementalChecker(_a) {
var typescript = _a.typescript, programConfigFile = _a.programConfigFile, compilerOptions = _a.compilerOptions, eslinter = _a.eslinter, vue = _a.vue, _b = _a.checkSyntacticErrors, checkSyntacticErrors = _b === void 0 ? false : _b, resolveModuleName = _a.resolveModuleName, resolveTypeReferenceDirective = _a.resolveTypeReferenceDirective;
this.currentEsLintErrors = new Map();
this.lastUpdatedFiles = [];
this.lastRemovedFiles = [];
this.eslinter = eslinter;
this.tsIncrementalCompiler = new CompilerHost_1.CompilerHost(typescript, vue, programConfigFile, compilerOptions, checkSyntacticErrors, resolveModuleName, resolveTypeReferenceDirective);
this.typescript = typescript;
}
ApiIncrementalChecker.prototype.hasEsLinter = function () {
return this.eslinter !== undefined;
};
ApiIncrementalChecker.prototype.isFileExcluded = function (filePath) {
return filePath.endsWith('.d.ts');
};
ApiIncrementalChecker.prototype.nextIteration = function () {
// do nothing
};
ApiIncrementalChecker.prototype.getTypeScriptIssues = function () {
return __awaiter(this, void 0, void 0, function () {
var tsDiagnostics;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.tsIncrementalCompiler.processChanges()];
case 1:
tsDiagnostics = _a.sent();
this.lastUpdatedFiles = tsDiagnostics.updatedFiles;
this.lastRemovedFiles = tsDiagnostics.removedFiles;
return [2 /*return*/, issue_1.createIssuesFromTsDiagnostics(tsDiagnostics.results, this.typescript)];
}
});
});
};
ApiIncrementalChecker.prototype.getEsLintIssues = function (cancellationToken) {
return __awaiter(this, void 0, void 0, function () {
var _i, _a, removedFile, _b, _c, updatedFile, report, reports;
return __generator(this, function (_d) {
if (!this.eslinter) {
throw new Error('EsLint is not enabled in the plugin.');
}
for (_i = 0, _a = this.lastRemovedFiles; _i < _a.length; _i++) {
removedFile = _a[_i];
this.currentEsLintErrors.delete(removedFile);
}
for (_b = 0, _c = this.lastUpdatedFiles; _b < _c.length; _b++) {
updatedFile = _c[_b];
cancellationToken.throwIfCancellationRequested();
if (this.isFileExcluded(updatedFile)) {
continue;
}
report = this.eslinter.getReport(updatedFile);
if (report !== undefined) {
this.currentEsLintErrors.set(updatedFile, report);
}
else if (this.currentEsLintErrors.has(updatedFile)) {
this.currentEsLintErrors.delete(updatedFile);
}
}
reports = Array.from(this.currentEsLintErrors.values());
return [2 /*return*/, issue_1.createIssuesFromEsLintReports(reports)];
});
});
};
return ApiIncrementalChecker;
}());
exports.ApiIncrementalChecker = ApiIncrementalChecker;
//# sourceMappingURL=ApiIncrementalChecker.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"ApiIncrementalChecker.js","sourceRoot":"./","sources":["ApiIncrementalChecker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,+CAA8C;AAE9C,iCAGiB;AAGjB;IAUE,+BAAY,EASe;YARzB,0BAAU,EACV,wCAAiB,EACjB,oCAAe,EACf,sBAAQ,EACR,YAAG,EACH,4BAA4B,EAA5B,iDAA4B,EAC5B,wCAAiB,EACjB,gEAA6B;QAdvB,wBAAmB,GAAG,IAAI,GAAG,EAAsB,CAAC;QACpD,qBAAgB,GAAa,EAAE,CAAC;QAChC,qBAAgB,GAAa,EAAE,CAAC;QActC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,IAAI,CAAC,qBAAqB,GAAG,IAAI,2BAAY,CAC3C,UAAU,EACV,GAAG,EACH,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,6BAA6B,CAC9B,CAAC;QAEF,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAEM,2CAAW,GAAlB;QACE,OAAO,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC;IACrC,CAAC;IAEM,8CAAc,GAArB,UAAsB,QAAgB;QACpC,OAAO,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAEM,6CAAa,GAApB;QACE,aAAa;IACf,CAAC;IAEY,mDAAmB,GAAhC;;;;;4BACwB,qBAAM,IAAI,CAAC,qBAAqB,CAAC,cAAc,EAAE,EAAA;;wBAAjE,aAAa,GAAG,SAAiD;wBACvE,IAAI,CAAC,gBAAgB,GAAG,aAAa,CAAC,YAAY,CAAC;wBACnD,IAAI,CAAC,gBAAgB,GAAG,aAAa,CAAC,YAAY,CAAC;wBAEnD,sBAAO,qCAA6B,CAClC,aAAa,CAAC,OAAO,EACrB,IAAI,CAAC,UAAU,CAChB,EAAC;;;;KACH;IAEY,+CAAe,GAA5B,UAA6B,iBAAoC;;;;gBAC/D,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;oBAClB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;iBACzD;gBAED,WAA+C,EAArB,KAAA,IAAI,CAAC,gBAAgB,EAArB,cAAqB,EAArB,IAAqB,EAAE;oBAAtC,WAAW;oBACpB,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;iBAC9C;gBAED,WAA+C,EAArB,KAAA,IAAI,CAAC,gBAAgB,EAArB,cAAqB,EAArB,IAAqB,EAAE;oBAAtC,WAAW;oBACpB,iBAAiB,CAAC,4BAA4B,EAAE,CAAC;oBACjD,IAAI,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE;wBACpC,SAAS;qBACV;oBAEK,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;oBAEpD,IAAI,MAAM,KAAK,SAAS,EAAE;wBACxB,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;qBACnD;yBAAM,IAAI,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;wBACpD,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;qBAC9C;iBACF;gBAEK,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAAE,CAAC,CAAC;gBAC9D,sBAAO,qCAA6B,CAAC,OAAO,CAAC,EAAC;;;KAC/C;IACH,4BAAC;AAAD,CAAC,AArFD,IAqFC;AArFY,sDAAqB"}

View file

@ -0,0 +1,22 @@
import * as ts from 'typescript';
export interface CancellationTokenData {
isCancelled: boolean;
cancellationFileName: string;
}
export declare class CancellationToken {
private typescript;
private isCancelled;
private cancellationFileName;
private lastCancellationCheckTime;
constructor(typescript: typeof ts, cancellationFileName?: string, isCancelled?: boolean);
static createFromJSON(typescript: typeof ts, json: CancellationTokenData): CancellationToken;
toJSON(): {
cancellationFileName: string;
isCancelled: boolean;
};
getCancellationFilePath(): string;
isCancellationRequested(): boolean;
throwIfCancellationRequested(): void;
requestCancellation(): void;
cleanupCancellation(): void;
}

View file

@ -0,0 +1,69 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var crypto_1 = __importDefault(require("crypto"));
var fs = __importStar(require("fs"));
var os = __importStar(require("os"));
var path = __importStar(require("path"));
var FsHelper_1 = require("./FsHelper");
var CancellationToken = /** @class */ (function () {
function CancellationToken(typescript, cancellationFileName, isCancelled) {
this.typescript = typescript;
this.isCancelled = !!isCancelled;
this.cancellationFileName =
cancellationFileName || crypto_1.default.randomBytes(64).toString('hex');
this.lastCancellationCheckTime = 0;
}
CancellationToken.createFromJSON = function (typescript, json) {
return new CancellationToken(typescript, json.cancellationFileName, json.isCancelled);
};
CancellationToken.prototype.toJSON = function () {
return {
cancellationFileName: this.cancellationFileName,
isCancelled: this.isCancelled
};
};
CancellationToken.prototype.getCancellationFilePath = function () {
return path.join(os.tmpdir(), this.cancellationFileName);
};
CancellationToken.prototype.isCancellationRequested = function () {
if (this.isCancelled) {
return true;
}
var time = Date.now();
var duration = Math.abs(time - this.lastCancellationCheckTime);
if (duration > 10) {
// check no more than once every 10 ms
this.lastCancellationCheckTime = time;
this.isCancelled = FsHelper_1.fileExistsSync(this.getCancellationFilePath());
}
return this.isCancelled;
};
CancellationToken.prototype.throwIfCancellationRequested = function () {
if (this.isCancellationRequested()) {
throw new this.typescript.OperationCanceledException();
}
};
CancellationToken.prototype.requestCancellation = function () {
fs.writeFileSync(this.getCancellationFilePath(), '');
this.isCancelled = true;
};
CancellationToken.prototype.cleanupCancellation = function () {
if (this.isCancelled && FsHelper_1.fileExistsSync(this.getCancellationFilePath())) {
fs.unlinkSync(this.getCancellationFilePath());
this.isCancelled = false;
}
};
return CancellationToken;
}());
exports.CancellationToken = CancellationToken;
//# sourceMappingURL=CancellationToken.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"CancellationToken.js","sourceRoot":"./","sources":["CancellationToken.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAA4B;AAC5B,qCAAyB;AACzB,qCAAyB;AACzB,yCAA6B;AAG7B,uCAA4C;AAO5C;IAIE,2BACU,UAAqB,EAC7B,oBAA6B,EAC7B,WAAqB;QAFb,eAAU,GAAV,UAAU,CAAW;QAI7B,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC;QACjC,IAAI,CAAC,oBAAoB;YACvB,oBAAoB,IAAI,gBAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACjE,IAAI,CAAC,yBAAyB,GAAG,CAAC,CAAC;IACrC,CAAC;IAEa,gCAAc,GAA5B,UACE,UAAqB,EACrB,IAA2B;QAE3B,OAAO,IAAI,iBAAiB,CAC1B,UAAU,EACV,IAAI,CAAC,oBAAoB,EACzB,IAAI,CAAC,WAAW,CACjB,CAAC;IACJ,CAAC;IAEM,kCAAM,GAAb;QACE,OAAO;YACL,oBAAoB,EAAE,IAAI,CAAC,oBAAoB;YAC/C,WAAW,EAAE,IAAI,CAAC,WAAW;SAC9B,CAAC;IACJ,CAAC;IAEM,mDAAuB,GAA9B;QACE,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAC3D,CAAC;IAEM,mDAAuB,GAA9B;QACE,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,OAAO,IAAI,CAAC;SACb;QAED,IAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACxB,IAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,yBAAyB,CAAC,CAAC;QAEjE,IAAI,QAAQ,GAAG,EAAE,EAAE;YACjB,sCAAsC;YACtC,IAAI,CAAC,yBAAyB,GAAG,IAAI,CAAC;YACtC,IAAI,CAAC,WAAW,GAAG,yBAAc,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC,CAAC;SACnE;QAED,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAEM,wDAA4B,GAAnC;QACE,IAAI,IAAI,CAAC,uBAAuB,EAAE,EAAE;YAClC,MAAM,IAAI,IAAI,CAAC,UAAU,CAAC,0BAA0B,EAAE,CAAC;SACxD;IACH,CAAC;IAEM,+CAAmB,GAA1B;QACE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,uBAAuB,EAAE,EAAE,EAAE,CAAC,CAAC;QACrD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAEM,+CAAmB,GAA1B;QACE,IAAI,IAAI,CAAC,WAAW,IAAI,yBAAc,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC,EAAE;YACtE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC,CAAC;YAC9C,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;SAC1B;IACH,CAAC;IACH,wBAAC;AAAD,CAAC,AAvED,IAuEC;AAvEY,8CAAiB"}

View file

@ -0,0 +1,51 @@
import * as ts from 'typescript';
import { ResolveModuleName, ResolveTypeReferenceDirective } from './resolution';
import { VueOptions } from './types/vue-options';
export declare class CompilerHost implements ts.WatchCompilerHostOfConfigFile<ts.EmitAndSemanticDiagnosticsBuilderProgram> {
private typescript;
private vueOptions;
private program?;
getProgram(): ts.Program;
getAllKnownFiles(): Set<string>;
configFileName: string;
optionsToExtend: ts.CompilerOptions;
private directoryWatchers;
private fileWatchers;
private knownFiles;
private gatheredDiagnostic;
private afterCompile;
private readonly tsHost;
protected lastProcessing?: Promise<ts.Diagnostic[]>;
private compilationStarted;
resolveModuleNames: ((moduleNames: string[], containingFile: string, reusedNames?: string[] | undefined, redirectedReference?: ts.ResolvedProjectReference | undefined) => (ts.ResolvedModule | undefined)[]) | undefined;
resolveTypeReferenceDirectives: ((typeReferenceDirectiveNames: string[], containingFile: string, redirectedReference?: ts.ResolvedProjectReference | undefined) => (ts.ResolvedTypeReferenceDirective | undefined)[]) | undefined;
constructor(typescript: typeof ts, vueOptions: VueOptions, programConfigFile: string, compilerOptions: ts.CompilerOptions, checkSyntacticErrors: boolean, userResolveModuleName?: ResolveModuleName, userResolveTypeReferenceDirective?: ResolveTypeReferenceDirective);
processChanges(): Promise<{
results: ts.Diagnostic[];
updatedFiles: string[];
removedFiles: string[];
}>;
setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): any;
clearTimeout(timeoutId: any): void;
onWatchStatusChange(): void;
watchDirectory(path: string, callback: ts.DirectoryWatcherCallback, recursive?: boolean): ts.FileWatcher;
watchFile(path: string, callback: ts.FileWatcherCallback, pollingInterval?: number): ts.FileWatcher;
fileExists(path: string): boolean;
readFile(path: string, encoding?: string): string | undefined;
directoryExists(path: string): boolean;
getDirectories(path: string): string[];
readDirectory(path: string, extensions?: ReadonlyArray<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>, depth?: number): string[];
createProgram: typeof ts.createEmitAndSemanticDiagnosticsBuilderProgram;
getCurrentDirectory(): string;
getDefaultLibFileName(options: ts.CompilerOptions): string;
getEnvironmentVariable(name: string): string | undefined;
getNewLine(): string;
realpath(path: string): string;
trace(s: string): void;
useCaseSensitiveFileNames(): boolean;
onUnRecoverableConfigFileDiagnostic(): void;
afterProgramCreate(program: ts.EmitAndSemanticDiagnosticsBuilderProgram): void;
createDirectory(): void;
writeFile(): void;
onCachedDirectoryStructureHostCreate?(): void;
}

View file

@ -0,0 +1,338 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var LinkedList_1 = require("./LinkedList");
var VueProgram_1 = require("./VueProgram");
var CompilerHost = /** @class */ (function () {
function CompilerHost(typescript, vueOptions, programConfigFile, compilerOptions, checkSyntacticErrors, userResolveModuleName, userResolveTypeReferenceDirective) {
var _this = this;
this.typescript = typescript;
this.vueOptions = vueOptions;
// intercept all watch events and collect them until we get notification to start compilation
this.directoryWatchers = new LinkedList_1.LinkedList();
this.fileWatchers = new LinkedList_1.LinkedList();
this.knownFiles = new Set();
this.gatheredDiagnostic = [];
this.afterCompile = function () {
/* do nothing */
};
this.compilationStarted = false;
this.createProgram = this.typescript
.createEmitAndSemanticDiagnosticsBuilderProgram;
this.tsHost = typescript.createWatchCompilerHost(programConfigFile, compilerOptions, typescript.sys, typescript.createEmitAndSemanticDiagnosticsBuilderProgram, function (diag) {
if (!checkSyntacticErrors &&
diag.code >= 1000 &&
diag.code < 2000 &&
diag.file // if diag.file is undefined, this is not a syntactic error, but a global error that should be emitted
) {
return;
}
_this.gatheredDiagnostic.push(diag);
}, function () {
// do nothing
});
this.configFileName = this.tsHost.configFileName;
this.optionsToExtend = this.tsHost.optionsToExtend || {};
if (userResolveModuleName) {
this.resolveModuleNames = function (moduleNames, containingFile) {
return moduleNames.map(function (moduleName) {
return userResolveModuleName(_this.typescript, moduleName, containingFile, _this.optionsToExtend, _this).resolvedModule;
});
};
}
if (userResolveTypeReferenceDirective) {
this.resolveTypeReferenceDirectives = function (typeDirectiveNames, containingFile) {
return typeDirectiveNames.map(function (typeDirectiveName) {
return userResolveTypeReferenceDirective(_this.typescript, typeDirectiveName, containingFile, _this.optionsToExtend, _this).resolvedTypeReferenceDirective;
});
};
}
}
CompilerHost.prototype.getProgram = function () {
if (!this.program) {
throw new Error('Program is not created yet.');
}
return this.program.getProgram().getProgram();
};
CompilerHost.prototype.getAllKnownFiles = function () {
return this.knownFiles;
};
CompilerHost.prototype.processChanges = function () {
return __awaiter(this, void 0, void 0, function () {
var initialCompile, errors, previousDiagnostic, resultPromise, files, updatedFiles, removedFiles, results;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!!this.lastProcessing) return [3 /*break*/, 2];
initialCompile = new Promise(function (resolve) {
_this.afterCompile = function () {
resolve(_this.gatheredDiagnostic);
_this.afterCompile = function () {
/* do nothing */
};
_this.compilationStarted = false;
};
});
this.lastProcessing = initialCompile;
this.program = this.typescript.createWatchProgram(this);
return [4 /*yield*/, initialCompile];
case 1:
errors = _a.sent();
return [2 /*return*/, {
results: errors,
updatedFiles: Array.from(this.knownFiles),
removedFiles: []
}];
case 2:
// since we do not have a way to pass cancellation token to typescript,
// we just wait until previous compilation finishes.
return [4 /*yield*/, this.lastProcessing];
case 3:
// since we do not have a way to pass cancellation token to typescript,
// we just wait until previous compilation finishes.
_a.sent();
previousDiagnostic = this.gatheredDiagnostic;
this.gatheredDiagnostic = [];
resultPromise = new Promise(function (resolve) {
_this.afterCompile = function () {
resolve(_this.gatheredDiagnostic);
_this.afterCompile = function () {
/* do nothing */
};
_this.compilationStarted = false;
};
});
this.lastProcessing = resultPromise;
files = [];
this.directoryWatchers.forEach(function (item) {
for (var _i = 0, _a = item.events; _i < _a.length; _i++) {
var e = _a[_i];
item.callback(e.fileName);
}
item.events.length = 0;
});
updatedFiles = [];
removedFiles = [];
this.fileWatchers.forEach(function (item) {
for (var _i = 0, _a = item.events; _i < _a.length; _i++) {
var e = _a[_i];
item.callback(e.fileName, e.eventKind);
files.push(e.fileName);
if (e.eventKind === _this.typescript.FileWatcherEventKind.Created ||
e.eventKind === _this.typescript.FileWatcherEventKind.Changed) {
updatedFiles.push(e.fileName);
}
else if (e.eventKind === _this.typescript.FileWatcherEventKind.Deleted) {
removedFiles.push(e.fileName);
}
}
item.events.length = 0;
});
// if the files are not relevant to typescript it may choose not to compile
// in this case we need to trigger promise resolution from here
if (!this.compilationStarted) {
// keep diagnostic from previous run
this.gatheredDiagnostic = previousDiagnostic;
this.afterCompile();
return [2 /*return*/, {
results: this.gatheredDiagnostic,
updatedFiles: [],
removedFiles: []
}];
}
return [4 /*yield*/, resultPromise];
case 4:
results = _a.sent();
return [2 /*return*/, { results: results, updatedFiles: updatedFiles, removedFiles: removedFiles }];
}
});
});
};
CompilerHost.prototype.setTimeout = function (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
callback, ms) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var args = [];
for (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var _i = 2;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_i < arguments.length;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_i++) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
args[_i - 2] = arguments[_i];
}
// There are 2 things we are hacking here:
// 1. This method only called from watch program to wait until all files
// are written to filesystem (for example, when doing 'save all')
// We are intercepting all change notifications, and letting
// them through only when webpack starts processing changes.
// Therefore, at this point normally files are already all saved,
// so we do not need to waste another 250 ms (hardcoded in TypeScript).
// On the other hand there may be occasional glitch, when our incremental
// compiler will receive the notification too late, and process it when
// next compilation would start.
// 2. It seems to be only reliable way to intercept a moment when TypeScript
// actually starts compilation.
//
// Ideally we probably should not let TypeScript call all those watching
// methods by itself, and instead forward changes from webpack.
// Unfortunately, at the moment TypeScript incremental API is quite
// immature (for example, minor changes in how you use it cause
// dramatic compilation time increase), so we have to stick with these
// hacks for now.
this.compilationStarted = true;
return (this.typescript.sys.setTimeout || setTimeout)(callback, 1, args);
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
CompilerHost.prototype.clearTimeout = function (timeoutId) {
(this.typescript.sys.clearTimeout || clearTimeout)(timeoutId);
};
CompilerHost.prototype.onWatchStatusChange = function () {
// do nothing
};
CompilerHost.prototype.watchDirectory = function (path, callback, recursive) {
var slot = { callback: callback, events: [] };
var node = this.directoryWatchers.add(slot);
this.tsHost.watchDirectory(path, function (fileName) {
slot.events.push({ fileName: fileName });
}, recursive);
return {
close: function () {
node.detachSelf();
}
};
};
CompilerHost.prototype.watchFile = function (path, callback, pollingInterval) {
var _this = this;
var slot = { callback: callback, events: [] };
var node = this.fileWatchers.add(slot);
this.knownFiles.add(path);
this.tsHost.watchFile(path, function (fileName, eventKind) {
if (eventKind === _this.typescript.FileWatcherEventKind.Created) {
_this.knownFiles.add(fileName);
}
else if (eventKind === _this.typescript.FileWatcherEventKind.Deleted) {
_this.knownFiles.delete(fileName);
}
slot.events.push({ fileName: fileName, eventKind: eventKind });
}, pollingInterval);
return {
close: function () {
node.detachSelf();
}
};
};
CompilerHost.prototype.fileExists = function (path) {
return this.tsHost.fileExists(path);
};
CompilerHost.prototype.readFile = function (path, encoding) {
var content = this.tsHost.readFile(path, encoding);
// get typescript contents from Vue file
if (content && VueProgram_1.VueProgram.isVue(path)) {
var resolved = VueProgram_1.VueProgram.resolveScriptBlock(this.typescript, content, this.vueOptions.compiler);
return resolved.content;
}
return content;
};
CompilerHost.prototype.directoryExists = function (path) {
return ((this.tsHost.directoryExists && this.tsHost.directoryExists(path)) ||
false);
};
CompilerHost.prototype.getDirectories = function (path) {
return ((this.tsHost.getDirectories && this.tsHost.getDirectories(path)) || []);
};
CompilerHost.prototype.readDirectory = function (path, extensions, exclude, include, depth) {
return this.typescript.sys.readDirectory(path, extensions, exclude, include, depth);
};
CompilerHost.prototype.getCurrentDirectory = function () {
return this.tsHost.getCurrentDirectory();
};
CompilerHost.prototype.getDefaultLibFileName = function (options) {
return this.tsHost.getDefaultLibFileName(options);
};
CompilerHost.prototype.getEnvironmentVariable = function (name) {
return (this.tsHost.getEnvironmentVariable &&
this.tsHost.getEnvironmentVariable(name));
};
CompilerHost.prototype.getNewLine = function () {
return this.tsHost.getNewLine();
};
CompilerHost.prototype.realpath = function (path) {
if (!this.tsHost.realpath) {
throw new Error('The realpath function is not supported by the CompilerHost.');
}
return this.tsHost.realpath(path);
};
CompilerHost.prototype.trace = function (s) {
if (this.tsHost.trace) {
this.tsHost.trace(s);
}
};
CompilerHost.prototype.useCaseSensitiveFileNames = function () {
return this.tsHost.useCaseSensitiveFileNames();
};
CompilerHost.prototype.onUnRecoverableConfigFileDiagnostic = function () {
// do nothing
};
CompilerHost.prototype.afterProgramCreate = function (program) {
// all actual diagnostics happens here
if (this.tsHost.afterProgramCreate) {
this.tsHost.afterProgramCreate(program);
}
this.afterCompile();
};
// the functions below are use internally by typescript. we cannot use non-emitting version of incremental watching API
// because it is
// - much slower for some reason,
// - writes files anyway (o_O)
// - has different way of providing diagnostics. (with this version we can at least reliably get it from afterProgramCreate)
CompilerHost.prototype.createDirectory = function () {
// pretend everything was ok
};
CompilerHost.prototype.writeFile = function () {
// pretend everything was ok
};
CompilerHost.prototype.onCachedDirectoryStructureHostCreate = function () {
// pretend everything was ok
};
return CompilerHost;
}());
exports.CompilerHost = CompilerHost;
//# sourceMappingURL=CompilerHost.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,25 @@
import * as ts from 'typescript';
import { LintReport } from './types/eslint';
export interface DataShape {
source?: ts.SourceFile;
linted: boolean;
eslints: LintReport[];
}
export declare class FilesRegister {
private dataFactory;
private files;
constructor(dataFactory: (_data?: DataShape) => DataShape);
keys(): string[];
add(filePath: string): void;
remove(filePath: string): void;
has(filePath: string): boolean;
get(filePath: string): {
mtime?: number | undefined;
data: DataShape;
};
ensure(filePath: string): void;
getData(filePath: string): DataShape;
mutateData(filePath: string, mutator: (data: DataShape) => void): void;
getMtime(filePath: string): number | undefined;
setMtime(filePath: string, mtime: number): void;
}

View file

@ -0,0 +1,58 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var FilesRegister = /** @class */ (function () {
function FilesRegister(dataFactory) {
this.dataFactory = dataFactory;
this.files = {};
this.dataFactory = dataFactory;
}
FilesRegister.prototype.keys = function () {
return Object.keys(this.files);
};
FilesRegister.prototype.add = function (filePath) {
this.files[filePath] = {
mtime: undefined,
data: this.dataFactory(undefined)
};
};
FilesRegister.prototype.remove = function (filePath) {
if (this.has(filePath)) {
delete this.files[filePath];
}
};
FilesRegister.prototype.has = function (filePath) {
return this.files.hasOwnProperty(filePath);
};
FilesRegister.prototype.get = function (filePath) {
if (!this.has(filePath)) {
throw new Error('File "' + filePath + '" not found in register.');
}
return this.files[filePath];
};
FilesRegister.prototype.ensure = function (filePath) {
if (!this.has(filePath)) {
this.add(filePath);
}
};
FilesRegister.prototype.getData = function (filePath) {
return this.get(filePath).data;
};
FilesRegister.prototype.mutateData = function (filePath, mutator) {
this.ensure(filePath);
mutator(this.files[filePath].data);
};
FilesRegister.prototype.getMtime = function (filePath) {
return this.get(filePath).mtime;
};
FilesRegister.prototype.setMtime = function (filePath, mtime) {
this.ensure(filePath);
if (this.files[filePath].mtime !== mtime) {
this.files[filePath].mtime = mtime;
// file has been changed - we have to reset data
this.files[filePath].data = this.dataFactory(this.files[filePath].data);
}
};
return FilesRegister;
}());
exports.FilesRegister = FilesRegister;
//# sourceMappingURL=FilesRegister.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"FilesRegister.js","sourceRoot":"./","sources":["FilesRegister.ts"],"names":[],"mappings":";;AASA;IAGE,uBAAoB,WAA6C;QAA7C,gBAAW,GAAX,WAAW,CAAkC;QAC/D,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAEM,4BAAI,GAAX;QACE,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAEM,2BAAG,GAAV,UAAW,QAAgB;QACzB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG;YACrB,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;SAClC,CAAC;IACJ,CAAC;IAEM,8BAAM,GAAb,UAAc,QAAgB;QAC5B,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;YACtB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;SAC7B;IACH,CAAC;IAEM,2BAAG,GAAV,UAAW,QAAgB;QACzB,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAEM,2BAAG,GAAV,UAAW,QAAgB;QACzB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,QAAQ,GAAG,QAAQ,GAAG,0BAA0B,CAAC,CAAC;SACnE;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAEM,8BAAM,GAAb,UAAc,QAAgB;QAC5B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;YACvB,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;SACpB;IACH,CAAC;IAEM,+BAAO,GAAd,UAAe,QAAgB;QAC7B,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC;IACjC,CAAC;IAEM,kCAAU,GAAjB,UAAkB,QAAgB,EAAE,OAAkC;QACpE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAEtB,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAEM,gCAAQ,GAAf,UAAgB,QAAgB;QAC9B,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC;IAClC,CAAC;IAEM,gCAAQ,GAAf,UAAgB,QAAgB,EAAE,KAAa;QAC7C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAEtB,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,KAAK,KAAK,KAAK,EAAE;YACxC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC;YACnC,gDAAgD;YAChD,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC;SACzE;IACH,CAAC;IACH,oBAAC;AAAD,CAAC,AAlED,IAkEC;AAlEY,sCAAa"}

View file

@ -0,0 +1,4 @@
/// <reference types="node" />
import * as fs from 'fs';
export declare function fileExistsSync(filePath: fs.PathLike): boolean;
export declare function throwIfIsInvalidSourceFileError(filepath: string, error: any): void;

View file

@ -0,0 +1,38 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs = __importStar(require("fs"));
function fileExistsSync(filePath) {
try {
fs.statSync(filePath);
}
catch (err) {
if (err.code === 'ENOENT') {
return false;
}
else {
throw err;
}
}
return true;
}
exports.fileExistsSync = fileExistsSync;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function throwIfIsInvalidSourceFileError(filepath, error) {
if (fileExistsSync(filepath) &&
// check the error type due to file system lag
!(error instanceof Error) &&
!(error.constructor.name === 'FatalError') &&
!(error.message && error.message.trim().startsWith('Invalid source file'))) {
// it's not because file doesn't exist - throw error
throw error;
}
}
exports.throwIfIsInvalidSourceFileError = throwIfIsInvalidSourceFileError;
//# sourceMappingURL=FsHelper.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"FsHelper.js","sourceRoot":"./","sources":["FsHelper.ts"],"names":[],"mappings":";;;;;;;;;AAAA,qCAAyB;AAEzB,SAAgB,cAAc,CAAC,QAAqB;IAClD,IAAI;QACF,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;KACvB;IAAC,OAAO,GAAG,EAAE;QACZ,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE;YACzB,OAAO,KAAK,CAAC;SACd;aAAM;YACL,MAAM,GAAG,CAAC;SACX;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAXD,wCAWC;AAED,8DAA8D;AAC9D,SAAgB,+BAA+B,CAAC,QAAgB,EAAE,KAAU;IAC1E,IACE,cAAc,CAAC,QAAQ,CAAC;QACxB,8CAA8C;QAC9C,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;QACzB,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,YAAY,CAAC;QAC1C,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAC,EAC1E;QACA,oDAAoD;QACpD,MAAM,KAAK,CAAC;KACb;AACH,CAAC;AAXD,0EAWC"}

View file

@ -0,0 +1,27 @@
import * as ts from 'typescript';
import { CancellationToken } from './CancellationToken';
import { IncrementalCheckerInterface, IncrementalCheckerParams } from './IncrementalCheckerInterface';
import { Issue } from './issue';
export declare class IncrementalChecker implements IncrementalCheckerInterface {
private files;
protected program?: ts.Program;
protected programConfig?: ts.ParsedCommandLine;
private readonly typescript;
private readonly programConfigFile;
private readonly compilerOptions;
private readonly eslinter;
private readonly vue;
private readonly checkSyntacticErrors;
private readonly resolveModuleName;
private readonly resolveTypeReferenceDirective;
constructor({ typescript, programConfigFile, compilerOptions, eslinter, vue, checkSyntacticErrors, resolveModuleName, resolveTypeReferenceDirective }: IncrementalCheckerParams);
static loadProgramConfig(typescript: typeof ts, configFile: string, compilerOptions: object): ts.ParsedCommandLine;
private static createProgram;
hasEsLinter(): boolean;
static isFileExcluded(filePath: string): boolean;
nextIteration(): void;
private loadVueProgram;
private loadDefaultProgram;
getTypeScriptIssues(cancellationToken: CancellationToken): Promise<Issue[]>;
getEsLintIssues(cancellationToken: CancellationToken): Promise<Issue[]>;
}

View file

@ -0,0 +1,216 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs = __importStar(require("fs"));
var path = __importStar(require("path"));
var FilesRegister_1 = require("./FilesRegister");
var resolution_1 = require("./resolution");
var VueProgram_1 = require("./VueProgram");
var issue_1 = require("./issue");
var IncrementalChecker = /** @class */ (function () {
function IncrementalChecker(_a) {
var typescript = _a.typescript, programConfigFile = _a.programConfigFile, compilerOptions = _a.compilerOptions, eslinter = _a.eslinter, vue = _a.vue, _b = _a.checkSyntacticErrors, checkSyntacticErrors = _b === void 0 ? false : _b, resolveModuleName = _a.resolveModuleName, resolveTypeReferenceDirective = _a.resolveTypeReferenceDirective;
this.files = new FilesRegister_1.FilesRegister(function () { return ({
// data shape
source: undefined,
linted: false,
eslints: []
}); });
this.typescript = typescript;
this.programConfigFile = programConfigFile;
this.compilerOptions = compilerOptions;
this.eslinter = eslinter;
this.vue = vue;
this.checkSyntacticErrors = checkSyntacticErrors;
this.resolveModuleName = resolveModuleName;
this.resolveTypeReferenceDirective = resolveTypeReferenceDirective;
}
IncrementalChecker.loadProgramConfig = function (typescript, configFile, compilerOptions) {
var tsconfig = typescript.readConfigFile(configFile, typescript.sys.readFile).config;
tsconfig.compilerOptions = tsconfig.compilerOptions || {};
tsconfig.compilerOptions = __assign({}, tsconfig.compilerOptions, compilerOptions);
var parsed = typescript.parseJsonConfigFileContent(tsconfig, typescript.sys, path.dirname(configFile));
return parsed;
};
IncrementalChecker.createProgram = function (typescript, programConfig, files, oldProgram, userResolveModuleName, userResolveTypeReferenceDirective) {
var host = typescript.createCompilerHost(programConfig.options);
var realGetSourceFile = host.getSourceFile;
var _a = resolution_1.makeResolutionFunctions(userResolveModuleName, userResolveTypeReferenceDirective), resolveModuleName = _a.resolveModuleName, resolveTypeReferenceDirective = _a.resolveTypeReferenceDirective;
host.resolveModuleNames = function (moduleNames, containingFile) {
return moduleNames.map(function (moduleName) {
return resolveModuleName(typescript, moduleName, containingFile, programConfig.options, host).resolvedModule;
});
};
host.resolveTypeReferenceDirectives = function (typeDirectiveNames, containingFile) {
return typeDirectiveNames.map(function (typeDirectiveName) {
return resolveTypeReferenceDirective(typescript, typeDirectiveName, containingFile, programConfig.options, host).resolvedTypeReferenceDirective;
});
};
host.getSourceFile = function (filePath, languageVersion, onError) {
try {
var stats = fs.statSync(filePath);
files.setMtime(filePath, stats.mtime.valueOf());
}
catch (e) {
// probably file does not exists
files.remove(filePath);
}
// get source file only if there is no source in files register
if (!files.has(filePath) || !files.getData(filePath).source) {
files.mutateData(filePath, function (data) {
data.source = realGetSourceFile(filePath, languageVersion, onError);
});
}
return files.getData(filePath).source;
};
return typescript.createProgram(programConfig.fileNames, programConfig.options, host, oldProgram // re-use old program
);
};
IncrementalChecker.prototype.hasEsLinter = function () {
return this.eslinter !== undefined;
};
IncrementalChecker.isFileExcluded = function (filePath) {
return filePath.endsWith('.d.ts');
};
IncrementalChecker.prototype.nextIteration = function () {
this.program = this.vue.enabled
? this.loadVueProgram(this.vue)
: this.loadDefaultProgram();
};
IncrementalChecker.prototype.loadVueProgram = function (vueOptions) {
this.programConfig =
this.programConfig ||
VueProgram_1.VueProgram.loadProgramConfig(this.typescript, this.programConfigFile, this.compilerOptions);
return VueProgram_1.VueProgram.createProgram(this.typescript, this.programConfig, path.dirname(this.programConfigFile), this.files, this.program, this.resolveModuleName, this.resolveTypeReferenceDirective, vueOptions);
};
IncrementalChecker.prototype.loadDefaultProgram = function () {
this.programConfig =
this.programConfig ||
IncrementalChecker.loadProgramConfig(this.typescript, this.programConfigFile, this.compilerOptions);
return IncrementalChecker.createProgram(this.typescript, this.programConfig, this.files, this.program, this.resolveModuleName, this.resolveTypeReferenceDirective);
};
IncrementalChecker.prototype.getTypeScriptIssues = function (cancellationToken) {
return __awaiter(this, void 0, void 0, function () {
var program, tsDiagnostics, filesToCheck;
var _this = this;
return __generator(this, function (_a) {
program = this.program;
if (!program) {
throw new Error('Invoked called before program initialized');
}
tsDiagnostics = [];
filesToCheck = program.getSourceFiles();
filesToCheck.forEach(function (sourceFile) {
if (cancellationToken) {
cancellationToken.throwIfCancellationRequested();
}
var tsDiagnosticsToRegister = _this
.checkSyntacticErrors
? program
.getSemanticDiagnostics(sourceFile, cancellationToken)
.concat(program.getSyntacticDiagnostics(sourceFile, cancellationToken))
: program.getSemanticDiagnostics(sourceFile, cancellationToken);
tsDiagnostics.push.apply(tsDiagnostics, tsDiagnosticsToRegister);
});
return [2 /*return*/, issue_1.createIssuesFromTsDiagnostics(tsDiagnostics, this.typescript)];
});
});
};
IncrementalChecker.prototype.getEsLintIssues = function (cancellationToken) {
return __awaiter(this, void 0, void 0, function () {
var filesToLint, currentEsLintErrors, reports;
var _this = this;
return __generator(this, function (_a) {
filesToLint = this.files
.keys()
.filter(function (filePath) {
return !_this.files.getData(filePath).linted &&
!IncrementalChecker.isFileExcluded(filePath);
});
currentEsLintErrors = new Map();
filesToLint.forEach(function (fileName) {
cancellationToken.throwIfCancellationRequested();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
var report = _this.eslinter.getReport(fileName);
if (report !== undefined) {
currentEsLintErrors.set(fileName, report);
}
});
// set lints in files register
currentEsLintErrors.forEach(function (lint, filePath) {
_this.files.mutateData(filePath, function (data) {
data.linted = true;
data.eslints.push(lint);
});
});
// set all files as linted
this.files.keys().forEach(function (filePath) {
_this.files.mutateData(filePath, function (data) {
data.linted = true;
});
});
reports = this.files
.keys()
.reduce(function (innerLints, filePath) {
return innerLints.concat(_this.files.getData(filePath).eslints);
}, []);
return [2 /*return*/, issue_1.createIssuesFromEsLintReports(reports)];
});
});
};
return IncrementalChecker;
}());
exports.IncrementalChecker = IncrementalChecker;
//# sourceMappingURL=IncrementalChecker.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,23 @@
import * as ts from 'typescript';
import { CancellationToken } from './CancellationToken';
import { ResolveTypeReferenceDirective, ResolveModuleName } from './resolution';
import { createEslinter } from './createEslinter';
import { Issue } from './issue';
import { VueOptions } from './types/vue-options';
export interface IncrementalCheckerInterface {
nextIteration(): void;
hasEsLinter(): boolean;
getTypeScriptIssues(cancellationToken: CancellationToken): Promise<Issue[]>;
getEsLintIssues(cancellationToken: CancellationToken): Promise<Issue[]>;
}
export interface IncrementalCheckerParams {
typescript: typeof ts;
context: string;
programConfigFile: string;
compilerOptions: ts.CompilerOptions;
eslinter: ReturnType<typeof createEslinter> | undefined;
checkSyntacticErrors: boolean;
resolveModuleName: ResolveModuleName | undefined;
resolveTypeReferenceDirective: ResolveTypeReferenceDirective | undefined;
vue: VueOptions;
}

View file

@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=IncrementalCheckerInterface.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"IncrementalCheckerInterface.js","sourceRoot":"./","sources":["IncrementalCheckerInterface.ts"],"names":[],"mappings":""}

View file

@ -0,0 +1,27 @@
export declare class HeadNode<T> {
next: LinkedListNode<T> | TailNode<T>;
constructor();
}
export declare class TailNode<T> {
previous: LinkedListNode<T> | HeadNode<T>;
constructor(head: HeadNode<T>);
}
export declare class LinkedListNode<T> {
next: LinkedListNode<T> | TailNode<T> | null;
previous: LinkedListNode<T> | HeadNode<T> | null;
readonly item: T;
constructor(item: T);
detachSelf(): void;
attachAfter(node: LinkedListNode<T> | HeadNode<T>): void;
attachBefore(node: LinkedListNode<T> | TailNode<T>): void;
}
export declare class LinkedList<T> {
head: HeadNode<T>;
tail: TailNode<T>;
constructor();
add(item: T): LinkedListNode<T>;
getItems(): T[];
forEach(callback: (item: T, node: LinkedListNode<T>) => void): void;
hasItems(): boolean;
getLastItem(): LinkedListNode<T>;
}

View file

@ -0,0 +1,98 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var HeadNode = /** @class */ (function () {
function HeadNode() {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
this.next = new TailNode(this);
}
return HeadNode;
}());
exports.HeadNode = HeadNode;
var TailNode = /** @class */ (function () {
function TailNode(head) {
this.previous = head;
}
return TailNode;
}());
exports.TailNode = TailNode;
var LinkedListNode = /** @class */ (function () {
function LinkedListNode(item) {
this.next = null;
this.previous = null;
this.item = item;
}
LinkedListNode.prototype.detachSelf = function () {
if (!this.next && !this.previous) {
throw new Error('node is not attached');
}
if (this.next) {
this.next.previous = this.previous;
}
if (this.previous) {
this.previous.next = this.next;
}
this.next = null;
this.previous = null;
};
LinkedListNode.prototype.attachAfter = function (node) {
if (this.next || this.previous) {
throw new Error('Node is inserted elsewhere');
}
this.next = node.next;
this.previous = node;
if (node.next) {
node.next.previous = this;
}
node.next = this;
};
LinkedListNode.prototype.attachBefore = function (node) {
if (!node.previous) {
throw new Error('no previous node found.');
}
this.attachAfter(node.previous);
};
return LinkedListNode;
}());
exports.LinkedListNode = LinkedListNode;
var LinkedList = /** @class */ (function () {
function LinkedList() {
this.head = new HeadNode();
this.tail = this.head.next;
}
LinkedList.prototype.add = function (item) {
var newNode = new LinkedListNode(item);
newNode.attachAfter(this.tail.previous);
return newNode;
};
LinkedList.prototype.getItems = function () {
var result = [];
this.forEach(function (item) {
result.push(item);
});
return result;
};
LinkedList.prototype.forEach = function (callback) {
var current = this.head.next;
while (current !== this.tail) {
// if item is not tail it is always a node
var item = current;
callback(item.item, item);
if (!item.next) {
throw new Error('badly attached item found.');
}
current = item.next;
}
};
LinkedList.prototype.hasItems = function () {
return this.head.next !== this.tail;
};
LinkedList.prototype.getLastItem = function () {
if (!this.hasItems()) {
throw new Error('no items in list.');
}
return this.head.next;
};
return LinkedList;
}());
exports.LinkedList = LinkedList;
//# sourceMappingURL=LinkedList.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"LinkedList.js","sourceRoot":"./","sources":["LinkedList.ts"],"names":[],"mappings":";;AAAA;IAGE;QACE,mEAAmE;QACnE,IAAI,CAAC,IAAI,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IACH,eAAC;AAAD,CAAC,AAPD,IAOC;AAPY,4BAAQ;AASrB;IAGE,kBAAY,IAAiB;QAC3B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;IACH,eAAC;AAAD,CAAC,AAND,IAMC;AANY,4BAAQ;AAOrB;IAKE,wBAAY,IAAO;QAJZ,SAAI,GAA2C,IAAI,CAAC;QACpD,aAAQ,GAA2C,IAAI,CAAC;QAI7D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAEM,mCAAU,GAAjB;QACE,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;SACzC;QACD,IAAI,IAAI,CAAC,IAAI,EAAE;YACb,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;SACpC;QACD,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjB,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;SAChC;QACD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;IAEM,oCAAW,GAAlB,UAAmB,IAAqC;QACtD,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;SAC/C;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QAErB,IAAI,IAAI,CAAC,IAAI,EAAE;YACb,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;SAC3B;QACD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAEM,qCAAY,GAAnB,UAAoB,IAAqC;QACvD,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;SAC5C;QACD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;IACH,qBAAC;AAAD,CAAC,AA3CD,IA2CC;AA3CY,wCAAc;AA4C3B;IAIE;QACE,IAAI,CAAC,IAAI,GAAG,IAAI,QAAQ,EAAK,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAmB,CAAC;IAC5C,CAAC;IAEM,wBAAG,GAAV,UAAW,IAAO;QAChB,IAAM,OAAO,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,CAAC;QACzC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxC,OAAO,OAAO,CAAC;IACjB,CAAC;IAEM,6BAAQ,GAAf;QACE,IAAM,MAAM,GAAQ,EAAE,CAAC;QACvB,IAAI,CAAC,OAAO,CAAC,UAAA,IAAI;YACf,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,4BAAO,GAAd,UAAe,QAAoD;QACjE,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QAC7B,OAAO,OAAO,KAAK,IAAI,CAAC,IAAI,EAAE;YAC5B,0CAA0C;YAC1C,IAAM,IAAI,GAAG,OAA4B,CAAC;YAC1C,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC1B,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;gBACd,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;aAC/C;YACD,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;SACrB;IACH,CAAC;IAEM,6BAAQ,GAAf;QACE,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC;IACtC,CAAC;IAEM,gCAAW,GAAlB;QACE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;SACtC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAyB,CAAC;IAC7C,CAAC;IACH,iBAAC;AAAD,CAAC,AA9CD,IA8CC;AA9CY,gCAAU"}

View file

@ -0,0 +1,5 @@
import { Issue } from './issue';
export interface Message {
diagnostics: Issue[];
lints: Issue[];
}

View file

@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=Message.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"Message.js","sourceRoot":"./","sources":["Message.ts"],"names":[],"mappings":""}

View file

@ -0,0 +1,5 @@
import { CancellationTokenData } from './CancellationToken';
import { Message } from './Message';
export declare const RUN = "run";
export declare type RunPayload = CancellationTokenData;
export declare type RunResult = Message | undefined;

View file

@ -0,0 +1,4 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RUN = 'run';
//# sourceMappingURL=RpcTypes.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"RpcTypes.js","sourceRoot":"./","sources":["RpcTypes.ts"],"names":[],"mappings":";;AAGa,QAAA,GAAG,GAAG,KAAK,CAAC"}

View file

@ -0,0 +1,23 @@
import * as ts from 'typescript';
import { FilesRegister } from './FilesRegister';
import { ResolveModuleName, ResolveTypeReferenceDirective } from './resolution';
import { VueOptions } from './types/vue-options';
interface ResolvedScript {
scriptKind: ts.ScriptKind;
content: string;
}
export declare class VueProgram {
static loadProgramConfig(typescript: typeof ts, configFile: string, compilerOptions: object): ts.ParsedCommandLine;
/**
* Search for default wildcard or wildcard from options, we only search for that in tsconfig CompilerOptions.paths.
* The path is resolved with thie given substitution and includes the CompilerOptions.baseUrl (if given).
* If no paths given in tsconfig, then the default substitution is '[tsconfig directory]/src'.
* (This is a fast, simplified inspiration of what's described here: https://github.com/Microsoft/TypeScript/issues/5039)
*/
static resolveNonTsModuleName(moduleName: string, containingFile: string, basedir: string, options: ts.CompilerOptions): string;
static isVue(filePath: string): boolean;
static createProgram(typescript: typeof ts, programConfig: ts.ParsedCommandLine, basedir: string, files: FilesRegister, oldProgram: ts.Program | undefined, userResolveModuleName: ResolveModuleName | undefined, userResolveTypeReferenceDirective: ResolveTypeReferenceDirective | undefined, vueOptions: VueOptions): ts.Program;
private static getScriptKindByLang;
static resolveScriptBlock(typescript: typeof ts, content: string, compiler: string): ResolvedScript;
}
export {};

View file

@ -0,0 +1,253 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs = __importStar(require("fs"));
var path = __importStar(require("path"));
var resolution_1 = require("./resolution");
var VueProgram = /** @class */ (function () {
function VueProgram() {
}
VueProgram.loadProgramConfig = function (typescript, configFile, compilerOptions) {
var extraExtensions = ['vue'];
var parseConfigHost = {
fileExists: typescript.sys.fileExists,
readFile: typescript.sys.readFile,
useCaseSensitiveFileNames: typescript.sys.useCaseSensitiveFileNames,
readDirectory: function (rootDir, extensions, excludes, includes, depth) {
return typescript.sys.readDirectory(rootDir, extensions.concat(extraExtensions), excludes, includes, depth);
}
};
var tsconfig = typescript.readConfigFile(configFile, typescript.sys.readFile).config;
tsconfig.compilerOptions = tsconfig.compilerOptions || {};
tsconfig.compilerOptions = __assign({}, tsconfig.compilerOptions, compilerOptions);
var parsed = typescript.parseJsonConfigFileContent(tsconfig, parseConfigHost, path.dirname(configFile));
parsed.options.allowNonTsExtensions = true;
return parsed;
};
/**
* Search for default wildcard or wildcard from options, we only search for that in tsconfig CompilerOptions.paths.
* The path is resolved with thie given substitution and includes the CompilerOptions.baseUrl (if given).
* If no paths given in tsconfig, then the default substitution is '[tsconfig directory]/src'.
* (This is a fast, simplified inspiration of what's described here: https://github.com/Microsoft/TypeScript/issues/5039)
*/
VueProgram.resolveNonTsModuleName = function (moduleName, containingFile, basedir, options) {
var baseUrl = options.baseUrl ? options.baseUrl : basedir;
var discardedSymbols = ['.', '..', '/'];
var wildcards = [];
if (options.paths) {
Object.keys(options.paths).forEach(function (key) {
var pathSymbol = key[0];
if (discardedSymbols.indexOf(pathSymbol) < 0 &&
wildcards.indexOf(pathSymbol) < 0) {
wildcards.push(pathSymbol);
}
});
}
else {
wildcards.push('@');
}
var isRelative = !path.isAbsolute(moduleName);
var correctWildcard;
wildcards.forEach(function (wildcard) {
if (moduleName.substr(0, 2) === wildcard + "/") {
correctWildcard = wildcard;
}
});
if (correctWildcard) {
var pattern = options.paths
? options.paths[correctWildcard + "/*"]
: undefined;
var substitution = pattern
? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
options.paths[correctWildcard + "/*"][0].replace('*', '')
: 'src';
moduleName = path.resolve(baseUrl, substitution, moduleName.substr(2));
}
else if (isRelative) {
moduleName = path.resolve(path.dirname(containingFile), moduleName);
}
return moduleName;
};
VueProgram.isVue = function (filePath) {
return path.extname(filePath) === '.vue';
};
VueProgram.createProgram = function (typescript, programConfig, basedir, files, oldProgram, userResolveModuleName, userResolveTypeReferenceDirective, vueOptions) {
var host = typescript.createCompilerHost(programConfig.options);
var realGetSourceFile = host.getSourceFile;
var _a = resolution_1.makeResolutionFunctions(userResolveModuleName, userResolveTypeReferenceDirective), resolveModuleName = _a.resolveModuleName, resolveTypeReferenceDirective = _a.resolveTypeReferenceDirective;
host.resolveModuleNames = function (moduleNames, containingFile) {
return moduleNames.map(function (moduleName) {
return resolveModuleName(typescript, moduleName, containingFile, programConfig.options, host).resolvedModule;
});
};
host.resolveTypeReferenceDirectives = function (typeDirectiveNames, containingFile) {
return typeDirectiveNames.map(function (typeDirectiveName) {
return resolveTypeReferenceDirective(typescript, typeDirectiveName, containingFile, programConfig.options, host).resolvedTypeReferenceDirective;
});
};
// We need a host that can parse Vue SFCs (single file components).
host.getSourceFile = function (filePath, languageVersion, onError) {
try {
var stats = fs.statSync(filePath);
files.setMtime(filePath, stats.mtime.valueOf());
}
catch (e) {
// probably file does not exists
files.remove(filePath);
}
// get source file only if there is no source in files register
if (!files.has(filePath) || !files.getData(filePath).source) {
files.mutateData(filePath, function (data) {
data.source = realGetSourceFile(filePath, languageVersion, onError);
});
}
var source = files.getData(filePath).source;
// get typescript contents from Vue file
if (source && VueProgram.isVue(filePath)) {
var resolved = VueProgram.resolveScriptBlock(typescript, source.text, vueOptions.compiler);
source = typescript.createSourceFile(filePath, resolved.content, languageVersion, true, resolved.scriptKind);
}
return source;
};
// We need a host with special module resolution for Vue files.
host.resolveModuleNames = function (moduleNames, containingFile) {
var resolvedModules = [];
for (var _i = 0, moduleNames_1 = moduleNames; _i < moduleNames_1.length; _i++) {
var moduleName = moduleNames_1[_i];
// Try to use standard resolution.
var resolvedModule = typescript.resolveModuleName(moduleName, containingFile, programConfig.options, {
fileExists: function (fileName) {
if (fileName.endsWith('.vue.ts')) {
return (host.fileExists(fileName.slice(0, -3)) ||
host.fileExists(fileName));
}
else {
return host.fileExists(fileName);
}
},
readFile: function (fileName) {
// This implementation is not necessary. Just for consistent behavior.
if (fileName.endsWith('.vue.ts') && !host.fileExists(fileName)) {
return host.readFile(fileName.slice(0, -3));
}
else {
return host.readFile(fileName);
}
}
}).resolvedModule;
if (resolvedModule) {
if (resolvedModule.resolvedFileName.endsWith('.vue.ts') &&
!host.fileExists(resolvedModule.resolvedFileName)) {
resolvedModule.resolvedFileName = resolvedModule.resolvedFileName.slice(0, -3);
}
resolvedModules.push(resolvedModule);
}
else {
// For non-ts extensions.
var absolutePath = VueProgram.resolveNonTsModuleName(moduleName, containingFile, basedir, programConfig.options);
if (VueProgram.isVue(moduleName)) {
resolvedModules.push({
resolvedFileName: absolutePath,
extension: '.ts'
});
}
else {
resolvedModules.push({
// If the file does exist, return an empty string (because we assume user has provided a ".d.ts" file for it).
resolvedFileName: host.fileExists(absolutePath)
? ''
: absolutePath,
extension: '.ts'
});
}
}
}
return resolvedModules;
};
return typescript.createProgram(programConfig.fileNames, programConfig.options, host, oldProgram // re-use old program
);
};
VueProgram.getScriptKindByLang = function (typescript, lang) {
if (lang === 'ts') {
return typescript.ScriptKind.TS;
}
else if (lang === 'tsx') {
return typescript.ScriptKind.TSX;
}
else if (lang === 'jsx') {
return typescript.ScriptKind.JSX;
}
else {
// when lang is "js" or no lang specified
return typescript.ScriptKind.JS;
}
};
VueProgram.resolveScriptBlock = function (typescript, content, compiler) {
// We need to import template compiler for vue lazily because it cannot be included it
// as direct dependency because it is an optional dependency of fork-ts-checker-webpack-plugin.
// Since its version must not mismatch with user-installed Vue.js,
// we should let the users install template compiler for vue by themselves.
var parser;
try {
parser = require(compiler);
}
catch (err) {
throw new Error('When you use `vue` option, make sure to install `' + compiler + '`.');
}
var script = parser.parseComponent(content, {
pad: 'space'
}).script;
// No <script> block
if (!script) {
return {
scriptKind: typescript.ScriptKind.JS,
content: 'export default {};\n'
};
}
var scriptKind = VueProgram.getScriptKindByLang(typescript, script.lang);
// There is src attribute
if (script.attrs.src) {
// import path cannot be end with '.ts[x]'
var src = script.attrs.src.replace(/\.tsx?$/i, '');
return {
scriptKind: scriptKind,
// For now, ignore the error when the src file is not found
// since it will produce incorrect code location.
// It's not a large problem since it's handled on webpack side.
content: '// @ts-ignore\n' +
("export { default } from '" + src + "';\n") +
'// @ts-ignore\n' +
("export * from '" + src + "';\n")
};
}
// Pad blank lines to retain diagnostics location
// We need to prepend `//` for each line to avoid
// false positive of no-consecutive-blank-lines TSLint rule
var offset = content.slice(0, script.start).split(/\r?\n/g).length;
var paddedContent = Array(offset).join('//\n') + script.content.slice(script.start);
return {
scriptKind: scriptKind,
content: paddedContent
};
};
return VueProgram;
}());
exports.VueProgram = VueProgram;
//# sourceMappingURL=VueProgram.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,4 @@
import { LintReport, Options as EslintOptions } from './types/eslint';
export declare function createEslinter(eslintOptions: EslintOptions): {
getReport: (filepath: string) => LintReport | undefined;
};

View file

@ -0,0 +1,39 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var path = __importStar(require("path"));
var FsHelper_1 = require("./FsHelper");
function createEslinter(eslintOptions) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
var CLIEngine = require('eslint').CLIEngine;
// See https://eslint.org/docs/developer-guide/nodejs-api#cliengine
var eslinter = new CLIEngine(eslintOptions);
function getReport(filepath) {
try {
if (eslinter.isPathIgnored(filepath) ||
path.extname(filepath).localeCompare('.json', undefined, {
sensitivity: 'accent'
}) === 0) {
return undefined;
}
var lintReport = eslinter.executeOnFiles([filepath]);
if (eslintOptions && eslintOptions.fix) {
CLIEngine.outputFixes(lintReport);
}
return lintReport;
}
catch (e) {
FsHelper_1.throwIfIsInvalidSourceFileError(filepath, e);
}
return undefined;
}
return { getReport: getReport };
}
exports.createEslinter = createEslinter;
//# sourceMappingURL=createEslinter.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"createEslinter.js","sourceRoot":"./","sources":["createEslinter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,yCAA6B;AAG7B,uCAA6D;AAE7D,SAAgB,cAAc,CAAC,aAA4B;IACzD,8DAA8D;IACtD,IAAA,uCAAS,CAAuB;IAExC,mEAAmE;IACnE,IAAM,QAAQ,GAAG,IAAI,SAAS,CAAC,aAAa,CAAC,CAAC;IAE9C,SAAS,SAAS,CAAC,QAAgB;QACjC,IAAI;YACF,IACE,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC;gBAChC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,SAAS,EAAE;oBACvD,WAAW,EAAE,QAAQ;iBACtB,CAAC,KAAK,CAAC,EACR;gBACA,OAAO,SAAS,CAAC;aAClB;YAED,IAAM,UAAU,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;YAEvD,IAAI,aAAa,IAAI,aAAa,CAAC,GAAG,EAAE;gBACtC,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;aACnC;YAED,OAAO,UAAU,CAAC;SACnB;QAAC,OAAO,CAAC,EAAE;YACV,0CAA+B,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;SAC9C;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,EAAE,SAAS,WAAA,EAAE,CAAC;AACvB,CAAC;AAhCD,wCAgCC"}

View file

@ -0,0 +1,17 @@
import { Formatter } from './Formatter';
interface CodeFrameFormatterOptions {
/** Syntax highlight the code as JavaScript for terminals. default: false */
highlightCode?: boolean;
/** The number of lines to show above the error. default: 2 */
linesBelow?: number;
/** The number of lines to show below the error. default: 3 */
linesAbove?: number;
/**
* Forcibly syntax highlight the code as JavaScript (for non-terminals);
* overrides highlightCode.
* default: false
*/
forceColor?: boolean;
}
declare function createCodeframeFormatter(options?: CodeFrameFormatterOptions): Formatter;
export { createCodeframeFormatter, CodeFrameFormatterOptions };

View file

@ -0,0 +1,68 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var os = __importStar(require("os"));
var fs = __importStar(require("fs"));
var chalk_1 = __importDefault(require("chalk"));
var FsHelper_1 = require("../FsHelper");
var issue_1 = require("../issue");
var InternalFormatter_1 = require("./InternalFormatter");
var code_frame_1 = require("@babel/code-frame");
function createCodeframeFormatter(options) {
return function codeframeFormatter(issue) {
var color = {
message: issue.severity === issue_1.IssueSeverity.WARNING
? chalk_1.default.bold.yellow
: chalk_1.default.bold.red,
position: chalk_1.default.dim
};
if (issue.origin === issue_1.IssueOrigin.INTERNAL) {
return InternalFormatter_1.createInternalFormatter()(issue);
}
var file = issue.file;
var source = file && FsHelper_1.fileExistsSync(file) && fs.readFileSync(file, 'utf-8');
var frame = '';
if (source) {
frame = code_frame_1.codeFrameColumns(source, {
start: {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
line: issue.line,
column: issue.character
}
}, __assign({ highlightCode: true }, (options || {})))
.split('\n')
.map(function (line) { return ' ' + line; })
.join(os.EOL);
}
var lines = [
color.message(issue.severity.toUpperCase() + " in " + issue.file + "(" + issue.line + "," + issue.character + "):"),
color.position(issue.line + ":" + issue.character + " " + issue.message)
];
if (frame) {
lines.push(frame);
}
return lines.join(os.EOL);
};
}
exports.createCodeframeFormatter = createCodeframeFormatter;
//# sourceMappingURL=CodeframeFormatter.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"CodeframeFormatter.js","sourceRoot":"./","sources":["formatter/CodeframeFormatter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyB;AACzB,qCAAyB;AACzB,gDAA0B;AAE1B,wCAA6C;AAC7C,kCAAsD;AAEtD,yDAA8D;AAC9D,gDAAqD;AAiBrD,SAAS,wBAAwB,CAC/B,OAAmC;IAEnC,OAAO,SAAS,kBAAkB,CAAC,KAAK;QACtC,IAAM,KAAK,GAAG;YACZ,OAAO,EACL,KAAK,CAAC,QAAQ,KAAK,qBAAa,CAAC,OAAO;gBACtC,CAAC,CAAC,eAAK,CAAC,IAAI,CAAC,MAAM;gBACnB,CAAC,CAAC,eAAK,CAAC,IAAI,CAAC,GAAG;YACpB,QAAQ,EAAE,eAAK,CAAC,GAAG;SACpB,CAAC;QAEF,IAAI,KAAK,CAAC,MAAM,KAAK,mBAAW,CAAC,QAAQ,EAAE;YACzC,OAAO,2CAAuB,EAAE,CAAC,KAAK,CAAC,CAAC;SACzC;QAED,IAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACxB,IAAM,MAAM,GACV,IAAI,IAAI,yBAAc,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACjE,IAAI,KAAK,GAAG,EAAE,CAAC;QAEf,IAAI,MAAM,EAAE;YACV,KAAK,GAAG,6BAAgB,CACtB,MAAM,EACN;gBACE,KAAK,EAAE;oBACL,oEAAoE;oBACpE,IAAI,EAAE,KAAK,CAAC,IAAK;oBACjB,MAAM,EAAE,KAAK,CAAC,SAAS;iBACxB;aACF,aAEC,aAAa,EAAE,IAAI,IAChB,CAAC,OAAO,IAAI,EAAE,CAAC,EAErB;iBACE,KAAK,CAAC,IAAI,CAAC;iBACX,GAAG,CAAC,UAAC,IAAY,IAAK,OAAA,IAAI,GAAG,IAAI,EAAX,CAAW,CAAC;iBAClC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;SACjB;QAED,IAAM,KAAK,GAAG;YACZ,KAAK,CAAC,OAAO,CACR,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,YAAO,KAAK,CAAC,IAAI,SAAI,KAAK,CAAC,IAAI,SAC5D,KAAK,CAAC,SAAS,OACb,CACL;YACD,KAAK,CAAC,QAAQ,CAAI,KAAK,CAAC,IAAI,SAAI,KAAK,CAAC,SAAS,SAAI,KAAK,CAAC,OAAS,CAAC;SACpE,CAAC;QACF,IAAI,KAAK,EAAE;YACT,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACnB;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC;AAEQ,4DAAwB"}

View file

@ -0,0 +1,3 @@
import { Formatter } from './Formatter';
declare function createDefaultFormatter(): Formatter;
export { createDefaultFormatter };

View file

@ -0,0 +1,39 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var os = __importStar(require("os"));
var chalk_1 = __importDefault(require("chalk"));
var issue_1 = require("../issue");
var InternalFormatter_1 = require("./InternalFormatter");
function createDefaultFormatter() {
return function defaultFormatter(issue) {
var color = {
message: issue.severity === issue_1.IssueSeverity.WARNING
? chalk_1.default.bold.yellow
: chalk_1.default.bold.red,
position: chalk_1.default.bold.cyan,
code: chalk_1.default.grey
};
if (issue.origin === issue_1.IssueOrigin.INTERNAL) {
return InternalFormatter_1.createInternalFormatter()(issue);
}
var code = issue.origin === issue_1.IssueOrigin.TYPESCRIPT ? "TS" + issue.code : issue.code;
return [
color.message(issue.severity.toUpperCase() + " in ") +
color.position(issue.file + "(" + issue.line + "," + issue.character + ")") +
color.message(':'),
color.code(code + ': ') + issue.message
].join(os.EOL);
};
}
exports.createDefaultFormatter = createDefaultFormatter;
//# sourceMappingURL=DefaultFormatter.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"DefaultFormatter.js","sourceRoot":"./","sources":["formatter/DefaultFormatter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAyB;AACzB,gDAA0B;AAE1B,kCAAsD;AAEtD,yDAA8D;AAE9D,SAAS,sBAAsB;IAC7B,OAAO,SAAS,gBAAgB,CAAC,KAAK;QACpC,IAAM,KAAK,GAAG;YACZ,OAAO,EACL,KAAK,CAAC,QAAQ,KAAK,qBAAa,CAAC,OAAO;gBACtC,CAAC,CAAC,eAAK,CAAC,IAAI,CAAC,MAAM;gBACnB,CAAC,CAAC,eAAK,CAAC,IAAI,CAAC,GAAG;YACpB,QAAQ,EAAE,eAAK,CAAC,IAAI,CAAC,IAAI;YACzB,IAAI,EAAE,eAAK,CAAC,IAAI;SACjB,CAAC;QAEF,IAAI,KAAK,CAAC,MAAM,KAAK,mBAAW,CAAC,QAAQ,EAAE;YACzC,OAAO,2CAAuB,EAAE,CAAC,KAAK,CAAC,CAAC;SACzC;QAED,IAAM,IAAI,GACR,KAAK,CAAC,MAAM,KAAK,mBAAW,CAAC,UAAU,CAAC,CAAC,CAAC,OAAK,KAAK,CAAC,IAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;QAE3E,OAAO;YACL,KAAK,CAAC,OAAO,CAAI,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,SAAM,CAAC;gBAClD,KAAK,CAAC,QAAQ,CAAI,KAAK,CAAC,IAAI,SAAI,KAAK,CAAC,IAAI,SAAI,KAAK,CAAC,SAAS,MAAG,CAAC;gBACjE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;YACpB,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,KAAK,CAAC,OAAO;SACxC,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC;AAEQ,wDAAsB"}

View file

@ -0,0 +1,3 @@
import { Issue } from '../issue';
declare type Formatter = (issue: Issue) => string;
export { Formatter };

View file

@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=Formatter.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"Formatter.js","sourceRoot":"./","sources":["formatter/Formatter.ts"],"names":[],"mappings":""}

View file

@ -0,0 +1,6 @@
import { Formatter } from './Formatter';
import { CodeFrameFormatterOptions } from './CodeframeFormatter';
declare type FormatterType = undefined | 'default' | 'codeframe' | Formatter;
declare type FormatterOptions = CodeFrameFormatterOptions;
declare function createFormatter(type?: FormatterType, options?: FormatterOptions): Formatter;
export { createFormatter, FormatterType, FormatterOptions };

View file

@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var CodeframeFormatter_1 = require("./CodeframeFormatter");
var DefaultFormatter_1 = require("./DefaultFormatter");
function createFormatter(type, options) {
if (typeof type === 'function') {
return type;
}
switch (type) {
case 'codeframe':
return CodeframeFormatter_1.createCodeframeFormatter(options);
case 'default':
case undefined:
return DefaultFormatter_1.createDefaultFormatter();
default:
throw new Error('Unknown "' +
type +
'" formatter. Available types are: default, codeframe.');
}
}
exports.createFormatter = createFormatter;
//# sourceMappingURL=FormatterFactory.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"FormatterFactory.js","sourceRoot":"./","sources":["formatter/FormatterFactory.ts"],"names":[],"mappings":";;AACA,2DAG8B;AAC9B,uDAA4D;AAK5D,SAAS,eAAe,CACtB,IAAoB,EACpB,OAA0B;IAE1B,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;QAC9B,OAAO,IAAI,CAAC;KACb;IAED,QAAQ,IAAI,EAAE;QACZ,KAAK,WAAW;YACd,OAAO,6CAAwB,CAAC,OAAO,CAAC,CAAC;QAE3C,KAAK,SAAS,CAAC;QACf,KAAK,SAAS;YACZ,OAAO,yCAAsB,EAAE,CAAC;QAElC;YACE,MAAM,IAAI,KAAK,CACb,WAAW;gBACT,IAAI;gBACJ,uDAAuD,CAC1D,CAAC;KACL;AACH,CAAC;AAEQ,0CAAe"}

View file

@ -0,0 +1,6 @@
import { Formatter } from './Formatter';
/**
* TODO: maybe we should not treat internal errors as issues
*/
declare function createInternalFormatter(): Formatter;
export { createInternalFormatter };

View file

@ -0,0 +1,40 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var chalk_1 = __importDefault(require("chalk"));
var os = __importStar(require("os"));
var issue_1 = require("../issue");
/**
* TODO: maybe we should not treat internal errors as issues
*/
function createInternalFormatter() {
return function internalFormatter(issue) {
var color = {
message: chalk_1.default.bold.red,
stack: chalk_1.default.grey
};
if (issue.origin === issue_1.IssueOrigin.INTERNAL) {
var lines = [
color.message('INTERNAL ' + issue.severity.toUpperCase()) + ": " + issue.message
];
if (issue.stack) {
lines.push('stack trace:', color.stack(issue.stack));
}
return lines.join(os.EOL);
}
else {
throw new Error("Not supported \"" + issue.origin + "\" issue origin.");
}
};
}
exports.createInternalFormatter = createInternalFormatter;
//# sourceMappingURL=InternalFormatter.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"InternalFormatter.js","sourceRoot":"./","sources":["formatter/InternalFormatter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAA0B;AAC1B,qCAAyB;AAEzB,kCAAuC;AAGvC;;GAEG;AACH,SAAS,uBAAuB;IAC9B,OAAO,SAAS,iBAAiB,CAAC,KAAK;QACrC,IAAM,KAAK,GAAG;YACZ,OAAO,EAAE,eAAK,CAAC,IAAI,CAAC,GAAG;YACvB,KAAK,EAAE,eAAK,CAAC,IAAI;SAClB,CAAC;QAEF,IAAI,KAAK,CAAC,MAAM,KAAK,mBAAW,CAAC,QAAQ,EAAE;YACzC,IAAM,KAAK,GAAG;gBACT,KAAK,CAAC,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,UAC1D,KAAK,CAAC,OACN;aACH,CAAC;YACF,IAAI,KAAK,CAAC,KAAK,EAAE;gBACf,KAAK,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;aACtD;YAED,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;SAC3B;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,qBAAkB,KAAK,CAAC,MAAM,qBAAiB,CAAC,CAAC;SAClE;IACH,CAAC,CAAC;AACJ,CAAC;AAEQ,0DAAuB"}

View file

@ -0,0 +1,3 @@
import { Formatter } from './Formatter';
declare function createRawFormatter(): Formatter;
export { createRawFormatter };

View file

@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var issue_1 = require("../issue");
function createRawFormatter() {
return function rawFormatter(issue) {
var code = issue.origin === issue_1.IssueOrigin.TYPESCRIPT ? "TS" + issue.code : issue.code;
return issue.severity.toUpperCase() + " " + code + ": " + issue.message;
};
}
exports.createRawFormatter = createRawFormatter;
//# sourceMappingURL=RawFormatter.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"RawFormatter.js","sourceRoot":"./","sources":["formatter/RawFormatter.ts"],"names":[],"mappings":";;AACA,kCAAuC;AAEvC,SAAS,kBAAkB;IACzB,OAAO,SAAS,YAAY,CAAC,KAAK;QAChC,IAAM,IAAI,GACR,KAAK,CAAC,MAAM,KAAK,mBAAW,CAAC,UAAU,CAAC,CAAC,CAAC,OAAK,KAAK,CAAC,IAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;QAE3E,OAAU,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,SAAI,IAAI,UAAK,KAAK,CAAC,OAAS,CAAC;IACrE,CAAC,CAAC;AACJ,CAAC;AAEQ,gDAAkB"}

View file

@ -0,0 +1,6 @@
export * from './Formatter';
export * from './DefaultFormatter';
export * from './CodeframeFormatter';
export * from './FormatterFactory';
export * from './InternalFormatter';
export * from './RawFormatter';

View file

@ -0,0 +1,11 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./DefaultFormatter"));
__export(require("./CodeframeFormatter"));
__export(require("./FormatterFactory"));
__export(require("./InternalFormatter"));
__export(require("./RawFormatter"));
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"./","sources":["formatter/index.ts"],"names":[],"mappings":";;;;;AACA,wCAAmC;AACnC,0CAAqC;AACrC,wCAAmC;AACnC,yCAAoC;AACpC,oCAA+B"}

View file

@ -0,0 +1,4 @@
import * as webpack from 'webpack';
import { AsyncSeriesHook, SyncHook } from 'tapable';
export declare type ForkTsCheckerHooks = 'serviceBeforeStart' | 'cancel' | 'serviceStartError' | 'waiting' | 'serviceStart' | 'receive' | 'serviceOutOfMemory' | 'emit' | 'done';
export declare function getForkTsCheckerWebpackPluginHooks(compiler: webpack.Compiler): Record<ForkTsCheckerHooks, SyncHook<any, any, any> | AsyncSeriesHook<any, any, any>>;

View file

@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tapable_1 = require("tapable");
var compilerHookMap = new WeakMap();
function createForkTsCheckerWebpackPluginHooks() {
return {
serviceBeforeStart: new tapable_1.AsyncSeriesHook([]),
cancel: new tapable_1.SyncHook(['cancellationToken']),
serviceStartError: new tapable_1.SyncHook(['error']),
waiting: new tapable_1.SyncHook([]),
serviceStart: new tapable_1.SyncHook(['tsconfigPath', 'memoryLimit']),
receive: new tapable_1.SyncHook(['diagnostics', 'lints']),
serviceOutOfMemory: new tapable_1.SyncHook([]),
emit: new tapable_1.SyncHook(['diagnostics', 'lints', 'elapsed']),
done: new tapable_1.SyncHook(['diagnostics', 'lints', 'elapsed'])
};
}
function getForkTsCheckerWebpackPluginHooks(compiler) {
var hooks = compilerHookMap.get(compiler);
if (hooks === undefined) {
hooks = createForkTsCheckerWebpackPluginHooks();
compilerHookMap.set(compiler, hooks);
}
return hooks;
}
exports.getForkTsCheckerWebpackPluginHooks = getForkTsCheckerWebpackPluginHooks;
//# sourceMappingURL=hooks.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"hooks.js","sourceRoot":"./","sources":["hooks.ts"],"names":[],"mappings":";;AACA,mCAAoD;AAiBpD,IAAM,eAAe,GAAG,IAAI,OAAO,EAA0C,CAAC;AAE9E,SAAS,qCAAqC;IAC5C,OAAO;QACL,kBAAkB,EAAE,IAAI,yBAAe,CAAC,EAAE,CAAC;QAC3C,MAAM,EAAE,IAAI,kBAAQ,CAAC,CAAC,mBAAmB,CAAC,CAAC;QAC3C,iBAAiB,EAAE,IAAI,kBAAQ,CAAC,CAAC,OAAO,CAAC,CAAC;QAC1C,OAAO,EAAE,IAAI,kBAAQ,CAAC,EAAE,CAAC;QACzB,YAAY,EAAE,IAAI,kBAAQ,CAAC,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;QAC3D,OAAO,EAAE,IAAI,kBAAQ,CAAC,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QAC/C,kBAAkB,EAAE,IAAI,kBAAQ,CAAC,EAAE,CAAC;QACpC,IAAI,EAAE,IAAI,kBAAQ,CAAC,CAAC,aAAa,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;QACvD,IAAI,EAAE,IAAI,kBAAQ,CAAC,CAAC,aAAa,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;KACxD,CAAC;AACJ,CAAC;AAED,SAAgB,kCAAkC,CAAC,QAA0B;IAC3E,IAAI,KAAK,GAAG,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1C,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,KAAK,GAAG,qCAAqC,EAAE,CAAC;QAChD,eAAe,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;KACtC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAPD,gFAOC"}

View file

@ -0,0 +1,108 @@
import { RpcProvider } from 'worker-rpc';
import { FormatterType, FormatterOptions } from './formatter';
import { VueOptions } from './types/vue-options';
import { Options as EslintOptions } from './types/eslint';
declare namespace ForkTsCheckerWebpackPlugin {
interface Logger {
error(message?: any): void;
warn(message?: any): void;
info(message?: any): void;
}
interface Options {
typescript: string;
tsconfig: string;
compilerOptions: object;
eslint: boolean;
/** Options to supply to eslint https://eslint.org/docs/developer-guide/nodejs-api#cliengine */
eslintOptions: EslintOptions;
async: boolean;
ignoreDiagnostics: number[];
ignoreLints: string[];
ignoreLintWarnings: boolean;
reportFiles: string[];
logger: Logger;
formatter: FormatterType;
formatterOptions: FormatterOptions;
silent: boolean;
checkSyntacticErrors: boolean;
memoryLimit: number;
vue: boolean | Partial<VueOptions>;
useTypescriptIncrementalApi: boolean;
measureCompilationTime: boolean;
resolveModuleNameModule: string;
resolveTypeReferenceDirectiveModule: string;
}
}
/**
* ForkTsCheckerWebpackPlugin
* Runs typescript type checker and linter on separate process.
* This speed-ups build a lot.
*
* Options description in README.md
*/
declare class ForkTsCheckerWebpackPlugin {
static readonly DEFAULT_MEMORY_LIMIT = 2048;
static getCompilerHooks(compiler: any): Record<import("./hooks").ForkTsCheckerHooks, import("tapable").SyncHook<any, any, any> | import("tapable").AsyncSeriesHook<any, any, any>>;
readonly options: Partial<ForkTsCheckerWebpackPlugin.Options>;
private tsconfig;
private compilerOptions;
private eslint;
private eslintOptions;
private ignoreDiagnostics;
private ignoreLints;
private ignoreLintWarnings;
private reportFiles;
private logger;
private silent;
private async;
private checkSyntacticErrors;
private memoryLimit;
private formatter;
private rawFormatter;
private useTypescriptIncrementalApi;
private resolveModuleNameModule;
private resolveTypeReferenceDirectiveModule;
private tsconfigPath;
private compiler;
private started;
private elapsed;
private cancellationToken;
private isWatching;
private checkDone;
private compilationDone;
private diagnostics;
private lints;
private emitCallback;
private doneCallback;
private typescriptPath;
private typescript;
private typescriptVersion;
private eslintVersion;
private service?;
protected serviceRpc?: RpcProvider;
private vue;
private measureTime;
private performance;
private startAt;
protected nodeArgs: string[];
constructor(options?: Partial<ForkTsCheckerWebpackPlugin.Options>);
private validateTypeScript;
private validateEslint;
private static prepareVueOptions;
apply(compiler: any): void;
private computeContextPath;
private pluginStart;
private pluginStop;
private pluginCompile;
private pluginEmit;
private pluginDone;
private spawnService;
private killService;
private handleServiceMessage;
private handleServiceExit;
private createEmitCallback;
private createNoopEmitCallback;
private printLoggerMessage;
private createDoneCallback;
}
export = ForkTsCheckerWebpackPlugin;

View file

@ -0,0 +1,510 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var path = __importStar(require("path"));
var childProcess = __importStar(require("child_process"));
var semver = __importStar(require("semver"));
var micromatch_1 = __importDefault(require("micromatch"));
var chalk_1 = __importDefault(require("chalk"));
var worker_rpc_1 = require("worker-rpc");
var CancellationToken_1 = require("./CancellationToken");
var formatter_1 = require("./formatter");
var FsHelper_1 = require("./FsHelper");
var hooks_1 = require("./hooks");
var RpcTypes_1 = require("./RpcTypes");
var issue_1 = require("./issue");
var checkerPluginName = 'fork-ts-checker-webpack-plugin';
/**
* ForkTsCheckerWebpackPlugin
* Runs typescript type checker and linter on separate process.
* This speed-ups build a lot.
*
* Options description in README.md
*/
var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
function ForkTsCheckerWebpackPlugin(options) {
this.eslint = false;
this.eslintOptions = {};
this.tsconfigPath = undefined;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.compiler = undefined;
this.started = undefined;
this.elapsed = undefined;
this.cancellationToken = undefined;
this.isWatching = false;
this.checkDone = false;
this.compilationDone = false;
this.diagnostics = [];
this.lints = [];
this.eslintVersion = undefined;
this.startAt = 0;
this.nodeArgs = [];
options = options || {};
this.options = __assign({}, options);
this.ignoreDiagnostics = options.ignoreDiagnostics || [];
this.ignoreLints = options.ignoreLints || [];
this.ignoreLintWarnings = options.ignoreLintWarnings === true;
this.reportFiles = options.reportFiles || [];
this.logger = options.logger || console;
this.silent = options.silent === true; // default false
this.async = options.async !== false; // default true
this.checkSyntacticErrors = options.checkSyntacticErrors === true; // default false
this.resolveModuleNameModule = options.resolveModuleNameModule;
this.resolveTypeReferenceDirectiveModule =
options.resolveTypeReferenceDirectiveModule;
this.memoryLimit =
options.memoryLimit || ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT;
this.formatter = formatter_1.createFormatter(options.formatter, options.formatterOptions);
this.rawFormatter = formatter_1.createRawFormatter();
this.emitCallback = this.createNoopEmitCallback();
this.doneCallback = this.createDoneCallback();
var _a = this.validateTypeScript(options), typescript = _a.typescript, typescriptPath = _a.typescriptPath, typescriptVersion = _a.typescriptVersion, tsconfig = _a.tsconfig, compilerOptions = _a.compilerOptions;
this.typescript = typescript;
this.typescriptPath = typescriptPath;
this.typescriptVersion = typescriptVersion;
this.tsconfig = tsconfig;
this.compilerOptions = compilerOptions;
if (options.eslint === true) {
var _b = this.validateEslint(options), eslintVersion = _b.eslintVersion, eslintOptions = _b.eslintOptions;
this.eslint = true;
this.eslintVersion = eslintVersion;
this.eslintOptions = eslintOptions;
}
this.vue = ForkTsCheckerWebpackPlugin.prepareVueOptions(options.vue);
this.useTypescriptIncrementalApi =
options.useTypescriptIncrementalApi === undefined
? semver.gte(this.typescriptVersion, '3.0.0') && !this.vue.enabled
: options.useTypescriptIncrementalApi;
this.measureTime = options.measureCompilationTime === true;
if (this.measureTime) {
if (semver.lt(process.version, '8.5.0')) {
throw new Error("To use 'measureCompilationTime' option, please update to Node.js >= v8.5.0 " +
("(current version is " + process.version + ")"));
}
// Node 8+ only
// eslint-disable-next-line node/no-unsupported-features/node-builtins
this.performance = require('perf_hooks').performance;
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ForkTsCheckerWebpackPlugin.getCompilerHooks = function (compiler) {
return hooks_1.getForkTsCheckerWebpackPluginHooks(compiler);
};
ForkTsCheckerWebpackPlugin.prototype.validateTypeScript = function (options) {
var typescriptPath = options.typescript || require.resolve('typescript');
var tsconfig = options.tsconfig || './tsconfig.json';
var compilerOptions = typeof options.compilerOptions === 'object'
? options.compilerOptions
: {};
var typescript, typescriptVersion;
try {
typescript = require(typescriptPath);
typescriptVersion = typescript.version;
}
catch (_ignored) {
throw new Error('When you use this plugin you must install `typescript`.');
}
if (semver.lt(typescriptVersion, '2.1.0')) {
throw new Error("Cannot use current typescript version of " + typescriptVersion + ", the minimum required version is 2.1.0");
}
return {
typescriptPath: typescriptPath,
typescript: typescript,
typescriptVersion: typescriptVersion,
tsconfig: tsconfig,
compilerOptions: compilerOptions
};
};
ForkTsCheckerWebpackPlugin.prototype.validateEslint = function (options) {
var eslintVersion;
var eslintOptions = typeof options.eslintOptions === 'object' ? options.eslintOptions : {};
if (semver.lt(process.version, '8.10.0')) {
throw new Error("To use 'eslint' option, please update to Node.js >= v8.10.0 " +
("(current version is " + process.version + ")"));
}
try {
eslintVersion = require('eslint').Linter.version;
}
catch (error) {
throw new Error("When you use 'eslint' option, make sure to install 'eslint'.");
}
return { eslintVersion: eslintVersion, eslintOptions: eslintOptions };
};
ForkTsCheckerWebpackPlugin.prepareVueOptions = function (vueOptions) {
var defaultVueOptions = {
compiler: 'vue-template-compiler',
enabled: false
};
if (typeof vueOptions === 'boolean') {
return Object.assign(defaultVueOptions, { enabled: vueOptions });
}
else if (typeof vueOptions === 'object' && vueOptions !== null) {
return Object.assign(defaultVueOptions, vueOptions);
}
else {
return defaultVueOptions;
}
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ForkTsCheckerWebpackPlugin.prototype.apply = function (compiler) {
this.compiler = compiler;
this.tsconfigPath = this.computeContextPath(this.tsconfig);
// validate config
var tsconfigOk = FsHelper_1.fileExistsSync(this.tsconfigPath);
// validate logger
if (this.logger) {
if (!this.logger.error || !this.logger.warn || !this.logger.info) {
throw new Error("Invalid logger object - doesn't provide `error`, `warn` or `info` method.");
}
}
if (!tsconfigOk) {
throw new Error('Cannot find "' +
this.tsconfigPath +
'" file. Please check webpack and ForkTsCheckerWebpackPlugin configuration. \n' +
'Possible errors: \n' +
' - wrong `context` directory in webpack configuration' +
' (if `tsconfig` is not set or is a relative path in fork plugin configuration)\n' +
' - wrong `tsconfig` path in fork plugin configuration' +
' (should be a relative or absolute path)');
}
this.pluginStart();
this.pluginStop();
this.pluginCompile();
this.pluginEmit();
this.pluginDone();
};
ForkTsCheckerWebpackPlugin.prototype.computeContextPath = function (filePath) {
return path.isAbsolute(filePath)
? filePath
: path.resolve(this.compiler.options.context, filePath);
};
ForkTsCheckerWebpackPlugin.prototype.pluginStart = function () {
var _this = this;
var run = function (compilation, callback) {
_this.isWatching = false;
callback();
};
var watchRun = function (compiler, callback) {
_this.isWatching = true;
callback();
};
this.compiler.hooks.run.tapAsync(checkerPluginName, run);
this.compiler.hooks.watchRun.tapAsync(checkerPluginName, watchRun);
};
ForkTsCheckerWebpackPlugin.prototype.pluginStop = function () {
var _this = this;
var watchClose = function () {
_this.killService();
};
var doneOrFailed = function () {
if (!_this.isWatching) {
_this.killService();
}
};
this.compiler.hooks.watchClose.tap(checkerPluginName, watchClose);
this.compiler.hooks.done.tap(checkerPluginName, doneOrFailed);
this.compiler.hooks.failed.tap(checkerPluginName, doneOrFailed);
process.on('exit', function () {
_this.killService();
});
};
ForkTsCheckerWebpackPlugin.prototype.pluginCompile = function () {
var _this = this;
var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
this.compiler.hooks.compile.tap(checkerPluginName, function () {
_this.compilationDone = false;
forkTsCheckerHooks.serviceBeforeStart.callAsync(function () {
if (_this.cancellationToken) {
// request cancellation if there is not finished job
_this.cancellationToken.requestCancellation();
forkTsCheckerHooks.cancel.call(_this.cancellationToken);
}
_this.checkDone = false;
_this.started = process.hrtime();
// create new token for current job
_this.cancellationToken = new CancellationToken_1.CancellationToken(_this.typescript);
if (!_this.service || !_this.service.connected) {
_this.spawnService();
}
try {
if (_this.measureTime) {
_this.startAt = _this.performance.now();
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
_this.serviceRpc.rpc(RpcTypes_1.RUN, _this.cancellationToken.toJSON()).then(function (result) {
if (result) {
_this.handleServiceMessage(result);
}
});
}
catch (error) {
if (!_this.silent && _this.logger) {
_this.logger.error(chalk_1.default.red('Cannot start checker service: ' +
(error ? error.toString() : 'Unknown error')));
}
forkTsCheckerHooks.serviceStartError.call(error);
}
});
});
};
ForkTsCheckerWebpackPlugin.prototype.pluginEmit = function () {
var _this = this;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var emit = function (compilation, callback) {
if (_this.isWatching && _this.async) {
callback();
return;
}
_this.emitCallback = _this.createEmitCallback(compilation, callback);
if (_this.checkDone) {
_this.emitCallback();
}
_this.compilationDone = true;
};
this.compiler.hooks.emit.tapAsync(checkerPluginName, emit);
};
ForkTsCheckerWebpackPlugin.prototype.pluginDone = function () {
var _this = this;
var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
this.compiler.hooks.done.tap(checkerPluginName, function () {
if (!_this.isWatching || !_this.async) {
return;
}
if (_this.checkDone) {
_this.doneCallback();
}
else {
if (_this.compiler) {
forkTsCheckerHooks.waiting.call();
}
if (!_this.silent && _this.logger) {
_this.logger.info('Type checking in progress...');
}
}
_this.compilationDone = true;
});
};
ForkTsCheckerWebpackPlugin.prototype.spawnService = function () {
var _this = this;
var env = __assign({}, process.env, { TYPESCRIPT_PATH: this.typescriptPath, TSCONFIG: this.tsconfigPath, COMPILER_OPTIONS: JSON.stringify(this.compilerOptions), CONTEXT: this.compiler.options.context, ESLINT: String(this.eslint), ESLINT_OPTIONS: JSON.stringify(this.eslintOptions), MEMORY_LIMIT: String(this.memoryLimit), CHECK_SYNTACTIC_ERRORS: String(this.checkSyntacticErrors), USE_INCREMENTAL_API: String(this.useTypescriptIncrementalApi === true), VUE: JSON.stringify(this.vue) });
if (typeof this.resolveModuleNameModule !== 'undefined') {
env.RESOLVE_MODULE_NAME = this.resolveModuleNameModule;
}
else {
delete env.RESOLVE_MODULE_NAME;
}
if (typeof this.resolveTypeReferenceDirectiveModule !== 'undefined') {
env.RESOLVE_TYPE_REFERENCE_DIRECTIVE = this.resolveTypeReferenceDirectiveModule;
}
else {
delete env.RESOLVE_TYPE_REFERENCE_DIRECTIVE;
}
this.service = childProcess.fork(path.resolve(__dirname, './service.js'), [], {
env: env,
execArgv: ['--max-old-space-size=' + this.memoryLimit].concat(this.nodeArgs),
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
});
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.serviceRpc = new worker_rpc_1.RpcProvider(function (message) { return _this.service.send(message); });
this.service.on('message', function (message) {
if (_this.serviceRpc) {
// ensure that serviceRpc is defined to avoid race-conditions
_this.serviceRpc.dispatch(message);
}
});
var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
forkTsCheckerHooks.serviceStart.call(this.tsconfigPath, this.memoryLimit);
if (!this.silent && this.logger) {
this.logger.info('Starting type checking service...');
}
this.service.on('exit', function (code, signal) {
return _this.handleServiceExit(code, signal);
});
};
ForkTsCheckerWebpackPlugin.prototype.killService = function () {
if (!this.service) {
return;
}
try {
if (this.cancellationToken) {
this.cancellationToken.cleanupCancellation();
}
// clean-up listeners
this.service.removeAllListeners();
this.service.kill();
this.service = undefined;
this.serviceRpc = undefined;
}
catch (e) {
if (this.logger && !this.silent) {
this.logger.error(e);
}
}
};
ForkTsCheckerWebpackPlugin.prototype.handleServiceMessage = function (message) {
var _this = this;
if (this.measureTime) {
var delta = this.performance.now() - this.startAt;
var deltaRounded = Math.round(delta * 100) / 100;
this.logger.info("Compilation took: " + deltaRounded + " ms.");
}
if (this.cancellationToken) {
this.cancellationToken.cleanupCancellation();
// job is done - nothing to cancel
this.cancellationToken = undefined;
}
this.checkDone = true;
this.elapsed = process.hrtime(this.started);
this.diagnostics = message.diagnostics;
this.lints = message.lints;
if (this.ignoreDiagnostics.length) {
this.diagnostics = this.diagnostics.filter(function (diagnostic) {
return !_this.ignoreDiagnostics.includes(parseInt(diagnostic.code, 10));
});
}
if (this.ignoreLints.length) {
this.lints = this.lints.filter(function (lint) { return !_this.ignoreLints.includes(lint.code); });
}
if (this.reportFiles.length) {
var reportFilesPredicate = function (issue) {
if (issue.file) {
var relativeFileName = path.relative(_this.compiler.options.context, issue.file);
var matchResult = micromatch_1.default([relativeFileName], _this.reportFiles);
if (matchResult.length === 0) {
return false;
}
}
return true;
};
this.diagnostics = this.diagnostics.filter(reportFilesPredicate);
this.lints = this.lints.filter(reportFilesPredicate);
}
var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
forkTsCheckerHooks.receive.call(this.diagnostics, this.lints);
if (this.compilationDone) {
this.isWatching && this.async ? this.doneCallback() : this.emitCallback();
}
};
ForkTsCheckerWebpackPlugin.prototype.handleServiceExit = function (_code, signal) {
if (signal !== 'SIGABRT' && signal !== 'SIGINT') {
return;
}
// probably out of memory :/
if (this.compiler) {
var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
forkTsCheckerHooks.serviceOutOfMemory.call();
}
if (!this.silent && this.logger) {
if (signal === 'SIGINT') {
this.logger.error(chalk_1.default.red('Type checking and linting interrupted - If running in a docker container, this may be caused ' +
"by the container running out of memory. If so, try increasing the container's memory limit " +
'or lowering the memoryLimit value in the ForkTsCheckerWebpackPlugin configuration.'));
}
else {
this.logger.error(chalk_1.default.red('Type checking and linting aborted - probably out of memory. ' +
'Check `memoryLimit` option in ForkTsCheckerWebpackPlugin configuration.'));
}
}
};
ForkTsCheckerWebpackPlugin.prototype.createEmitCallback = function (compilation, callback) {
return function emitCallback() {
var _this = this;
if (!this.elapsed) {
throw new Error('Execution order error');
}
var elapsed = Math.round(this.elapsed[0] * 1e9 + this.elapsed[1]);
var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
forkTsCheckerHooks.emit.call(this.diagnostics, this.lints, elapsed);
this.diagnostics.concat(this.lints).forEach(function (issue) {
// webpack message format
var formatted = {
rawMessage: _this.rawFormatter(issue),
message: _this.formatter(issue),
location: {
line: issue.line,
character: issue.character
},
file: issue.file
};
if (issue.severity === issue_1.IssueSeverity.WARNING) {
if (!_this.ignoreLintWarnings) {
compilation.warnings.push(formatted);
}
}
else {
compilation.errors.push(formatted);
}
});
callback();
};
};
ForkTsCheckerWebpackPlugin.prototype.createNoopEmitCallback = function () {
// this function is empty intentionally
// eslint-disable-next-line @typescript-eslint/no-empty-function
return function noopEmitCallback() { };
};
ForkTsCheckerWebpackPlugin.prototype.printLoggerMessage = function (issue, formattedIssue) {
if (issue.severity === issue_1.IssueSeverity.WARNING) {
if (this.ignoreLintWarnings) {
return;
}
this.logger.warn(formattedIssue);
}
else {
this.logger.error(formattedIssue);
}
};
ForkTsCheckerWebpackPlugin.prototype.createDoneCallback = function () {
return function doneCallback() {
var _this = this;
if (!this.elapsed) {
throw new Error('Execution order error');
}
var elapsed = Math.round(this.elapsed[0] * 1e9 + this.elapsed[1]);
if (this.compiler) {
var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
forkTsCheckerHooks.done.call(this.diagnostics, this.lints, elapsed);
}
if (!this.silent && this.logger) {
if (this.diagnostics.length || this.lints.length) {
(this.lints || []).concat(this.diagnostics).forEach(function (diagnostic) {
var formattedDiagnostic = _this.formatter(diagnostic);
_this.printLoggerMessage(diagnostic, formattedDiagnostic);
});
}
if (!this.diagnostics.length) {
this.logger.info(chalk_1.default.green('No type errors found'));
}
this.logger.info('Version: typescript ' +
chalk_1.default.bold(this.typescriptVersion) +
(this.eslint
? ', eslint ' + chalk_1.default.bold(this.eslintVersion)
: ''));
this.logger.info("Time: " + chalk_1.default.bold(Math.round(elapsed / 1e6).toString()) + " ms");
}
};
};
ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT = 2048;
return ForkTsCheckerWebpackPlugin;
}());
module.exports = ForkTsCheckerWebpackPlugin;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,15 @@
import { IssueSeverity } from './IssueSeverity';
import { IssueOrigin } from './IssueOrigin';
interface Issue {
origin: IssueOrigin;
severity: IssueSeverity;
code: string;
message: string;
file?: string;
line?: number;
character?: number;
stack?: string;
}
declare function isIssue(value: unknown): value is Issue;
declare function deduplicateAndSortIssues(issues: Issue[]): Issue[];
export { Issue, isIssue, deduplicateAndSortIssues };

View file

@ -0,0 +1,59 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var IssueSeverity_1 = require("./IssueSeverity");
var IssueOrigin_1 = require("./IssueOrigin");
function isIssue(value) {
return (!!value &&
typeof value === 'object' &&
IssueOrigin_1.isIssueOrigin(value.origin) &&
IssueSeverity_1.isIssueSeverity(value.severity) &&
!!value.code &&
!!value.message);
}
exports.isIssue = isIssue;
function compareOptionalStrings(stringA, stringB) {
if (stringA === stringB) {
return 0;
}
if (stringA === undefined || stringA === null) {
return -1;
}
if (stringB === undefined || stringB === null) {
return 1;
}
return stringA.toString().localeCompare(stringB.toString());
}
function compareNumbers(numberA, numberB) {
if (numberA === numberB) {
return 0;
}
if (numberA === undefined || numberA === null) {
return -1;
}
if (numberB === undefined || numberB === null) {
return 1;
}
return Math.sign(numberA - numberB);
}
function compareIssues(issueA, issueB) {
return (IssueOrigin_1.compareIssueOrigins(issueA.origin, issueB.origin) ||
compareOptionalStrings(issueA.file, issueB.file) ||
IssueSeverity_1.compareIssueSeverities(issueA.severity, issueB.severity) ||
compareNumbers(issueA.line, issueB.line) ||
compareNumbers(issueA.character, issueB.character) ||
compareOptionalStrings(issueA.code, issueB.code) ||
compareOptionalStrings(issueA.message, issueB.message) ||
compareOptionalStrings(issueA.stack, issueB.stack) ||
0 /* EqualTo */);
}
function equalsIssues(issueA, issueB) {
return compareIssues(issueA, issueB) === 0;
}
function deduplicateAndSortIssues(issues) {
var sortedIssues = issues.filter(isIssue).sort(compareIssues);
return sortedIssues.filter(function (issue, index) {
return index === 0 || !equalsIssues(issue, sortedIssues[index - 1]);
});
}
exports.deduplicateAndSortIssues = deduplicateAndSortIssues;
//# sourceMappingURL=Issue.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"Issue.js","sourceRoot":"./","sources":["issue/Issue.ts"],"names":[],"mappings":";;AAAA,iDAIyB;AACzB,6CAAgF;AAahF,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,CACL,CAAC,CAAC,KAAK;QACP,OAAO,KAAK,KAAK,QAAQ;QACzB,2BAAa,CAAE,KAAe,CAAC,MAAM,CAAC;QACtC,+BAAe,CAAE,KAAe,CAAC,QAAQ,CAAC;QAC1C,CAAC,CAAE,KAAe,CAAC,IAAI;QACvB,CAAC,CAAE,KAAe,CAAC,OAAO,CAC3B,CAAC;AACJ,CAAC;AA2De,0BAAO;AAzDvB,SAAS,sBAAsB,CAAC,OAAgB,EAAE,OAAgB;IAChE,IAAI,OAAO,KAAK,OAAO,EAAE;QACvB,OAAO,CAAC,CAAC;KACV;IAED,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,EAAE;QAC7C,OAAO,CAAC,CAAC,CAAC;KACX;IACD,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,EAAE;QAC7C,OAAO,CAAC,CAAC;KACV;IAED,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,cAAc,CAAC,OAAgB,EAAE,OAAgB;IACxD,IAAI,OAAO,KAAK,OAAO,EAAE;QACvB,OAAO,CAAC,CAAC;KACV;IAED,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,EAAE;QAC7C,OAAO,CAAC,CAAC,CAAC;KACX;IACD,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,EAAE;QAC7C,OAAO,CAAC,CAAC;KACV;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,CAAC;AACtC,CAAC;AAED,SAAS,aAAa,CAAC,MAAa,EAAE,MAAa;IACjD,OAAO,CACL,iCAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;QACjD,sBAAsB,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC;QAChD,sCAAsB,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;QACxD,cAAc,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC;QACxC,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC;QAClD,sBAAsB,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC;QAChD,sBAAsB,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;QACtD,sBAAsB,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;QAClD,CAAC,CAAC,aAAa,CAChB,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,MAAa,EAAE,MAAa;IAChD,OAAO,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,wBAAwB,CAAC,MAAe;IAC/C,IAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAEhE,OAAO,YAAY,CAAC,MAAM,CACxB,UAAC,KAAK,EAAE,KAAK;QACX,OAAA,KAAK,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAA5D,CAA4D,CAC/D,CAAC;AACJ,CAAC;AAEwB,4DAAwB"}

View file

@ -0,0 +1,9 @@
declare const IssueOrigin: {
readonly TYPESCRIPT: "typescript";
readonly ESLINT: "eslint";
readonly INTERNAL: "internal";
};
declare type IssueOrigin = typeof IssueOrigin[keyof typeof IssueOrigin];
declare function isIssueOrigin(value: unknown): value is IssueOrigin;
declare function compareIssueOrigins(originA: IssueOrigin, originB: IssueOrigin): number;
export { IssueOrigin, isIssueOrigin, compareIssueOrigins };

View file

@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var IssueOrigin = {
TYPESCRIPT: 'typescript',
ESLINT: 'eslint',
INTERNAL: 'internal'
};
exports.IssueOrigin = IssueOrigin;
function isIssueOrigin(value) {
return [
IssueOrigin.TYPESCRIPT,
IssueOrigin.ESLINT,
IssueOrigin.INTERNAL
].includes(value);
}
exports.isIssueOrigin = isIssueOrigin;
function compareIssueOrigins(originA, originB) {
var _a = [originA, originB].map(function (origin) {
return [
IssueOrigin.ESLINT /* 0 */,
IssueOrigin.TYPESCRIPT /* 1 */,
IssueOrigin.INTERNAL /* 2 */
].indexOf(origin);
}), priorityA = _a[0], priorityB = _a[1];
return Math.sign(priorityB - priorityA);
}
exports.compareIssueOrigins = compareIssueOrigins;
//# sourceMappingURL=IssueOrigin.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"IssueOrigin.js","sourceRoot":"./","sources":["issue/IssueOrigin.ts"],"names":[],"mappings":";;AAAA,IAAM,WAAW,GAAG;IAClB,UAAU,EAAE,YAAY;IACxB,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;CACZ,CAAC;AAuBF,kCAAW;AApBpB,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO;QACL,WAAW,CAAC,UAAU;QACtB,WAAW,CAAC,MAAM;QAClB,WAAW,CAAC,QAAQ;KACrB,CAAC,QAAQ,CAAC,KAAoB,CAAC,CAAC;AACnC,CAAC;AAcqB,sCAAa;AAZnC,SAAS,mBAAmB,CAAC,OAAoB,EAAE,OAAoB;IAC/D,IAAA;;;;;;MAML,EANM,iBAAS,EAAE,iBAMjB,CAAC;IAEF,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;AAC1C,CAAC;AAEoC,kDAAmB"}

View file

@ -0,0 +1,8 @@
declare const IssueSeverity: {
readonly ERROR: "error";
readonly WARNING: "warning";
};
declare type IssueSeverity = typeof IssueSeverity[keyof typeof IssueSeverity];
declare function isIssueSeverity(value: unknown): value is IssueSeverity;
declare function compareIssueSeverities(severityA: IssueSeverity, severityB: IssueSeverity): number;
export { IssueSeverity, isIssueSeverity, compareIssueSeverities };

View file

@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var IssueSeverity = {
ERROR: 'error',
WARNING: 'warning'
};
exports.IssueSeverity = IssueSeverity;
function isIssueSeverity(value) {
return [IssueSeverity.ERROR, IssueSeverity.WARNING].includes(value);
}
exports.isIssueSeverity = isIssueSeverity;
function compareIssueSeverities(severityA, severityB) {
var _a = [severityA, severityB].map(function (severity) {
return [IssueSeverity.WARNING /* 0 */, IssueSeverity.ERROR /* 1 */].indexOf(severity);
}), priorityA = _a[0], priorityB = _a[1];
return Math.sign(priorityB - priorityA);
}
exports.compareIssueSeverities = compareIssueSeverities;
//# sourceMappingURL=IssueSeverity.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"IssueSeverity.js","sourceRoot":"./","sources":["issue/IssueSeverity.ts"],"names":[],"mappings":";;AAAA,IAAM,aAAa,GAAG;IACpB,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;CACV,CAAC;AAsBF,sCAAa;AAnBtB,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,QAAQ,CAC1D,KAAsB,CACvB,CAAC;AACJ,CAAC;AAeuB,0CAAe;AAbvC,SAAS,sBAAsB,CAC7B,SAAwB,EACxB,SAAwB;IAElB,IAAA;;MAIL,EAJM,iBAAS,EAAE,iBAIjB,CAAC;IAEF,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;AAC1C,CAAC;AAEwC,wDAAsB"}

View file

@ -0,0 +1,4 @@
import { Issue } from '../Issue';
import { LintReport } from '../../types/eslint';
declare function createIssuesFromEsLintReports(reports: LintReport[]): Issue[];
export { createIssuesFromEsLintReports };

View file

@ -0,0 +1,44 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var Issue_1 = require("../Issue");
var IssueOrigin_1 = require("../IssueOrigin");
var IssueSeverity_1 = require("../IssueSeverity");
function createIssueFromEsLintMessage(message) {
return {
origin: IssueOrigin_1.IssueOrigin.ESLINT,
code: message.ruleId ? String(message.ruleId) : '[unknown]',
severity: message.severity === 1 ? IssueSeverity_1.IssueSeverity.WARNING : IssueSeverity_1.IssueSeverity.ERROR,
message: message.message,
file: message.filePath,
line: message.line,
character: message.column
};
}
function createFileAwareEsLintMessagesFromEsLintResult(result) {
return result.messages.map(function (message) { return (__assign({}, message, { filePath: result.filePath })); });
}
function createFileAwareEsLintMessagesFromEsLintReport(report) {
return report.results.reduce(function (messages, result) { return messages.concat(createFileAwareEsLintMessagesFromEsLintResult(result)); }, []);
}
function createFileAwareEsLintMessagesFromEsLintReports(reports) {
return reports.reduce(function (messages, report) { return messages.concat(createFileAwareEsLintMessagesFromEsLintReport(report)); }, []);
}
function createIssuesFromEsLintMessages(messages) {
return Issue_1.deduplicateAndSortIssues(messages.map(createIssueFromEsLintMessage));
}
function createIssuesFromEsLintReports(reports) {
return createIssuesFromEsLintMessages(createFileAwareEsLintMessagesFromEsLintReports(reports));
}
exports.createIssuesFromEsLintReports = createIssuesFromEsLintReports;
//# sourceMappingURL=EsLintIssueFactory.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"EsLintIssueFactory.js","sourceRoot":"./","sources":["issue/eslint/EsLintIssueFactory.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,kCAA2D;AAC3D,8CAA6C;AAC7C,kDAAiD;AAGjD,SAAS,4BAA4B,CAAC,OAA+B;IACnE,OAAO;QACL,MAAM,EAAE,yBAAW,CAAC,MAAM;QAC1B,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW;QAC3D,QAAQ,EACN,OAAO,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,6BAAa,CAAC,OAAO,CAAC,CAAC,CAAC,6BAAa,CAAC,KAAK;QACtE,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,IAAI,EAAE,OAAO,CAAC,QAAQ;QACtB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,SAAS,EAAE,OAAO,CAAC,MAAM;KAC1B,CAAC;AACJ,CAAC;AAED,SAAS,6CAA6C,CACpD,MAAkB;IAElB,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAA,OAAO,IAAI,OAAA,cACjC,OAAO,IACV,QAAQ,EAAE,MAAM,CAAC,QAAQ,IACzB,EAHoC,CAGpC,CAAC,CAAC;AACN,CAAC;AAED,SAAS,6CAA6C,CACpD,MAAkB;IAElB,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAC1B,UAAC,QAAQ,EAAE,MAAM,IAAK,OACjB,QAAQ,QACR,6CAA6C,CAAC,MAAM,CAAC,GAFpC,CAGrB,EACD,EAAE,CACH,CAAC;AACJ,CAAC;AAED,SAAS,8CAA8C,CACrD,OAAqB;IAErB,OAAO,OAAO,CAAC,MAAM,CACnB,UAAC,QAAQ,EAAE,MAAM,IAAK,OACjB,QAAQ,QACR,6CAA6C,CAAC,MAAM,CAAC,GAFpC,CAGrB,EACD,EAAE,CACH,CAAC;AACJ,CAAC;AAED,SAAS,8BAA8B,CACrC,QAAkC;IAElC,OAAO,gCAAwB,CAAC,QAAQ,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,6BAA6B,CAAC,OAAqB;IAC1D,OAAO,8BAA8B,CACnC,8CAA8C,CAAC,OAAO,CAAC,CACxD,CAAC;AACJ,CAAC;AAEQ,sEAA6B"}

View file

@ -0,0 +1,9 @@
import { LintMessage } from '../../types/eslint';
/**
* We need to define custom interface because of eslint architecture which
* groups lint messages per file
*/
interface FileAwareEsLintMessage extends LintMessage {
filePath?: string;
}
export { FileAwareEsLintMessage };

View file

@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=FileAwareEsLintMessage.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"FileAwareEsLintMessage.js","sourceRoot":"./","sources":["issue/eslint/FileAwareEsLintMessage.ts"],"names":[],"mappings":""}

View file

@ -0,0 +1,2 @@
export * from './FileAwareEsLintMessage';
export * from './EsLintIssueFactory';

View file

@ -0,0 +1,7 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./EsLintIssueFactory"));
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"./","sources":["issue/eslint/index.ts"],"names":[],"mappings":";;;;;AACA,0CAAqC"}

View file

@ -0,0 +1,6 @@
export * from './Issue';
export * from './IssueOrigin';
export * from './IssueSeverity';
export * from './typescript';
export * from './eslint';
export * from './internal';

View file

@ -0,0 +1,12 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./Issue"));
__export(require("./IssueOrigin"));
__export(require("./IssueSeverity"));
__export(require("./typescript"));
__export(require("./eslint"));
__export(require("./internal"));
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"./","sources":["issue/index.ts"],"names":[],"mappings":";;;;;AAAA,6BAAwB;AACxB,mCAA8B;AAC9B,qCAAgC;AAEhC,kCAA6B;AAC7B,8BAAyB;AACzB,gCAA2B"}

View file

@ -0,0 +1,8 @@
import { Issue } from '../Issue';
interface ErrorLike {
message?: string;
stack?: string;
toString?: () => string;
}
declare function createIssueFromInternalError(error: ErrorLike): Issue;
export { createIssueFromInternalError };

View file

@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var IssueOrigin_1 = require("../IssueOrigin");
var IssueSeverity_1 = require("../IssueSeverity");
function createIssueFromInternalError(error) {
return {
origin: IssueOrigin_1.IssueOrigin.INTERNAL,
severity: IssueSeverity_1.IssueSeverity.ERROR,
code: 'INTERNAL',
message: typeof error.message === 'string'
? error.message
: (error.toString && error.toString()) || '',
stack: typeof error.stack === 'string' ? error.stack : undefined
};
}
exports.createIssueFromInternalError = createIssueFromInternalError;
//# sourceMappingURL=InternalIssueFactory.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"InternalIssueFactory.js","sourceRoot":"./","sources":["issue/internal/InternalIssueFactory.ts"],"names":[],"mappings":";;AACA,8CAA6C;AAC7C,kDAAiD;AAQjD,SAAS,4BAA4B,CAAC,KAAgB;IACpD,OAAO;QACL,MAAM,EAAE,yBAAW,CAAC,QAAQ;QAC5B,QAAQ,EAAE,6BAAa,CAAC,KAAK;QAC7B,IAAI,EAAE,UAAU;QAChB,OAAO,EACL,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;YAC/B,CAAC,CAAC,KAAK,CAAC,OAAO;YACf,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE;QAChD,KAAK,EAAE,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;KACjE,CAAC;AACJ,CAAC;AAEQ,oEAA4B"}

View file

@ -0,0 +1 @@
export * from './InternalIssueFactory';

View file

@ -0,0 +1,7 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./InternalIssueFactory"));
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"./","sources":["issue/internal/index.ts"],"names":[],"mappings":";;;;;AAAA,4CAAuC"}

View file

@ -0,0 +1,5 @@
import * as ts from 'typescript';
import { Issue } from '../Issue';
declare function createIssueFromTsDiagnostic(diagnostic: ts.Diagnostic, typescript: typeof ts): Issue;
declare function createIssuesFromTsDiagnostics(diagnostics: ts.Diagnostic[], typescript: typeof ts): Issue[];
export { createIssueFromTsDiagnostic, createIssuesFromTsDiagnostics };

View file

@ -0,0 +1,37 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Issue_1 = require("../Issue");
var IssueOrigin_1 = require("../IssueOrigin");
var IssueSeverity_1 = require("../IssueSeverity");
function createIssueFromTsDiagnostic(diagnostic, typescript) {
var file;
var line;
var character;
if (diagnostic.file) {
file = diagnostic.file.fileName;
if (diagnostic.start) {
var position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
line = position.line + 1;
character = position.character + 1;
}
}
return {
origin: IssueOrigin_1.IssueOrigin.TYPESCRIPT,
code: String(diagnostic.code),
// we don't handle Suggestion and Message diagnostics
severity: diagnostic.category === 0 ? IssueSeverity_1.IssueSeverity.WARNING : IssueSeverity_1.IssueSeverity.ERROR,
message: typescript.flattenDiagnosticMessageText(diagnostic.messageText, '\n'),
file: file,
line: line,
character: character
};
}
exports.createIssueFromTsDiagnostic = createIssueFromTsDiagnostic;
function createIssuesFromTsDiagnostics(diagnostics, typescript) {
function createIssueFromTsDiagnosticWithFormatter(diagnostic) {
return createIssueFromTsDiagnostic(diagnostic, typescript);
}
return Issue_1.deduplicateAndSortIssues(diagnostics.map(createIssueFromTsDiagnosticWithFormatter));
}
exports.createIssuesFromTsDiagnostics = createIssuesFromTsDiagnostics;
//# sourceMappingURL=TypeScriptIssueFactory.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"TypeScriptIssueFactory.js","sourceRoot":"./","sources":["issue/typescript/TypeScriptIssueFactory.ts"],"names":[],"mappings":";;AACA,kCAA2D;AAC3D,8CAA6C;AAC7C,kDAAiD;AAEjD,SAAS,2BAA2B,CAClC,UAAyB,EACzB,UAAqB;IAErB,IAAI,IAAwB,CAAC;IAC7B,IAAI,IAAwB,CAAC;IAC7B,IAAI,SAA6B,CAAC;IAElC,IAAI,UAAU,CAAC,IAAI,EAAE;QACnB,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC;QAEhC,IAAI,UAAU,CAAC,KAAK,EAAE;YACpB,IAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,6BAA6B,CAC5D,UAAU,CAAC,KAAK,CACjB,CAAC;YACF,IAAI,GAAG,QAAQ,CAAC,IAAI,GAAG,CAAC,CAAC;YACzB,SAAS,GAAG,QAAQ,CAAC,SAAS,GAAG,CAAC,CAAC;SACpC;KACF;IAED,OAAO;QACL,MAAM,EAAE,yBAAW,CAAC,UAAU;QAC9B,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC;QAC7B,qDAAqD;QACrD,QAAQ,EACN,UAAU,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,6BAAa,CAAC,OAAO,CAAC,CAAC,CAAC,6BAAa,CAAC,KAAK;QACzE,OAAO,EAAE,UAAU,CAAC,4BAA4B,CAC9C,UAAU,CAAC,WAAW,EACtB,IAAI,CACL;QACD,IAAI,MAAA;QACJ,IAAI,MAAA;QACJ,SAAS,WAAA;KACV,CAAC;AACJ,CAAC;AAcQ,kEAA2B;AAZpC,SAAS,6BAA6B,CACpC,WAA4B,EAC5B,UAAqB;IAErB,SAAS,wCAAwC,CAAC,UAAyB;QACzE,OAAO,2BAA2B,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,gCAAwB,CAC7B,WAAW,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAC1D,CAAC;AACJ,CAAC;AAEqC,sEAA6B"}

View file

@ -0,0 +1 @@
export * from './TypeScriptIssueFactory';

View file

@ -0,0 +1,7 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./TypeScriptIssueFactory"));
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"./","sources":["issue/typescript/index.ts"],"names":[],"mappings":";;;;;AAAA,8CAAyC"}

Some files were not shown because too many files have changed in this diff Show more