This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
import webpack from 'webpack';
import { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
declare function interceptDoneToGetWebpackDevServerTap(compiler: webpack.Compiler, configuration: ForkTsCheckerWebpackPluginConfiguration, state: ForkTsCheckerWebpackPluginState): void;
export { interceptDoneToGetWebpackDevServerTap };

View File

@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function interceptDoneToGetWebpackDevServerTap(compiler, configuration, state) {
// inspired by https://github.com/ypresto/fork-ts-checker-async-overlay-webpack-plugin
compiler.hooks.done.intercept({
register: (tap) => {
if (tap.name === 'webpack-dev-server' &&
tap.type === 'sync' &&
configuration.logger.devServer) {
state.webpackDevServerDoneTap = tap;
}
return tap;
},
});
}
exports.interceptDoneToGetWebpackDevServerTap = interceptDoneToGetWebpackDevServerTap;

View File

@@ -0,0 +1,20 @@
import * as webpack from 'webpack';
import { SyncHook, SyncWaterfallHook, AsyncSeriesWaterfallHook } from 'tapable';
import { FilesChange } from '../reporter';
import { Issue } from '../issue';
declare function createForkTsCheckerWebpackPluginHooks(): {
start: AsyncSeriesWaterfallHook<FilesChange, webpack.compilation.Compilation, any>;
waiting: SyncHook<webpack.compilation.Compilation, any, any>;
canceled: SyncHook<webpack.compilation.Compilation, any, any>;
error: SyncHook<Error, webpack.compilation.Compilation, any>;
issues: SyncWaterfallHook<Issue[], webpack.compilation.Compilation | undefined, void>;
};
declare type ForkTsCheckerWebpackPluginHooks = ReturnType<typeof createForkTsCheckerWebpackPluginHooks>;
declare function getForkTsCheckerWebpackPluginHooks(compiler: webpack.Compiler | webpack.MultiCompiler): {
start: AsyncSeriesWaterfallHook<FilesChange, webpack.compilation.Compilation, any>;
waiting: SyncHook<webpack.compilation.Compilation, any, any>;
canceled: SyncHook<webpack.compilation.Compilation, any, any>;
error: SyncHook<Error, webpack.compilation.Compilation, any>;
issues: SyncWaterfallHook<Issue[], webpack.compilation.Compilation | undefined, void>;
};
export { getForkTsCheckerWebpackPluginHooks, ForkTsCheckerWebpackPluginHooks };

View File

@@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tapable_1 = require("tapable");
const compilerHookMap = new WeakMap();
function createForkTsCheckerWebpackPluginHooks() {
return {
start: new tapable_1.AsyncSeriesWaterfallHook([
'change',
'compilation',
]),
waiting: new tapable_1.SyncHook(['compilation']),
canceled: new tapable_1.SyncHook(['compilation']),
error: new tapable_1.SyncHook(['error', 'compilation']),
issues: new tapable_1.SyncWaterfallHook([
'issues',
'compilation',
]),
};
}
function forwardForkTsCheckerWebpackPluginHooks(source, target) {
source.start.tapPromise('ForkTsCheckerWebpackPlugin', target.start.promise);
source.waiting.tap('ForkTsCheckerWebpackPlugin', target.waiting.call);
source.canceled.tap('ForkTsCheckerWebpackPlugin', target.canceled.call);
source.error.tap('ForkTsCheckerWebpackPlugin', target.error.call);
source.issues.tap('ForkTsCheckerWebpackPlugin', target.issues.call);
}
function getForkTsCheckerWebpackPluginHooks(compiler) {
let hooks = compilerHookMap.get(compiler);
if (hooks === undefined) {
hooks = createForkTsCheckerWebpackPluginHooks();
compilerHookMap.set(compiler, hooks);
// proxy hooks for multi-compiler
if ('compilers' in compiler) {
compiler.compilers.forEach((childCompiler) => {
const childHooks = getForkTsCheckerWebpackPluginHooks(childCompiler);
if (hooks) {
forwardForkTsCheckerWebpackPluginHooks(childHooks, hooks);
}
});
}
}
return hooks;
}
exports.getForkTsCheckerWebpackPluginHooks = getForkTsCheckerWebpackPluginHooks;

View File

@@ -0,0 +1,5 @@
import webpack from 'webpack';
import { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
declare function tapAfterCompileToAddDependencies(compiler: webpack.Compiler, configuration: ForkTsCheckerWebpackPluginConfiguration, state: ForkTsCheckerWebpackPluginState): void;
export { tapAfterCompileToAddDependencies };

View File

@@ -0,0 +1,27 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
function tapAfterCompileToAddDependencies(compiler, configuration, state) {
compiler.hooks.afterCompile.tapPromise('ForkTsCheckerWebpackPlugin', (compilation) => __awaiter(this, void 0, void 0, function* () {
if (compilation.compiler !== compiler) {
// run only for the compiler that the plugin was registered for
return;
}
const dependencies = yield state.dependenciesPromise;
if (dependencies) {
state.lastDependencies = dependencies;
dependencies.files.forEach((file) => {
compilation.fileDependencies.add(file);
});
}
}));
}
exports.tapAfterCompileToAddDependencies = tapAfterCompileToAddDependencies;

View File

@@ -0,0 +1,5 @@
import webpack from 'webpack';
import { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
declare function tapAfterCompileToGetIssues(compiler: webpack.Compiler, configuration: ForkTsCheckerWebpackPluginConfiguration, state: ForkTsCheckerWebpackPluginState): void;
export { tapAfterCompileToGetIssues };

View File

@@ -0,0 +1,48 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const pluginHooks_1 = require("./pluginHooks");
const IssueWebpackError_1 = require("../issue/IssueWebpackError");
function tapAfterCompileToGetIssues(compiler, configuration, state) {
const hooks = pluginHooks_1.getForkTsCheckerWebpackPluginHooks(compiler);
compiler.hooks.afterCompile.tapPromise('ForkTsCheckerWebpackPlugin', (compilation) => __awaiter(this, void 0, void 0, function* () {
if (compilation.compiler !== compiler) {
// run only for the compiler that the plugin was registered for
return;
}
let issues = [];
try {
issues = yield state.issuesPromise;
}
catch (error) {
hooks.error.call(error, compilation);
return;
}
if (!issues) {
// some error has been thrown or it was canceled
return;
}
// filter list of issues by provided issue predicate
issues = issues.filter(configuration.issue.predicate);
// modify list of issues in the plugin hooks
issues = hooks.issues.call(issues, compilation);
issues.forEach((issue) => {
const error = new IssueWebpackError_1.IssueWebpackError(configuration.formatter(issue), issue);
if (issue.severity === 'warning') {
compilation.warnings.push(error);
}
else {
compilation.errors.push(error);
}
});
}));
}
exports.tapAfterCompileToGetIssues = tapAfterCompileToGetIssues;

View File

@@ -0,0 +1,4 @@
import webpack from 'webpack';
import { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
declare function tapAfterEnvironmentToPatchWatching(compiler: webpack.Compiler, state: ForkTsCheckerWebpackPluginState): void;
export { tapAfterEnvironmentToPatchWatching };

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const InclusiveNodeWatchFileSystem_1 = require("../watch/InclusiveNodeWatchFileSystem");
function tapAfterEnvironmentToPatchWatching(compiler, state) {
compiler.hooks.afterEnvironment.tap('ForkTsCheckerWebpackPlugin', () => {
const watchFileSystem = compiler.watchFileSystem;
if (watchFileSystem) {
// wrap original watch file system
compiler.watchFileSystem = new InclusiveNodeWatchFileSystem_1.InclusiveNodeWatchFileSystem(watchFileSystem, compiler, state);
}
});
}
exports.tapAfterEnvironmentToPatchWatching = tapAfterEnvironmentToPatchWatching;

View File

@@ -0,0 +1,5 @@
import webpack from 'webpack';
import { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
declare function tapDoneToAsyncGetIssues(compiler: webpack.Compiler, configuration: ForkTsCheckerWebpackPluginConfiguration, state: ForkTsCheckerWebpackPluginState): void;
export { tapDoneToAsyncGetIssues };

View File

@@ -0,0 +1,85 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = __importDefault(require("chalk"));
const pluginHooks_1 = require("./pluginHooks");
const WebpackFormatter_1 = require("../formatter/WebpackFormatter");
const IssueWebpackError_1 = require("../issue/IssueWebpackError");
const isPending_1 = __importDefault(require("../utils/async/isPending"));
const wait_1 = __importDefault(require("../utils/async/wait"));
function tapDoneToAsyncGetIssues(compiler, configuration, state) {
const hooks = pluginHooks_1.getForkTsCheckerWebpackPluginHooks(compiler);
compiler.hooks.done.tap('ForkTsCheckerWebpackPlugin', (stats) => __awaiter(this, void 0, void 0, function* () {
if (stats.compilation.compiler !== compiler) {
// run only for the compiler that the plugin was registered for
return;
}
const reportPromise = state.issuesReportPromise;
const issuesPromise = state.issuesPromise;
let issues;
try {
if (yield isPending_1.default(issuesPromise)) {
hooks.waiting.call(stats.compilation);
configuration.logger.issues.log(chalk_1.default.cyan('Issues checking in progress...'));
}
else {
// wait 10ms to log issues after webpack stats
yield wait_1.default(10);
}
issues = yield issuesPromise;
}
catch (error) {
hooks.error.call(error, stats.compilation);
return;
}
if (!issues) {
// some error has been thrown or it was canceled
return;
}
if (reportPromise !== state.issuesReportPromise) {
// there is a newer report - ignore this one
return;
}
// filter list of issues by provided issue predicate
issues = issues.filter(configuration.issue.predicate);
// modify list of issues in the plugin hooks
issues = hooks.issues.call(issues, stats.compilation);
const formatter = WebpackFormatter_1.createWebpackFormatter(configuration.formatter);
if (issues.length) {
// follow webpack's approach - one process.write to stderr with all errors and warnings
configuration.logger.issues.error(issues.map((issue) => formatter(issue)).join('\n'));
}
else {
configuration.logger.issues.log(chalk_1.default.green('No issues found.'));
}
// report issues to webpack-dev-server, if it's listening
// skip reporting if there are no issues, to avoid an extra hot reload
if (issues.length && state.webpackDevServerDoneTap) {
issues.forEach((issue) => {
const error = new IssueWebpackError_1.IssueWebpackError(configuration.formatter(issue), issue);
if (issue.severity === 'warning') {
stats.compilation.warnings.push(error);
}
else {
stats.compilation.errors.push(error);
}
});
state.webpackDevServerDoneTap.fn(stats);
}
if (stats.startTime) {
configuration.logger.infrastructure.info(`Time: ${Math.round(Date.now() - stats.startTime).toString()} ms`);
}
}));
}
exports.tapDoneToAsyncGetIssues = tapDoneToAsyncGetIssues;

View File

@@ -0,0 +1,4 @@
import webpack from 'webpack';
import { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
declare function tapErrorToLogMessage(compiler: webpack.Compiler, configuration: ForkTsCheckerWebpackPluginConfiguration): void;
export { tapErrorToLogMessage };

View File

@@ -0,0 +1,27 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const pluginHooks_1 = require("./pluginHooks");
const RpcIpcMessagePortClosedError_1 = require("../rpc/rpc-ipc/error/RpcIpcMessagePortClosedError");
const chalk_1 = __importDefault(require("chalk"));
function tapErrorToLogMessage(compiler, configuration) {
const hooks = pluginHooks_1.getForkTsCheckerWebpackPluginHooks(compiler);
hooks.error.tap('ForkTsCheckerWebpackPlugin', (error) => {
configuration.logger.issues.error(String(error));
if (error instanceof RpcIpcMessagePortClosedError_1.RpcIpcMessagePortClosedError) {
if (error.signal === 'SIGINT') {
configuration.logger.issues.error(chalk_1.default.red('Issues checking service 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 {
configuration.logger.issues.error(chalk_1.default.red('Issues checking service aborted - probably out of memory. ' +
'Check the `memoryLimit` option in the ForkTsCheckerWebpackPlugin configuration.\n' +
"If increasing the memory doesn't solve the issue, it's most probably a bug in the TypeScript or EsLint."));
}
}
});
}
exports.tapErrorToLogMessage = tapErrorToLogMessage;

View File

@@ -0,0 +1,6 @@
import webpack from 'webpack';
import { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
import { ReporterRpcClient } from '../reporter';
declare function tapStartToConnectAndRunReporter(compiler: webpack.Compiler, issuesReporter: ReporterRpcClient, dependenciesReporter: ReporterRpcClient, configuration: ForkTsCheckerWebpackPluginConfiguration, state: ForkTsCheckerWebpackPluginState): void;
export { tapStartToConnectAndRunReporter };

View File

@@ -0,0 +1,125 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const pluginHooks_1 = require("./pluginHooks");
const reporter_1 = require("../reporter");
const OperationCanceledError_1 = require("../error/OperationCanceledError");
const tapDoneToAsyncGetIssues_1 = require("./tapDoneToAsyncGetIssues");
const tapAfterCompileToGetIssues_1 = require("./tapAfterCompileToGetIssues");
const interceptDoneToGetWebpackDevServerTap_1 = require("./interceptDoneToGetWebpackDevServerTap");
const ForkTsCheckerWebpackPlugin_1 = require("../ForkTsCheckerWebpackPlugin");
function tapStartToConnectAndRunReporter(compiler, issuesReporter, dependenciesReporter, configuration, state) {
const hooks = pluginHooks_1.getForkTsCheckerWebpackPluginHooks(compiler);
compiler.hooks.run.tap('ForkTsCheckerWebpackPlugin', () => {
if (!state.initialized) {
state.initialized = true;
state.watching = false;
tapAfterCompileToGetIssues_1.tapAfterCompileToGetIssues(compiler, configuration, state);
}
});
compiler.hooks.watchRun.tap('ForkTsCheckerWebpackPlugin', () => __awaiter(this, void 0, void 0, function* () {
if (!state.initialized) {
state.initialized = true;
state.watching = true;
if (configuration.async) {
tapDoneToAsyncGetIssues_1.tapDoneToAsyncGetIssues(compiler, configuration, state);
interceptDoneToGetWebpackDevServerTap_1.interceptDoneToGetWebpackDevServerTap(compiler, configuration, state);
}
else {
tapAfterCompileToGetIssues_1.tapAfterCompileToGetIssues(compiler, configuration, state);
}
}
}));
compiler.hooks.compilation.tap('ForkTsCheckerWebpackPlugin', (compilation) => __awaiter(this, void 0, void 0, function* () {
if (compilation.compiler !== compiler) {
// run only for the compiler that the plugin was registered for
return;
}
let change = {};
if (state.watching) {
change = reporter_1.getFilesChange(compiler);
configuration.logger.infrastructure.info([
'Calling reporter service for incremental check.',
` Changed files: ${JSON.stringify(change.changedFiles)}`,
` Deleted files: ${JSON.stringify(change.deletedFiles)}`,
].join('\n'));
}
else {
configuration.logger.infrastructure.info('Calling reporter service for single check.');
}
let resolveDependencies;
let rejectDependencies;
let resolveIssues;
let rejectIssues;
state.dependenciesPromise = new Promise((resolve, reject) => {
resolveDependencies = resolve;
rejectDependencies = reject;
});
state.issuesPromise = new Promise((resolve, reject) => {
resolveIssues = resolve;
rejectIssues = reject;
});
const previousIssuesReportPromise = state.issuesReportPromise;
const previousDependenciesReportPromise = state.dependenciesReportPromise;
change = yield hooks.start.promise(change, compilation);
state.issuesReportPromise = ForkTsCheckerWebpackPlugin_1.ForkTsCheckerWebpackPlugin.issuesPool.submit((done) => new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
try {
yield issuesReporter.connect();
const previousReport = yield previousIssuesReportPromise;
if (previousReport) {
yield previousReport.close();
}
const report = yield issuesReporter.getReport(change);
resolve(report);
report.getIssues().then(resolveIssues).catch(rejectIssues).finally(done);
}
catch (error) {
if (error instanceof OperationCanceledError_1.OperationCanceledError) {
hooks.canceled.call(compilation);
}
else {
hooks.error.call(error, compilation);
}
resolve(undefined);
resolveIssues(undefined);
done();
}
})));
state.dependenciesReportPromise = ForkTsCheckerWebpackPlugin_1.ForkTsCheckerWebpackPlugin.dependenciesPool.submit((done) => new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
try {
yield dependenciesReporter.connect();
const previousReport = yield previousDependenciesReportPromise;
if (previousReport) {
yield previousReport.close();
}
const report = yield dependenciesReporter.getReport(change);
resolve(report);
report
.getDependencies()
.then(resolveDependencies)
.catch(rejectDependencies)
.finally(done);
}
catch (error) {
if (error instanceof OperationCanceledError_1.OperationCanceledError) {
hooks.canceled.call(compilation);
}
else {
hooks.error.call(error, compilation);
}
resolve(undefined);
resolveDependencies(undefined);
done();
}
})));
}));
}
exports.tapStartToConnectAndRunReporter = tapStartToConnectAndRunReporter;

View File

@@ -0,0 +1,5 @@
import webpack from 'webpack';
import { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
import { ReporterRpcClient } from '../reporter';
declare function tapStopToDisconnectReporter(compiler: webpack.Compiler, issuesReporter: ReporterRpcClient, dependenciesReporter: ReporterRpcClient, state: ForkTsCheckerWebpackPluginState): void;
export { tapStopToDisconnectReporter };

View File

@@ -0,0 +1,29 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
function tapStopToDisconnectReporter(compiler, issuesReporter, dependenciesReporter, state) {
compiler.hooks.watchClose.tap('ForkTsCheckerWebpackPlugin', () => {
issuesReporter.disconnect();
dependenciesReporter.disconnect();
});
compiler.hooks.done.tap('ForkTsCheckerWebpackPlugin', () => __awaiter(this, void 0, void 0, function* () {
if (!state.watching) {
yield Promise.all([issuesReporter.disconnect(), dependenciesReporter.disconnect()]);
}
}));
compiler.hooks.failed.tap('ForkTsCheckerWebpackPlugin', () => {
if (!state.watching) {
issuesReporter.disconnect();
dependenciesReporter.disconnect();
}
});
}
exports.tapStopToDisconnectReporter = tapStopToDisconnectReporter;