Skip to content

Commit d48440f

Browse files
committed
export main plugin class and update all imports ? = require(?) to named exports
1 parent 2077eb4 commit d48440f

27 files changed

+105
-121
lines changed

src/CancellationToken.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import crypto = require('crypto');
2-
import fs = require('fs');
3-
import os = require('os');
4-
import path = require('path');
5-
import ts = require('typescript');
1+
import * as crypto from 'crypto';
2+
import * as fs from 'fs';
3+
import * as os from 'os';
4+
import * as path from 'path';
5+
import * as ts from 'typescript';
66

77
interface CancellationTokenData {
88
isCancelled: boolean;
99
cancellationFileName: string;
1010
}
1111

12-
class CancellationToken {
12+
export class CancellationToken {
1313
isCancelled: boolean;
1414
cancellationFileName: string;
1515
lastCancellationCheckTime: number;
@@ -72,5 +72,3 @@ class CancellationToken {
7272
}
7373
}
7474
}
75-
76-
export = CancellationToken;

src/FilesRegister.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import ts = require('typescript');
1+
import * as ts from 'typescript';
22

33
interface DataShape {
44
source: ts.SourceFile;
55
linted: boolean;
66
lints: any[];
77
}
88

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

@@ -74,4 +74,4 @@ class FilesRegister {
7474
}
7575
}
7676
}
77-
export = FilesRegister;
77+

src/FilesWatcher.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import chokidar = require('chokidar');
2-
import path = require('path');
1+
import * as chokidar from 'chokidar';
2+
import * as path from 'path';
33
import startsWith = require('lodash.startswith');
44

5-
class FilesWatcher {
5+
export class FilesWatcher {
66
watchPaths: string[];
77
watchExtensions: string[];
88
watchers: chokidar.FSWatcher[];
@@ -71,5 +71,3 @@ class FilesWatcher {
7171
}
7272
}
7373
}
74-
75-
export = FilesWatcher;

src/IncrementalChecker.ts

+16-18
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import fs = require('fs');
1+
import * as fs from 'fs';
22
import endsWith = require('lodash.endswith');
3-
import path = require('path');
4-
import ts = require('typescript');
5-
import tslintTypes = require('tslint'); // Imported for types alone; actual requires take place in methods below
6-
import FilesRegister = require('./FilesRegister');
7-
import FilesWatcher = require('./FilesWatcher');
8-
import WorkSet = require('./WorkSet');
9-
import NormalizedMessage = require('./NormalizedMessage');
10-
import CancellationToken = require('./CancellationToken');
11-
import minimatch = require('minimatch');
12-
import VueProgram = require('./VueProgram');
3+
import * as path from 'path';
4+
import * as ts from 'typescript';
5+
import { Configuration, Linter } from 'tslint'; // Imported for types alone; actual requires take place in methods below
6+
import { FilesRegister } from './FilesRegister';
7+
import { FilesWatcher } from './FilesWatcher';
8+
import { WorkSet } from './WorkSet';
9+
import { NormalizedMessage } from './NormalizedMessage';
10+
import { CancellationToken } from './CancellationToken';
11+
import * as minimatch from 'minimatch';
12+
import { VueProgram } from './VueProgram';
1313

1414
// Need some augmentation here - linterOptions.exclude is not (yet) part of the official
1515
// types for tslint.
16-
interface ConfigurationFile extends tslintTypes.Configuration.IConfigurationFile {
16+
interface ConfigurationFile extends Configuration.IConfigurationFile {
1717
linterOptions?: {
1818
typeCheck?: boolean;
1919
exclude?: string[];
2020
};
2121
}
2222

23-
class IncrementalChecker {
23+
export class IncrementalChecker {
2424
programConfigFile: string;
2525
linterConfigFile: string | false;
2626
watchPaths: string[];
@@ -29,7 +29,7 @@ class IncrementalChecker {
2929
checkSyntacticErrors: boolean;
3030
files: FilesRegister;
3131

32-
linter: tslintTypes.Linter;
32+
linter: Linter;
3333
linterConfig: ConfigurationFile;
3434
linterExclusions: minimatch.IMinimatch[];
3535

@@ -78,7 +78,7 @@ class IncrementalChecker {
7878
}
7979

8080
static loadLinterConfig(configFile: string): ConfigurationFile {
81-
const tslint: typeof tslintTypes = require('tslint');
81+
const tslint = require('tslint');
8282

8383
return tslint.Configuration.loadConfigurationFromPath(configFile) as ConfigurationFile;
8484
}
@@ -124,7 +124,7 @@ class IncrementalChecker {
124124
}
125125

126126
static createLinter(program: ts.Program) {
127-
const tslint: typeof tslintTypes = require('tslint');
127+
const tslint = require('tslint');
128128

129129
return new tslint.Linter({ fix: false }, program);
130130
}
@@ -279,5 +279,3 @@ class IncrementalChecker {
279279
);
280280
}
281281
}
282-
283-
export = IncrementalChecker;

src/Message.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import NormalizedMessage = require('./NormalizedMessage');
1+
import { NormalizedMessage } from './NormalizedMessage';
22

3-
export default interface Message {
3+
export interface Message {
44
diagnostics: NormalizedMessage[];
55
lints: NormalizedMessage[];
66
}

src/NormalizedMessage.ts

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// Imported for types alone; actual requires take place in methods below
2-
import tsTypes = require('typescript');
3-
import tslintTypes = require('tslint');
1+
import { Diagnostic, DiagnosticCategory, flattenDiagnosticMessageText } from 'typescript';
2+
import { RuleFailure } from 'tslint';
43

54
type ErrorType = 'diagnostic' | 'lint';
65
type Severity = 'error' | 'warning';
@@ -15,7 +14,7 @@ interface NormalizedMessageJson {
1514
character: number;
1615
}
1716

18-
class NormalizedMessage {
17+
export class NormalizedMessage {
1918
static TYPE_DIAGNOSTIC: ErrorType = 'diagnostic';
2019
static TYPE_LINT: ErrorType = 'lint';
2120

@@ -42,8 +41,7 @@ class NormalizedMessage {
4241
}
4342

4443
// message types
45-
static createFromDiagnostic(diagnostic: tsTypes.Diagnostic) {
46-
const ts: typeof tsTypes = require('typescript');
44+
static createFromDiagnostic(diagnostic: Diagnostic) {
4745
let file: string;
4846
let line: number;
4947
let character: number;
@@ -57,15 +55,15 @@ class NormalizedMessage {
5755
return new NormalizedMessage({
5856
type: NormalizedMessage.TYPE_DIAGNOSTIC,
5957
code: diagnostic.code,
60-
severity: ts.DiagnosticCategory[diagnostic.category].toLowerCase() as Severity,
61-
content: ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'),
58+
severity: DiagnosticCategory[diagnostic.category].toLowerCase() as Severity,
59+
content: flattenDiagnosticMessageText(diagnostic.messageText, '\n'),
6260
file: file,
6361
line: line,
6462
character: character
6563
});
6664
}
6765

68-
static createFromLint(lint: tslintTypes.RuleFailure) {
66+
static createFromLint(lint: RuleFailure) {
6967
const position = lint.getStartPosition().getLineAndCharacter();
7068

7169
return new NormalizedMessage({
@@ -216,5 +214,3 @@ class NormalizedMessage {
216214
return this.character;
217215
}
218216
}
219-
220-
export = NormalizedMessage;

src/VueProgram.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import fs = require('fs');
2-
import path = require('path');
3-
import ts = require('typescript');
4-
import FilesRegister = require('./FilesRegister');
5-
import FilesWatcher = require('./FilesWatcher');
1+
import * as fs from 'fs';
2+
import * as path from 'path';
3+
import * as ts from 'typescript';
4+
import { FilesRegister } from './FilesRegister';
5+
import { FilesWatcher } from './FilesWatcher';
66
// tslint:disable-next-line
7-
import vueCompiler = require('vue-template-compiler');
7+
import * as vueCompiler from 'vue-template-compiler';
88

99
interface ResolvedScript {
1010
scriptKind: ts.ScriptKind;
1111
content: string;
1212
}
1313

14-
class VueProgram {
14+
export class VueProgram {
1515
static loadProgramConfig(configFile: string) {
1616
const extraExtensions = ['vue'];
1717

@@ -252,5 +252,3 @@ class VueProgram {
252252
};
253253
}
254254
}
255-
256-
export = VueProgram;

src/WorkResult.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import Message from './Message';
1+
import { Message } from './Message';
22

3-
class WorkResult {
3+
export class WorkResult {
44
workResult: {};
55
workDomain: any[];
66

@@ -47,5 +47,3 @@ class WorkResult {
4747
}, initial);
4848
}
4949
}
50-
51-
export = WorkResult;

src/WorkSet.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import ts = require('typescript');
1+
import * as ts from 'typescript';
22

3-
class WorkSet {
3+
export class WorkSet {
44
workDomain: ReadonlyArray<ts.SourceFile> | string[];
55
workNumber: number;
66
workDivision: number;
@@ -28,5 +28,3 @@ class WorkSet {
2828
}
2929
}
3030
}
31-
32-
export = WorkSet;

src/cluster.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import childProcess = require('child_process');
2-
import path = require('path');
3-
import process = require('process');
1+
import * as childProcess from 'child_process';
2+
import * as path from 'path';
3+
import * as process from 'process';
44

5-
import WorkResult = require('./WorkResult');
6-
import NormalizedMessage = require('./NormalizedMessage');
7-
import Message from './Message';
5+
import { WorkResult } from './WorkResult';
6+
import { NormalizedMessage } from './NormalizedMessage';
7+
import { Message } from './Message';
88

99
// fork workers...
1010
const division = parseInt(process.env.WORK_DIVISION, 10);

src/formatter/codeframeFormatter.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import os = require('os');
1+
import * as os from 'os';
22
import codeFrame = require('babel-code-frame');
33
import chalk from 'chalk';
4-
import fs = require('fs');
5-
import NormalizedMessage = require('../NormalizedMessage');
4+
import * as fs from 'fs';
5+
import { NormalizedMessage } from '../NormalizedMessage';
66

77
/**
88
* Create new code frame formatter.
99
*
1010
* @param options Options for babel-code-frame - see https://www.npmjs.com/package/babel-code-frame
1111
* @returns {codeframeFormatter}
1212
*/
13-
export = function createCodeframeFormatter(options: any) {
13+
export function createCodeframeFormatter(options: any) {
1414
return function codeframeFormatter(message: NormalizedMessage, useColors: boolean) {
1515
const colors = new chalk.constructor({enabled: useColors});
1616
const messageColor = message.isWarningSeverity() ? colors.bold.yellow : colors.bold.red;

src/formatter/defaultFormatter.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11

22
import chalk from 'chalk';
3-
import os = require('os');
4-
import NormalizedMessage = require('../NormalizedMessage');
3+
import * as os from 'os';
4+
import { NormalizedMessage } from '../NormalizedMessage';
55

66
/**
77
* Creates new default formatter.
88
*
99
* @returns {defaultFormatter}
1010
*/
11-
export = function createDefaultFormatter() {
11+
export function createDefaultFormatter() {
1212
return function defaultFormatter(message: NormalizedMessage, useColors: boolean) {
1313
const colors = new chalk.constructor({enabled: useColors});
1414
const messageColor = message.isWarningSeverity() ? colors.bold.yellow : colors.bold.red;

src/index.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import path = require('path');
2-
import process = require('process');
3-
import childProcess = require('child_process');
1+
import * as path from 'path';
2+
import * as process from 'process';
3+
import * as childProcess from 'child_process';
44
import chalk, { Chalk } from 'chalk';
5-
import fs = require('fs');
6-
import os = require('os');
5+
import * as fs from 'fs';
6+
import * as os from 'os';
77
import * as webpack from 'webpack';
88
import isString = require('lodash.isstring');
99
import isFunction = require('lodash.isfunction');
10-
import CancellationToken = require('./CancellationToken');
11-
import NormalizedMessage = require('./NormalizedMessage');
12-
import createDefaultFormatter = require('./formatter/defaultFormatter');
13-
import createCodeframeFormatter = require('./formatter/codeframeFormatter');
14-
import Message from './Message';
10+
import { CancellationToken } from './CancellationToken';
11+
import { NormalizedMessage } from './NormalizedMessage';
12+
import { createDefaultFormatter } from './formatter/defaultFormatter';
13+
import { createCodeframeFormatter } from './formatter/codeframeFormatter';
14+
import { Message } from './Message';
1515

16-
const AsyncSeriesHook = require("tapable").AsyncSeriesHook;
17-
const SyncHook = require("tapable").SyncHook;
16+
import { AsyncSeriesHook } from 'tapable';
17+
import { SyncHook } from 'tapable';
1818

1919
const checkerPluginName = 'fork-ts-checker-webpack-plugin';
2020

@@ -63,7 +63,7 @@ interface Options {
6363
*
6464
* Options description in README.md
6565
*/
66-
class ForkTsCheckerWebpackPlugin {
66+
export class ForkTsCheckerWebpackPlugin {
6767
static DEFAULT_MEMORY_LIMIT = 2048;
6868
static ONE_CPU = 1;
6969
static ALL_CPUS = os.cpus() ? os.cpus().length : 1;
@@ -703,4 +703,4 @@ class ForkTsCheckerWebpackPlugin {
703703
}
704704
}
705705

706-
export = ForkTsCheckerWebpackPlugin;
706+
export default ForkTsCheckerWebpackPlugin

src/service.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import process = require('process');
2-
import ts = require('typescript');
3-
import IncrementalChecker = require('./IncrementalChecker');
4-
import CancellationToken = require('./CancellationToken');
5-
import NormalizedMessage = require('./NormalizedMessage');
1+
import * as process from 'process';
2+
import * as ts from 'typescript';
3+
import { IncrementalChecker } from './IncrementalChecker';
4+
import { CancellationToken } from './CancellationToken';
5+
import { NormalizedMessage } from './NormalizedMessage';
66

77
const checker = new IncrementalChecker(
88
process.env.TSCONFIG,

src/types/vue-template-compiler.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* which may included vue-template-compiler v2.6.0.
44
*/
55
declare module 'vue-template-compiler' {
6-
import Vue, { VNode } from "vue"
6+
import Vue, { VNode } from 'vue';
77

88
/*
99
* Template compilation options / results
@@ -224,4 +224,4 @@ declare module 'vue-template-compiler' {
224224
file: string,
225225
options?: SFCParserOptions
226226
): SFCDescriptor;
227-
}
227+
}

0 commit comments

Comments
 (0)