Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .npmignore

This file was deleted.

1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ install:
- yarn add $WEBPACK $TSLOADER $VUELOADER -D
- yarn lint
env:
- WEBPACK=webpack@^4.0.0 TSLOADER=ts-loader@^5.0.0 VUELOADER=vue-loader@^15.2.4
- WEBPACK=webpack@^4.0.0 TSLOADER=ts-loader@^4.3.0 VUELOADER=vue-loader@^15.2.4
- WEBPACK=webpack@^3.10.0 TSLOADER=ts-loader@^3.4.0 VUELOADER=vue-loader@^13.5.0
- WEBPACK=webpack@^2.7.0 TSLOADER=ts-loader@^3.4.0 VUELOADER=vue-loader@^13.5.0
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## v0.5.0
* Removed unused dependency `resolve`.
* Replace `lodash` usage with native calls.
* Test against ts-loader v5
* **Breaking changes**:
* Dropped support for node v6, minimum is now v8.9
* **Internal**:
* 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/Realytics/fork-ts-checker-webpack-plugin/pull/174) (#174)
Expand Down
Binary file removed fork-ts-checker-webpack-plugin-v0.4.11.tgz
Binary file not shown.
28 changes: 12 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.4.15",
"description": "Runs typescript type checker and linter on separate process.",
"main": "lib/index.js",
"types": "lib/types/index.d.ts",
"types": "lib/index.d.ts",
"files": [
"lib"
],
Expand Down Expand Up @@ -37,7 +37,7 @@
"webpack-plugin"
],
"engines": {
"node": ">=6.11.5"
"node": ">=8.9.0"
},
"author": "Piotr Oleś <[email protected]>",
"contributors": [
Expand All @@ -51,27 +51,25 @@
"devDependencies": {
"@types/babel-code-frame": "^6.20.1",
"@types/chokidar": "^1.7.5",
"@types/lodash": "^4.14.117",
"@types/micromatch": "^3.1.0",
"@types/minimatch": "^3.0.1",
"@types/node": "^8.0.26",
"@types/resolve": "0.0.4",
"@types/webpack": "^4.4.9",
"chai": "^3.5.0",
"css-loader": "^0.28.7",
"@types/node": "^8.10.38",
"@types/webpack": "^4.4.19",
"chai": "^4.2.0",
"css-loader": "0.28.11",
"eslint": "^5.7.0",
"husky": "^1.1.2",
"husky": "^1.1.4",
"istanbul": "^0.4.5",
"lint-staged": "^7.3.0",
"lint-staged": "^8.0.5",
"mocha": "^5.2.0",
"mock-fs": "^4.3.0",
"mock-require": "^2.0.2",
"mock-require": "^3.0.2",
"prettier": "^1.14.3",
"rimraf": "^2.5.4",
"sinon": "^2.3.1",
"ts-loader": "4.3.0",
"sinon": "^7.1.1",
"ts-loader": "^5.3.0",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0",
"tslint-config-prettier": "^1.16.0",
"typescript": "^3.0.1",
"vue": "^2.5.16",
"vue-class-component": "^6.1.1",
Expand All @@ -88,10 +86,8 @@
"babel-code-frame": "^6.22.0",
"chalk": "^2.4.1",
"chokidar": "^2.0.4",
"lodash": "^4.17.11",
"micromatch": "^3.1.10",
"minimatch": "^3.0.4",
"resolve": "^1.5.0",
"tapable": "^1.0.0"
},
"husky": {
Expand Down
2 changes: 1 addition & 1 deletion src/CancellationToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class CancellationToken {
isCancelled: boolean;
cancellationFileName: string;
lastCancellationCheckTime: number;
constructor(cancellationFileName: string, isCancelled: boolean) {
constructor(cancellationFileName?: string, isCancelled?: boolean) {
this.isCancelled = !!isCancelled;
this.cancellationFileName =
cancellationFileName || crypto.randomBytes(64).toString('hex');
Expand Down
13 changes: 7 additions & 6 deletions src/FilesRegister.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import * as ts from 'typescript';
import { RuleFailure } from 'tslint';

interface DataShape {
source: ts.SourceFile;
export interface DataShape {
source?: ts.SourceFile;
linted: boolean;
lints: any[];
lints: RuleFailure[];
}

export class FilesRegister {
files: { [filePath: string]: { mtime: number; data: DataShape } };
dataFactory: (_data?: any) => DataShape; // It doesn't seem that the _data parameter is ever used?
files: { [filePath: string]: { mtime?: number; data: DataShape } };
dataFactory: (_data?: DataShape) => DataShape; // It doesn't seem that the _data parameter is ever used?

constructor(dataFactory: (_data?: any) => DataShape) {
constructor(dataFactory: (_data?: DataShape) => DataShape) {
this.files = {};
this.dataFactory = dataFactory;
}
Expand Down
3 changes: 1 addition & 2 deletions src/FilesWatcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as chokidar from 'chokidar';
import * as path from 'path';
import startsWith = require('lodash/startsWith');

export class FilesWatcher {
watchPaths: string[];
Expand Down Expand Up @@ -47,7 +46,7 @@ export class FilesWatcher {
return (
this.isWatching() &&
this.isFileSupported(filePath) &&
this.watchPaths.some(watchPath => startsWith(filePath, watchPath))
this.watchPaths.some(watchPath => filePath.startsWith(watchPath))
);
}

Expand Down
62 changes: 31 additions & 31 deletions src/IncrementalChecker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as fs from 'fs';
import endsWith = require('lodash/endsWith');
import * as path from 'path';
import * as ts from 'typescript';
import { Configuration, Linter } from 'tslint'; // Imported for types alone; actual requires take place in methods below
import { Configuration, Linter, RuleFailure } from 'tslint'; // Imported for types alone; actual requires take place in methods below
import { FilesRegister } from './FilesRegister';
import { FilesWatcher } from './FilesWatcher';
import { WorkSet } from './WorkSet';
Expand Down Expand Up @@ -31,13 +30,13 @@ export class IncrementalChecker {
checkSyntacticErrors: boolean;
files: FilesRegister;

linter: Linter;
linterConfig: ConfigurationFile;
linter?: Linter;
linterConfig?: ConfigurationFile;
linterExclusions: minimatch.IMinimatch[];

program: ts.Program;
programConfig: ts.ParsedCommandLine;
watcher: FilesWatcher;
program?: ts.Program;
programConfig?: ts.ParsedCommandLine;
watcher?: FilesWatcher;

vue: boolean;

Expand Down Expand Up @@ -146,12 +145,16 @@ export class IncrementalChecker {
return new tslint.Linter({ fix: this.linterAutoFix }, program);
}

hasLinter(): boolean {
return !!this.linter;
}

static isFileExcluded(
filePath: string,
linterExclusions: minimatch.IMinimatch[]
): boolean {
return (
endsWith(filePath, '.d.ts') ||
filePath.endsWith('.d.ts') ||
linterExclusions.some(matcher => matcher.match(filePath))
);
}
Expand Down Expand Up @@ -195,7 +198,7 @@ export class IncrementalChecker {
this.program = this.vue ? this.loadVueProgram() : this.loadDefaultProgram();

if (this.linterConfig) {
this.linter = this.createLinter(this.program);
this.linter = this.createLinter(this.program!);
}
}

Expand All @@ -211,8 +214,8 @@ export class IncrementalChecker {
this.programConfig,
path.dirname(this.programConfigFile),
this.files,
this.watcher,
this.program
this.watcher!,
this.program!
);
}

Expand All @@ -227,19 +230,19 @@ export class IncrementalChecker {
return IncrementalChecker.createProgram(
this.programConfig,
this.files,
this.watcher,
this.program
this.watcher!,
this.program!
);
}

hasLinter() {
return this.linter !== undefined;
}

getDiagnostics(cancellationToken: CancellationToken) {
const { program } = this;
if (!program) {
throw new Error('Invoked called before program initialized');
}
const diagnostics: ts.Diagnostic[] = [];
// select files to check (it's semantic check - we have to include all files :/)
const filesToCheck = this.program.getSourceFiles();
const filesToCheck = program.getSourceFiles();

// calculate subset of work to do
const workSet = new WorkSet(
Expand All @@ -256,17 +259,14 @@ export class IncrementalChecker {

const diagnosticsToRegister: ReadonlyArray<ts.Diagnostic> = this
.checkSyntacticErrors
? []
.concat(
this.program.getSemanticDiagnostics(sourceFile, cancellationToken)
)
.concat(
this.program.getSyntacticDiagnostics(
sourceFile,
cancellationToken
? program.getSemanticDiagnostics(sourceFile, cancellationToken)
.concat(
program.getSyntacticDiagnostics(
sourceFile,
cancellationToken
)
)
: this.program.getSemanticDiagnostics(sourceFile, cancellationToken);
)
: program.getSemanticDiagnostics(sourceFile, cancellationToken);

diagnostics.push.apply(diagnostics, diagnosticsToRegister);
});
Expand All @@ -278,7 +278,7 @@ export class IncrementalChecker {
}

getLints(cancellationToken: CancellationToken) {
if (!this.hasLinter()) {
if (!this.linter) {
throw new Error('Cannot get lints - checker has no linter.');
}

Expand All @@ -303,7 +303,7 @@ export class IncrementalChecker {
cancellationToken.throwIfCancellationRequested();

try {
this.linter.lint(fileName, undefined, this.linterConfig);
this.linter!.lint(fileName, undefined!, this.linterConfig); // REVIEW: this shouldn't work?
} catch (e) {
if (
fs.existsSync(fileName) &&
Expand Down Expand Up @@ -341,7 +341,7 @@ export class IncrementalChecker {
.reduce(
(innerLints, filePath) =>
innerLints.concat(this.files.getData(filePath).lints),
[]
[] as RuleFailure[]
);

// normalize and deduplicate lints
Expand Down
34 changes: 23 additions & 11 deletions src/NormalizedMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ interface NormalizedMessageJson {
code: string | number;
severity: Severity;
content: string;
file: string;
line: number;
character: number;
file?: string;
line?: number;
character?: number;
}

export class NormalizedMessage {
Expand All @@ -30,9 +30,9 @@ export class NormalizedMessage {
code: string | number;
severity: Severity;
content: string;
file: string;
line: number;
character: number;
file?: string;
line?: number;
character?: number;

constructor(data: NormalizedMessageJson) {
this.type = data.type;
Expand All @@ -46,11 +46,14 @@ export class NormalizedMessage {

// message types
static createFromDiagnostic(diagnostic: Diagnostic) {
let file: string;
let line: number;
let character: number;
let file: string | undefined;
let line: number | undefined;
let character: number | undefined;
if (diagnostic.file) {
file = diagnostic.file.fileName;
if (!diagnostic.start) {
throw new Error('Expected diagnostics to have start');
}
const position = diagnostic.file.getLineAndCharacterOfPosition(
diagnostic.start
);
Expand Down Expand Up @@ -162,7 +165,7 @@ export class NormalizedMessage {
return priorities[0] - priorities[1];
}

static compareOptionalStrings(stringA: string, stringB: string) {
static compareOptionalStrings(stringA?: string, stringB?: string) {
if (stringA === stringB) {
return 0;
}
Expand All @@ -176,7 +179,16 @@ export class NormalizedMessage {
return stringA.toString().localeCompare(stringB.toString());
}

static compareNumbers(numberA: number, numberB: number) {
static compareNumbers(numberA?: number, numberB?: number) {
if (numberA === numberB) {
return 0;
}
if (numberA === undefined || numberA === null) {
return -1;
}
if (numberB === undefined || numberB === null) {
return 1;
}
return numberA - numberB;
}

Expand Down
4 changes: 2 additions & 2 deletions src/VueProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class VueProgram {
? options.paths[`${correctWildcard}/*`]
: undefined;
const substitution = pattern
? options.paths[`${correctWildcard}/*`][0].replace('*', '')
? options.paths![`${correctWildcard}/*`][0].replace('*', '')
: 'src';
moduleName = path.resolve(baseUrl, substitution, moduleName.substr(2));
} else if (isRelative) {
Expand Down Expand Up @@ -234,7 +234,7 @@ export class VueProgram {
);
}

private static getScriptKindByLang(lang: string) {
private static getScriptKindByLang(lang?: string) {
if (lang === 'ts') {
return ts.ScriptKind.TS;
} else if (lang === 'tsx') {
Expand Down
Loading