0.2.0 - Mid migration

This commit is contained in:
Daniel Mason 2022-04-25 14:47:15 +12:00
parent 139e6a915e
commit 7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions

View file

@ -0,0 +1,18 @@
import * as ts from 'typescript';
import { IncrementalCheckerInterface, IncrementalCheckerParams } from './IncrementalCheckerInterface';
import { CancellationToken } from './CancellationToken';
import { CompilerHost } from './CompilerHost';
export declare class ApiIncrementalChecker implements IncrementalCheckerInterface {
protected readonly tsIncrementalCompiler: CompilerHost;
protected readonly typescript: typeof ts;
private currentEsLintErrors;
private lastUpdatedFiles;
private lastRemovedFiles;
private readonly eslinter;
constructor({ typescript, programConfigFile, compilerOptions, eslinter, vue, checkSyntacticErrors, resolveModuleName, resolveTypeReferenceDirective }: IncrementalCheckerParams);
hasEsLinter(): boolean;
isFileExcluded(filePath: string): boolean;
nextIteration(): void;
getTypeScriptIssues(): Promise<import("./issue/Issue").Issue[]>;
getEsLintIssues(cancellationToken: CancellationToken): Promise<import("./issue/Issue").Issue[]>;
}

View file

@ -0,0 +1,107 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var CompilerHost_1 = require("./CompilerHost");
var issue_1 = require("./issue");
var ApiIncrementalChecker = /** @class */ (function () {
function ApiIncrementalChecker(_a) {
var typescript = _a.typescript, programConfigFile = _a.programConfigFile, compilerOptions = _a.compilerOptions, eslinter = _a.eslinter, vue = _a.vue, _b = _a.checkSyntacticErrors, checkSyntacticErrors = _b === void 0 ? false : _b, resolveModuleName = _a.resolveModuleName, resolveTypeReferenceDirective = _a.resolveTypeReferenceDirective;
this.currentEsLintErrors = new Map();
this.lastUpdatedFiles = [];
this.lastRemovedFiles = [];
this.eslinter = eslinter;
this.tsIncrementalCompiler = new CompilerHost_1.CompilerHost(typescript, vue, programConfigFile, compilerOptions, checkSyntacticErrors, resolveModuleName, resolveTypeReferenceDirective);
this.typescript = typescript;
}
ApiIncrementalChecker.prototype.hasEsLinter = function () {
return this.eslinter !== undefined;
};
ApiIncrementalChecker.prototype.isFileExcluded = function (filePath) {
return filePath.endsWith('.d.ts');
};
ApiIncrementalChecker.prototype.nextIteration = function () {
// do nothing
};
ApiIncrementalChecker.prototype.getTypeScriptIssues = function () {
return __awaiter(this, void 0, void 0, function () {
var tsDiagnostics;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.tsIncrementalCompiler.processChanges()];
case 1:
tsDiagnostics = _a.sent();
this.lastUpdatedFiles = tsDiagnostics.updatedFiles;
this.lastRemovedFiles = tsDiagnostics.removedFiles;
return [2 /*return*/, issue_1.createIssuesFromTsDiagnostics(tsDiagnostics.results, this.typescript)];
}
});
});
};
ApiIncrementalChecker.prototype.getEsLintIssues = function (cancellationToken) {
return __awaiter(this, void 0, void 0, function () {
var _i, _a, removedFile, _b, _c, updatedFile, report, reports;
return __generator(this, function (_d) {
if (!this.eslinter) {
throw new Error('EsLint is not enabled in the plugin.');
}
for (_i = 0, _a = this.lastRemovedFiles; _i < _a.length; _i++) {
removedFile = _a[_i];
this.currentEsLintErrors.delete(removedFile);
}
for (_b = 0, _c = this.lastUpdatedFiles; _b < _c.length; _b++) {
updatedFile = _c[_b];
cancellationToken.throwIfCancellationRequested();
if (this.isFileExcluded(updatedFile)) {
continue;
}
report = this.eslinter.getReport(updatedFile);
if (report !== undefined) {
this.currentEsLintErrors.set(updatedFile, report);
}
else if (this.currentEsLintErrors.has(updatedFile)) {
this.currentEsLintErrors.delete(updatedFile);
}
}
reports = Array.from(this.currentEsLintErrors.values());
return [2 /*return*/, issue_1.createIssuesFromEsLintReports(reports)];
});
});
};
return ApiIncrementalChecker;
}());
exports.ApiIncrementalChecker = ApiIncrementalChecker;
//# sourceMappingURL=ApiIncrementalChecker.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"ApiIncrementalChecker.js","sourceRoot":"./","sources":["ApiIncrementalChecker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,+CAA8C;AAE9C,iCAGiB;AAGjB;IAUE,+BAAY,EASe;YARzB,0BAAU,EACV,wCAAiB,EACjB,oCAAe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ACpB,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;iBAC9C;gBAED,WAA+C,EAArB,KAAA,IAAI,CAAC,gBAAgB,EAArB,cAAqB,EAArB,IAAqB,EAAE;oBAAtC,WAAW;oBACpB,iBAAiB,CAAC,4BAA4B,EAAE,CAAC;oBACjD,IAAI,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE;wBACpC,SAAS;qBACV;oBAEK,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;oBAEpD,IAAI,MAAM,KAAK,SAAS,EAAE;wBACxB,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;qBACnD;yBAAM,IAAI,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;wBACpD,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;qBAC9C;iBACF;gBAEK,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAAE,CAAC,CAAC;gBAC9D,sBAAO,qCAA6B,CAAC,OAAO,CAAC,EAAC;;;KAC/C;IACH,4BAAC;AAAD,CAAC,AArFD,IAqFC;AArFY,sDAAqB"}

View file

@ -0,0 +1,22 @@
import * as ts from 'typescript';
export interface CancellationTokenData {
isCancelled: boolean;
cancellationFileName: string;
}
export declare class CancellationToken {
private typescript;
private isCancelled;
private cancellationFileName;
private lastCancellationCheckTime;
constructor(typescript: typeof ts, cancellationFileName?: string, isCancelled?: boolean);
static createFromJSON(typescript: typeof ts, json: CancellationTokenData): CancellationToken;
toJSON(): {
cancellationFileName: string;
isCancelled: boolean;
};
getCancellationFilePath(): string;
isCancellationRequested(): boolean;
throwIfCancellationRequested(): void;
requestCancellation(): void;
cleanupCancellation(): void;
}

View file

@ -0,0 +1,69 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var crypto_1 = __importDefault(require("crypto"));
var fs = __importStar(require("fs"));
var os = __importStar(require("os"));
var path = __importStar(require("path"));
var FsHelper_1 = require("./FsHelper");
var CancellationToken = /** @class */ (function () {
function CancellationToken(typescript, cancellationFileName, isCancelled) {
this.typescript = typescript;
this.isCancelled = !!isCancelled;
this.cancellationFileName =
cancellationFileName || crypto_1.default.randomBytes(64).toString('hex');
this.lastCancellationCheckTime = 0;
}
CancellationToken.createFromJSON = function (typescript, json) {
return new CancellationToken(typescript, json.cancellationFileName, json.isCancelled);
};
CancellationToken.prototype.toJSON = function () {
return {
cancellationFileName: this.cancellationFileName,
isCancelled: this.isCancelled
};
};
CancellationToken.prototype.getCancellationFilePath = function () {
return path.join(os.tmpdir(), this.cancellationFileName);
};
CancellationToken.prototype.isCancellationRequested = function () {
if (this.isCancelled) {
return true;
}
var time = Date.now();
var duration = Math.abs(time - this.lastCancellationCheckTime);
if (duration > 10) {
// check no more than once every 10 ms
this.lastCancellationCheckTime = time;
this.isCancelled = FsHelper_1.fileExistsSync(this.getCancellationFilePath());
}
return this.isCancelled;
};
CancellationToken.prototype.throwIfCancellationRequested = function () {
if (this.isCancellationRequested()) {
throw new this.typescript.OperationCanceledException();
}
};
CancellationToken.prototype.requestCancellation = function () {
fs.writeFileSync(this.getCancellationFilePath(), '');
this.isCancelled = true;
};
CancellationToken.prototype.cleanupCancellation = function () {
if (this.isCancelled && FsHelper_1.fileExistsSync(this.getCancellationFilePath())) {
fs.unlinkSync(this.getCancellationFilePath());
this.isCancelled = false;
}
};
return CancellationToken;
}());
exports.CancellationToken = CancellationToken;
//# sourceMappingURL=CancellationToken.js.map

View file

@ -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I,CAAC;YACtC,IAAI,CAAC,WAAW,GAAG,yBAAc,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC,CAAC;SACnE;QAED,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAEM,wDAA4B,GAAnC;QACE,IAAI,IAAI,CAAC,uBAAuB,EAAE,EAAE;YAClC,MAAM,IAAI,IAAI,CAAC,UAAU,CAAC,0BAA0B,EAAE,CAAC;SACxD;IACH,CAAC;IAEM,+CAAmB,GAA1B;QACE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,uBAAuB,EAAE,EAAE,EAAE,CAAC,CAAC;QACrD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAEM,+CAAmB,GAA1B;QACE,IAAI,IAAI,CAAC,WAAW,IAAI,yBAAc,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC,EAAE;YACtE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC,CAAC;YAC9C,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;SAC1B;IACH,CAAC;IACH,wBAAC;AAAD,CAAC,AAvED,IAuEC;AAvEY,8CAAiB"}

View file

@ -0,0 +1,51 @@
import * as ts from 'typescript';
import { ResolveModuleName, ResolveTypeReferenceDirective } from './resolution';
import { VueOptions } from './types/vue-options';
export declare class CompilerHost implements ts.WatchCompilerHostOfConfigFile<ts.EmitAndSemanticDiagnosticsBuilderProgram> {
private typescript;
private vueOptions;
private program?;
getProgram(): ts.Program;
getAllKnownFiles(): Set<string>;
configFileName: string;
optionsToExtend: ts.CompilerOptions;
private directoryWatchers;
private fileWatchers;
private knownFiles;
private gatheredDiagnostic;
private afterCompile;
private readonly tsHost;
protected lastProcessing?: Promise<ts.Diagnostic[]>;
private compilationStarted;
resolveModuleNames: ((moduleNames: string[], containingFile: string, reusedNames?: string[] | undefined, redirectedReference?: ts.ResolvedProjectReference | undefined) => (ts.ResolvedModule | undefined)[]) | undefined;
resolveTypeReferenceDirectives: ((typeReferenceDirectiveNames: string[], containingFile: string, redirectedReference?: ts.ResolvedProjectReference | undefined) => (ts.ResolvedTypeReferenceDirective | undefined)[]) | undefined;
constructor(typescript: typeof ts, vueOptions: VueOptions, programConfigFile: string, compilerOptions: ts.CompilerOptions, checkSyntacticErrors: boolean, userResolveModuleName?: ResolveModuleName, userResolveTypeReferenceDirective?: ResolveTypeReferenceDirective);
processChanges(): Promise<{
results: ts.Diagnostic[];
updatedFiles: string[];
removedFiles: string[];
}>;
setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): any;
clearTimeout(timeoutId: any): void;
onWatchStatusChange(): void;
watchDirectory(path: string, callback: ts.DirectoryWatcherCallback, recursive?: boolean): ts.FileWatcher;
watchFile(path: string, callback: ts.FileWatcherCallback, pollingInterval?: number): ts.FileWatcher;
fileExists(path: string): boolean;
readFile(path: string, encoding?: string): string | undefined;
directoryExists(path: string): boolean;
getDirectories(path: string): string[];
readDirectory(path: string, extensions?: ReadonlyArray<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>, depth?: number): string[];
createProgram: typeof ts.createEmitAndSemanticDiagnosticsBuilderProgram;
getCurrentDirectory(): string;
getDefaultLibFileName(options: ts.CompilerOptions): string;
getEnvironmentVariable(name: string): string | undefined;
getNewLine(): string;
realpath(path: string): string;
trace(s: string): void;
useCaseSensitiveFileNames(): boolean;
onUnRecoverableConfigFileDiagnostic(): void;
afterProgramCreate(program: ts.EmitAndSemanticDiagnosticsBuilderProgram): void;
createDirectory(): void;
writeFile(): void;
onCachedDirectoryStructureHostCreate?(): void;
}

View file

@ -0,0 +1,338 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var LinkedList_1 = require("./LinkedList");
var VueProgram_1 = require("./VueProgram");
var CompilerHost = /** @class */ (function () {
function CompilerHost(typescript, vueOptions, programConfigFile, compilerOptions, checkSyntacticErrors, userResolveModuleName, userResolveTypeReferenceDirective) {
var _this = this;
this.typescript = typescript;
this.vueOptions = vueOptions;
// intercept all watch events and collect them until we get notification to start compilation
this.directoryWatchers = new LinkedList_1.LinkedList();
this.fileWatchers = new LinkedList_1.LinkedList();
this.knownFiles = new Set();
this.gatheredDiagnostic = [];
this.afterCompile = function () {
/* do nothing */
};
this.compilationStarted = false;
this.createProgram = this.typescript
.createEmitAndSemanticDiagnosticsBuilderProgram;
this.tsHost = typescript.createWatchCompilerHost(programConfigFile, compilerOptions, typescript.sys, typescript.createEmitAndSemanticDiagnosticsBuilderProgram, function (diag) {
if (!checkSyntacticErrors &&
diag.code >= 1000 &&
diag.code < 2000 &&
diag.file // if diag.file is undefined, this is not a syntactic error, but a global error that should be emitted
) {
return;
}
_this.gatheredDiagnostic.push(diag);
}, function () {
// do nothing
});
this.configFileName = this.tsHost.configFileName;
this.optionsToExtend = this.tsHost.optionsToExtend || {};
if (userResolveModuleName) {
this.resolveModuleNames = function (moduleNames, containingFile) {
return moduleNames.map(function (moduleName) {
return userResolveModuleName(_this.typescript, moduleName, containingFile, _this.optionsToExtend, _this).resolvedModule;
});
};
}
if (userResolveTypeReferenceDirective) {
this.resolveTypeReferenceDirectives = function (typeDirectiveNames, containingFile) {
return typeDirectiveNames.map(function (typeDirectiveName) {
return userResolveTypeReferenceDirective(_this.typescript, typeDirectiveName, containingFile, _this.optionsToExtend, _this).resolvedTypeReferenceDirective;
});
};
}
}
CompilerHost.prototype.getProgram = function () {
if (!this.program) {
throw new Error('Program is not created yet.');
}
return this.program.getProgram().getProgram();
};
CompilerHost.prototype.getAllKnownFiles = function () {
return this.knownFiles;
};
CompilerHost.prototype.processChanges = function () {
return __awaiter(this, void 0, void 0, function () {
var initialCompile, errors, previousDiagnostic, resultPromise, files, updatedFiles, removedFiles, results;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!!this.lastProcessing) return [3 /*break*/, 2];
initialCompile = new Promise(function (resolve) {
_this.afterCompile = function () {
resolve(_this.gatheredDiagnostic);
_this.afterCompile = function () {
/* do nothing */
};
_this.compilationStarted = false;
};
});
this.lastProcessing = initialCompile;
this.program = this.typescript.createWatchProgram(this);
return [4 /*yield*/, initialCompile];
case 1:
errors = _a.sent();
return [2 /*return*/, {
results: errors,
updatedFiles: Array.from(this.knownFiles),
removedFiles: []
}];
case 2:
// since we do not have a way to pass cancellation token to typescript,
// we just wait until previous compilation finishes.
return [4 /*yield*/, this.lastProcessing];
case 3:
// since we do not have a way to pass cancellation token to typescript,
// we just wait until previous compilation finishes.
_a.sent();
previousDiagnostic = this.gatheredDiagnostic;
this.gatheredDiagnostic = [];
resultPromise = new Promise(function (resolve) {
_this.afterCompile = function () {
resolve(_this.gatheredDiagnostic);
_this.afterCompile = function () {
/* do nothing */
};
_this.compilationStarted = false;
};
});
this.lastProcessing = resultPromise;
files = [];
this.directoryWatchers.forEach(function (item) {
for (var _i = 0, _a = item.events; _i < _a.length; _i++) {
var e = _a[_i];
item.callback(e.fileName);
}
item.events.length = 0;
});
updatedFiles = [];
removedFiles = [];
this.fileWatchers.forEach(function (item) {
for (var _i = 0, _a = item.events; _i < _a.length; _i++) {
var e = _a[_i];
item.callback(e.fileName, e.eventKind);
files.push(e.fileName);
if (e.eventKind === _this.typescript.FileWatcherEventKind.Created ||
e.eventKind === _this.typescript.FileWatcherEventKind.Changed) {
updatedFiles.push(e.fileName);
}
else if (e.eventKind === _this.typescript.FileWatcherEventKind.Deleted) {
removedFiles.push(e.fileName);
}
}
item.events.length = 0;
});
// if the files are not relevant to typescript it may choose not to compile
// in this case we need to trigger promise resolution from here
if (!this.compilationStarted) {
// keep diagnostic from previous run
this.gatheredDiagnostic = previousDiagnostic;
this.afterCompile();
return [2 /*return*/, {
results: this.gatheredDiagnostic,
updatedFiles: [],
removedFiles: []
}];
}
return [4 /*yield*/, resultPromise];
case 4:
results = _a.sent();
return [2 /*return*/, { results: results, updatedFiles: updatedFiles, removedFiles: removedFiles }];
}
});
});
};
CompilerHost.prototype.setTimeout = function (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
callback, ms) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var args = [];
for (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var _i = 2;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_i < arguments.length;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_i++) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
args[_i - 2] = arguments[_i];
}
// There are 2 things we are hacking here:
// 1. This method only called from watch program to wait until all files
// are written to filesystem (for example, when doing 'save all')
// We are intercepting all change notifications, and letting
// them through only when webpack starts processing changes.
// Therefore, at this point normally files are already all saved,
// so we do not need to waste another 250 ms (hardcoded in TypeScript).
// On the other hand there may be occasional glitch, when our incremental
// compiler will receive the notification too late, and process it when
// next compilation would start.
// 2. It seems to be only reliable way to intercept a moment when TypeScript
// actually starts compilation.
//
// Ideally we probably should not let TypeScript call all those watching
// methods by itself, and instead forward changes from webpack.
// Unfortunately, at the moment TypeScript incremental API is quite
// immature (for example, minor changes in how you use it cause
// dramatic compilation time increase), so we have to stick with these
// hacks for now.
this.compilationStarted = true;
return (this.typescript.sys.setTimeout || setTimeout)(callback, 1, args);
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
CompilerHost.prototype.clearTimeout = function (timeoutId) {
(this.typescript.sys.clearTimeout || clearTimeout)(timeoutId);
};
CompilerHost.prototype.onWatchStatusChange = function () {
// do nothing
};
CompilerHost.prototype.watchDirectory = function (path, callback, recursive) {
var slot = { callback: callback, events: [] };
var node = this.directoryWatchers.add(slot);
this.tsHost.watchDirectory(path, function (fileName) {
slot.events.push({ fileName: fileName });
}, recursive);
return {
close: function () {
node.detachSelf();
}
};
};
CompilerHost.prototype.watchFile = function (path, callback, pollingInterval) {
var _this = this;
var slot = { callback: callback, events: [] };
var node = this.fileWatchers.add(slot);
this.knownFiles.add(path);
this.tsHost.watchFile(path, function (fileName, eventKind) {
if (eventKind === _this.typescript.FileWatcherEventKind.Created) {
_this.knownFiles.add(fileName);
}
else if (eventKind === _this.typescript.FileWatcherEventKind.Deleted) {
_this.knownFiles.delete(fileName);
}
slot.events.push({ fileName: fileName, eventKind: eventKind });
}, pollingInterval);
return {
close: function () {
node.detachSelf();
}
};
};
CompilerHost.prototype.fileExists = function (path) {
return this.tsHost.fileExists(path);
};
CompilerHost.prototype.readFile = function (path, encoding) {
var content = this.tsHost.readFile(path, encoding);
// get typescript contents from Vue file
if (content && VueProgram_1.VueProgram.isVue(path)) {
var resolved = VueProgram_1.VueProgram.resolveScriptBlock(this.typescript, content, this.vueOptions.compiler);
return resolved.content;
}
return content;
};
CompilerHost.prototype.directoryExists = function (path) {
return ((this.tsHost.directoryExists && this.tsHost.directoryExists(path)) ||
false);
};
CompilerHost.prototype.getDirectories = function (path) {
return ((this.tsHost.getDirectories && this.tsHost.getDirectories(path)) || []);
};
CompilerHost.prototype.readDirectory = function (path, extensions, exclude, include, depth) {
return this.typescript.sys.readDirectory(path, extensions, exclude, include, depth);
};
CompilerHost.prototype.getCurrentDirectory = function () {
return this.tsHost.getCurrentDirectory();
};
CompilerHost.prototype.getDefaultLibFileName = function (options) {
return this.tsHost.getDefaultLibFileName(options);
};
CompilerHost.prototype.getEnvironmentVariable = function (name) {
return (this.tsHost.getEnvironmentVariable &&
this.tsHost.getEnvironmentVariable(name));
};
CompilerHost.prototype.getNewLine = function () {
return this.tsHost.getNewLine();
};
CompilerHost.prototype.realpath = function (path) {
if (!this.tsHost.realpath) {
throw new Error('The realpath function is not supported by the CompilerHost.');
}
return this.tsHost.realpath(path);
};
CompilerHost.prototype.trace = function (s) {
if (this.tsHost.trace) {
this.tsHost.trace(s);
}
};
CompilerHost.prototype.useCaseSensitiveFileNames = function () {
return this.tsHost.useCaseSensitiveFileNames();
};
CompilerHost.prototype.onUnRecoverableConfigFileDiagnostic = function () {
// do nothing
};
CompilerHost.prototype.afterProgramCreate = function (program) {
// all actual diagnostics happens here
if (this.tsHost.afterProgramCreate) {
this.tsHost.afterProgramCreate(program);
}
this.afterCompile();
};
// the functions below are use internally by typescript. we cannot use non-emitting version of incremental watching API
// because it is
// - much slower for some reason,
// - writes files anyway (o_O)
// - has different way of providing diagnostics. (with this version we can at least reliably get it from afterProgramCreate)
CompilerHost.prototype.createDirectory = function () {
// pretend everything was ok
};
CompilerHost.prototype.writeFile = function () {
// pretend everything was ok
};
CompilerHost.prototype.onCachedDirectoryStructureHostCreate = function () {
// pretend everything was ok
};
return CompilerHost;
}());
exports.CompilerHost = CompilerHost;
//# sourceMappingURL=CompilerHost.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,25 @@
import * as ts from 'typescript';
import { LintReport } from './types/eslint';
export interface DataShape {
source?: ts.SourceFile;
linted: boolean;
eslints: LintReport[];
}
export declare class FilesRegister {
private dataFactory;
private files;
constructor(dataFactory: (_data?: DataShape) => DataShape);
keys(): string[];
add(filePath: string): void;
remove(filePath: string): void;
has(filePath: string): boolean;
get(filePath: string): {
mtime?: number | undefined;
data: DataShape;
};
ensure(filePath: string): void;
getData(filePath: string): DataShape;
mutateData(filePath: string, mutator: (data: DataShape) => void): void;
getMtime(filePath: string): number | undefined;
setMtime(filePath: string, mtime: number): void;
}

View file

@ -0,0 +1,58 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var FilesRegister = /** @class */ (function () {
function FilesRegister(dataFactory) {
this.dataFactory = dataFactory;
this.files = {};
this.dataFactory = dataFactory;
}
FilesRegister.prototype.keys = function () {
return Object.keys(this.files);
};
FilesRegister.prototype.add = function (filePath) {
this.files[filePath] = {
mtime: undefined,
data: this.dataFactory(undefined)
};
};
FilesRegister.prototype.remove = function (filePath) {
if (this.has(filePath)) {
delete this.files[filePath];
}
};
FilesRegister.prototype.has = function (filePath) {
return this.files.hasOwnProperty(filePath);
};
FilesRegister.prototype.get = function (filePath) {
if (!this.has(filePath)) {
throw new Error('File "' + filePath + '" not found in register.');
}
return this.files[filePath];
};
FilesRegister.prototype.ensure = function (filePath) {
if (!this.has(filePath)) {
this.add(filePath);
}
};
FilesRegister.prototype.getData = function (filePath) {
return this.get(filePath).data;
};
FilesRegister.prototype.mutateData = function (filePath, mutator) {
this.ensure(filePath);
mutator(this.files[filePath].data);
};
FilesRegister.prototype.getMtime = function (filePath) {
return this.get(filePath).mtime;
};
FilesRegister.prototype.setMtime = function (filePath, mtime) {
this.ensure(filePath);
if (this.files[filePath].mtime !== mtime) {
this.files[filePath].mtime = mtime;
// file has been changed - we have to reset data
this.files[filePath].data = this.dataFactory(this.files[filePath].data);
}
};
return FilesRegister;
}());
exports.FilesRegister = FilesRegister;
//# sourceMappingURL=FilesRegister.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"FilesRegister.js","sourceRoot":"./","sources":["FilesRegister.ts"],"names":[],"mappings":";;AASA;IAGE,uBAAoB,WAA6C;QAA7C,gBAAW,GAAX,WAAW,CAAkC;QAC/D,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAEM,4BAAI,GAAX;QACE,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAEM,2BAAG,GAAV,UAAW,QAAgB;QACzB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG;YACrB,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;SAClC,CAAC;IACJ,CAAC;IAEM,8BAAM,GAAb,UAAc,QAAgB;QAC5B,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;YACtB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;SAC7B;IACH,CAAC;IAEM,2BAAG,GAAV,UAAW,QAAgB;QACzB,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAEM,2BAAG,GAAV,UAAW,QAAgB;QACzB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,QAAQ,GAAG,QAA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ePath: fs.PathLike): boolean;
export declare function throwIfIsInvalidSourceFileError(filepath: string, error: any): void;

View file

@ -0,0 +1,38 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs = __importStar(require("fs"));
function fileExistsSync(filePath) {
try {
fs.statSync(filePath);
}
catch (err) {
if (err.code === 'ENOENT') {
return false;
}
else {
throw err;
}
}
return true;
}
exports.fileExistsSync = fileExistsSync;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function throwIfIsInvalidSourceFileError(filepath, error) {
if (fileExistsSync(filepath) &&
// check the error type due to file system lag
!(error instanceof Error) &&
!(error.constructor.name === 'FatalError') &&
!(error.message && error.message.trim().startsWith('Invalid source file'))) {
// it's not because file doesn't exist - throw error
throw error;
}
}
exports.throwIfIsInvalidSourceFileError = throwIfIsInvalidSourceFileError;
//# sourceMappingURL=FsHelper.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"FsHelper.js","sourceRoot":"./","sources":["FsHelper.ts"],"names":[],"mappings":";;;;;;;;;AAAA,qCAAyB;AAEzB,SAAgB,cAAc,CAAC,QAAqB;IAClD,IAAI;QACF,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;KACvB;IAAC,OAAO,GAAG,EAAE;QACZ,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE;YACzB,OAAO,KAAK,CAAC;SACd;aAAM;YACL,MAAM,GAAG,CAAC;SACX;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAXD,wCAWC;AAED,8DAA8D;AAC9D,SAAgB,+BAA+B,CAAC,QAAgB,EAAE,KAAU;IAC1E,IACE,cAAc,CAAC,QAAQ,CAAC;QACxB,8CAA8C;QAC9C,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;QACzB,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,YAAY,CAAC;QAC1C,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAC,EAC1E;QACA,oDAAoD;QACpD,MAAM,KAAK,CAAC;KACb;AACH,CAAC;AAXD,0EAWC"}

View file

@ -0,0 +1,27 @@
import * as ts from 'typescript';
import { CancellationToken } from './CancellationToken';
import { IncrementalCheckerInterface, IncrementalCheckerParams } from './IncrementalCheckerInterface';
import { Issue } from './issue';
export declare class IncrementalChecker implements IncrementalCheckerInterface {
private files;
protected program?: ts.Program;
protected programConfig?: ts.ParsedCommandLine;
private readonly typescript;
private readonly programConfigFile;
private readonly compilerOptions;
private readonly eslinter;
private readonly vue;
private readonly checkSyntacticErrors;
private readonly resolveModuleName;
private readonly resolveTypeReferenceDirective;
constructor({ typescript, programConfigFile, compilerOptions, eslinter, vue, checkSyntacticErrors, resolveModuleName, resolveTypeReferenceDirective }: IncrementalCheckerParams);
static loadProgramConfig(typescript: typeof ts, configFile: string, compilerOptions: object): ts.ParsedCommandLine;
private static createProgram;
hasEsLinter(): boolean;
static isFileExcluded(filePath: string): boolean;
nextIteration(): void;
private loadVueProgram;
private loadDefaultProgram;
getTypeScriptIssues(cancellationToken: CancellationToken): Promise<Issue[]>;
getEsLintIssues(cancellationToken: CancellationToken): Promise<Issue[]>;
}

View file

@ -0,0 +1,216 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs = __importStar(require("fs"));
var path = __importStar(require("path"));
var FilesRegister_1 = require("./FilesRegister");
var resolution_1 = require("./resolution");
var VueProgram_1 = require("./VueProgram");
var issue_1 = require("./issue");
var IncrementalChecker = /** @class */ (function () {
function IncrementalChecker(_a) {
var typescript = _a.typescript, programConfigFile = _a.programConfigFile, compilerOptions = _a.compilerOptions, eslinter = _a.eslinter, vue = _a.vue, _b = _a.checkSyntacticErrors, checkSyntacticErrors = _b === void 0 ? false : _b, resolveModuleName = _a.resolveModuleName, resolveTypeReferenceDirective = _a.resolveTypeReferenceDirective;
this.files = new FilesRegister_1.FilesRegister(function () { return ({
// data shape
source: undefined,
linted: false,
eslints: []
}); });
this.typescript = typescript;
this.programConfigFile = programConfigFile;
this.compilerOptions = compilerOptions;
this.eslinter = eslinter;
this.vue = vue;
this.checkSyntacticErrors = checkSyntacticErrors;
this.resolveModuleName = resolveModuleName;
this.resolveTypeReferenceDirective = resolveTypeReferenceDirective;
}
IncrementalChecker.loadProgramConfig = function (typescript, configFile, compilerOptions) {
var tsconfig = typescript.readConfigFile(configFile, typescript.sys.readFile).config;
tsconfig.compilerOptions = tsconfig.compilerOptions || {};
tsconfig.compilerOptions = __assign({}, tsconfig.compilerOptions, compilerOptions);
var parsed = typescript.parseJsonConfigFileContent(tsconfig, typescript.sys, path.dirname(configFile));
return parsed;
};
IncrementalChecker.createProgram = function (typescript, programConfig, files, oldProgram, userResolveModuleName, userResolveTypeReferenceDirective) {
var host = typescript.createCompilerHost(programConfig.options);
var realGetSourceFile = host.getSourceFile;
var _a = resolution_1.makeResolutionFunctions(userResolveModuleName, userResolveTypeReferenceDirective), resolveModuleName = _a.resolveModuleName, resolveTypeReferenceDirective = _a.resolveTypeReferenceDirective;
host.resolveModuleNames = function (moduleNames, containingFile) {
return moduleNames.map(function (moduleName) {
return resolveModuleName(typescript, moduleName, containingFile, programConfig.options, host).resolvedModule;
});
};
host.resolveTypeReferenceDirectives = function (typeDirectiveNames, containingFile) {
return typeDirectiveNames.map(function (typeDirectiveName) {
return resolveTypeReferenceDirective(typescript, typeDirectiveName, containingFile, programConfig.options, host).resolvedTypeReferenceDirective;
});
};
host.getSourceFile = function (filePath, languageVersion, onError) {
try {
var stats = fs.statSync(filePath);
files.setMtime(filePath, stats.mtime.valueOf());
}
catch (e) {
// probably file does not exists
files.remove(filePath);
}
// get source file only if there is no source in files register
if (!files.has(filePath) || !files.getData(filePath).source) {
files.mutateData(filePath, function (data) {
data.source = realGetSourceFile(filePath, languageVersion, onError);
});
}
return files.getData(filePath).source;
};
return typescript.createProgram(programConfig.fileNames, programConfig.options, host, oldProgram // re-use old program
);
};
IncrementalChecker.prototype.hasEsLinter = function () {
return this.eslinter !== undefined;
};
IncrementalChecker.isFileExcluded = function (filePath) {
return filePath.endsWith('.d.ts');
};
IncrementalChecker.prototype.nextIteration = function () {
this.program = this.vue.enabled
? this.loadVueProgram(this.vue)
: this.loadDefaultProgram();
};
IncrementalChecker.prototype.loadVueProgram = function (vueOptions) {
this.programConfig =
this.programConfig ||
VueProgram_1.VueProgram.loadProgramConfig(this.typescript, this.programConfigFile, this.compilerOptions);
return VueProgram_1.VueProgram.createProgram(this.typescript, this.programConfig, path.dirname(this.programConfigFile), this.files, this.program, this.resolveModuleName, this.resolveTypeReferenceDirective, vueOptions);
};
IncrementalChecker.prototype.loadDefaultProgram = function () {
this.programConfig =
this.programConfig ||
IncrementalChecker.loadProgramConfig(this.typescript, this.programConfigFile, this.compilerOptions);
return IncrementalChecker.createProgram(this.typescript, this.programConfig, this.files, this.program, this.resolveModuleName, this.resolveTypeReferenceDirective);
};
IncrementalChecker.prototype.getTypeScriptIssues = function (cancellationToken) {
return __awaiter(this, void 0, void 0, function () {
var program, tsDiagnostics, filesToCheck;
var _this = this;
return __generator(this, function (_a) {
program = this.program;
if (!program) {
throw new Error('Invoked called before program initialized');
}
tsDiagnostics = [];
filesToCheck = program.getSourceFiles();
filesToCheck.forEach(function (sourceFile) {
if (cancellationToken) {
cancellationToken.throwIfCancellationRequested();
}
var tsDiagnosticsToRegister = _this
.checkSyntacticErrors
? program
.getSemanticDiagnostics(sourceFile, cancellationToken)
.concat(program.getSyntacticDiagnostics(sourceFile, cancellationToken))
: program.getSemanticDiagnostics(sourceFile, cancellationToken);
tsDiagnostics.push.apply(tsDiagnostics, tsDiagnosticsToRegister);
});
return [2 /*return*/, issue_1.createIssuesFromTsDiagnostics(tsDiagnostics, this.typescript)];
});
});
};
IncrementalChecker.prototype.getEsLintIssues = function (cancellationToken) {
return __awaiter(this, void 0, void 0, function () {
var filesToLint, currentEsLintErrors, reports;
var _this = this;
return __generator(this, function (_a) {
filesToLint = this.files
.keys()
.filter(function (filePath) {
return !_this.files.getData(filePath).linted &&
!IncrementalChecker.isFileExcluded(filePath);
});
currentEsLintErrors = new Map();
filesToLint.forEach(function (fileName) {
cancellationToken.throwIfCancellationRequested();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
var report = _this.eslinter.getReport(fileName);
if (report !== undefined) {
currentEsLintErrors.set(fileName, report);
}
});
// set lints in files register
currentEsLintErrors.forEach(function (lint, filePath) {
_this.files.mutateData(filePath, function (data) {
data.linted = true;
data.eslints.push(lint);
});
});
// set all files as linted
this.files.keys().forEach(function (filePath) {
_this.files.mutateData(filePath, function (data) {
data.linted = true;
});
});
reports = this.files
.keys()
.reduce(function (innerLints, filePath) {
return innerLints.concat(_this.files.getData(filePath).eslints);
}, []);
return [2 /*return*/, issue_1.createIssuesFromEsLintReports(reports)];
});
});
};
return IncrementalChecker;
}());
exports.IncrementalChecker = IncrementalChecker;
//# sourceMappingURL=IncrementalChecker.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,23 @@
import * as ts from 'typescript';
import { CancellationToken } from './CancellationToken';
import { ResolveTypeReferenceDirective, ResolveModuleName } from './resolution';
import { createEslinter } from './createEslinter';
import { Issue } from './issue';
import { VueOptions } from './types/vue-options';
export interface IncrementalCheckerInterface {
nextIteration(): void;
hasEsLinter(): boolean;
getTypeScriptIssues(cancellationToken: CancellationToken): Promise<Issue[]>;
getEsLintIssues(cancellationToken: CancellationToken): Promise<Issue[]>;
}
export interface IncrementalCheckerParams {
typescript: typeof ts;
context: string;
programConfigFile: string;
compilerOptions: ts.CompilerOptions;
eslinter: ReturnType<typeof createEslinter> | undefined;
checkSyntacticErrors: boolean;
resolveModuleName: ResolveModuleName | undefined;
resolveTypeReferenceDirective: ResolveTypeReferenceDirective | undefined;
vue: VueOptions;
}

View file

@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=IncrementalCheckerInterface.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"IncrementalCheckerInterface.js","sourceRoot":"./","sources":["IncrementalCheckerInterface.ts"],"names":[],"mappings":""}

View file

@ -0,0 +1,27 @@
export declare class HeadNode<T> {
next: LinkedListNode<T> | TailNode<T>;
constructor();
}
export declare class TailNode<T> {
previous: LinkedListNode<T> | HeadNode<T>;
constructor(head: HeadNode<T>);
}
export declare class LinkedListNode<T> {
next: LinkedListNode<T> | TailNode<T> | null;
previous: LinkedListNode<T> | HeadNode<T> | null;
readonly item: T;
constructor(item: T);
detachSelf(): void;
attachAfter(node: LinkedListNode<T> | HeadNode<T>): void;
attachBefore(node: LinkedListNode<T> | TailNode<T>): void;
}
export declare class LinkedList<T> {
head: HeadNode<T>;
tail: TailNode<T>;
constructor();
add(item: T): LinkedListNode<T>;
getItems(): T[];
forEach(callback: (item: T, node: LinkedListNode<T>) => void): void;
hasItems(): boolean;
getLastItem(): LinkedListNode<T>;
}

View file

@ -0,0 +1,98 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var HeadNode = /** @class */ (function () {
function HeadNode() {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
this.next = new TailNode(this);
}
return HeadNode;
}());
exports.HeadNode = HeadNode;
var TailNode = /** @class */ (function () {
function TailNode(head) {
this.previous = head;
}
return TailNode;
}());
exports.TailNode = TailNode;
var LinkedListNode = /** @class */ (function () {
function LinkedListNode(item) {
this.next = null;
this.previous = null;
this.item = item;
}
LinkedListNode.prototype.detachSelf = function () {
if (!this.next && !this.previous) {
throw new Error('node is not attached');
}
if (this.next) {
this.next.previous = this.previous;
}
if (this.previous) {
this.previous.next = this.next;
}
this.next = null;
this.previous = null;
};
LinkedListNode.prototype.attachAfter = function (node) {
if (this.next || this.previous) {
throw new Error('Node is inserted elsewhere');
}
this.next = node.next;
this.previous = node;
if (node.next) {
node.next.previous = this;
}
node.next = this;
};
LinkedListNode.prototype.attachBefore = function (node) {
if (!node.previous) {
throw new Error('no previous node found.');
}
this.attachAfter(node.previous);
};
return LinkedListNode;
}());
exports.LinkedListNode = LinkedListNode;
var LinkedList = /** @class */ (function () {
function LinkedList() {
this.head = new HeadNode();
this.tail = this.head.next;
}
LinkedList.prototype.add = function (item) {
var newNode = new LinkedListNode(item);
newNode.attachAfter(this.tail.previous);
return newNode;
};
LinkedList.prototype.getItems = function () {
var result = [];
this.forEach(function (item) {
result.push(item);
});
return result;
};
LinkedList.prototype.forEach = function (callback) {
var current = this.head.next;
while (current !== this.tail) {
// if item is not tail it is always a node
var item = current;
callback(item.item, item);
if (!item.next) {
throw new Error('badly attached item found.');
}
current = item.next;
}
};
LinkedList.prototype.hasItems = function () {
return this.head.next !== this.tail;
};
LinkedList.prototype.getLastItem = function () {
if (!this.hasItems()) {
throw new Error('no items in list.');
}
return this.head.next;
};
return LinkedList;
}());
exports.LinkedList = LinkedList;
//# sourceMappingURL=LinkedList.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"LinkedList.js","sourceRoot":"./","sources":["LinkedList.ts"],"names":[],"mappings":";;AAAA;IAGE;QACE,mEAAmE;QACnE,IAAI,CAAC,IAAI,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IACH,eAAC;AAAD,CAAC,AAPD,IAOC;AAPY,4BAAQ;AASrB;IAGE,kBAAY,IAAiB;QAC3B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;IACH,eAAC;AAAD,C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,KAAK,CAAC,mBAAmB,CAAC,CAAC;SACtC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAyB,CAAC;IAC7C,CAAC;IACH,iBAAC;AAAD,CAAC,AA9CD,IA8CC;AA9CY,gCAAU"}

View file

@ -0,0 +1,5 @@
import { Issue } from './issue';
export interface Message {
diagnostics: Issue[];
lints: Issue[];
}

View file

@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=Message.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"Message.js","sourceRoot":"./","sources":["Message.ts"],"names":[],"mappings":""}

View file

@ -0,0 +1,5 @@
import { CancellationTokenData } from './CancellationToken';
import { Message } from './Message';
export declare const RUN = "run";
export declare type RunPayload = CancellationTokenData;
export declare type RunResult = Message | undefined;

View file

@ -0,0 +1,4 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RUN = 'run';
//# sourceMappingURL=RpcTypes.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"RpcTypes.js","sourceRoot":"./","sources":["RpcTypes.ts"],"names":[],"mappings":";;AAGa,QAAA,GAAG,GAAG,KAAK,CAAC"}

View file

@ -0,0 +1,23 @@
import * as ts from 'typescript';
import { FilesRegister } from './FilesRegister';
import { ResolveModuleName, ResolveTypeReferenceDirective } from './resolution';
import { VueOptions } from './types/vue-options';
interface ResolvedScript {
scriptKind: ts.ScriptKind;
content: string;
}
export declare class VueProgram {
static loadProgramConfig(typescript: typeof ts, configFile: string, compilerOptions: object): ts.ParsedCommandLine;
/**
* Search for default wildcard or wildcard from options, we only search for that in tsconfig CompilerOptions.paths.
* The path is resolved with thie given substitution and includes the CompilerOptions.baseUrl (if given).
* If no paths given in tsconfig, then the default substitution is '[tsconfig directory]/src'.
* (This is a fast, simplified inspiration of what's described here: https://github.com/Microsoft/TypeScript/issues/5039)
*/
static resolveNonTsModuleName(moduleName: string, containingFile: string, basedir: string, options: ts.CompilerOptions): string;
static isVue(filePath: string): boolean;
static createProgram(typescript: typeof ts, programConfig: ts.ParsedCommandLine, basedir: string, files: FilesRegister, oldProgram: ts.Program | undefined, userResolveModuleName: ResolveModuleName | undefined, userResolveTypeReferenceDirective: ResolveTypeReferenceDirective | undefined, vueOptions: VueOptions): ts.Program;
private static getScriptKindByLang;
static resolveScriptBlock(typescript: typeof ts, content: string, compiler: string): ResolvedScript;
}
export {};

View file

@ -0,0 +1,253 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs = __importStar(require("fs"));
var path = __importStar(require("path"));
var resolution_1 = require("./resolution");
var VueProgram = /** @class */ (function () {
function VueProgram() {
}
VueProgram.loadProgramConfig = function (typescript, configFile, compilerOptions) {
var extraExtensions = ['vue'];
var parseConfigHost = {
fileExists: typescript.sys.fileExists,
readFile: typescript.sys.readFile,
useCaseSensitiveFileNames: typescript.sys.useCaseSensitiveFileNames,
readDirectory: function (rootDir, extensions, excludes, includes, depth) {
return typescript.sys.readDirectory(rootDir, extensions.concat(extraExtensions), excludes, includes, depth);
}
};
var tsconfig = typescript.readConfigFile(configFile, typescript.sys.readFile).config;
tsconfig.compilerOptions = tsconfig.compilerOptions || {};
tsconfig.compilerOptions = __assign({}, tsconfig.compilerOptions, compilerOptions);
var parsed = typescript.parseJsonConfigFileContent(tsconfig, parseConfigHost, path.dirname(configFile));
parsed.options.allowNonTsExtensions = true;
return parsed;
};
/**
* Search for default wildcard or wildcard from options, we only search for that in tsconfig CompilerOptions.paths.
* The path is resolved with thie given substitution and includes the CompilerOptions.baseUrl (if given).
* If no paths given in tsconfig, then the default substitution is '[tsconfig directory]/src'.
* (This is a fast, simplified inspiration of what's described here: https://github.com/Microsoft/TypeScript/issues/5039)
*/
VueProgram.resolveNonTsModuleName = function (moduleName, containingFile, basedir, options) {
var baseUrl = options.baseUrl ? options.baseUrl : basedir;
var discardedSymbols = ['.', '..', '/'];
var wildcards = [];
if (options.paths) {
Object.keys(options.paths).forEach(function (key) {
var pathSymbol = key[0];
if (discardedSymbols.indexOf(pathSymbol) < 0 &&
wildcards.indexOf(pathSymbol) < 0) {
wildcards.push(pathSymbol);
}
});
}
else {
wildcards.push('@');
}
var isRelative = !path.isAbsolute(moduleName);
var correctWildcard;
wildcards.forEach(function (wildcard) {
if (moduleName.substr(0, 2) === wildcard + "/") {
correctWildcard = wildcard;
}
});
if (correctWildcard) {
var pattern = options.paths
? options.paths[correctWildcard + "/*"]
: undefined;
var substitution = pattern
? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
options.paths[correctWildcard + "/*"][0].replace('*', '')
: 'src';
moduleName = path.resolve(baseUrl, substitution, moduleName.substr(2));
}
else if (isRelative) {
moduleName = path.resolve(path.dirname(containingFile), moduleName);
}
return moduleName;
};
VueProgram.isVue = function (filePath) {
return path.extname(filePath) === '.vue';
};
VueProgram.createProgram = function (typescript, programConfig, basedir, files, oldProgram, userResolveModuleName, userResolveTypeReferenceDirective, vueOptions) {
var host = typescript.createCompilerHost(programConfig.options);
var realGetSourceFile = host.getSourceFile;
var _a = resolution_1.makeResolutionFunctions(userResolveModuleName, userResolveTypeReferenceDirective), resolveModuleName = _a.resolveModuleName, resolveTypeReferenceDirective = _a.resolveTypeReferenceDirective;
host.resolveModuleNames = function (moduleNames, containingFile) {
return moduleNames.map(function (moduleName) {
return resolveModuleName(typescript, moduleName, containingFile, programConfig.options, host).resolvedModule;
});
};
host.resolveTypeReferenceDirectives = function (typeDirectiveNames, containingFile) {
return typeDirectiveNames.map(function (typeDirectiveName) {
return resolveTypeReferenceDirective(typescript, typeDirectiveName, containingFile, programConfig.options, host).resolvedTypeReferenceDirective;
});
};
// We need a host that can parse Vue SFCs (single file components).
host.getSourceFile = function (filePath, languageVersion, onError) {
try {
var stats = fs.statSync(filePath);
files.setMtime(filePath, stats.mtime.valueOf());
}
catch (e) {
// probably file does not exists
files.remove(filePath);
}
// get source file only if there is no source in files register
if (!files.has(filePath) || !files.getData(filePath).source) {
files.mutateData(filePath, function (data) {
data.source = realGetSourceFile(filePath, languageVersion, onError);
});
}
var source = files.getData(filePath).source;
// get typescript contents from Vue file
if (source && VueProgram.isVue(filePath)) {
var resolved = VueProgram.resolveScriptBlock(typescript, source.text, vueOptions.compiler);
source = typescript.createSourceFile(filePath, resolved.content, languageVersion, true, resolved.scriptKind);
}
return source;
};
// We need a host with special module resolution for Vue files.
host.resolveModuleNames = function (moduleNames, containingFile) {
var resolvedModules = [];
for (var _i = 0, moduleNames_1 = moduleNames; _i < moduleNames_1.length; _i++) {
var moduleName = moduleNames_1[_i];
// Try to use standard resolution.
var resolvedModule = typescript.resolveModuleName(moduleName, containingFile, programConfig.options, {
fileExists: function (fileName) {
if (fileName.endsWith('.vue.ts')) {
return (host.fileExists(fileName.slice(0, -3)) ||
host.fileExists(fileName));
}
else {
return host.fileExists(fileName);
}
},
readFile: function (fileName) {
// This implementation is not necessary. Just for consistent behavior.
if (fileName.endsWith('.vue.ts') && !host.fileExists(fileName)) {
return host.readFile(fileName.slice(0, -3));
}
else {
return host.readFile(fileName);
}
}
}).resolvedModule;
if (resolvedModule) {
if (resolvedModule.resolvedFileName.endsWith('.vue.ts') &&
!host.fileExists(resolvedModule.resolvedFileName)) {
resolvedModule.resolvedFileName = resolvedModule.resolvedFileName.slice(0, -3);
}
resolvedModules.push(resolvedModule);
}
else {
// For non-ts extensions.
var absolutePath = VueProgram.resolveNonTsModuleName(moduleName, containingFile, basedir, programConfig.options);
if (VueProgram.isVue(moduleName)) {
resolvedModules.push({
resolvedFileName: absolutePath,
extension: '.ts'
});
}
else {
resolvedModules.push({
// If the file does exist, return an empty string (because we assume user has provided a ".d.ts" file for it).
resolvedFileName: host.fileExists(absolutePath)
? ''
: absolutePath,
extension: '.ts'
});
}
}
}
return resolvedModules;
};
return typescript.createProgram(programConfig.fileNames, programConfig.options, host, oldProgram // re-use old program
);
};
VueProgram.getScriptKindByLang = function (typescript, lang) {
if (lang === 'ts') {
return typescript.ScriptKind.TS;
}
else if (lang === 'tsx') {
return typescript.ScriptKind.TSX;
}
else if (lang === 'jsx') {
return typescript.ScriptKind.JSX;
}
else {
// when lang is "js" or no lang specified
return typescript.ScriptKind.JS;
}
};
VueProgram.resolveScriptBlock = function (typescript, content, compiler) {
// We need to import template compiler for vue lazily because it cannot be included it
// as direct dependency because it is an optional dependency of fork-ts-checker-webpack-plugin.
// Since its version must not mismatch with user-installed Vue.js,
// we should let the users install template compiler for vue by themselves.
var parser;
try {
parser = require(compiler);
}
catch (err) {
throw new Error('When you use `vue` option, make sure to install `' + compiler + '`.');
}
var script = parser.parseComponent(content, {
pad: 'space'
}).script;
// No <script> block
if (!script) {
return {
scriptKind: typescript.ScriptKind.JS,
content: 'export default {};\n'
};
}
var scriptKind = VueProgram.getScriptKindByLang(typescript, script.lang);
// There is src attribute
if (script.attrs.src) {
// import path cannot be end with '.ts[x]'
var src = script.attrs.src.replace(/\.tsx?$/i, '');
return {
scriptKind: scriptKind,
// For now, ignore the error when the src file is not found
// since it will produce incorrect code location.
// It's not a large problem since it's handled on webpack side.
content: '// @ts-ignore\n' +
("export { default } from '" + src + "';\n") +
'// @ts-ignore\n' +
("export * from '" + src + "';\n")
};
}
// Pad blank lines to retain diagnostics location
// We need to prepend `//` for each line to avoid
// false positive of no-consecutive-blank-lines TSLint rule
var offset = content.slice(0, script.start).split(/\r?\n/g).length;
var paddedContent = Array(offset).join('//\n') + script.content.slice(script.start);
return {
scriptKind: scriptKind,
content: paddedContent
};
};
return VueProgram;
}());
exports.VueProgram = VueProgram;
//# sourceMappingURL=VueProgram.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,4 @@
import { LintReport, Options as EslintOptions } from './types/eslint';
export declare function createEslinter(eslintOptions: EslintOptions): {
getReport: (filepath: string) => LintReport | undefined;
};

View file

@ -0,0 +1,39 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var path = __importStar(require("path"));
var FsHelper_1 = require("./FsHelper");
function createEslinter(eslintOptions) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
var CLIEngine = require('eslint').CLIEngine;
// See https://eslint.org/docs/developer-guide/nodejs-api#cliengine
var eslinter = new CLIEngine(eslintOptions);
function getReport(filepath) {
try {
if (eslinter.isPathIgnored(filepath) ||
path.extname(filepath).localeCompare('.json', undefined, {
sensitivity: 'accent'
}) === 0) {
return undefined;
}
var lintReport = eslinter.executeOnFiles([filepath]);
if (eslintOptions && eslintOptions.fix) {
CLIEngine.outputFixes(lintReport);
}
return lintReport;
}
catch (e) {
FsHelper_1.throwIfIsInvalidSourceFileError(filepath, e);
}
return undefined;
}
return { getReport: getReport };
}
exports.createEslinter = createEslinter;
//# sourceMappingURL=createEslinter.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"createEslinter.js","sourceRoot":"./","sources":["createEslinter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,yCAA6B;AAG7B,uCAA6D;AAE7D,SAAgB,cAAc,CAAC,aAA4B;IACzD,8DAA8D;IACtD,IAAA,uCAAS,CAAuB;IAExC,mEAAmE;IACnE,IAAM,QAAQ,GAAG,IAAI,SAAS,CAAC,aAAa,CAAC,CAAC;IAE9C,SAAS,SAAS,CAAC,QAAgB;QACjC,IAAI;YACF,IACE,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC;gBAChC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,SAAS,EAAE;oBACvD,WAAW,EAAE,QAAQ;iBACtB,CAAC,KAAK,CAAC,EACR;gBACA,OAAO,SAAS,CAAC;aAClB;YAED,IAAM,UAAU,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;YAEvD,IAAI,aAAa,IAAI,aAAa,CAAC,GAAG,EAAE;gBACtC,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;aACnC;YAED,OAAO,UAAU,CAAC;SACnB;QAAC,OAAO,CAAC,EAAE;YACV,0CAA+B,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;SAC9C;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,EAAE,SAAS,WAAA,EAAE,CAAC;AACvB,CAAC;AAhCD,wCAgCC"}

View file

@ -0,0 +1,17 @@
import { Formatter } from './Formatter';
interface CodeFrameFormatterOptions {
/** Syntax highlight the code as JavaScript for terminals. default: false */
highlightCode?: boolean;
/** The number of lines to show above the error. default: 2 */
linesBelow?: number;
/** The number of lines to show below the error. default: 3 */
linesAbove?: number;
/**
* Forcibly syntax highlight the code as JavaScript (for non-terminals);
* overrides highlightCode.
* default: false
*/
forceColor?: boolean;
}
declare function createCodeframeFormatter(options?: CodeFrameFormatterOptions): Formatter;
export { createCodeframeFormatter, CodeFrameFormatterOptions };

View file

@ -0,0 +1,68 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var os = __importStar(require("os"));
var fs = __importStar(require("fs"));
var chalk_1 = __importDefault(require("chalk"));
var FsHelper_1 = require("../FsHelper");
var issue_1 = require("../issue");
var InternalFormatter_1 = require("./InternalFormatter");
var code_frame_1 = require("@babel/code-frame");
function createCodeframeFormatter(options) {
return function codeframeFormatter(issue) {
var color = {
message: issue.severity === issue_1.IssueSeverity.WARNING
? chalk_1.default.bold.yellow
: chalk_1.default.bold.red,
position: chalk_1.default.dim
};
if (issue.origin === issue_1.IssueOrigin.INTERNAL) {
return InternalFormatter_1.createInternalFormatter()(issue);
}
var file = issue.file;
var source = file && FsHelper_1.fileExistsSync(file) && fs.readFileSync(file, 'utf-8');
var frame = '';
if (source) {
frame = code_frame_1.codeFrameColumns(source, {
start: {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
line: issue.line,
column: issue.character
}
}, __assign({ highlightCode: true }, (options || {})))
.split('\n')
.map(function (line) { return ' ' + line; })
.join(os.EOL);
}
var lines = [
color.message(issue.severity.toUpperCase() + " in " + issue.file + "(" + issue.line + "," + issue.character + "):"),
color.position(issue.line + ":" + issue.character + " " + issue.message)
];
if (frame) {
lines.push(frame);
}
return lines.join(os.EOL);
};
}
exports.createCodeframeFormatter = createCodeframeFormatter;
//# sourceMappingURL=CodeframeFormatter.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"CodeframeFormatter.js","sourceRoot":"./","sources":["formatter/CodeframeFormatter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyB;AACzB,qCAAyB;AACzB,gDAA0B;AAE1B,wCAA6C;AAC7C,kCAAsD;AAEtD,yDAA8D;AAC9D,gDAAqD;AAiBrD,SAAS,wBAAwB,CAC/B,OAAmC;IAEnC,OAAO,SAAS,kBAAkB,CAAC,KAAK;QACtC,IAAM,KAAK,GAAG;YACZ,OAAO,EACL,KAAK,CAAC,QAAQ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CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACnB;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC;AAEQ,4DAAwB"}

View file

@ -0,0 +1,3 @@
import { Formatter } from './Formatter';
declare function createDefaultFormatter(): Formatter;
export { createDefaultFormatter };

View file

@ -0,0 +1,39 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var os = __importStar(require("os"));
var chalk_1 = __importDefault(require("chalk"));
var issue_1 = require("../issue");
var InternalFormatter_1 = require("./InternalFormatter");
function createDefaultFormatter() {
return function defaultFormatter(issue) {
var color = {
message: issue.severity === issue_1.IssueSeverity.WARNING
? chalk_1.default.bold.yellow
: chalk_1.default.bold.red,
position: chalk_1.default.bold.cyan,
code: chalk_1.default.grey
};
if (issue.origin === issue_1.IssueOrigin.INTERNAL) {
return InternalFormatter_1.createInternalFormatter()(issue);
}
var code = issue.origin === issue_1.IssueOrigin.TYPESCRIPT ? "TS" + issue.code : issue.code;
return [
color.message(issue.severity.toUpperCase() + " in ") +
color.position(issue.file + "(" + issue.line + "," + issue.character + ")") +
color.message(':'),
color.code(code + ': ') + issue.message
].join(os.EOL);
};
}
exports.createDefaultFormatter = createDefaultFormatter;
//# sourceMappingURL=DefaultFormatter.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"DefaultFormatter.js","sourceRoot":"./","sources":["formatter/DefaultFormatter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAyB;AACzB,gDAA0B;AAE1B,kCAAsD;AAEtD,yDAA8D;AAE9D,SAAS,sBAAsB;IAC7B,OAAO,SAAS,gBAAgB,CAAC,KAAK;QACpC,IAAM,KAAK,GAAG;YACZ,OAAO,EACL,KAAK,CAAC,QAAQ,KAAK,qBAAa,CAAC,OAAO;gBACtC,CAAC,CAAC,eAAK,CAAC,IAAI,CAAC,MAAM;gBACnB,CAAC,CAAC,eAAK,CAAC,IAAI,CAAC,GAAG;YACpB,QAAQ,EAAE,eAAK,CAAC,IAAI,CAAC,IAAI;YACzB,IAAI,EAAE,eAAK,CAAC,IAAI;SACjB,CAAC;QAEF,IAAI,KAAK,CAAC,MAAM,KAAK,mBAAW,CAAC,QAAQ,EAAE;YACzC,OAAO,2CAAuB,EAAE,CAAC,KAAK,CAAC,CAAC;SACzC;QAED,IAAM,IAAI,GACR,KAAK,CAAC,MAAM,KAAK,mBAAW,CAAC,UAAU,CAAC,CAAC,CAAC,OAAK,KAAK,CAAC,IAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;QAE3E,OAAO;YACL,KAAK,CAAC,OAAO,CAAI,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,SAAM,CAAC;gBAClD,KAAK,CAAC,QAAQ,CAAI,KAAK,CAAC,IAAI,SAAI,KAAK,CAAC,IAAI,SAAI,KAAK,CAAC,SAAS,MAAG,CAAC;gBACjE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;YACpB,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,KAAK,CAAC,OAAO;SACxC,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC;AAEQ,wDAAsB"}

View file

@ -0,0 +1,3 @@
import { Issue } from '../issue';
declare type Formatter = (issue: Issue) => string;
export { Formatter };

View file

@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=Formatter.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"Formatter.js","sourceRoot":"./","sources":["formatter/Formatter.ts"],"names":[],"mappings":""}

View file

@ -0,0 +1,6 @@
import { Formatter } from './Formatter';
import { CodeFrameFormatterOptions } from './CodeframeFormatter';
declare type FormatterType = undefined | 'default' | 'codeframe' | Formatter;
declare type FormatterOptions = CodeFrameFormatterOptions;
declare function createFormatter(type?: FormatterType, options?: FormatterOptions): Formatter;
export { createFormatter, FormatterType, FormatterOptions };

View file

@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var CodeframeFormatter_1 = require("./CodeframeFormatter");
var DefaultFormatter_1 = require("./DefaultFormatter");
function createFormatter(type, options) {
if (typeof type === 'function') {
return type;
}
switch (type) {
case 'codeframe':
return CodeframeFormatter_1.createCodeframeFormatter(options);
case 'default':
case undefined:
return DefaultFormatter_1.createDefaultFormatter();
default:
throw new Error('Unknown "' +
type +
'" formatter. Available types are: default, codeframe.');
}
}
exports.createFormatter = createFormatter;
//# sourceMappingURL=FormatterFactory.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"FormatterFactory.js","sourceRoot":"./","sources":["formatter/FormatterFactory.ts"],"names":[],"mappings":";;AACA,2DAG8B;AAC9B,uDAA4D;AAK5D,SAAS,eAAe,CACtB,IAAoB,EACpB,OAA0B;IAE1B,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;QAC9B,OAAO,IAAI,CAAC;KACb;IAED,QAAQ,IAAI,EAAE;QACZ,KAAK,WAAW;YACd,OAAO,6CAAwB,CAAC,OAAO,CAAC,CAAC;QAE3C,KAAK,SAAS,CAAC;QACf,KAAK,SAAS;YACZ,OAAO,yCAAsB,EAAE,CAAC;QAElC;YACE,MAAM,IAAI,KAAK,CACb,WAAW;gBACT,IAAI;gBACJ,uDAAuD,CAC1D,CAAC;KACL;AACH,CAAC;AAEQ,0CAAe"}

View file

@ -0,0 +1,6 @@
import { Formatter } from './Formatter';
/**
* TODO: maybe we should not treat internal errors as issues
*/
declare function createInternalFormatter(): Formatter;
export { createInternalFormatter };

View file

@ -0,0 +1,40 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var chalk_1 = __importDefault(require("chalk"));
var os = __importStar(require("os"));
var issue_1 = require("../issue");
/**
* TODO: maybe we should not treat internal errors as issues
*/
function createInternalFormatter() {
return function internalFormatter(issue) {
var color = {
message: chalk_1.default.bold.red,
stack: chalk_1.default.grey
};
if (issue.origin === issue_1.IssueOrigin.INTERNAL) {
var lines = [
color.message('INTERNAL ' + issue.severity.toUpperCase()) + ": " + issue.message
];
if (issue.stack) {
lines.push('stack trace:', color.stack(issue.stack));
}
return lines.join(os.EOL);
}
else {
throw new Error("Not supported \"" + issue.origin + "\" issue origin.");
}
};
}
exports.createInternalFormatter = createInternalFormatter;
//# sourceMappingURL=InternalFormatter.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"InternalFormatter.js","sourceRoot":"./","sources":["formatter/InternalFormatter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAA0B;AAC1B,qCAAyB;AAEzB,kCAAuC;AAGvC;;GAEG;AACH,SAAS,uBAAuB;IAC9B,OAAO,SAAS,iBAAiB,CAAC,KAAK;QACrC,IAAM,KAAK,GAAG;YACZ,OAAO,EAAE,eAAK,CAAC,IAAI,CAAC,GAAG;YACvB,KAAK,EAAE,eAAK,CAAC,IAAI;SAClB,CAAC;QAEF,IAAI,KAAK,CAAC,MAAM,KAAK,mBAAW,CAAC,QAAQ,EAAE;YACzC,IAAM,KAAK,GAAG;gBACT,KAAK,CAAC,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,UAC1D,KAAK,CAAC,OACN;aACH,CAAC;YACF,IAAI,KAAK,CAAC,KAAK,EAAE;gBACf,KAAK,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;aACtD;YAED,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;SAC3B;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,qBAAkB,KAAK,CAAC,MAAM,qBAAiB,CAAC,CAAC;SAClE;IACH,CAAC,CAAC;AACJ,CAAC;AAEQ,0DAAuB"}

View file

@ -0,0 +1,3 @@
import { Formatter } from './Formatter';
declare function createRawFormatter(): Formatter;
export { createRawFormatter };

View file

@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var issue_1 = require("../issue");
function createRawFormatter() {
return function rawFormatter(issue) {
var code = issue.origin === issue_1.IssueOrigin.TYPESCRIPT ? "TS" + issue.code : issue.code;
return issue.severity.toUpperCase() + " " + code + ": " + issue.message;
};
}
exports.createRawFormatter = createRawFormatter;
//# sourceMappingURL=RawFormatter.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"RawFormatter.js","sourceRoot":"./","sources":["formatter/RawFormatter.ts"],"names":[],"mappings":";;AACA,kCAAuC;AAEvC,SAAS,kBAAkB;IACzB,OAAO,SAAS,YAAY,CAAC,KAAK;QAChC,IAAM,IAAI,GACR,KAAK,CAAC,MAAM,KAAK,mBAAW,CAAC,UAAU,CAAC,CAAC,CAAC,OAAK,KAAK,CAAC,IAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;QAE3E,OAAU,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,SAAI,IAAI,UAAK,KAAK,CAAC,OAAS,CAAC;IACrE,CAAC,CAAC;AACJ,CAAC;AAEQ,gDAAkB"}

View file

@ -0,0 +1,6 @@
export * from './Formatter';
export * from './DefaultFormatter';
export * from './CodeframeFormatter';
export * from './FormatterFactory';
export * from './InternalFormatter';
export * from './RawFormatter';

View file

@ -0,0 +1,11 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./DefaultFormatter"));
__export(require("./CodeframeFormatter"));
__export(require("./FormatterFactory"));
__export(require("./InternalFormatter"));
__export(require("./RawFormatter"));
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"./","sources":["formatter/index.ts"],"names":[],"mappings":";;;;;AACA,wCAAmC;AACnC,0CAAqC;AACrC,wCAAmC;AACnC,yCAAoC;AACpC,oCAA+B"}

View file

@ -0,0 +1,4 @@
import * as webpack from 'webpack';
import { AsyncSeriesHook, SyncHook } from 'tapable';
export declare type ForkTsCheckerHooks = 'serviceBeforeStart' | 'cancel' | 'serviceStartError' | 'waiting' | 'serviceStart' | 'receive' | 'serviceOutOfMemory' | 'emit' | 'done';
export declare function getForkTsCheckerWebpackPluginHooks(compiler: webpack.Compiler): Record<ForkTsCheckerHooks, SyncHook<any, any, any> | AsyncSeriesHook<any, any, any>>;

View file

@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tapable_1 = require("tapable");
var compilerHookMap = new WeakMap();
function createForkTsCheckerWebpackPluginHooks() {
return {
serviceBeforeStart: new tapable_1.AsyncSeriesHook([]),
cancel: new tapable_1.SyncHook(['cancellationToken']),
serviceStartError: new tapable_1.SyncHook(['error']),
waiting: new tapable_1.SyncHook([]),
serviceStart: new tapable_1.SyncHook(['tsconfigPath', 'memoryLimit']),
receive: new tapable_1.SyncHook(['diagnostics', 'lints']),
serviceOutOfMemory: new tapable_1.SyncHook([]),
emit: new tapable_1.SyncHook(['diagnostics', 'lints', 'elapsed']),
done: new tapable_1.SyncHook(['diagnostics', 'lints', 'elapsed'])
};
}
function getForkTsCheckerWebpackPluginHooks(compiler) {
var hooks = compilerHookMap.get(compiler);
if (hooks === undefined) {
hooks = createForkTsCheckerWebpackPluginHooks();
compilerHookMap.set(compiler, hooks);
}
return hooks;
}
exports.getForkTsCheckerWebpackPluginHooks = getForkTsCheckerWebpackPluginHooks;
//# sourceMappingURL=hooks.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"hooks.js","sourceRoot":"./","sources":["hooks.ts"],"names":[],"mappings":";;AACA,mCAAoD;AAiBpD,IAAM,eAAe,GAAG,IAAI,OAAO,EAA0C,CAAC;AAE9E,SAAS,qCAAqC;IAC5C,OAAO;QACL,kBAAkB,EAAE,IAAI,yBAAe,CAAC,EAAE,CAAC;QAC3C,MAAM,EAAE,IAAI,kBAAQ,CAAC,CAAC,mBAAmB,CAAC,CAAC;QAC3C,iBAAiB,EAAE,IAAI,kBAAQ,CAAC,CAAC,OAAO,CAAC,CAAC;QAC1C,OAAO,EAAE,IAAI,kBAAQ,CAAC,EAAE,CAAC;QACzB,YAAY,EAAE,IAAI,kBAAQ,CAAC,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;QAC3D,OAAO,EAAE,IAAI,kBAAQ,CAAC,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QAC/C,kBAAkB,EAAE,IAAI,kBAAQ,CAAC,EAAE,CAAC;QACpC,IAAI,EAAE,IAAI,kBAAQ,CAAC,CAAC,aAAa,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;QACvD,IAAI,EAAE,IAAI,kBAAQ,CAAC,CAAC,aAAa,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;KACxD,CAAC;AACJ,CAAC;AAED,SAAgB,kCAAkC,CAAC,QAA0B;IAC3E,IAAI,KAAK,GAAG,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1C,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,KAAK,GAAG,qCAAqC,EAAE,CAAC;QAChD,eAAe,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;KACtC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAPD,gFAOC"}

View file

@ -0,0 +1,108 @@
import { RpcProvider } from 'worker-rpc';
import { FormatterType, FormatterOptions } from './formatter';
import { VueOptions } from './types/vue-options';
import { Options as EslintOptions } from './types/eslint';
declare namespace ForkTsCheckerWebpackPlugin {
interface Logger {
error(message?: any): void;
warn(message?: any): void;
info(message?: any): void;
}
interface Options {
typescript: string;
tsconfig: string;
compilerOptions: object;
eslint: boolean;
/** Options to supply to eslint https://eslint.org/docs/developer-guide/nodejs-api#cliengine */
eslintOptions: EslintOptions;
async: boolean;
ignoreDiagnostics: number[];
ignoreLints: string[];
ignoreLintWarnings: boolean;
reportFiles: string[];
logger: Logger;
formatter: FormatterType;
formatterOptions: FormatterOptions;
silent: boolean;
checkSyntacticErrors: boolean;
memoryLimit: number;
vue: boolean | Partial<VueOptions>;
useTypescriptIncrementalApi: boolean;
measureCompilationTime: boolean;
resolveModuleNameModule: string;
resolveTypeReferenceDirectiveModule: string;
}
}
/**
* ForkTsCheckerWebpackPlugin
* Runs typescript type checker and linter on separate process.
* This speed-ups build a lot.
*
* Options description in README.md
*/
declare class ForkTsCheckerWebpackPlugin {
static readonly DEFAULT_MEMORY_LIMIT = 2048;
static getCompilerHooks(compiler: any): Record<import("./hooks").ForkTsCheckerHooks, import("tapable").SyncHook<any, any, any> | import("tapable").AsyncSeriesHook<any, any, any>>;
readonly options: Partial<ForkTsCheckerWebpackPlugin.Options>;
private tsconfig;
private compilerOptions;
private eslint;
private eslintOptions;
private ignoreDiagnostics;
private ignoreLints;
private ignoreLintWarnings;
private reportFiles;
private logger;
private silent;
private async;
private checkSyntacticErrors;
private memoryLimit;
private formatter;
private rawFormatter;
private useTypescriptIncrementalApi;
private resolveModuleNameModule;
private resolveTypeReferenceDirectiveModule;
private tsconfigPath;
private compiler;
private started;
private elapsed;
private cancellationToken;
private isWatching;
private checkDone;
private compilationDone;
private diagnostics;
private lints;
private emitCallback;
private doneCallback;
private typescriptPath;
private typescript;
private typescriptVersion;
private eslintVersion;
private service?;
protected serviceRpc?: RpcProvider;
private vue;
private measureTime;
private performance;
private startAt;
protected nodeArgs: string[];
constructor(options?: Partial<ForkTsCheckerWebpackPlugin.Options>);
private validateTypeScript;
private validateEslint;
private static prepareVueOptions;
apply(compiler: any): void;
private computeContextPath;
private pluginStart;
private pluginStop;
private pluginCompile;
private pluginEmit;
private pluginDone;
private spawnService;
private killService;
private handleServiceMessage;
private handleServiceExit;
private createEmitCallback;
private createNoopEmitCallback;
private printLoggerMessage;
private createDoneCallback;
}
export = ForkTsCheckerWebpackPlugin;

View file

@ -0,0 +1,510 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var path = __importStar(require("path"));
var childProcess = __importStar(require("child_process"));
var semver = __importStar(require("semver"));
var micromatch_1 = __importDefault(require("micromatch"));
var chalk_1 = __importDefault(require("chalk"));
var worker_rpc_1 = require("worker-rpc");
var CancellationToken_1 = require("./CancellationToken");
var formatter_1 = require("./formatter");
var FsHelper_1 = require("./FsHelper");
var hooks_1 = require("./hooks");
var RpcTypes_1 = require("./RpcTypes");
var issue_1 = require("./issue");
var checkerPluginName = 'fork-ts-checker-webpack-plugin';
/**
* ForkTsCheckerWebpackPlugin
* Runs typescript type checker and linter on separate process.
* This speed-ups build a lot.
*
* Options description in README.md
*/
var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
function ForkTsCheckerWebpackPlugin(options) {
this.eslint = false;
this.eslintOptions = {};
this.tsconfigPath = undefined;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.compiler = undefined;
this.started = undefined;
this.elapsed = undefined;
this.cancellationToken = undefined;
this.isWatching = false;
this.checkDone = false;
this.compilationDone = false;
this.diagnostics = [];
this.lints = [];
this.eslintVersion = undefined;
this.startAt = 0;
this.nodeArgs = [];
options = options || {};
this.options = __assign({}, options);
this.ignoreDiagnostics = options.ignoreDiagnostics || [];
this.ignoreLints = options.ignoreLints || [];
this.ignoreLintWarnings = options.ignoreLintWarnings === true;
this.reportFiles = options.reportFiles || [];
this.logger = options.logger || console;
this.silent = options.silent === true; // default false
this.async = options.async !== false; // default true
this.checkSyntacticErrors = options.checkSyntacticErrors === true; // default false
this.resolveModuleNameModule = options.resolveModuleNameModule;
this.resolveTypeReferenceDirectiveModule =
options.resolveTypeReferenceDirectiveModule;
this.memoryLimit =
options.memoryLimit || ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT;
this.formatter = formatter_1.createFormatter(options.formatter, options.formatterOptions);
this.rawFormatter = formatter_1.createRawFormatter();
this.emitCallback = this.createNoopEmitCallback();
this.doneCallback = this.createDoneCallback();
var _a = this.validateTypeScript(options), typescript = _a.typescript, typescriptPath = _a.typescriptPath, typescriptVersion = _a.typescriptVersion, tsconfig = _a.tsconfig, compilerOptions = _a.compilerOptions;
this.typescript = typescript;
this.typescriptPath = typescriptPath;
this.typescriptVersion = typescriptVersion;
this.tsconfig = tsconfig;
this.compilerOptions = compilerOptions;
if (options.eslint === true) {
var _b = this.validateEslint(options), eslintVersion = _b.eslintVersion, eslintOptions = _b.eslintOptions;
this.eslint = true;
this.eslintVersion = eslintVersion;
this.eslintOptions = eslintOptions;
}
this.vue = ForkTsCheckerWebpackPlugin.prepareVueOptions(options.vue);
this.useTypescriptIncrementalApi =
options.useTypescriptIncrementalApi === undefined
? semver.gte(this.typescriptVersion, '3.0.0') && !this.vue.enabled
: options.useTypescriptIncrementalApi;
this.measureTime = options.measureCompilationTime === true;
if (this.measureTime) {
if (semver.lt(process.version, '8.5.0')) {
throw new Error("To use 'measureCompilationTime' option, please update to Node.js >= v8.5.0 " +
("(current version is " + process.version + ")"));
}
// Node 8+ only
// eslint-disable-next-line node/no-unsupported-features/node-builtins
this.performance = require('perf_hooks').performance;
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ForkTsCheckerWebpackPlugin.getCompilerHooks = function (compiler) {
return hooks_1.getForkTsCheckerWebpackPluginHooks(compiler);
};
ForkTsCheckerWebpackPlugin.prototype.validateTypeScript = function (options) {
var typescriptPath = options.typescript || require.resolve('typescript');
var tsconfig = options.tsconfig || './tsconfig.json';
var compilerOptions = typeof options.compilerOptions === 'object'
? options.compilerOptions
: {};
var typescript, typescriptVersion;
try {
typescript = require(typescriptPath);
typescriptVersion = typescript.version;
}
catch (_ignored) {
throw new Error('When you use this plugin you must install `typescript`.');
}
if (semver.lt(typescriptVersion, '2.1.0')) {
throw new Error("Cannot use current typescript version of " + typescriptVersion + ", the minimum required version is 2.1.0");
}
return {
typescriptPath: typescriptPath,
typescript: typescript,
typescriptVersion: typescriptVersion,
tsconfig: tsconfig,
compilerOptions: compilerOptions
};
};
ForkTsCheckerWebpackPlugin.prototype.validateEslint = function (options) {
var eslintVersion;
var eslintOptions = typeof options.eslintOptions === 'object' ? options.eslintOptions : {};
if (semver.lt(process.version, '8.10.0')) {
throw new Error("To use 'eslint' option, please update to Node.js >= v8.10.0 " +
("(current version is " + process.version + ")"));
}
try {
eslintVersion = require('eslint').Linter.version;
}
catch (error) {
throw new Error("When you use 'eslint' option, make sure to install 'eslint'.");
}
return { eslintVersion: eslintVersion, eslintOptions: eslintOptions };
};
ForkTsCheckerWebpackPlugin.prepareVueOptions = function (vueOptions) {
var defaultVueOptions = {
compiler: 'vue-template-compiler',
enabled: false
};
if (typeof vueOptions === 'boolean') {
return Object.assign(defaultVueOptions, { enabled: vueOptions });
}
else if (typeof vueOptions === 'object' && vueOptions !== null) {
return Object.assign(defaultVueOptions, vueOptions);
}
else {
return defaultVueOptions;
}
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ForkTsCheckerWebpackPlugin.prototype.apply = function (compiler) {
this.compiler = compiler;
this.tsconfigPath = this.computeContextPath(this.tsconfig);
// validate config
var tsconfigOk = FsHelper_1.fileExistsSync(this.tsconfigPath);
// validate logger
if (this.logger) {
if (!this.logger.error || !this.logger.warn || !this.logger.info) {
throw new Error("Invalid logger object - doesn't provide `error`, `warn` or `info` method.");
}
}
if (!tsconfigOk) {
throw new Error('Cannot find "' +
this.tsconfigPath +
'" file. Please check webpack and ForkTsCheckerWebpackPlugin configuration. \n' +
'Possible errors: \n' +
' - wrong `context` directory in webpack configuration' +
' (if `tsconfig` is not set or is a relative path in fork plugin configuration)\n' +
' - wrong `tsconfig` path in fork plugin configuration' +
' (should be a relative or absolute path)');
}
this.pluginStart();
this.pluginStop();
this.pluginCompile();
this.pluginEmit();
this.pluginDone();
};
ForkTsCheckerWebpackPlugin.prototype.computeContextPath = function (filePath) {
return path.isAbsolute(filePath)
? filePath
: path.resolve(this.compiler.options.context, filePath);
};
ForkTsCheckerWebpackPlugin.prototype.pluginStart = function () {
var _this = this;
var run = function (compilation, callback) {
_this.isWatching = false;
callback();
};
var watchRun = function (compiler, callback) {
_this.isWatching = true;
callback();
};
this.compiler.hooks.run.tapAsync(checkerPluginName, run);
this.compiler.hooks.watchRun.tapAsync(checkerPluginName, watchRun);
};
ForkTsCheckerWebpackPlugin.prototype.pluginStop = function () {
var _this = this;
var watchClose = function () {
_this.killService();
};
var doneOrFailed = function () {
if (!_this.isWatching) {
_this.killService();
}
};
this.compiler.hooks.watchClose.tap(checkerPluginName, watchClose);
this.compiler.hooks.done.tap(checkerPluginName, doneOrFailed);
this.compiler.hooks.failed.tap(checkerPluginName, doneOrFailed);
process.on('exit', function () {
_this.killService();
});
};
ForkTsCheckerWebpackPlugin.prototype.pluginCompile = function () {
var _this = this;
var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
this.compiler.hooks.compile.tap(checkerPluginName, function () {
_this.compilationDone = false;
forkTsCheckerHooks.serviceBeforeStart.callAsync(function () {
if (_this.cancellationToken) {
// request cancellation if there is not finished job
_this.cancellationToken.requestCancellation();
forkTsCheckerHooks.cancel.call(_this.cancellationToken);
}
_this.checkDone = false;
_this.started = process.hrtime();
// create new token for current job
_this.cancellationToken = new CancellationToken_1.CancellationToken(_this.typescript);
if (!_this.service || !_this.service.connected) {
_this.spawnService();
}
try {
if (_this.measureTime) {
_this.startAt = _this.performance.now();
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
_this.serviceRpc.rpc(RpcTypes_1.RUN, _this.cancellationToken.toJSON()).then(function (result) {
if (result) {
_this.handleServiceMessage(result);
}
});
}
catch (error) {
if (!_this.silent && _this.logger) {
_this.logger.error(chalk_1.default.red('Cannot start checker service: ' +
(error ? error.toString() : 'Unknown error')));
}
forkTsCheckerHooks.serviceStartError.call(error);
}
});
});
};
ForkTsCheckerWebpackPlugin.prototype.pluginEmit = function () {
var _this = this;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var emit = function (compilation, callback) {
if (_this.isWatching && _this.async) {
callback();
return;
}
_this.emitCallback = _this.createEmitCallback(compilation, callback);
if (_this.checkDone) {
_this.emitCallback();
}
_this.compilationDone = true;
};
this.compiler.hooks.emit.tapAsync(checkerPluginName, emit);
};
ForkTsCheckerWebpackPlugin.prototype.pluginDone = function () {
var _this = this;
var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
this.compiler.hooks.done.tap(checkerPluginName, function () {
if (!_this.isWatching || !_this.async) {
return;
}
if (_this.checkDone) {
_this.doneCallback();
}
else {
if (_this.compiler) {
forkTsCheckerHooks.waiting.call();
}
if (!_this.silent && _this.logger) {
_this.logger.info('Type checking in progress...');
}
}
_this.compilationDone = true;
});
};
ForkTsCheckerWebpackPlugin.prototype.spawnService = function () {
var _this = this;
var env = __assign({}, process.env, { TYPESCRIPT_PATH: this.typescriptPath, TSCONFIG: this.tsconfigPath, COMPILER_OPTIONS: JSON.stringify(this.compilerOptions), CONTEXT: this.compiler.options.context, ESLINT: String(this.eslint), ESLINT_OPTIONS: JSON.stringify(this.eslintOptions), MEMORY_LIMIT: String(this.memoryLimit), CHECK_SYNTACTIC_ERRORS: String(this.checkSyntacticErrors), USE_INCREMENTAL_API: String(this.useTypescriptIncrementalApi === true), VUE: JSON.stringify(this.vue) });
if (typeof this.resolveModuleNameModule !== 'undefined') {
env.RESOLVE_MODULE_NAME = this.resolveModuleNameModule;
}
else {
delete env.RESOLVE_MODULE_NAME;
}
if (typeof this.resolveTypeReferenceDirectiveModule !== 'undefined') {
env.RESOLVE_TYPE_REFERENCE_DIRECTIVE = this.resolveTypeReferenceDirectiveModule;
}
else {
delete env.RESOLVE_TYPE_REFERENCE_DIRECTIVE;
}
this.service = childProcess.fork(path.resolve(__dirname, './service.js'), [], {
env: env,
execArgv: ['--max-old-space-size=' + this.memoryLimit].concat(this.nodeArgs),
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
});
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.serviceRpc = new worker_rpc_1.RpcProvider(function (message) { return _this.service.send(message); });
this.service.on('message', function (message) {
if (_this.serviceRpc) {
// ensure that serviceRpc is defined to avoid race-conditions
_this.serviceRpc.dispatch(message);
}
});
var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
forkTsCheckerHooks.serviceStart.call(this.tsconfigPath, this.memoryLimit);
if (!this.silent && this.logger) {
this.logger.info('Starting type checking service...');
}
this.service.on('exit', function (code, signal) {
return _this.handleServiceExit(code, signal);
});
};
ForkTsCheckerWebpackPlugin.prototype.killService = function () {
if (!this.service) {
return;
}
try {
if (this.cancellationToken) {
this.cancellationToken.cleanupCancellation();
}
// clean-up listeners
this.service.removeAllListeners();
this.service.kill();
this.service = undefined;
this.serviceRpc = undefined;
}
catch (e) {
if (this.logger && !this.silent) {
this.logger.error(e);
}
}
};
ForkTsCheckerWebpackPlugin.prototype.handleServiceMessage = function (message) {
var _this = this;
if (this.measureTime) {
var delta = this.performance.now() - this.startAt;
var deltaRounded = Math.round(delta * 100) / 100;
this.logger.info("Compilation took: " + deltaRounded + " ms.");
}
if (this.cancellationToken) {
this.cancellationToken.cleanupCancellation();
// job is done - nothing to cancel
this.cancellationToken = undefined;
}
this.checkDone = true;
this.elapsed = process.hrtime(this.started);
this.diagnostics = message.diagnostics;
this.lints = message.lints;
if (this.ignoreDiagnostics.length) {
this.diagnostics = this.diagnostics.filter(function (diagnostic) {
return !_this.ignoreDiagnostics.includes(parseInt(diagnostic.code, 10));
});
}
if (this.ignoreLints.length) {
this.lints = this.lints.filter(function (lint) { return !_this.ignoreLints.includes(lint.code); });
}
if (this.reportFiles.length) {
var reportFilesPredicate = function (issue) {
if (issue.file) {
var relativeFileName = path.relative(_this.compiler.options.context, issue.file);
var matchResult = micromatch_1.default([relativeFileName], _this.reportFiles);
if (matchResult.length === 0) {
return false;
}
}
return true;
};
this.diagnostics = this.diagnostics.filter(reportFilesPredicate);
this.lints = this.lints.filter(reportFilesPredicate);
}
var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
forkTsCheckerHooks.receive.call(this.diagnostics, this.lints);
if (this.compilationDone) {
this.isWatching && this.async ? this.doneCallback() : this.emitCallback();
}
};
ForkTsCheckerWebpackPlugin.prototype.handleServiceExit = function (_code, signal) {
if (signal !== 'SIGABRT' && signal !== 'SIGINT') {
return;
}
// probably out of memory :/
if (this.compiler) {
var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
forkTsCheckerHooks.serviceOutOfMemory.call();
}
if (!this.silent && this.logger) {
if (signal === 'SIGINT') {
this.logger.error(chalk_1.default.red('Type checking and linting interrupted - If running in a docker container, this may be caused ' +
"by the container running out of memory. If so, try increasing the container's memory limit " +
'or lowering the memoryLimit value in the ForkTsCheckerWebpackPlugin configuration.'));
}
else {
this.logger.error(chalk_1.default.red('Type checking and linting aborted - probably out of memory. ' +
'Check `memoryLimit` option in ForkTsCheckerWebpackPlugin configuration.'));
}
}
};
ForkTsCheckerWebpackPlugin.prototype.createEmitCallback = function (compilation, callback) {
return function emitCallback() {
var _this = this;
if (!this.elapsed) {
throw new Error('Execution order error');
}
var elapsed = Math.round(this.elapsed[0] * 1e9 + this.elapsed[1]);
var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
forkTsCheckerHooks.emit.call(this.diagnostics, this.lints, elapsed);
this.diagnostics.concat(this.lints).forEach(function (issue) {
// webpack message format
var formatted = {
rawMessage: _this.rawFormatter(issue),
message: _this.formatter(issue),
location: {
line: issue.line,
character: issue.character
},
file: issue.file
};
if (issue.severity === issue_1.IssueSeverity.WARNING) {
if (!_this.ignoreLintWarnings) {
compilation.warnings.push(formatted);
}
}
else {
compilation.errors.push(formatted);
}
});
callback();
};
};
ForkTsCheckerWebpackPlugin.prototype.createNoopEmitCallback = function () {
// this function is empty intentionally
// eslint-disable-next-line @typescript-eslint/no-empty-function
return function noopEmitCallback() { };
};
ForkTsCheckerWebpackPlugin.prototype.printLoggerMessage = function (issue, formattedIssue) {
if (issue.severity === issue_1.IssueSeverity.WARNING) {
if (this.ignoreLintWarnings) {
return;
}
this.logger.warn(formattedIssue);
}
else {
this.logger.error(formattedIssue);
}
};
ForkTsCheckerWebpackPlugin.prototype.createDoneCallback = function () {
return function doneCallback() {
var _this = this;
if (!this.elapsed) {
throw new Error('Execution order error');
}
var elapsed = Math.round(this.elapsed[0] * 1e9 + this.elapsed[1]);
if (this.compiler) {
var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
forkTsCheckerHooks.done.call(this.diagnostics, this.lints, elapsed);
}
if (!this.silent && this.logger) {
if (this.diagnostics.length || this.lints.length) {
(this.lints || []).concat(this.diagnostics).forEach(function (diagnostic) {
var formattedDiagnostic = _this.formatter(diagnostic);
_this.printLoggerMessage(diagnostic, formattedDiagnostic);
});
}
if (!this.diagnostics.length) {
this.logger.info(chalk_1.default.green('No type errors found'));
}
this.logger.info('Version: typescript ' +
chalk_1.default.bold(this.typescriptVersion) +
(this.eslint
? ', eslint ' + chalk_1.default.bold(this.eslintVersion)
: ''));
this.logger.info("Time: " + chalk_1.default.bold(Math.round(elapsed / 1e6).toString()) + " ms");
}
};
};
ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT = 2048;
return ForkTsCheckerWebpackPlugin;
}());
module.exports = ForkTsCheckerWebpackPlugin;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,15 @@
import { IssueSeverity } from './IssueSeverity';
import { IssueOrigin } from './IssueOrigin';
interface Issue {
origin: IssueOrigin;
severity: IssueSeverity;
code: string;
message: string;
file?: string;
line?: number;
character?: number;
stack?: string;
}
declare function isIssue(value: unknown): value is Issue;
declare function deduplicateAndSortIssues(issues: Issue[]): Issue[];
export { Issue, isIssue, deduplicateAndSortIssues };

View file

@ -0,0 +1,59 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var IssueSeverity_1 = require("./IssueSeverity");
var IssueOrigin_1 = require("./IssueOrigin");
function isIssue(value) {
return (!!value &&
typeof value === 'object' &&
IssueOrigin_1.isIssueOrigin(value.origin) &&
IssueSeverity_1.isIssueSeverity(value.severity) &&
!!value.code &&
!!value.message);
}
exports.isIssue = isIssue;
function compareOptionalStrings(stringA, stringB) {
if (stringA === stringB) {
return 0;
}
if (stringA === undefined || stringA === null) {
return -1;
}
if (stringB === undefined || stringB === null) {
return 1;
}
return stringA.toString().localeCompare(stringB.toString());
}
function compareNumbers(numberA, numberB) {
if (numberA === numberB) {
return 0;
}
if (numberA === undefined || numberA === null) {
return -1;
}
if (numberB === undefined || numberB === null) {
return 1;
}
return Math.sign(numberA - numberB);
}
function compareIssues(issueA, issueB) {
return (IssueOrigin_1.compareIssueOrigins(issueA.origin, issueB.origin) ||
compareOptionalStrings(issueA.file, issueB.file) ||
IssueSeverity_1.compareIssueSeverities(issueA.severity, issueB.severity) ||
compareNumbers(issueA.line, issueB.line) ||
compareNumbers(issueA.character, issueB.character) ||
compareOptionalStrings(issueA.code, issueB.code) ||
compareOptionalStrings(issueA.message, issueB.message) ||
compareOptionalStrings(issueA.stack, issueB.stack) ||
0 /* EqualTo */);
}
function equalsIssues(issueA, issueB) {
return compareIssues(issueA, issueB) === 0;
}
function deduplicateAndSortIssues(issues) {
var sortedIssues = issues.filter(isIssue).sort(compareIssues);
return sortedIssues.filter(function (issue, index) {
return index === 0 || !equalsIssues(issue, sortedIssues[index - 1]);
});
}
exports.deduplicateAndSortIssues = deduplicateAndSortIssues;
//# sourceMappingURL=Issue.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"Issue.js","sourceRoot":"./","sources":["issue/Issue.ts"],"names":[],"mappings":";;AAAA,iDAIyB;AACzB,6CAAgF;AAahF,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,CACL,CAAC,CAAC,KAAK;QACP,OAAO,KAAK,KAAK,QAAQ;QACzB,2BAAa,CAAE,KAAe,CAAC,MAAM,CAAC;QACtC,+BAAe,CAAE,KAAe,CAAC,QAAQ,CAAC;QAC1C,CAAC,CAAE,KAAe,CAAC,IAAI;QACvB,CAAC,CAAE,KAAe,CAAC,OAAO,CAC3B,CAAC;AACJ,CAAC;AA2De,0BAAO;AAzDvB,SAAS,sBAAsB,CAAC,OAAgB,EAAE,OAAgB;IAChE,IAAI,OAAO,KAAK,OAAO,EAAE;QACvB,OAAO,CAAC,CAAC;KACV;IAED,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,EAAE;QAC7C,OAAO,CAAC,CAAC,CAAC;KACX;IACD,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,EAAE;QAC7C,OAAO,CAAC,CAAC;KACV;IAED,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC9D,CA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CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAEhE,OAAO,YAAY,CAAC,MAAM,CACxB,UAAC,KAAK,EAAE,KAAK;QACX,OAAA,KAAK,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAA5D,CAA4D,CAC/D,CAAC;AACJ,CAAC;AAEwB,4DAAwB"}

View file

@ -0,0 +1,9 @@
declare const IssueOrigin: {
readonly TYPESCRIPT: "typescript";
readonly ESLINT: "eslint";
readonly INTERNAL: "internal";
};
declare type IssueOrigin = typeof IssueOrigin[keyof typeof IssueOrigin];
declare function isIssueOrigin(value: unknown): value is IssueOrigin;
declare function compareIssueOrigins(originA: IssueOrigin, originB: IssueOrigin): number;
export { IssueOrigin, isIssueOrigin, compareIssueOrigins };

View file

@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var IssueOrigin = {
TYPESCRIPT: 'typescript',
ESLINT: 'eslint',
INTERNAL: 'internal'
};
exports.IssueOrigin = IssueOrigin;
function isIssueOrigin(value) {
return [
IssueOrigin.TYPESCRIPT,
IssueOrigin.ESLINT,
IssueOrigin.INTERNAL
].includes(value);
}
exports.isIssueOrigin = isIssueOrigin;
function compareIssueOrigins(originA, originB) {
var _a = [originA, originB].map(function (origin) {
return [
IssueOrigin.ESLINT /* 0 */,
IssueOrigin.TYPESCRIPT /* 1 */,
IssueOrigin.INTERNAL /* 2 */
].indexOf(origin);
}), priorityA = _a[0], priorityB = _a[1];
return Math.sign(priorityB - priorityA);
}
exports.compareIssueOrigins = compareIssueOrigins;
//# sourceMappingURL=IssueOrigin.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"IssueOrigin.js","sourceRoot":"./","sources":["issue/IssueOrigin.ts"],"names":[],"mappings":";;AAAA,IAAM,WAAW,GAAG;IAClB,UAAU,EAAE,YAAY;IACxB,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;CACZ,CAAC;AAuBF,kCAAW;AApBpB,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO;QACL,WAAW,CAAC,UAAU;QACtB,WAAW,CAAC,MAAM;QAClB,WAAW,CAAC,QAAQ;KACrB,CAAC,QAAQ,CAAC,KAAoB,CAAC,CAAC;AACnC,CAAC;AAcqB,sCAAa;AAZnC,SAAS,mBAAmB,CAAC,OAAoB,EAAE,OAAoB;IAC/D,IAAA;;;;;;MAML,EANM,iBAAS,EAAE,iBAMjB,CAAC;IAEF,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;AAC1C,CAAC;AAEoC,kDAAmB"}

View file

@ -0,0 +1,8 @@
declare const IssueSeverity: {
readonly ERROR: "error";
readonly WARNING: "warning";
};
declare type IssueSeverity = typeof IssueSeverity[keyof typeof IssueSeverity];
declare function isIssueSeverity(value: unknown): value is IssueSeverity;
declare function compareIssueSeverities(severityA: IssueSeverity, severityB: IssueSeverity): number;
export { IssueSeverity, isIssueSeverity, compareIssueSeverities };

View file

@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var IssueSeverity = {
ERROR: 'error',
WARNING: 'warning'
};
exports.IssueSeverity = IssueSeverity;
function isIssueSeverity(value) {
return [IssueSeverity.ERROR, IssueSeverity.WARNING].includes(value);
}
exports.isIssueSeverity = isIssueSeverity;
function compareIssueSeverities(severityA, severityB) {
var _a = [severityA, severityB].map(function (severity) {
return [IssueSeverity.WARNING /* 0 */, IssueSeverity.ERROR /* 1 */].indexOf(severity);
}), priorityA = _a[0], priorityB = _a[1];
return Math.sign(priorityB - priorityA);
}
exports.compareIssueSeverities = compareIssueSeverities;
//# sourceMappingURL=IssueSeverity.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"IssueSeverity.js","sourceRoot":"./","sources":["issue/IssueSeverity.ts"],"names":[],"mappings":";;AAAA,IAAM,aAAa,GAAG;IACpB,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;CACV,CAAC;AAsBF,sCAAa;AAnBtB,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,QAAQ,CAC1D,KAAsB,CACvB,CAAC;AACJ,CAAC;AAeuB,0CAAe;AAbvC,SAAS,sBAAsB,CAC7B,SAAwB,EACxB,SAAwB;IAElB,IAAA;;MAIL,EAJM,iBAAS,EAAE,iBAIjB,CAAC;IAEF,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;AAC1C,CAAC;AAEwC,wDAAsB"}

View file

@ -0,0 +1,4 @@
import { Issue } from '../Issue';
import { LintReport } from '../../types/eslint';
declare function createIssuesFromEsLintReports(reports: LintReport[]): Issue[];
export { createIssuesFromEsLintReports };

View file

@ -0,0 +1,44 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var Issue_1 = require("../Issue");
var IssueOrigin_1 = require("../IssueOrigin");
var IssueSeverity_1 = require("../IssueSeverity");
function createIssueFromEsLintMessage(message) {
return {
origin: IssueOrigin_1.IssueOrigin.ESLINT,
code: message.ruleId ? String(message.ruleId) : '[unknown]',
severity: message.severity === 1 ? IssueSeverity_1.IssueSeverity.WARNING : IssueSeverity_1.IssueSeverity.ERROR,
message: message.message,
file: message.filePath,
line: message.line,
character: message.column
};
}
function createFileAwareEsLintMessagesFromEsLintResult(result) {
return result.messages.map(function (message) { return (__assign({}, message, { filePath: result.filePath })); });
}
function createFileAwareEsLintMessagesFromEsLintReport(report) {
return report.results.reduce(function (messages, result) { return messages.concat(createFileAwareEsLintMessagesFromEsLintResult(result)); }, []);
}
function createFileAwareEsLintMessagesFromEsLintReports(reports) {
return reports.reduce(function (messages, report) { return messages.concat(createFileAwareEsLintMessagesFromEsLintReport(report)); }, []);
}
function createIssuesFromEsLintMessages(messages) {
return Issue_1.deduplicateAndSortIssues(messages.map(createIssueFromEsLintMessage));
}
function createIssuesFromEsLintReports(reports) {
return createIssuesFromEsLintMessages(createFileAwareEsLintMessagesFromEsLintReports(reports));
}
exports.createIssuesFromEsLintReports = createIssuesFromEsLintReports;
//# sourceMappingURL=EsLintIssueFactory.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"EsLintIssueFactory.js","sourceRoot":"./","sources":["issue/eslint/EsLintIssueFactory.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,kCAA2D;AAC3D,8CAA6C;AAC7C,kDAAiD;AAGjD,SAAS,4BAA4B,CAAC,OAA+B;IACnE,OAAO;QACL,MAAM,EAAE,yBAAW,CAAC,MAAM;QAC1B,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW;QAC3D,QAAQ,EACN,OAAO,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,6BAAa,CAAC,OAAO,CAAC,CAAC,CAAC,6BAAa,CAAC,KAAK;QACtE,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,IAAI,EAAE,OAAO,CAAC,QAAQ;QACtB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,SAAS,EAAE,OAAO,CAAC,MAAM;KAC1B,CAAC;AACJ,CAAC;AAED,SAAS,6CAA6C,CACpD,MAAkB;IAElB,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAA,OAAO,IAAI,OAAA,cACjC,OAAO,IACV,QAAQ,EAAE,MAAM,CAAC,QAAQ,IACzB,EAHoC,CAGpC,CAAC,CAAC;AACN,CAAC;AAED,SAAS,6CAA6C,CACpD,MAAkB;IAElB,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAC1B,UAAC,QAAQ,EAAE,MAAM,IAAK,OACjB,QAAQ,QACR,6CAA6C,CAAC,MAAM,CAAC,GAFpC,CAGrB,EACD,EAAE,CACH,CAAC;AACJ,CAAC;AAED,SAAS,8CAA8C,CACrD,OAAqB;IAErB,OAAO,OAAO,CAAC,MAAM,CACnB,UAAC,QAAQ,EAAE,MAAM,IAAK,OACjB,QAAQ,QACR,6CAA6C,CAAC,MAAM,CAAC,GAFpC,CAGrB,EACD,EAAE,CACH,CAAC;AACJ,CAAC;AAED,SAAS,8BAA8B,CACrC,QAAkC;IAElC,OAAO,gCAAwB,CAAC,QAAQ,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,6BAA6B,CAAC,OAAqB;IAC1D,OAAO,8BAA8B,CACnC,8CAA8C,CAAC,OAAO,CAAC,CACxD,CAAC;AACJ,CAAC;AAEQ,sEAA6B"}

View file

@ -0,0 +1,9 @@
import { LintMessage } from '../../types/eslint';
/**
* We need to define custom interface because of eslint architecture which
* groups lint messages per file
*/
interface FileAwareEsLintMessage extends LintMessage {
filePath?: string;
}
export { FileAwareEsLintMessage };

View file

@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=FileAwareEsLintMessage.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"FileAwareEsLintMessage.js","sourceRoot":"./","sources":["issue/eslint/FileAwareEsLintMessage.ts"],"names":[],"mappings":""}

View file

@ -0,0 +1,2 @@
export * from './FileAwareEsLintMessage';
export * from './EsLintIssueFactory';

View file

@ -0,0 +1,7 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./EsLintIssueFactory"));
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"./","sources":["issue/eslint/index.ts"],"names":[],"mappings":";;;;;AACA,0CAAqC"}

View file

@ -0,0 +1,6 @@
export * from './Issue';
export * from './IssueOrigin';
export * from './IssueSeverity';
export * from './typescript';
export * from './eslint';
export * from './internal';

View file

@ -0,0 +1,12 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./Issue"));
__export(require("./IssueOrigin"));
__export(require("./IssueSeverity"));
__export(require("./typescript"));
__export(require("./eslint"));
__export(require("./internal"));
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"./","sources":["issue/index.ts"],"names":[],"mappings":";;;;;AAAA,6BAAwB;AACxB,mCAA8B;AAC9B,qCAAgC;AAEhC,kCAA6B;AAC7B,8BAAyB;AACzB,gCAA2B"}

View file

@ -0,0 +1,8 @@
import { Issue } from '../Issue';
interface ErrorLike {
message?: string;
stack?: string;
toString?: () => string;
}
declare function createIssueFromInternalError(error: ErrorLike): Issue;
export { createIssueFromInternalError };

View file

@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var IssueOrigin_1 = require("../IssueOrigin");
var IssueSeverity_1 = require("../IssueSeverity");
function createIssueFromInternalError(error) {
return {
origin: IssueOrigin_1.IssueOrigin.INTERNAL,
severity: IssueSeverity_1.IssueSeverity.ERROR,
code: 'INTERNAL',
message: typeof error.message === 'string'
? error.message
: (error.toString && error.toString()) || '',
stack: typeof error.stack === 'string' ? error.stack : undefined
};
}
exports.createIssueFromInternalError = createIssueFromInternalError;
//# sourceMappingURL=InternalIssueFactory.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"InternalIssueFactory.js","sourceRoot":"./","sources":["issue/internal/InternalIssueFactory.ts"],"names":[],"mappings":";;AACA,8CAA6C;AAC7C,kDAAiD;AAQjD,SAAS,4BAA4B,CAAC,KAAgB;IACpD,OAAO;QACL,MAAM,EAAE,yBAAW,CAAC,QAAQ;QAC5B,QAAQ,EAAE,6BAAa,CAAC,KAAK;QAC7B,IAAI,EAAE,UAAU;QAChB,OAAO,EACL,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;YAC/B,CAAC,CAAC,KAAK,CAAC,OAAO;YACf,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE;QAChD,KAAK,EAAE,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;KACjE,CAAC;AACJ,CAAC;AAEQ,oEAA4B"}

View file

@ -0,0 +1 @@
export * from './InternalIssueFactory';

View file

@ -0,0 +1,7 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./InternalIssueFactory"));
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"./","sources":["issue/internal/index.ts"],"names":[],"mappings":";;;;;AAAA,4CAAuC"}

View file

@ -0,0 +1,5 @@
import * as ts from 'typescript';
import { Issue } from '../Issue';
declare function createIssueFromTsDiagnostic(diagnostic: ts.Diagnostic, typescript: typeof ts): Issue;
declare function createIssuesFromTsDiagnostics(diagnostics: ts.Diagnostic[], typescript: typeof ts): Issue[];
export { createIssueFromTsDiagnostic, createIssuesFromTsDiagnostics };

View file

@ -0,0 +1,37 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Issue_1 = require("../Issue");
var IssueOrigin_1 = require("../IssueOrigin");
var IssueSeverity_1 = require("../IssueSeverity");
function createIssueFromTsDiagnostic(diagnostic, typescript) {
var file;
var line;
var character;
if (diagnostic.file) {
file = diagnostic.file.fileName;
if (diagnostic.start) {
var position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
line = position.line + 1;
character = position.character + 1;
}
}
return {
origin: IssueOrigin_1.IssueOrigin.TYPESCRIPT,
code: String(diagnostic.code),
// we don't handle Suggestion and Message diagnostics
severity: diagnostic.category === 0 ? IssueSeverity_1.IssueSeverity.WARNING : IssueSeverity_1.IssueSeverity.ERROR,
message: typescript.flattenDiagnosticMessageText(diagnostic.messageText, '\n'),
file: file,
line: line,
character: character
};
}
exports.createIssueFromTsDiagnostic = createIssueFromTsDiagnostic;
function createIssuesFromTsDiagnostics(diagnostics, typescript) {
function createIssueFromTsDiagnosticWithFormatter(diagnostic) {
return createIssueFromTsDiagnostic(diagnostic, typescript);
}
return Issue_1.deduplicateAndSortIssues(diagnostics.map(createIssueFromTsDiagnosticWithFormatter));
}
exports.createIssuesFromTsDiagnostics = createIssuesFromTsDiagnostics;
//# sourceMappingURL=TypeScriptIssueFactory.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"TypeScriptIssueFactory.js","sourceRoot":"./","sources":["issue/typescript/TypeScriptIssueFactory.ts"],"names":[],"mappings":";;AACA,kCAA2D;AAC3D,8CAA6C;AAC7C,kDAAiD;AAEjD,SAAS,2BAA2B,CAClC,UAAyB,EACzB,UAAqB;IAErB,IAAI,IAAwB,CAAC;IAC7B,IAAI,IAAwB,CAAC;IAC7B,IAAI,SAA6B,CAAC;IAElC,IAAI,UAAU,CAAC,IAAI,EAAE;QACnB,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC;QAEhC,IAAI,UAAU,CAAC,KAAK,EAAE;YACpB,IAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,6BAA6B,CAC5D,UAAU,CAAC,KAAK,CACjB,CAAC;YACF,IAAI,GAAG,QAAQ,CAAC,IAAI,GAAG,CAAC,CAAC;YACzB,SAAS,GAAG,QAAQ,CAAC,SAAS,GAAG,CAAC,CAAC;SACpC;KACF;IAED,OAAO;QACL,MAAM,EAAE,yBAAW,CAAC,UAAU;QAC9B,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC;QAC7B,qDAAqD;QACrD,QAAQ,EACN,UAAU,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,6BAAa,CAAC,OAAO,CAAC,CAAC,CAAC,6BAAa,CAAC,KAAK;QACzE,OAAO,EAAE,UAAU,CAAC,4BAA4B,CAC9C,UAAU,CAAC,WAAW,EACtB,IAAI,CACL;QACD,IAAI,MAAA;QACJ,IAAI,MAAA;QACJ,SAAS,WAAA;KACV,CAAC;AACJ,CAAC;AAcQ,kEAA2B;AAZpC,SAAS,6BAA6B,CACpC,WAA4B,EAC5B,UAAqB;IAErB,SAAS,wCAAwC,CAAC,UAAyB;QACzE,OAAO,2BAA2B,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,gCAAwB,CAC7B,WAAW,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAC1D,CAAC;AACJ,CAAC;AAEqC,sEAA6B"}

View file

@ -0,0 +1 @@
export * from './TypeScriptIssueFactory';

View file

@ -0,0 +1,7 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./TypeScriptIssueFactory"));
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"./","sources":["issue/typescript/index.ts"],"names":[],"mappings":";;;;;AAAA,8CAAyC"}

View file

@ -0,0 +1,21 @@
import * as ts from 'typescript';
export interface TypeScriptPatchConfig {
/**
* Ususally, the compilerHost created with typescript.createWatchCompilerHost will bail out of diagnostics collection if there has been any syntactic error.
* (see [`emitFilesAndReportErrors`](https://github.com/Microsoft/TypeScript/blob/89386ddda7dafc63cb35560e05412487f47cc267/src/compiler/watch.ts#L141) )
* If this plugin is running with `checkSyntacticErrors: false`, this might lead to situations where no syntactic errors are reported within webpack
* (because the file causing a syntactic error might not get processed by ts-loader), but there are semantic errors that would be missed due to this behavior.
* This ensures that the compilerHost always assumes that there were no syntactic errors to be found and continues to check for semantic errors.
*/
skipGetSyntacticDiagnostics: boolean;
}
/**
* While it is often possible to pass a wrapped or modified copy of `typescript` or `typescript.sys` as a function argument to override/extend some typescript-internal behavior,
* sometimes the typescript-internal code ignores these passed objects and directly references the internal `typescript` object reference.
* In these situations, the only way of consistently overriding some behavior is to directly replace methods on the `typescript` object.
*
* So beware, this method directly modifies the passed `typescript` object!
* @param typescript TypeScript instance to patch
* @param config
*/
export declare function patchTypescript(typescript: typeof ts, config: TypeScriptPatchConfig): void;

View file

@ -0,0 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Overrides the [`typescript.createEmitAndSemanticDiagnosticsBuilderProgram`](https://github.com/Microsoft/TypeScript/blob/89386ddda7dafc63cb35560e05412487f47cc267/src/compiler/builder.ts#L1176)
* method to return a `ts.Program` instance that does not emit syntactic errors,
* to prevent the [`typescript.createWatchCompilerHost`](https://github.com/Microsoft/TypeScript/blob/89386ddda7dafc63cb35560e05412487f47cc267/src/compiler/watch.ts#L333)
* method from bailing during diagnostic collection in the [`emitFilesAndReportErrors`](https://github.com/Microsoft/TypeScript/blob/89386ddda7dafc63cb35560e05412487f47cc267/src/compiler/watch.ts#L141) callback.
*
* See the description of TypeScriptPatchConfig.skipGetSyntacticDiagnostics and
* [this github discussion](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/issues/257#issuecomment-485414182)
* for further information on this problem & solution.
*/
function patchSkipGetSyntacticDiagnostics(typescript) {
var originalCreateEmitAndSemanticDiagnosticsBuilderProgram = typescript.createEmitAndSemanticDiagnosticsBuilderProgram;
var patchedMethods = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
createEmitAndSemanticDiagnosticsBuilderProgram: function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var program = originalCreateEmitAndSemanticDiagnosticsBuilderProgram.apply(typescript,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
args);
program.getSyntacticDiagnostics = function () { return []; };
return program;
}
};
// directly patch the typescript object!
Object.assign(typescript, patchedMethods);
}
/**
* While it is often possible to pass a wrapped or modified copy of `typescript` or `typescript.sys` as a function argument to override/extend some typescript-internal behavior,
* sometimes the typescript-internal code ignores these passed objects and directly references the internal `typescript` object reference.
* In these situations, the only way of consistently overriding some behavior is to directly replace methods on the `typescript` object.
*
* So beware, this method directly modifies the passed `typescript` object!
* @param typescript TypeScript instance to patch
* @param config
*/
function patchTypescript(typescript, config) {
if (config.skipGetSyntacticDiagnostics) {
patchSkipGetSyntacticDiagnostics(typescript);
}
}
exports.patchTypescript = patchTypescript;
//# sourceMappingURL=patchTypescript.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"patchTypescript.js","sourceRoot":"./","sources":["patchTypescript.ts"],"names":[],"mappings":";;AAaA;;;;;;;;;GASG;AACH,SAAS,gCAAgC,CAAC,UAAqB;IAE3D,IAAA,kHAAsG,CACzF;IAEf,IAAM,cAAc,GAGhB;QACF,8DAA8D;QAC9D,8CAA8C,EAA9C;YAA+C,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YAC3D,IAAM,OAAO,GAAG,sDAAsD,CAAC,KAAK,CAC1E,UAAU;YACV,8DAA8D;YAC9D,IAAW,CACZ,CAAC;YACF,OAAO,CAAC,uBAAuB,GAAG,cAAM,OAAA,EAAE,EAAF,CAAE,CAAC;YAC3C,OAAO,OAAO,CAAC;QACjB,CAAC;KACF,CAAC;IAEF,wCAAwC;IACxC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAC7B,UAAqB,EACrB,MAA6B;IAE7B,IAAI,MAAM,CAAC,2BAA2B,EAAE;QACtC,gCAAgC,CAAC,UAAU,CAAC,CAAC;KAC9C;AACH,CAAC;AAPD,0CAOC"}

View file

@ -0,0 +1,7 @@
import * as ts from 'typescript';
export declare type ResolveModuleName = (typescript: typeof ts, moduleName: string, containingFile: string, compilerOptions: ts.CompilerOptions, moduleResolutionHost: ts.ModuleResolutionHost) => ts.ResolvedModuleWithFailedLookupLocations;
export declare type ResolveTypeReferenceDirective = (typescript: typeof ts, typeDirectiveName: string, containingFile: string, compilerOptions: ts.CompilerOptions, moduleResolutionHost: ts.ModuleResolutionHost) => ts.ResolvedTypeReferenceDirectiveWithFailedLookupLocations;
export declare function makeResolutionFunctions(resolveModuleName: ResolveModuleName | undefined, resolveTypeReferenceDirective: ResolveTypeReferenceDirective | undefined): {
resolveModuleName: ResolveModuleName;
resolveTypeReferenceDirective: ResolveTypeReferenceDirective;
};

Some files were not shown because too many files have changed in this diff Show more