Skip to content

Export main plugin class and update all imports ? = require(?) to named exports #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 6, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.4.10

* [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)

## v0.4.9

* [Set "compilationDone" before resolving "forkTsCheckerServiceBeforeStart"](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/146) (#146)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fork-ts-checker-webpack-plugin",
"version": "0.4.9",
"version": "0.4.10",
"description": "Runs typescript type checker and linter on separate process.",
"main": "lib/index.js",
"types": "lib/types/index.d.ts",
Expand Down
14 changes: 6 additions & 8 deletions src/CancellationToken.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import crypto = require('crypto');
import fs = require('fs');
import os = require('os');
import path = require('path');
import ts = require('typescript');
import * as crypto from 'crypto';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as ts from 'typescript';

interface CancellationTokenData {
isCancelled: boolean;
cancellationFileName: string;
}

class CancellationToken {
export class CancellationToken {
isCancelled: boolean;
cancellationFileName: string;
lastCancellationCheckTime: number;
Expand Down Expand Up @@ -72,5 +72,3 @@ class CancellationToken {
}
}
}

export = CancellationToken;
6 changes: 3 additions & 3 deletions src/FilesRegister.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import ts = require('typescript');
import * as ts from 'typescript';

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

class FilesRegister {
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?

Expand Down Expand Up @@ -74,4 +74,4 @@ class FilesRegister {
}
}
}
export = FilesRegister;

8 changes: 3 additions & 5 deletions src/FilesWatcher.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import chokidar = require('chokidar');
import path = require('path');
import * as chokidar from 'chokidar';
import * as path from 'path';
import startsWith = require('lodash.startswith');

class FilesWatcher {
export class FilesWatcher {
watchPaths: string[];
watchExtensions: string[];
watchers: chokidar.FSWatcher[];
Expand Down Expand Up @@ -71,5 +71,3 @@ class FilesWatcher {
}
}
}

export = FilesWatcher;
34 changes: 16 additions & 18 deletions src/IncrementalChecker.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import fs = require('fs');
import * as fs from 'fs';
import endsWith = require('lodash.endswith');
import path = require('path');
import ts = require('typescript');
import tslintTypes = require('tslint'); // Imported for types alone; actual requires take place in methods below
import FilesRegister = require('./FilesRegister');
import FilesWatcher = require('./FilesWatcher');
import WorkSet = require('./WorkSet');
import NormalizedMessage = require('./NormalizedMessage');
import CancellationToken = require('./CancellationToken');
import minimatch = require('minimatch');
import VueProgram = require('./VueProgram');
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 { FilesRegister } from './FilesRegister';
import { FilesWatcher } from './FilesWatcher';
import { WorkSet } from './WorkSet';
import { NormalizedMessage } from './NormalizedMessage';
import { CancellationToken } from './CancellationToken';
import * as minimatch from 'minimatch';
import { VueProgram } from './VueProgram';

// Need some augmentation here - linterOptions.exclude is not (yet) part of the official
// types for tslint.
interface ConfigurationFile extends tslintTypes.Configuration.IConfigurationFile {
interface ConfigurationFile extends Configuration.IConfigurationFile {
linterOptions?: {
typeCheck?: boolean;
exclude?: string[];
};
}

class IncrementalChecker {
export class IncrementalChecker {
programConfigFile: string;
linterConfigFile: string | false;
watchPaths: string[];
Expand All @@ -29,7 +29,7 @@ class IncrementalChecker {
checkSyntacticErrors: boolean;
files: FilesRegister;

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

Expand Down Expand Up @@ -78,7 +78,7 @@ class IncrementalChecker {
}

static loadLinterConfig(configFile: string): ConfigurationFile {
const tslint: typeof tslintTypes = require('tslint');
const tslint = require('tslint');

return tslint.Configuration.loadConfigurationFromPath(configFile) as ConfigurationFile;
}
Expand Down Expand Up @@ -124,7 +124,7 @@ class IncrementalChecker {
}

static createLinter(program: ts.Program) {
const tslint: typeof tslintTypes = require('tslint');
const tslint = require('tslint');

return new tslint.Linter({ fix: false }, program);
}
Expand Down Expand Up @@ -279,5 +279,3 @@ class IncrementalChecker {
);
}
}

export = IncrementalChecker;
4 changes: 2 additions & 2 deletions src/Message.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import NormalizedMessage = require('./NormalizedMessage');
import { NormalizedMessage } from './NormalizedMessage';

export default interface Message {
export interface Message {
diagnostics: NormalizedMessage[];
lints: NormalizedMessage[];
}
18 changes: 7 additions & 11 deletions src/NormalizedMessage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Imported for types alone; actual requires take place in methods below
import tsTypes = require('typescript');
import tslintTypes = require('tslint');
import { Diagnostic, DiagnosticCategory, flattenDiagnosticMessageText } from 'typescript';
import { RuleFailure } from 'tslint';

type ErrorType = 'diagnostic' | 'lint';
type Severity = 'error' | 'warning';
Expand All @@ -15,7 +14,7 @@ interface NormalizedMessageJson {
character: number;
}

class NormalizedMessage {
export class NormalizedMessage {
static TYPE_DIAGNOSTIC: ErrorType = 'diagnostic';
static TYPE_LINT: ErrorType = 'lint';

Expand All @@ -42,8 +41,7 @@ class NormalizedMessage {
}

// message types
static createFromDiagnostic(diagnostic: tsTypes.Diagnostic) {
const ts: typeof tsTypes = require('typescript');
static createFromDiagnostic(diagnostic: Diagnostic) {
let file: string;
let line: number;
let character: number;
Expand All @@ -57,15 +55,15 @@ class NormalizedMessage {
return new NormalizedMessage({
type: NormalizedMessage.TYPE_DIAGNOSTIC,
code: diagnostic.code,
severity: ts.DiagnosticCategory[diagnostic.category].toLowerCase() as Severity,
content: ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'),
severity: DiagnosticCategory[diagnostic.category].toLowerCase() as Severity,
content: flattenDiagnosticMessageText(diagnostic.messageText, '\n'),
file: file,
line: line,
character: character
});
}

static createFromLint(lint: tslintTypes.RuleFailure) {
static createFromLint(lint: RuleFailure) {
const position = lint.getStartPosition().getLineAndCharacter();

return new NormalizedMessage({
Expand Down Expand Up @@ -216,5 +214,3 @@ class NormalizedMessage {
return this.character;
}
}

export = NormalizedMessage;
16 changes: 7 additions & 9 deletions src/VueProgram.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import fs = require('fs');
import path = require('path');
import ts = require('typescript');
import FilesRegister = require('./FilesRegister');
import FilesWatcher = require('./FilesWatcher');
import * as fs from 'fs';
import * as path from 'path';
import * as ts from 'typescript';
import { FilesRegister } from './FilesRegister';
import { FilesWatcher } from './FilesWatcher';
// tslint:disable-next-line
import vueCompiler = require('vue-template-compiler');
import * as vueCompiler from 'vue-template-compiler';

interface ResolvedScript {
scriptKind: ts.ScriptKind;
content: string;
}

class VueProgram {
export class VueProgram {
static loadProgramConfig(configFile: string) {
const extraExtensions = ['vue'];

Expand Down Expand Up @@ -252,5 +252,3 @@ class VueProgram {
};
}
}

export = VueProgram;
6 changes: 2 additions & 4 deletions src/WorkResult.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Message from './Message';
import { Message } from './Message';

class WorkResult {
export class WorkResult {
workResult: {};
workDomain: any[];

Expand Down Expand Up @@ -47,5 +47,3 @@ class WorkResult {
}, initial);
}
}

export = WorkResult;
6 changes: 2 additions & 4 deletions src/WorkSet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ts = require('typescript');
import * as ts from 'typescript';

class WorkSet {
export class WorkSet {
workDomain: ReadonlyArray<ts.SourceFile> | string[];
workNumber: number;
workDivision: number;
Expand Down Expand Up @@ -28,5 +28,3 @@ class WorkSet {
}
}
}

export = WorkSet;
12 changes: 6 additions & 6 deletions src/cluster.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import childProcess = require('child_process');
import path = require('path');
import process = require('process');
import * as childProcess from 'child_process';
import * as path from 'path';
import * as process from 'process';

import WorkResult = require('./WorkResult');
import NormalizedMessage = require('./NormalizedMessage');
import Message from './Message';
import { WorkResult } from './WorkResult';
import { NormalizedMessage } from './NormalizedMessage';
import { Message } from './Message';

// fork workers...
const division = parseInt(process.env.WORK_DIVISION, 10);
Expand Down
8 changes: 4 additions & 4 deletions src/formatter/codeframeFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import os = require('os');
import * as os from 'os';
import codeFrame = require('babel-code-frame');
import chalk from 'chalk';
import fs = require('fs');
import NormalizedMessage = require('../NormalizedMessage');
import * as fs from 'fs';
import { NormalizedMessage } from '../NormalizedMessage';

/**
* Create new code frame formatter.
*
* @param options Options for babel-code-frame - see https://www.npmjs.com/package/babel-code-frame
* @returns {codeframeFormatter}
*/
export = function createCodeframeFormatter(options: any) {
export function createCodeframeFormatter(options: any) {
return function codeframeFormatter(message: NormalizedMessage, useColors: boolean) {
const colors = new chalk.constructor({enabled: useColors});
const messageColor = message.isWarningSeverity() ? colors.bold.yellow : colors.bold.red;
Expand Down
6 changes: 3 additions & 3 deletions src/formatter/defaultFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

import chalk from 'chalk';
import os = require('os');
import NormalizedMessage = require('../NormalizedMessage');
import * as os from 'os';
import { NormalizedMessage } from '../NormalizedMessage';

/**
* Creates new default formatter.
*
* @returns {defaultFormatter}
*/
export = function createDefaultFormatter() {
export function createDefaultFormatter() {
return function defaultFormatter(message: NormalizedMessage, useColors: boolean) {
const colors = new chalk.constructor({enabled: useColors});
const messageColor = message.isWarningSeverity() ? colors.bold.yellow : colors.bold.red;
Expand Down
28 changes: 15 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import path = require('path');
import process = require('process');
import childProcess = require('child_process');
import * as path from 'path';
import * as process from 'process';
import * as childProcess from 'child_process';
import chalk, { Chalk } from 'chalk';
import fs = require('fs');
import os = require('os');
import * as fs from 'fs';
import * as os from 'os';
import * as webpack from 'webpack';
import isString = require('lodash.isstring');
import isFunction = require('lodash.isfunction');
import CancellationToken = require('./CancellationToken');
import NormalizedMessage = require('./NormalizedMessage');
import createDefaultFormatter = require('./formatter/defaultFormatter');
import createCodeframeFormatter = require('./formatter/codeframeFormatter');
import Message from './Message';
import { CancellationToken } from './CancellationToken';
import { NormalizedMessage } from './NormalizedMessage';
import { createDefaultFormatter } from './formatter/defaultFormatter';
import { createCodeframeFormatter } from './formatter/codeframeFormatter';
import { Message } from './Message';

const AsyncSeriesHook = require("tapable").AsyncSeriesHook;
const SyncHook = require("tapable").SyncHook;
import { AsyncSeriesHook } from 'tapable';
import { SyncHook } from 'tapable';

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

Expand Down Expand Up @@ -703,4 +703,6 @@ class ForkTsCheckerWebpackPlugin {
}
}

export = ForkTsCheckerWebpackPlugin;
export = ForkTsCheckerWebpackPlugin

namespace ForkTsCheckerWebpackPlugin {}
10 changes: 5 additions & 5 deletions src/service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import process = require('process');
import ts = require('typescript');
import IncrementalChecker = require('./IncrementalChecker');
import CancellationToken = require('./CancellationToken');
import NormalizedMessage = require('./NormalizedMessage');
import * as process from 'process';
import * as ts from 'typescript';
import { IncrementalChecker } from './IncrementalChecker';
import { CancellationToken } from './CancellationToken';
import { NormalizedMessage } from './NormalizedMessage';

const checker = new IncrementalChecker(
process.env.TSCONFIG,
Expand Down
Loading