fork-ts-checker-webpack-plugin 7.0.0-alpha.10 → 7.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ForkTsCheckerWebpackPlugin.d.ts +1 -1
- package/lib/ForkTsCheckerWebpackPlugin.js +29 -9
- package/lib/ForkTsCheckerWebpackPluginConfiguration.d.ts +1 -1
- package/lib/ForkTsCheckerWebpackPluginConfiguration.js +1 -1
- package/lib/ForkTsCheckerWebpackPluginOptions.d.ts +1 -1
- package/lib/ForkTsCheckerWebpackPluginState.d.ts +2 -3
- package/lib/ForkTsCheckerWebpackPluginState.js +1 -2
- package/lib/{reporter/FilesChange.d.ts → files-change.d.ts} +4 -4
- package/lib/{reporter/FilesChange.js → files-change.js} +2 -2
- package/lib/{reporter/FilesMatch.d.ts → files-match.d.ts} +0 -0
- package/lib/{reporter/FilesMatch.js → files-match.js} +0 -0
- package/lib/hooks/interceptDoneToGetWebpackDevServerTap.js +3 -0
- package/lib/hooks/pluginHooks.d.ts +1 -1
- package/lib/hooks/tapAfterCompileToAddDependencies.js +3 -0
- package/lib/hooks/tapAfterCompileToGetIssues.js +3 -0
- package/lib/hooks/tapAfterEnvironmentToPatchWatching.js +6 -0
- package/lib/hooks/tapDoneToAsyncGetIssues.js +5 -6
- package/lib/hooks/tapErrorToLogMessage.js +2 -2
- package/lib/hooks/tapStartToRunWorkers.d.ts +8 -0
- package/lib/hooks/tapStartToRunWorkers.js +95 -0
- package/lib/hooks/tapStopToTerminateWorkers.d.ts +5 -0
- package/lib/hooks/tapStopToTerminateWorkers.js +26 -0
- package/lib/infrastructure-logger.d.ts +10 -0
- package/lib/infrastructure-logger.js +15 -0
- package/lib/{typescript-reporter → typescript}/TypeScriptConfigurationOverwrite.d.ts +0 -0
- package/lib/{typescript-reporter → typescript}/TypeScriptConfigurationOverwrite.js +0 -0
- package/lib/{typescript-reporter → typescript}/TypeScriptDiagnosticsOptions.d.ts +0 -0
- package/lib/{typescript-reporter → typescript}/TypeScriptDiagnosticsOptions.js +0 -0
- package/lib/{typescript-reporter → typescript}/TypeScriptReporterConfiguration.d.ts +0 -0
- package/lib/{typescript-reporter → typescript}/TypeScriptReporterConfiguration.js +0 -0
- package/lib/{typescript-reporter → typescript}/TypeScriptReporterOptions.d.ts +0 -0
- package/lib/{typescript-reporter → typescript}/TypeScriptReporterOptions.js +0 -0
- package/lib/{typescript-reporter → typescript}/TypeScriptSupport.d.ts +0 -0
- package/lib/{typescript-reporter → typescript}/TypeScriptSupport.js +0 -0
- package/lib/{typescript-reporter → typescript}/extension/TypeScriptEmbeddedExtension.d.ts +0 -0
- package/lib/{typescript-reporter → typescript}/extension/TypeScriptEmbeddedExtension.js +0 -0
- package/lib/{typescript-reporter → typescript}/extension/TypeScriptExtension.d.ts +1 -1
- package/lib/{typescript-reporter → typescript}/extension/TypeScriptExtension.js +0 -0
- package/lib/{typescript-reporter → typescript}/extension/vue/TypeScriptVueExtension.d.ts +0 -0
- package/lib/{typescript-reporter → typescript}/extension/vue/TypeScriptVueExtension.js +0 -0
- package/lib/{typescript-reporter → typescript}/extension/vue/TypeScriptVueExtensionConfiguration.d.ts +0 -0
- package/lib/{typescript-reporter → typescript}/extension/vue/TypeScriptVueExtensionConfiguration.js +0 -0
- package/lib/{typescript-reporter → typescript}/extension/vue/TypeScriptVueExtensionOptions.d.ts +0 -0
- package/lib/{typescript-reporter → typescript}/extension/vue/TypeScriptVueExtensionOptions.js +0 -0
- package/lib/{typescript-reporter → typescript}/extension/vue/TypeScriptVueExtensionSupport.d.ts +0 -0
- package/lib/{typescript-reporter → typescript}/extension/vue/TypeScriptVueExtensionSupport.js +0 -0
- package/lib/{typescript-reporter → typescript}/extension/vue/types/vue-template-compiler.d.ts +0 -0
- package/lib/{typescript-reporter → typescript}/extension/vue/types/vue-template-compiler.js +0 -0
- package/lib/{typescript-reporter → typescript}/extension/vue/types/vue__compiler-sfc.d.ts +0 -0
- package/lib/{typescript-reporter → typescript}/extension/vue/types/vue__compiler-sfc.js +0 -0
- package/lib/typescript/worker/get-dependencies-worker.d.ts +5 -0
- package/lib/typescript/worker/get-dependencies-worker.js +18 -0
- package/lib/typescript/worker/get-issues-worker.d.ts +5 -0
- package/lib/typescript/worker/get-issues-worker.js +76 -0
- package/lib/typescript/worker/lib/artifacts.d.ts +4 -0
- package/lib/typescript/worker/lib/artifacts.js +90 -0
- package/lib/typescript/worker/lib/config.d.ts +14 -0
- package/lib/typescript/worker/lib/config.js +114 -0
- package/lib/typescript/worker/lib/dependencies.d.ts +3 -0
- package/lib/typescript/worker/lib/dependencies.js +87 -0
- package/lib/typescript/worker/lib/diagnostics.d.ts +7 -0
- package/lib/typescript/worker/lib/diagnostics.js +100 -0
- package/lib/typescript/worker/lib/extensions.d.ts +3 -0
- package/lib/typescript/worker/lib/extensions.js +11 -0
- package/lib/{typescript-reporter/file-system/FileSystem.d.ts → typescript/worker/lib/file-system/file-system.d.ts} +1 -2
- package/lib/{reporter/Report.js → typescript/worker/lib/file-system/file-system.js} +0 -0
- package/lib/typescript/worker/lib/file-system/mem-file-system.d.ts +5 -0
- package/lib/typescript/worker/lib/file-system/mem-file-system.js +78 -0
- package/lib/typescript/worker/lib/file-system/passive-file-system.d.ts +5 -0
- package/lib/typescript/worker/lib/file-system/passive-file-system.js +65 -0
- package/lib/typescript/worker/lib/file-system/real-file-system.d.ts +5 -0
- package/lib/typescript/worker/lib/file-system/real-file-system.js +187 -0
- package/lib/typescript/worker/lib/host/compiler-host.d.ts +2 -0
- package/lib/typescript/worker/lib/host/compiler-host.js +17 -0
- package/lib/typescript/worker/lib/host/watch-compiler-host.d.ts +2 -0
- package/lib/typescript/worker/lib/host/watch-compiler-host.js +32 -0
- package/lib/typescript/worker/lib/host/watch-solution-builder-host.d.ts +2 -0
- package/lib/typescript/worker/lib/host/watch-solution-builder-host.js +54 -0
- package/lib/typescript/worker/lib/performance.d.ts +3 -0
- package/lib/typescript/worker/lib/performance.js +32 -0
- package/lib/typescript/worker/lib/program/program.d.ts +2 -0
- package/lib/typescript/worker/lib/program/program.js +32 -0
- package/lib/typescript/worker/lib/program/solution-builder.d.ts +2 -0
- package/lib/typescript/worker/lib/program/solution-builder.js +39 -0
- package/lib/typescript/worker/lib/program/watch-program.d.ts +3 -0
- package/lib/typescript/worker/lib/program/watch-program.js +49 -0
- package/lib/{typescript-reporter/reporter/ControlledTypeScriptSystem.d.ts → typescript/worker/lib/system.d.ts} +4 -6
- package/lib/typescript/worker/lib/system.js +209 -0
- package/lib/typescript/worker/lib/tracing.d.ts +4 -0
- package/lib/typescript/worker/lib/tracing.js +28 -0
- package/lib/typescript/worker/lib/tsbuildinfo.d.ts +4 -0
- package/lib/typescript/worker/lib/tsbuildinfo.js +92 -0
- package/lib/typescript/worker/lib/typescript.d.ts +2 -0
- package/lib/typescript/worker/lib/typescript.js +6 -0
- package/lib/typescript/worker/lib/worker-config.d.ts +2 -0
- package/lib/typescript/worker/lib/worker-config.js +5 -0
- package/lib/utils/async/pool.d.ts +1 -1
- package/lib/utils/async/pool.js +3 -14
- package/lib/{rpc/rpc-ipc/error/RpcIpcMessagePortClosedError.d.ts → utils/rpc/error.d.ts} +2 -3
- package/lib/utils/rpc/error.js +12 -0
- package/lib/utils/rpc/expose.d.ts +1 -0
- package/lib/utils/rpc/expose.js +78 -0
- package/lib/utils/rpc/index.d.ts +5 -0
- package/lib/utils/rpc/index.js +12 -0
- package/lib/utils/rpc/types.d.ts +19 -0
- package/lib/{reporter/Reporter.js → utils/rpc/types.js} +0 -0
- package/lib/utils/rpc/worker.d.ts +13 -0
- package/lib/utils/rpc/worker.js +79 -0
- package/lib/utils/rpc/wrap.d.ts +4 -0
- package/lib/utils/rpc/wrap.js +96 -0
- package/lib/watch/InclusiveNodeWatchFileSystem.js +7 -7
- package/package.json +1 -1
- package/lib/error/OperationCanceledError.d.ts +0 -4
- package/lib/error/OperationCanceledError.js +0 -10
- package/lib/hooks/tapStartToConnectAndRunReporter.d.ts +0 -6
- package/lib/hooks/tapStartToConnectAndRunReporter.js +0 -130
- package/lib/hooks/tapStopToDisconnectReporter.d.ts +0 -5
- package/lib/hooks/tapStopToDisconnectReporter.js +0 -30
- package/lib/profile/Performance.d.ts +0 -11
- package/lib/profile/Performance.js +0 -63
- package/lib/reporter/AggregatedReporter.d.ts +0 -6
- package/lib/reporter/AggregatedReporter.js +0 -61
- package/lib/reporter/Report.d.ts +0 -8
- package/lib/reporter/Reporter.d.ts +0 -6
- package/lib/reporter/index.d.ts +0 -7
- package/lib/reporter/index.js +0 -19
- package/lib/reporter/reporter-rpc/ReporterRpcClient.d.ts +0 -10
- package/lib/reporter/reporter-rpc/ReporterRpcClient.js +0 -85
- package/lib/reporter/reporter-rpc/ReporterRpcProcedure.d.ts +0 -13
- package/lib/reporter/reporter-rpc/ReporterRpcProcedure.js +0 -15
- package/lib/reporter/reporter-rpc/ReporterRpcService.d.ts +0 -9
- package/lib/reporter/reporter-rpc/ReporterRpcService.js +0 -77
- package/lib/rpc/RpcClient.d.ts +0 -10
- package/lib/rpc/RpcClient.js +0 -79
- package/lib/rpc/RpcHost.d.ts +0 -6
- package/lib/rpc/RpcHost.js +0 -2
- package/lib/rpc/RpcMessage.d.ts +0 -26
- package/lib/rpc/RpcMessage.js +0 -48
- package/lib/rpc/RpcMessageChannel.d.ts +0 -10
- package/lib/rpc/RpcMessageChannel.js +0 -50
- package/lib/rpc/RpcMessagePort.d.ts +0 -14
- package/lib/rpc/RpcMessagePort.js +0 -2
- package/lib/rpc/RpcProcedure.d.ts +0 -5
- package/lib/rpc/RpcProcedure.js +0 -2
- package/lib/rpc/RpcService.d.ts +0 -12
- package/lib/rpc/RpcService.js +0 -64
- package/lib/rpc/error/RpcMessagePortClosedError.d.ts +0 -3
- package/lib/rpc/error/RpcMessagePortClosedError.js +0 -6
- package/lib/rpc/error/RpcRemoteError.d.ts +0 -6
- package/lib/rpc/error/RpcRemoteError.js +0 -18
- package/lib/rpc/index.d.ts +0 -7
- package/lib/rpc/index.js +0 -19
- package/lib/rpc/rpc-ipc/ProcessLike.d.ts +0 -12
- package/lib/rpc/rpc-ipc/ProcessLike.js +0 -3
- package/lib/rpc/rpc-ipc/RpcIpcMessageChannel.d.ts +0 -3
- package/lib/rpc/rpc-ipc/RpcIpcMessageChannel.js +0 -11
- package/lib/rpc/rpc-ipc/RpcIpcMessagePort.d.ts +0 -5
- package/lib/rpc/rpc-ipc/RpcIpcMessagePort.js +0 -151
- package/lib/rpc/rpc-ipc/error/RpcIpcMessagePortClosedError.js +0 -13
- package/lib/rpc/rpc-ipc/index.d.ts +0 -2
- package/lib/rpc/rpc-ipc/index.js +0 -14
- package/lib/typescript-reporter/file-system/FileSystem.js +0 -2
- package/lib/typescript-reporter/file-system/MemFileSystem.d.ts +0 -8
- package/lib/typescript-reporter/file-system/MemFileSystem.js +0 -83
- package/lib/typescript-reporter/file-system/PassiveFileSystem.d.ts +0 -9
- package/lib/typescript-reporter/file-system/PassiveFileSystem.js +0 -69
- package/lib/typescript-reporter/file-system/RealFileSystem.d.ts +0 -8
- package/lib/typescript-reporter/file-system/RealFileSystem.js +0 -181
- package/lib/typescript-reporter/issue/TypeScriptIssueFactory.d.ts +0 -4
- package/lib/typescript-reporter/issue/TypeScriptIssueFactory.js +0 -57
- package/lib/typescript-reporter/profile/TypeScriptPerformance.d.ts +0 -10
- package/lib/typescript-reporter/profile/TypeScriptPerformance.js +0 -34
- package/lib/typescript-reporter/reporter/ControlledCompilerHost.d.ts +0 -5
- package/lib/typescript-reporter/reporter/ControlledCompilerHost.js +0 -14
- package/lib/typescript-reporter/reporter/ControlledTypeScriptSystem.js +0 -218
- package/lib/typescript-reporter/reporter/ControlledWatchCompilerHost.d.ts +0 -5
- package/lib/typescript-reporter/reporter/ControlledWatchCompilerHost.js +0 -29
- package/lib/typescript-reporter/reporter/ControlledWatchSolutionBuilderHost.d.ts +0 -5
- package/lib/typescript-reporter/reporter/ControlledWatchSolutionBuilderHost.js +0 -51
- package/lib/typescript-reporter/reporter/TypeScriptConfigurationParser.d.ts +0 -8
- package/lib/typescript-reporter/reporter/TypeScriptConfigurationParser.js +0 -142
- package/lib/typescript-reporter/reporter/TypeScriptReporter.d.ts +0 -4
- package/lib/typescript-reporter/reporter/TypeScriptReporter.js +0 -376
- package/lib/typescript-reporter/reporter/TypeScriptReporterRpcClient.d.ts +0 -4
- package/lib/typescript-reporter/reporter/TypeScriptReporterRpcClient.js +0 -14
- package/lib/typescript-reporter/reporter/TypeScriptReporterRpcService.d.ts +0 -1
- package/lib/typescript-reporter/reporter/TypeScriptReporterRpcService.js +0 -11
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.system = void 0;
|
|
16
|
+
const path_1 = require("path");
|
|
17
|
+
const forwardSlash_1 = __importDefault(require("../../../utils/path/forwardSlash"));
|
|
18
|
+
const mem_file_system_1 = require("./file-system/mem-file-system");
|
|
19
|
+
const passive_file_system_1 = require("./file-system/passive-file-system");
|
|
20
|
+
const real_file_system_1 = require("./file-system/real-file-system");
|
|
21
|
+
const typescript_1 = require("./typescript");
|
|
22
|
+
const worker_config_1 = require("./worker-config");
|
|
23
|
+
const mode = worker_config_1.config.mode;
|
|
24
|
+
let artifacts = {
|
|
25
|
+
files: [],
|
|
26
|
+
dirs: [],
|
|
27
|
+
excluded: [],
|
|
28
|
+
extensions: [],
|
|
29
|
+
};
|
|
30
|
+
let isInitialRun = true;
|
|
31
|
+
// watchers
|
|
32
|
+
const fileWatcherCallbacksMap = new Map();
|
|
33
|
+
const directoryWatcherCallbacksMap = new Map();
|
|
34
|
+
const recursiveDirectoryWatcherCallbacksMap = new Map();
|
|
35
|
+
const deletedFiles = new Map();
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
const timeoutCallbacks = new Set();
|
|
38
|
+
// based on the ts.ignorePaths
|
|
39
|
+
const ignoredPaths = ['/node_modules/.', '/.git', '/.#'];
|
|
40
|
+
exports.system = Object.assign(Object.assign({}, typescript_1.typescript.sys), { useCaseSensitiveFileNames: true, fileExists(path) {
|
|
41
|
+
const stats = getReadFileSystem(path).readStats(path);
|
|
42
|
+
return !!stats && stats.isFile();
|
|
43
|
+
},
|
|
44
|
+
readFile(path, encoding) {
|
|
45
|
+
return getReadFileSystem(path).readFile(path, encoding);
|
|
46
|
+
},
|
|
47
|
+
getFileSize(path) {
|
|
48
|
+
const stats = getReadFileSystem(path).readStats(path);
|
|
49
|
+
return stats ? stats.size : 0;
|
|
50
|
+
},
|
|
51
|
+
writeFile(path, data) {
|
|
52
|
+
getWriteFileSystem(path).writeFile(path, data);
|
|
53
|
+
exports.system.invokeFileChanged(path);
|
|
54
|
+
},
|
|
55
|
+
deleteFile(path) {
|
|
56
|
+
getWriteFileSystem(path).deleteFile(path);
|
|
57
|
+
exports.system.invokeFileDeleted(path);
|
|
58
|
+
},
|
|
59
|
+
directoryExists(path) {
|
|
60
|
+
var _a;
|
|
61
|
+
return Boolean((_a = getReadFileSystem(path).readStats(path)) === null || _a === void 0 ? void 0 : _a.isDirectory());
|
|
62
|
+
},
|
|
63
|
+
createDirectory(path) {
|
|
64
|
+
getWriteFileSystem(path).createDir(path);
|
|
65
|
+
invokeDirectoryWatchers(path);
|
|
66
|
+
},
|
|
67
|
+
getDirectories(path) {
|
|
68
|
+
const dirents = getReadFileSystem(path).readDir(path);
|
|
69
|
+
return dirents
|
|
70
|
+
.filter((dirent) => dirent.isDirectory() ||
|
|
71
|
+
(dirent.isSymbolicLink() && exports.system.directoryExists(path_1.join(path, dirent.name))))
|
|
72
|
+
.map((dirent) => dirent.name);
|
|
73
|
+
},
|
|
74
|
+
getModifiedTime(path) {
|
|
75
|
+
const stats = getReadFileSystem(path).readStats(path);
|
|
76
|
+
if (stats) {
|
|
77
|
+
return stats.mtime;
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
setModifiedTime(path, date) {
|
|
81
|
+
getWriteFileSystem(path).updateTimes(path, date, date);
|
|
82
|
+
invokeDirectoryWatchers(path);
|
|
83
|
+
invokeFileWatchers(path, typescript_1.typescript.FileWatcherEventKind.Changed);
|
|
84
|
+
},
|
|
85
|
+
watchFile(path, callback) {
|
|
86
|
+
return createWatcher(fileWatcherCallbacksMap, path, callback);
|
|
87
|
+
},
|
|
88
|
+
watchDirectory(path, callback, recursive = false) {
|
|
89
|
+
return createWatcher(recursive ? recursiveDirectoryWatcherCallbacksMap : directoryWatcherCallbacksMap, path, callback);
|
|
90
|
+
},
|
|
91
|
+
// use immediate instead of timeout to avoid waiting 250ms for batching files changes
|
|
92
|
+
setTimeout: (callback, timeout, ...args) => {
|
|
93
|
+
const timeoutId = setImmediate(() => {
|
|
94
|
+
callback(...args);
|
|
95
|
+
timeoutCallbacks.delete(timeoutId);
|
|
96
|
+
});
|
|
97
|
+
timeoutCallbacks.add(timeoutId);
|
|
98
|
+
return timeoutId;
|
|
99
|
+
}, clearTimeout: (timeoutId) => {
|
|
100
|
+
clearImmediate(timeoutId);
|
|
101
|
+
timeoutCallbacks.delete(timeoutId);
|
|
102
|
+
}, waitForQueued() {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
while (timeoutCallbacks.size > 0) {
|
|
105
|
+
yield new Promise((resolve) => setImmediate(resolve));
|
|
106
|
+
}
|
|
107
|
+
isInitialRun = false;
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
invokeFileCreated(path) {
|
|
111
|
+
const normalizedPath = real_file_system_1.realFileSystem.normalizePath(path);
|
|
112
|
+
invokeFileWatchers(path, typescript_1.typescript.FileWatcherEventKind.Created);
|
|
113
|
+
invokeDirectoryWatchers(normalizedPath);
|
|
114
|
+
deletedFiles.set(normalizedPath, false);
|
|
115
|
+
},
|
|
116
|
+
invokeFileChanged(path) {
|
|
117
|
+
const normalizedPath = real_file_system_1.realFileSystem.normalizePath(path);
|
|
118
|
+
if (deletedFiles.get(normalizedPath) || !fileWatcherCallbacksMap.has(normalizedPath)) {
|
|
119
|
+
invokeFileWatchers(path, typescript_1.typescript.FileWatcherEventKind.Created);
|
|
120
|
+
invokeDirectoryWatchers(normalizedPath);
|
|
121
|
+
deletedFiles.set(normalizedPath, false);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
invokeFileWatchers(path, typescript_1.typescript.FileWatcherEventKind.Changed);
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
invokeFileDeleted(path) {
|
|
128
|
+
const normalizedPath = real_file_system_1.realFileSystem.normalizePath(path);
|
|
129
|
+
if (!deletedFiles.get(normalizedPath)) {
|
|
130
|
+
invokeFileWatchers(path, typescript_1.typescript.FileWatcherEventKind.Deleted);
|
|
131
|
+
invokeDirectoryWatchers(path);
|
|
132
|
+
deletedFiles.set(normalizedPath, true);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
invalidateCache() {
|
|
136
|
+
real_file_system_1.realFileSystem.clearCache();
|
|
137
|
+
mem_file_system_1.memFileSystem.clearCache();
|
|
138
|
+
passive_file_system_1.passiveFileSystem.clearCache();
|
|
139
|
+
},
|
|
140
|
+
setArtifacts(nextArtifacts) {
|
|
141
|
+
artifacts = nextArtifacts;
|
|
142
|
+
} });
|
|
143
|
+
function createWatcher(watchersMap, path, callback) {
|
|
144
|
+
const normalizedPath = real_file_system_1.realFileSystem.normalizePath(path);
|
|
145
|
+
const watchers = watchersMap.get(normalizedPath) || [];
|
|
146
|
+
const nextWatchers = [...watchers, callback];
|
|
147
|
+
watchersMap.set(normalizedPath, nextWatchers);
|
|
148
|
+
return {
|
|
149
|
+
close: () => {
|
|
150
|
+
const watchers = watchersMap.get(normalizedPath) || [];
|
|
151
|
+
const nextWatchers = watchers.filter((watcher) => watcher !== callback);
|
|
152
|
+
if (nextWatchers.length > 0) {
|
|
153
|
+
watchersMap.set(normalizedPath, nextWatchers);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
watchersMap.delete(normalizedPath);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function invokeFileWatchers(path, event) {
|
|
162
|
+
const normalizedPath = real_file_system_1.realFileSystem.normalizePath(path);
|
|
163
|
+
if (normalizedPath.endsWith('.js')) {
|
|
164
|
+
// trigger relevant .d.ts file watcher - handles the case, when we have webpack watcher
|
|
165
|
+
// that points to a symlinked package
|
|
166
|
+
invokeFileWatchers(normalizedPath.slice(0, -3) + '.d.ts', event);
|
|
167
|
+
}
|
|
168
|
+
const fileWatcherCallbacks = fileWatcherCallbacksMap.get(normalizedPath);
|
|
169
|
+
if (fileWatcherCallbacks) {
|
|
170
|
+
// typescript expects normalized paths with posix forward slash
|
|
171
|
+
fileWatcherCallbacks.forEach((fileWatcherCallback) => fileWatcherCallback(forwardSlash_1.default(normalizedPath), event));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function invokeDirectoryWatchers(path) {
|
|
175
|
+
const normalizedPath = real_file_system_1.realFileSystem.normalizePath(path);
|
|
176
|
+
const directory = path_1.dirname(normalizedPath);
|
|
177
|
+
if (ignoredPaths.some((ignoredPath) => forwardSlash_1.default(normalizedPath).includes(ignoredPath))) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const directoryWatcherCallbacks = directoryWatcherCallbacksMap.get(directory);
|
|
181
|
+
if (directoryWatcherCallbacks) {
|
|
182
|
+
directoryWatcherCallbacks.forEach((directoryWatcherCallback) => directoryWatcherCallback(forwardSlash_1.default(normalizedPath)));
|
|
183
|
+
}
|
|
184
|
+
recursiveDirectoryWatcherCallbacksMap.forEach((recursiveDirectoryWatcherCallbacks, watchedDirectory) => {
|
|
185
|
+
if (watchedDirectory === directory ||
|
|
186
|
+
(directory.startsWith(watchedDirectory) &&
|
|
187
|
+
forwardSlash_1.default(directory)[watchedDirectory.length] === '/')) {
|
|
188
|
+
recursiveDirectoryWatcherCallbacks.forEach((recursiveDirectoryWatcherCallback) => recursiveDirectoryWatcherCallback(forwardSlash_1.default(normalizedPath)));
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function isArtifact(path) {
|
|
193
|
+
return ((artifacts.dirs.some((dir) => path.includes(dir)) ||
|
|
194
|
+
artifacts.files.some((file) => path === file)) &&
|
|
195
|
+
artifacts.extensions.some((extension) => path.endsWith(extension)));
|
|
196
|
+
}
|
|
197
|
+
function getReadFileSystem(path) {
|
|
198
|
+
if (!isInitialRun && (mode === 'readonly' || mode === 'write-tsbuildinfo') && isArtifact(path)) {
|
|
199
|
+
return mem_file_system_1.memFileSystem;
|
|
200
|
+
}
|
|
201
|
+
return passive_file_system_1.passiveFileSystem;
|
|
202
|
+
}
|
|
203
|
+
function getWriteFileSystem(path) {
|
|
204
|
+
if (mode === 'write-references' ||
|
|
205
|
+
(mode === 'write-tsbuildinfo' && path.endsWith('.tsbuildinfo'))) {
|
|
206
|
+
return real_file_system_1.realFileSystem;
|
|
207
|
+
}
|
|
208
|
+
return passive_file_system_1.passiveFileSystem;
|
|
209
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dumpTracingLegendIfNeeded = exports.stopTracingIfNeeded = exports.startTracingIfNeeded = void 0;
|
|
4
|
+
const config_1 = require("./config");
|
|
5
|
+
const typescript_1 = require("./typescript");
|
|
6
|
+
const worker_config_1 = require("./worker-config");
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
+
const tracing = typescript_1.typescript.tracing;
|
|
9
|
+
function startTracingIfNeeded(compilerOptions) {
|
|
10
|
+
if (compilerOptions.generateTrace && tracing) {
|
|
11
|
+
tracing.startTracing(config_1.getConfigFilePathFromCompilerOptions(compilerOptions), compilerOptions.generateTrace, worker_config_1.config.build);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.startTracingIfNeeded = startTracingIfNeeded;
|
|
15
|
+
function stopTracingIfNeeded(program) {
|
|
16
|
+
const compilerOptions = program.getCompilerOptions();
|
|
17
|
+
if (compilerOptions.generateTrace && tracing) {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
+
tracing.stopTracing(program.getProgram().getTypeCatalog());
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.stopTracingIfNeeded = stopTracingIfNeeded;
|
|
23
|
+
function dumpTracingLegendIfNeeded() {
|
|
24
|
+
if (tracing) {
|
|
25
|
+
tracing.dumpLegend();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.dumpTracingLegendIfNeeded = dumpTracingLegendIfNeeded;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type * as ts from 'typescript';
|
|
2
|
+
export declare function invalidateTsBuildInfo(): void;
|
|
3
|
+
export declare function emitTsBuildInfoIfNeeded(builderProgram: ts.BuilderProgram): void;
|
|
4
|
+
export declare function getTsBuildInfoEmitPath(compilerOptions: ts.CompilerOptions): string | undefined;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.getTsBuildInfoEmitPath = exports.emitTsBuildInfoIfNeeded = exports.invalidateTsBuildInfo = void 0;
|
|
23
|
+
const path = __importStar(require("path"));
|
|
24
|
+
const config_1 = require("./config");
|
|
25
|
+
const system_1 = require("./system");
|
|
26
|
+
const typescript_1 = require("./typescript");
|
|
27
|
+
const worker_config_1 = require("./worker-config");
|
|
28
|
+
function invalidateTsBuildInfo() {
|
|
29
|
+
const parsedConfig = config_1.getParsedConfig();
|
|
30
|
+
// try to remove outdated .tsbuildinfo file for incremental mode
|
|
31
|
+
if (typeof typescript_1.typescript.getTsBuildInfoEmitOutputFilePath === 'function' &&
|
|
32
|
+
worker_config_1.config.mode !== 'readonly' &&
|
|
33
|
+
parsedConfig.options.incremental) {
|
|
34
|
+
const tsBuildInfoPath = typescript_1.typescript.getTsBuildInfoEmitOutputFilePath(parsedConfig.options);
|
|
35
|
+
if (tsBuildInfoPath) {
|
|
36
|
+
try {
|
|
37
|
+
system_1.system.deleteFile(tsBuildInfoPath);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
// silent
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.invalidateTsBuildInfo = invalidateTsBuildInfo;
|
|
46
|
+
function emitTsBuildInfoIfNeeded(builderProgram) {
|
|
47
|
+
const parsedConfig = config_1.getParsedConfig();
|
|
48
|
+
if (worker_config_1.config.mode !== 'readonly' && parsedConfig && isIncrementalEnabled(parsedConfig.options)) {
|
|
49
|
+
const program = builderProgram.getProgram();
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
if (typeof program.emitBuildInfo === 'function') {
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
program.emitBuildInfo();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.emitTsBuildInfoIfNeeded = emitTsBuildInfoIfNeeded;
|
|
58
|
+
function getTsBuildInfoEmitPath(compilerOptions) {
|
|
59
|
+
if (typeof typescript_1.typescript.getTsBuildInfoEmitOutputFilePath === 'function') {
|
|
60
|
+
return typescript_1.typescript.getTsBuildInfoEmitOutputFilePath(compilerOptions);
|
|
61
|
+
}
|
|
62
|
+
const removeJsonExtension = (filePath) => filePath.endsWith('.json') ? filePath.slice(0, -'.json'.length) : filePath;
|
|
63
|
+
// based on the implementation from typescript
|
|
64
|
+
const configFile = compilerOptions.configFilePath;
|
|
65
|
+
if (!isIncrementalEnabled(compilerOptions)) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
if (compilerOptions.tsBuildInfoFile) {
|
|
69
|
+
return compilerOptions.tsBuildInfoFile;
|
|
70
|
+
}
|
|
71
|
+
const outPath = compilerOptions.outFile || compilerOptions.out;
|
|
72
|
+
let buildInfoExtensionLess;
|
|
73
|
+
if (outPath) {
|
|
74
|
+
buildInfoExtensionLess = removeJsonExtension(outPath);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
if (!configFile) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
const configFileExtensionLess = removeJsonExtension(configFile);
|
|
81
|
+
buildInfoExtensionLess = compilerOptions.outDir
|
|
82
|
+
? compilerOptions.rootDir
|
|
83
|
+
? path.resolve(compilerOptions.outDir, path.relative(compilerOptions.rootDir, configFileExtensionLess))
|
|
84
|
+
: path.resolve(compilerOptions.outDir, path.basename(configFileExtensionLess))
|
|
85
|
+
: configFileExtensionLess;
|
|
86
|
+
}
|
|
87
|
+
return buildInfoExtensionLess + '.tsbuildinfo';
|
|
88
|
+
}
|
|
89
|
+
exports.getTsBuildInfoEmitPath = getTsBuildInfoEmitPath;
|
|
90
|
+
function isIncrementalEnabled(compilerOptions) {
|
|
91
|
+
return Boolean((compilerOptions.incremental || compilerOptions.composite) && !compilerOptions.outFile);
|
|
92
|
+
}
|
package/lib/utils/async/pool.js
CHANGED
|
@@ -18,21 +18,10 @@ function createPool(size) {
|
|
|
18
18
|
while (pendingPromises.length >= pool.size) {
|
|
19
19
|
yield Promise.race(pendingPromises).catch(() => undefined);
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const taskPromise = new Promise((taskResolve, taskReject) => {
|
|
24
|
-
resolve = taskResolve;
|
|
25
|
-
reject = taskReject;
|
|
21
|
+
const taskPromise = task().finally(() => {
|
|
22
|
+
pendingPromises = pendingPromises.filter((pendingPromise) => pendingPromise !== taskPromise);
|
|
26
23
|
});
|
|
27
|
-
|
|
28
|
-
task(() => {
|
|
29
|
-
doneResolve(undefined);
|
|
30
|
-
pendingPromises = pendingPromises.filter((pendingPromise) => pendingPromise !== donePromise);
|
|
31
|
-
})
|
|
32
|
-
.then(resolve)
|
|
33
|
-
.catch(reject);
|
|
34
|
-
});
|
|
35
|
-
pendingPromises.push(donePromise);
|
|
24
|
+
pendingPromises.push(taskPromise);
|
|
36
25
|
return taskPromise;
|
|
37
26
|
});
|
|
38
27
|
},
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
declare class RpcIpcMessagePortClosedError extends RpcMessagePortClosedError {
|
|
1
|
+
declare class RpcExitError extends Error {
|
|
3
2
|
readonly code?: string | number | null | undefined;
|
|
4
3
|
readonly signal?: string | null | undefined;
|
|
5
4
|
constructor(message: string, code?: string | number | null | undefined, signal?: string | null | undefined);
|
|
6
5
|
}
|
|
7
|
-
export {
|
|
6
|
+
export { RpcExitError };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RpcExitError = void 0;
|
|
4
|
+
class RpcExitError extends Error {
|
|
5
|
+
constructor(message, code, signal) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.signal = signal;
|
|
9
|
+
this.name = 'RpcExitError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.RpcExitError = RpcExitError;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function exposeRpc(fn: (...args: any[]) => any): void;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.exposeRpc = void 0;
|
|
16
|
+
const process_1 = __importDefault(require("process"));
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
function exposeRpc(fn) {
|
|
19
|
+
const sendMessage = (message) => new Promise((resolve, reject) => {
|
|
20
|
+
if (!process_1.default.send) {
|
|
21
|
+
reject(new Error(`Process ${process_1.default.pid} doesn't have IPC channels`));
|
|
22
|
+
}
|
|
23
|
+
else if (!process_1.default.connected) {
|
|
24
|
+
reject(new Error(`Process ${process_1.default.pid} doesn't have open IPC channels`));
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
process_1.default.send(message, undefined, undefined, (error) => {
|
|
28
|
+
if (error) {
|
|
29
|
+
reject(error);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
resolve(undefined);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const handleMessage = (message) => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
if (message.type === 'call') {
|
|
39
|
+
if (!process_1.default.send) {
|
|
40
|
+
// process disconnected - skip
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
let value;
|
|
44
|
+
let error;
|
|
45
|
+
try {
|
|
46
|
+
value = yield fn(...message.args);
|
|
47
|
+
}
|
|
48
|
+
catch (fnError) {
|
|
49
|
+
error = fnError;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
if (error) {
|
|
53
|
+
yield sendMessage({
|
|
54
|
+
type: 'reject',
|
|
55
|
+
id: message.id,
|
|
56
|
+
error,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
yield sendMessage({
|
|
61
|
+
type: 'resolve',
|
|
62
|
+
id: message.id,
|
|
63
|
+
value,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (sendError) {
|
|
68
|
+
// we can't send things back to the parent process - let's use stdout to communicate error
|
|
69
|
+
if (error) {
|
|
70
|
+
console.error(error);
|
|
71
|
+
}
|
|
72
|
+
console.error(sendError);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
process_1.default.on('message', handleMessage);
|
|
77
|
+
}
|
|
78
|
+
exports.exposeRpc = exposeRpc;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RpcExitError = exports.getRpcWorkerData = exports.createRpcWorker = exports.wrapRpc = exports.exposeRpc = void 0;
|
|
4
|
+
var expose_1 = require("./expose");
|
|
5
|
+
Object.defineProperty(exports, "exposeRpc", { enumerable: true, get: function () { return expose_1.exposeRpc; } });
|
|
6
|
+
var wrap_1 = require("./wrap");
|
|
7
|
+
Object.defineProperty(exports, "wrapRpc", { enumerable: true, get: function () { return wrap_1.wrapRpc; } });
|
|
8
|
+
var worker_1 = require("./worker");
|
|
9
|
+
Object.defineProperty(exports, "createRpcWorker", { enumerable: true, get: function () { return worker_1.createRpcWorker; } });
|
|
10
|
+
Object.defineProperty(exports, "getRpcWorkerData", { enumerable: true, get: function () { return worker_1.getRpcWorkerData; } });
|
|
11
|
+
var error_1 = require("./error");
|
|
12
|
+
Object.defineProperty(exports, "RpcExitError", { enumerable: true, get: function () { return error_1.RpcExitError; } });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface RpcCallMessage {
|
|
2
|
+
type: 'call';
|
|
3
|
+
id: string;
|
|
4
|
+
args: unknown[];
|
|
5
|
+
}
|
|
6
|
+
interface RpcResolveMessage {
|
|
7
|
+
type: 'resolve';
|
|
8
|
+
id: string;
|
|
9
|
+
value: unknown;
|
|
10
|
+
}
|
|
11
|
+
interface RpcRejectMessage {
|
|
12
|
+
type: 'reject';
|
|
13
|
+
id: string;
|
|
14
|
+
error: unknown;
|
|
15
|
+
}
|
|
16
|
+
declare type RpcMessage = RpcCallMessage | RpcResolveMessage | RpcRejectMessage;
|
|
17
|
+
declare type RpcMethod = (...args: any[]) => any;
|
|
18
|
+
declare type RpcRemoteMethod<T extends RpcMethod> = T extends (...args: infer A) => infer R ? R extends Promise<any> ? (...args: A) => R : (...args: A) => Promise<R> : (...args: unknown[]) => Promise<unknown>;
|
|
19
|
+
export { RpcCallMessage, RpcResolveMessage, RpcRejectMessage, RpcMessage, RpcMethod, RpcRemoteMethod, };
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { ChildProcess } from 'child_process';
|
|
3
|
+
import type { RpcMethod, RpcRemoteMethod } from './types';
|
|
4
|
+
interface RpcWorkerBase {
|
|
5
|
+
connect(): void;
|
|
6
|
+
terminate(): void;
|
|
7
|
+
readonly connected: boolean;
|
|
8
|
+
readonly process: ChildProcess | undefined;
|
|
9
|
+
}
|
|
10
|
+
declare type RpcWorker<T extends RpcMethod = RpcMethod> = RpcWorkerBase & RpcRemoteMethod<T>;
|
|
11
|
+
declare function createRpcWorker<T extends RpcMethod>(modulePath: string, data: unknown, memoryLimit?: number): RpcWorker<T>;
|
|
12
|
+
declare function getRpcWorkerData(): unknown;
|
|
13
|
+
export { createRpcWorker, getRpcWorkerData, RpcWorker };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.getRpcWorkerData = exports.createRpcWorker = void 0;
|
|
23
|
+
const child_process = __importStar(require("child_process"));
|
|
24
|
+
const process = __importStar(require("process"));
|
|
25
|
+
const wrap_1 = require("./wrap");
|
|
26
|
+
const WORKER_DATA_ENV_KEY = 'WORKER_DATA';
|
|
27
|
+
function createRpcWorker(modulePath, data, memoryLimit) {
|
|
28
|
+
const options = {
|
|
29
|
+
env: Object.assign(Object.assign({}, process.env), { [WORKER_DATA_ENV_KEY]: JSON.stringify(data || {}) }),
|
|
30
|
+
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
|
31
|
+
serialization: 'advanced',
|
|
32
|
+
};
|
|
33
|
+
if (memoryLimit) {
|
|
34
|
+
options.execArgv = [`--max-old-space-size=${memoryLimit}`];
|
|
35
|
+
}
|
|
36
|
+
let childProcess;
|
|
37
|
+
let remoteMethod;
|
|
38
|
+
const worker = {
|
|
39
|
+
connect() {
|
|
40
|
+
if (childProcess && !childProcess.connected) {
|
|
41
|
+
childProcess.kill('SIGTERM');
|
|
42
|
+
childProcess = undefined;
|
|
43
|
+
remoteMethod = undefined;
|
|
44
|
+
}
|
|
45
|
+
if (!(childProcess === null || childProcess === void 0 ? void 0 : childProcess.connected)) {
|
|
46
|
+
childProcess = child_process.fork(modulePath, options);
|
|
47
|
+
remoteMethod = wrap_1.wrapRpc(childProcess);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
terminate() {
|
|
51
|
+
if (childProcess) {
|
|
52
|
+
childProcess.kill('SIGTERM');
|
|
53
|
+
childProcess = undefined;
|
|
54
|
+
remoteMethod = undefined;
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
get connected() {
|
|
58
|
+
return Boolean(childProcess === null || childProcess === void 0 ? void 0 : childProcess.connected);
|
|
59
|
+
},
|
|
60
|
+
get process() {
|
|
61
|
+
return childProcess;
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
return Object.assign((...args) => {
|
|
65
|
+
if (!worker.connected) {
|
|
66
|
+
// try to auto-connect
|
|
67
|
+
worker.connect();
|
|
68
|
+
}
|
|
69
|
+
if (!remoteMethod) {
|
|
70
|
+
return Promise.reject('Worker is not connected - cannot perform RPC.');
|
|
71
|
+
}
|
|
72
|
+
return remoteMethod(...args);
|
|
73
|
+
}, worker);
|
|
74
|
+
}
|
|
75
|
+
exports.createRpcWorker = createRpcWorker;
|
|
76
|
+
function getRpcWorkerData() {
|
|
77
|
+
return JSON.parse(process.env[WORKER_DATA_ENV_KEY] || '{}');
|
|
78
|
+
}
|
|
79
|
+
exports.getRpcWorkerData = getRpcWorkerData;
|