Skip to content

Commit b374d43

Browse files
committed
fixup! chore: min node version, dep updates and ts-loader in test matrix
1 parent 4f32390 commit b374d43

18 files changed

+259
-319
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: node_js
22
node_js:
3+
- '6'
34
- '8'
45
install:
56
- yarn install

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"webpack-plugin"
3838
],
3939
"engines": {
40-
"node": ">=8.9.0"
40+
"node": ">=6.11.5"
4141
},
4242
"author": "Piotr Oleś <[email protected]>",
4343
"contributors": [

src/CancellationToken.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@ interface CancellationTokenData {
1010
}
1111

1212
export class CancellationToken {
13-
isCancelled: boolean;
14-
cancellationFileName: string;
15-
lastCancellationCheckTime: number;
13+
private isCancelled: boolean;
14+
private cancellationFileName: string;
15+
private lastCancellationCheckTime: number;
1616
constructor(cancellationFileName?: string, isCancelled?: boolean) {
1717
this.isCancelled = !!isCancelled;
1818
this.cancellationFileName =
1919
cancellationFileName || crypto.randomBytes(64).toString('hex');
2020
this.lastCancellationCheckTime = 0;
2121
}
2222

23-
static createFromJSON(json: CancellationTokenData) {
23+
public static createFromJSON(json: CancellationTokenData) {
2424
return new CancellationToken(json.cancellationFileName, json.isCancelled);
2525
}
2626

27-
toJSON() {
27+
public toJSON() {
2828
return {
2929
cancellationFileName: this.cancellationFileName,
3030
isCancelled: this.isCancelled
3131
};
3232
}
3333

34-
getCancellationFilePath() {
34+
public getCancellationFilePath() {
3535
return path.join(os.tmpdir(), this.cancellationFileName);
3636
}
3737

38-
isCancellationRequested() {
38+
public isCancellationRequested() {
3939
if (this.isCancelled) {
4040
return true;
4141
}
@@ -52,18 +52,18 @@ export class CancellationToken {
5252
return this.isCancelled;
5353
}
5454

55-
throwIfCancellationRequested() {
55+
public throwIfCancellationRequested() {
5656
if (this.isCancellationRequested()) {
5757
throw new ts.OperationCanceledException();
5858
}
5959
}
6060

61-
requestCancellation() {
61+
public requestCancellation() {
6262
fs.writeFileSync(this.getCancellationFilePath(), '');
6363
this.isCancelled = true;
6464
}
6565

66-
cleanupCancellation() {
66+
public cleanupCancellation() {
6767
if (this.isCancelled && fs.existsSync(this.getCancellationFilePath())) {
6868
fs.unlinkSync(this.getCancellationFilePath());
6969
this.isCancelled = false;

src/FilesRegister.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,64 +8,63 @@ export interface DataShape {
88
}
99

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

14-
constructor(dataFactory: (_data?: DataShape) => DataShape) {
13+
constructor(private dataFactory: (_data?: DataShape) => DataShape) {
1514
this.files = {};
1615
this.dataFactory = dataFactory;
1716
}
1817

19-
keys() {
18+
public keys() {
2019
return Object.keys(this.files);
2120
}
2221

23-
add(filePath: string) {
22+
public add(filePath: string) {
2423
this.files[filePath] = {
2524
mtime: undefined,
2625
data: this.dataFactory(undefined)
2726
};
2827
}
2928

30-
remove(filePath: string) {
29+
public remove(filePath: string) {
3130
if (this.has(filePath)) {
3231
delete this.files[filePath];
3332
}
3433
}
3534

36-
has(filePath: string) {
35+
public has(filePath: string) {
3736
return this.files.hasOwnProperty(filePath);
3837
}
3938

40-
get(filePath: string) {
39+
public get(filePath: string) {
4140
if (!this.has(filePath)) {
4241
throw new Error('File "' + filePath + '" not found in register.');
4342
}
4443

4544
return this.files[filePath];
4645
}
4746

48-
ensure(filePath: string) {
47+
public ensure(filePath: string) {
4948
if (!this.has(filePath)) {
5049
this.add(filePath);
5150
}
5251
}
5352

54-
getData(filePath: string) {
53+
public getData(filePath: string) {
5554
return this.get(filePath).data;
5655
}
5756

58-
mutateData(filePath: string, mutator: (data: DataShape) => void) {
57+
public mutateData(filePath: string, mutator: (data: DataShape) => void) {
5958
this.ensure(filePath);
6059

6160
mutator(this.files[filePath].data);
6261
}
6362

64-
getMtime(filePath: string) {
63+
public getMtime(filePath: string) {
6564
return this.get(filePath).mtime;
6665
}
6766

68-
setMtime(filePath: string, mtime: number) {
67+
public setMtime(filePath: string, mtime: number) {
6968
this.ensure(filePath);
7069

7170
if (this.files[filePath].mtime !== mtime) {

src/FilesWatcher.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,19 @@ import * as chokidar from 'chokidar';
22
import * as path from 'path';
33

44
export class FilesWatcher {
5-
watchPaths: string[];
6-
watchExtensions: string[];
7-
watchers: chokidar.FSWatcher[];
8-
listeners: { [eventName: string]: Function[] };
9-
constructor(watchPaths: string[], watchExtensions: string[]) {
10-
this.watchPaths = watchPaths;
5+
private watchers: chokidar.FSWatcher[];
6+
private listeners: { [eventName: string]: Function[] };
7+
constructor(private watchPaths: string[], private watchExtensions: string[]) {
118
this.watchExtensions = watchExtensions;
129
this.watchers = [];
1310
this.listeners = {};
1411
}
1512

16-
isFileSupported(filePath: string) {
13+
public isFileSupported(filePath: string) {
1714
return this.watchExtensions.indexOf(path.extname(filePath)) !== -1;
1815
}
1916

20-
watch() {
17+
public watch() {
2118
if (this.isWatching()) {
2219
throw new Error('Cannot watch again - already watching.');
2320
}
@@ -42,27 +39,27 @@ export class FilesWatcher {
4239
});
4340
}
4441

45-
isWatchingFile(filePath: string) {
42+
public isWatchingFile(filePath: string) {
4643
return (
4744
this.isWatching() &&
4845
this.isFileSupported(filePath) &&
4946
this.watchPaths.some(watchPath => filePath.startsWith(watchPath))
5047
);
5148
}
5249

53-
isWatching() {
50+
public isWatching() {
5451
return this.watchers.length > 0;
5552
}
5653

57-
on(event: string, listener: Function) {
54+
public on(event: string, listener: Function) {
5855
if (!this.listeners[event]) {
5956
this.listeners[event] = [];
6057
}
6158

6259
this.listeners[event].push(listener);
6360
}
6461

65-
off(event: string, listener: Function) {
62+
public off(event: string, listener: Function) {
6663
if (this.listeners[event]) {
6764
this.listeners[event] = this.listeners[event].filter(
6865
oldListener => oldListener !== listener

src/IncrementalChecker.ts

Lines changed: 38 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -20,60 +20,39 @@ interface ConfigurationFile extends Configuration.IConfigurationFile {
2020
}
2121

2222
export class IncrementalChecker {
23-
programConfigFile: string;
24-
compilerOptions: object;
25-
linterConfigFile: string | false;
26-
linterAutoFix: boolean;
27-
watchPaths: string[];
28-
workNumber: number;
29-
workDivision: number;
30-
checkSyntacticErrors: boolean;
31-
files: FilesRegister;
32-
33-
linter?: Linter;
34-
linterConfig?: ConfigurationFile;
35-
linterExclusions: minimatch.IMinimatch[];
36-
37-
program?: ts.Program;
38-
programConfig?: ts.ParsedCommandLine;
39-
watcher?: FilesWatcher;
40-
41-
vue: boolean;
23+
// it's shared between compilations
24+
private files = new FilesRegister(() => ({
25+
// data shape
26+
source: undefined,
27+
linted: false,
28+
lints: []
29+
}));
30+
31+
private linter?: Linter;
32+
private linterConfig?: ConfigurationFile;
33+
34+
// Use empty array of exclusions in general to avoid having
35+
// to check of its existence later on.
36+
private linterExclusions: minimatch.IMinimatch[] = [];
37+
38+
private program?: ts.Program;
39+
private programConfig?: ts.ParsedCommandLine;
40+
private watcher?: FilesWatcher;
4241

4342
constructor(
44-
programConfigFile: string,
45-
compilerOptions: object,
46-
linterConfigFile: string | false,
47-
linterAutoFix: boolean,
48-
watchPaths: string[],
49-
workNumber: number,
50-
workDivision: number,
51-
checkSyntacticErrors: boolean,
52-
vue: boolean
43+
private programConfigFile: string,
44+
private compilerOptions: object,
45+
private linterConfigFile: string | false,
46+
private linterAutoFix: boolean,
47+
private watchPaths: string[],
48+
private workNumber: number = 0,
49+
private workDivision: number = 1,
50+
private checkSyntacticErrors: boolean = false,
51+
private vue: boolean = false,
5352
) {
54-
this.programConfigFile = programConfigFile;
55-
this.compilerOptions = compilerOptions;
56-
this.linterConfigFile = linterConfigFile;
57-
this.linterAutoFix = linterAutoFix;
58-
this.watchPaths = watchPaths;
59-
this.workNumber = workNumber || 0;
60-
this.workDivision = workDivision || 1;
61-
this.checkSyntacticErrors = checkSyntacticErrors || false;
62-
this.vue = vue || false;
63-
// Use empty array of exclusions in general to avoid having
64-
// to check of its existence later on.
65-
this.linterExclusions = [];
66-
67-
// it's shared between compilations
68-
this.files = new FilesRegister(() => ({
69-
// data shape
70-
source: undefined,
71-
linted: false,
72-
lints: []
73-
}));
7453
}
7554

76-
static loadProgramConfig(configFile: string, compilerOptions: object) {
55+
public static loadProgramConfig(configFile: string, compilerOptions: object) {
7756
const tsconfig = ts.readConfigFile(configFile, ts.sys.readFile).config;
7857

7958
tsconfig.compilerOptions = tsconfig.compilerOptions || {};
@@ -91,15 +70,15 @@ export class IncrementalChecker {
9170
return parsed;
9271
}
9372

94-
static loadLinterConfig(configFile: string): ConfigurationFile {
73+
private static loadLinterConfig(configFile: string): ConfigurationFile {
9574
const tslint = require('tslint');
9675

9776
return tslint.Configuration.loadConfigurationFromPath(
9877
configFile
9978
) as ConfigurationFile;
10079
}
10180

102-
static createProgram(
81+
private static createProgram(
10382
programConfig: ts.ParsedCommandLine,
10483
files: FilesRegister,
10584
watcher: FilesWatcher,
@@ -139,17 +118,17 @@ export class IncrementalChecker {
139118
);
140119
}
141120

142-
createLinter(program: ts.Program) {
121+
private createLinter(program: ts.Program) {
143122
const tslint = require('tslint');
144123

145124
return new tslint.Linter({ fix: this.linterAutoFix }, program);
146125
}
147126

148-
hasLinter(): boolean {
127+
public hasLinter(): boolean {
149128
return !!this.linter;
150129
}
151130

152-
static isFileExcluded(
131+
public static isFileExcluded(
153132
filePath: string,
154133
linterExclusions: minimatch.IMinimatch[]
155134
): boolean {
@@ -159,7 +138,7 @@ export class IncrementalChecker {
159138
);
160139
}
161140

162-
nextIteration() {
141+
public nextIteration() {
163142
if (!this.watcher) {
164143
const watchExtensions = this.vue
165144
? ['.ts', '.tsx', '.vue']
@@ -202,7 +181,7 @@ export class IncrementalChecker {
202181
}
203182
}
204183

205-
loadVueProgram() {
184+
private loadVueProgram() {
206185
this.programConfig =
207186
this.programConfig ||
208187
VueProgram.loadProgramConfig(
@@ -219,7 +198,7 @@ export class IncrementalChecker {
219198
);
220199
}
221200

222-
loadDefaultProgram() {
201+
private loadDefaultProgram() {
223202
this.programConfig =
224203
this.programConfig ||
225204
IncrementalChecker.loadProgramConfig(
@@ -235,7 +214,7 @@ export class IncrementalChecker {
235214
);
236215
}
237216

238-
getDiagnostics(cancellationToken: CancellationToken) {
217+
public getDiagnostics(cancellationToken: CancellationToken) {
239218
const { program } = this;
240219
if (!program) {
241220
throw new Error('Invoked called before program initialized');
@@ -277,7 +256,7 @@ export class IncrementalChecker {
277256
);
278257
}
279258

280-
getLints(cancellationToken: CancellationToken) {
259+
public getLints(cancellationToken: CancellationToken) {
281260
if (!this.linter) {
282261
throw new Error('Cannot get lints - checker has no linter.');
283262
}

0 commit comments

Comments
 (0)