Skip to content
This repository was archived by the owner on Dec 1, 2019. It is now read-only.

Using the new watch api of compiler #519

Merged
merged 6 commits into from
Feb 24, 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
18 changes: 9 additions & 9 deletions src/cache.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as zlib from 'zlib';
import { createHash } from 'crypto';
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import * as zlib from "zlib";
import { createHash } from "crypto";

export interface CompiledModule {
fileName: string;
Expand All @@ -12,7 +12,7 @@ export interface CompiledModule {
}

export function findCompiledModule(fileName: string): CompiledModule {
let baseFileName = fileName.replace(/(\.ts|\.tsx)$/, '');
let baseFileName = fileName.replace(/(\.ts|\.tsx)$/, "");
let compiledFileName = `${baseFileName}.js`;

if (fs.existsSync(compiledFileName)) {
Expand Down Expand Up @@ -64,7 +64,7 @@ function write(filename: string, result: any) {
* @return {String}
*/
function filename(source: string, identifier, options) {
let hash = createHash('sha512') as any;
let hash = createHash("sha512") as any;
let contents = JSON.stringify({
identifier: identifier,
options: options,
Expand All @@ -73,7 +73,7 @@ function filename(source: string, identifier, options) {

hash.end(contents);

return hash.read().toString('hex') + '.json.gzip';
return hash.read().toString("hex") + ".json.gzip";
}

export interface CacheParams<T> {
Expand All @@ -94,7 +94,7 @@ export function cache<T>(params: CacheParams<T>): Promise<{cached: boolean, resu
let options = params.options || {};
let transform = params.transform;
let identifier = params.identifier;
let directory = (typeof params.directory === 'string') ?
let directory = (typeof params.directory === "string") ?
params.directory :
os.tmpdir();

Expand Down
38 changes: 19 additions & 19 deletions src/checker/checker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as _ from 'lodash';
import * as childProcess from 'child_process';
import * as path from 'path';
import { QueuedSender, createQueuedSender } from './send';
import * as _ from "lodash";
import * as childProcess from "child_process";
import * as path from "path";
import { QueuedSender, createQueuedSender } from "./send";

import {
CompilerInfo,
Expand All @@ -15,7 +15,7 @@ import {
UpdateFile,
TsConfig,
RemoveFile
} from './protocol';
} from "./protocol";

export interface Resolve {
resolve: (...args: any[]) => void;
Expand Down Expand Up @@ -44,8 +44,8 @@ export class Checker {
) {
const execArgv = getExecArgv();
const checker: childProcess.ChildProcess = fork
? childProcess.fork(path.join(__dirname, 'runtime.js'), [], { execArgv })
: require('./runtime').run();
? childProcess.fork(path.join(__dirname, "runtime.js"), [], { execArgv })
: require("./runtime").run();

this.sender = fork
? createQueuedSender(checker)
Expand All @@ -57,11 +57,11 @@ export class Checker {
this.compilerConfig = compilerConfig;
this.webpackOptions = webpackOptions;

checker.on('error', (e) => {
console.error('Typescript checker error:', e);
checker.on("error", (e) => {
console.error("Typescript checker error:", e);
});

checker.on('message', (res: Res) => {
checker.on("message", (res: Res) => {
const {seq, success, payload} = res;
if (seq && this.pending.has(seq)) {
const resolver = this.pending.get(seq);
Expand All @@ -73,14 +73,14 @@ export class Checker {

this.pending.delete(seq);
} else {
console.warn('Unknown message: ', payload);
console.warn("Unknown message: ", payload);
}
});

this.req({
type: 'Init',
type: "Init",
payload: {
compilerInfo: _.omit(compilerInfo, 'tsImpl'),
compilerInfo: _.omit(compilerInfo, "tsImpl"),
loaderConfig,
compilerConfig,
webpackOptions,
Expand All @@ -104,7 +104,7 @@ export class Checker {

emitFile(fileName: string, text: string): Promise<EmitFile.ResPayload> {
return this.req({
type: 'EmitFile',
type: "EmitFile",
payload: {
fileName,
text
Expand All @@ -114,7 +114,7 @@ export class Checker {

updateFile(fileName: string, text: string, ifExist = false) {
return this.req({
type: 'UpdateFile',
type: "UpdateFile",
payload: {
fileName,
text,
Expand All @@ -125,7 +125,7 @@ export class Checker {

removeFile(fileName: string) {
return this.req({
type: 'RemoveFile',
type: "RemoveFile",
payload: {
fileName,
}
Expand All @@ -134,18 +134,18 @@ export class Checker {

getDiagnostics(): Promise<any> {
return this.req({
type: 'Diagnostics'
type: "Diagnostics"
} as Diagnostics.Request);
}

getFiles(): any {
return this.req({
type: 'Files'
type: "Files"
} as Files.Request);
}

kill() {
this.checker.kill('SIGKILL');
this.checker.kill("SIGKILL");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/checker/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Checker } from './checker';
export { Checker } from "./checker";
28 changes: 14 additions & 14 deletions src/checker/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { LoaderConfig, CompilerInfo, TsConfig } from '../interfaces';
import { LoaderConfig, CompilerInfo, TsConfig } from "../interfaces";
export { CompilerInfo, LoaderConfig, TsConfig }

export type MessageType = 'Init' | 'UpdateFile' | 'Diagnostics' | 'EmitFile' | 'Files' | 'RemoveFile'
export type MessageType = "Init" | "UpdateFile" | "Diagnostics" | "EmitFile" | "Files" | "RemoveFile"
export const MessageType = {
Init: 'Init' as 'Init',
Files: 'Files' as 'Files',
UpdateFile: 'UpdateFile' as 'UpdateFile',
RemoveFile: 'RemoveFile' as 'RemoveFile',
Diagnostics: 'Diagnostics' as 'Diagnostics',
EmitFile: 'EmitFile' as 'EmitFile',
Init: "Init" as "Init",
Files: "Files" as "Files",
UpdateFile: "UpdateFile" as "UpdateFile",
RemoveFile: "RemoveFile" as "RemoveFile",
Diagnostics: "Diagnostics" as "Diagnostics",
EmitFile: "EmitFile" as "EmitFile",
};

export interface ReqBase {
Expand Down Expand Up @@ -44,7 +44,7 @@ export namespace Init {
}

export interface Request extends ReqBase {
type: 'Init';
type: "Init";
payload: Payload;
}

Expand All @@ -59,7 +59,7 @@ export namespace UpdateFile {
}

export interface Request extends ReqBase {
type: 'UpdateFile';
type: "UpdateFile";
payload: Payload;
}

Expand All @@ -77,7 +77,7 @@ export namespace RemoveFile {
}

export interface Request extends ReqBase {
type: 'RemoveFile';
type: "RemoveFile";
payload: Payload;
}

Expand All @@ -94,7 +94,7 @@ export namespace EmitFile {
}

export interface Request extends ReqBase {
type: 'EmitFile';
type: "EmitFile";
payload: ReqPayload;
}

Expand All @@ -114,7 +114,7 @@ export namespace EmitFile {

export namespace Files {
export interface Request extends ReqBase {
type: 'Files';
type: "Files";
}

export interface Response {
Expand All @@ -126,7 +126,7 @@ export namespace Files {

export namespace Diagnostics {
export interface Request extends ReqBase {
type: 'Diagnostics';
type: "Diagnostics";
}

export interface Response {
Expand Down
Loading