Skip to content

Commit 237b1fd

Browse files
milewskijohnnyreilly
authored andcommitted
Export main plugin class and update all imports ? = require(?) to named exports (#163)
* export main plugin class and update all imports ? = require(?) to named exports * add commonjs export * revert export back to the original state * update version and changelog
1 parent 2077eb4 commit 237b1fd

29 files changed

+109
-119
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v0.4.10
2+
3+
* [Allow fork-ts-checker-webpack-plugin to be imported in .ts files using ESM import syntax](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/163) (#163)
4+
15
## v0.4.9
26

37
* [Set "compilationDone" before resolving "forkTsCheckerServiceBeforeStart"](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/146) (#146)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fork-ts-checker-webpack-plugin",
3-
"version": "0.4.9",
3+
"version": "0.4.10",
44
"description": "Runs typescript type checker and linter on separate process.",
55
"main": "lib/index.js",
66
"types": "lib/types/index.d.ts",

src/CancellationToken.ts

Lines changed: 6 additions & 8 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 5 deletions
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

Lines changed: 16 additions & 18 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 7 additions & 11 deletions
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

Lines changed: 7 additions & 9 deletions
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

Lines changed: 2 additions & 4 deletions
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;

0 commit comments

Comments
 (0)