@unpackjs/core 1.7.3 → 1.7.5

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.
Files changed (50) hide show
  1. package/compiled/commander/index.d.ts +88 -12
  2. package/compiled/commander/index.js +367 -129
  3. package/compiled/commander/package.json +1 -1
  4. package/compiled/css-loader/index.js +22 -24
  5. package/compiled/less-loader/index.js +8 -8
  6. package/compiled/postcss-loader/index.js +10 -10
  7. package/compiled/sass-loader/index.js +9 -8
  8. package/compiled/sass-loader/package.json +1 -1
  9. package/compiled/style-loader/index.js +10 -10
  10. package/dist/bundler-config/chunkSplit.cjs +0 -4
  11. package/dist/bundler-config/chunkSplit.d.ts.map +1 -1
  12. package/dist/bundler-config/chunkSplit.js +0 -4
  13. package/dist/bundler-config/css.cjs +1 -2
  14. package/dist/bundler-config/css.d.ts.map +1 -1
  15. package/dist/bundler-config/css.js +1 -2
  16. package/dist/bundler-config/experimentCss.cjs +4 -1
  17. package/dist/bundler-config/experimentCss.d.ts.map +1 -1
  18. package/dist/bundler-config/experimentCss.js +4 -1
  19. package/dist/bundler-config/index.cjs +2 -1
  20. package/dist/bundler-config/index.d.ts.map +1 -1
  21. package/dist/bundler-config/index.js +2 -1
  22. package/dist/bundler-config/jsMinify.cjs +1 -1
  23. package/dist/bundler-config/jsMinify.js +1 -1
  24. package/dist/createUnpack.cjs +2 -2
  25. package/dist/createUnpack.js +2 -2
  26. package/dist/plugin-progress/webpack.d.ts.map +1 -1
  27. package/dist/prebundleDeps.cjs +2 -1
  28. package/dist/prebundleDeps.d.ts.map +1 -1
  29. package/dist/prebundleDeps.js +2 -1
  30. package/dist/run/dev.cjs +1 -1
  31. package/dist/run/dev.js +1 -1
  32. package/dist/types/config.d.ts +1 -6
  33. package/dist/types/config.d.ts.map +1 -1
  34. package/package.json +10 -11
  35. package/dist/thread-loader/WorkerError.cjs +0 -41
  36. package/dist/thread-loader/WorkerError.js +0 -31
  37. package/dist/thread-loader/WorkerPool.cjs +0 -407
  38. package/dist/thread-loader/WorkerPool.js +0 -387
  39. package/dist/thread-loader/index.cjs +0 -100
  40. package/dist/thread-loader/index.js +0 -85
  41. package/dist/thread-loader/readBuffer.cjs +0 -55
  42. package/dist/thread-loader/readBuffer.js +0 -45
  43. package/dist/thread-loader/serializer.cjs +0 -46
  44. package/dist/thread-loader/serializer.js +0 -31
  45. package/dist/thread-loader/utils.cjs +0 -84
  46. package/dist/thread-loader/utils.js +0 -60
  47. package/dist/thread-loader/worker.cjs +0 -377
  48. package/dist/thread-loader/worker.js +0 -382
  49. package/dist/thread-loader/workerPools.cjs +0 -57
  50. package/dist/thread-loader/workerPools.js +0 -33
@@ -1,46 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var serializer_exports = {};
19
- __export(serializer_exports, {
20
- replacer: () => replacer,
21
- reviver: () => reviver
22
- });
23
- module.exports = __toCommonJS(serializer_exports);
24
- function replacer(_key, value) {
25
- if (value instanceof RegExp) {
26
- return {
27
- __serialized_type: "RegExp",
28
- source: value.source,
29
- flags: value.flags
30
- };
31
- }
32
- return value;
33
- }
34
- function reviver(_key, value) {
35
- if (typeof value === "object" && value !== null) {
36
- if (value.__serialized_type === "RegExp") {
37
- return new RegExp(value.source, value.flags);
38
- }
39
- }
40
- return value;
41
- }
42
- // Annotate the CommonJS export names for ESM import in node:
43
- 0 && (module.exports = {
44
- replacer,
45
- reviver
46
- });
@@ -1,31 +0,0 @@
1
- import { createRequire } from 'node:module';
2
- var require = createRequire(import.meta['url']);
3
-
4
- import path from "path";
5
- import { fileURLToPath } from "url";
6
- var getFilename = () => fileURLToPath(import.meta.url);
7
- var getDirname = () => path.dirname(getFilename());
8
- var __dirname = /* @__PURE__ */ getDirname();
9
- var __filename = /* @__PURE__ */ getFilename();
10
- function replacer(_key, value) {
11
- if (value instanceof RegExp) {
12
- return {
13
- __serialized_type: "RegExp",
14
- source: value.source,
15
- flags: value.flags
16
- };
17
- }
18
- return value;
19
- }
20
- function reviver(_key, value) {
21
- if (typeof value === "object" && value !== null) {
22
- if (value.__serialized_type === "RegExp") {
23
- return new RegExp(value.source, value.flags);
24
- }
25
- }
26
- return value;
27
- }
28
- export {
29
- replacer,
30
- reviver
31
- };
@@ -1,84 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var utils_exports = {};
29
- __export(utils_exports, {
30
- utils: () => utils
31
- });
32
- module.exports = __toCommonJS(utils_exports);
33
- var import_node_path = __toESM(require("node:path"));
34
- const WINDOWS_ABS_PATH_REGEXP = /^[a-zA-Z]:[\\/]/;
35
- const WINDOWS_PATH_SEPARATOR_REGEXP = /\\/g;
36
- const relativePathToRequest = (relativePath) => {
37
- if (relativePath === "")
38
- return "./.";
39
- if (relativePath === "..")
40
- return "../.";
41
- if (relativePath.startsWith("../"))
42
- return relativePath;
43
- return `./${relativePath}`;
44
- };
45
- const absoluteToRequest = (context, maybeAbsolutePath) => {
46
- if (maybeAbsolutePath[0] === "/") {
47
- if (maybeAbsolutePath.length > 1 && maybeAbsolutePath[maybeAbsolutePath.length - 1] === "/") {
48
- return maybeAbsolutePath;
49
- }
50
- const querySplitPos = maybeAbsolutePath.indexOf("?");
51
- let resource = querySplitPos === -1 ? maybeAbsolutePath : maybeAbsolutePath.slice(0, querySplitPos);
52
- resource = relativePathToRequest(import_node_path.default.posix.relative(context, resource));
53
- return querySplitPos === -1 ? resource : resource + maybeAbsolutePath.slice(querySplitPos);
54
- }
55
- if (WINDOWS_ABS_PATH_REGEXP.test(maybeAbsolutePath)) {
56
- const querySplitPos = maybeAbsolutePath.indexOf("?");
57
- let resource = querySplitPos === -1 ? maybeAbsolutePath : maybeAbsolutePath.slice(0, querySplitPos);
58
- resource = import_node_path.default.win32.relative(context, resource);
59
- if (!WINDOWS_ABS_PATH_REGEXP.test(resource)) {
60
- resource = relativePathToRequest(resource.replace(WINDOWS_PATH_SEPARATOR_REGEXP, "/"));
61
- }
62
- return querySplitPos === -1 ? resource : resource + maybeAbsolutePath.slice(querySplitPos);
63
- }
64
- return maybeAbsolutePath;
65
- };
66
- const requestToAbsolute = (context, relativePath) => {
67
- if (relativePath.startsWith("./") || relativePath.startsWith("../"))
68
- return import_node_path.default.join(context, relativePath);
69
- return relativePath;
70
- };
71
- const contextify = (context, request) => {
72
- return request.split("!").map((r) => absoluteToRequest(context, r)).join("!");
73
- };
74
- const absolutify = (context, request) => {
75
- return request.split("!").map((r) => requestToAbsolute(context, r)).join("!");
76
- };
77
- const utils = {
78
- contextify,
79
- absolutify
80
- };
81
- // Annotate the CommonJS export names for ESM import in node:
82
- 0 && (module.exports = {
83
- utils
84
- });
@@ -1,60 +0,0 @@
1
- import { createRequire } from 'node:module';
2
- var require = createRequire(import.meta['url']);
3
-
4
- import path from "path";
5
- import { fileURLToPath } from "url";
6
- var getFilename = () => fileURLToPath(import.meta.url);
7
- var getDirname = () => path.dirname(getFilename());
8
- var __dirname = /* @__PURE__ */ getDirname();
9
- var __filename = /* @__PURE__ */ getFilename();
10
- import path2 from "node:path";
11
- const WINDOWS_ABS_PATH_REGEXP = /^[a-zA-Z]:[\\/]/;
12
- const WINDOWS_PATH_SEPARATOR_REGEXP = /\\/g;
13
- const relativePathToRequest = (relativePath) => {
14
- if (relativePath === "")
15
- return "./.";
16
- if (relativePath === "..")
17
- return "../.";
18
- if (relativePath.startsWith("../"))
19
- return relativePath;
20
- return `./${relativePath}`;
21
- };
22
- const absoluteToRequest = (context, maybeAbsolutePath) => {
23
- if (maybeAbsolutePath[0] === "/") {
24
- if (maybeAbsolutePath.length > 1 && maybeAbsolutePath[maybeAbsolutePath.length - 1] === "/") {
25
- return maybeAbsolutePath;
26
- }
27
- const querySplitPos = maybeAbsolutePath.indexOf("?");
28
- let resource = querySplitPos === -1 ? maybeAbsolutePath : maybeAbsolutePath.slice(0, querySplitPos);
29
- resource = relativePathToRequest(path2.posix.relative(context, resource));
30
- return querySplitPos === -1 ? resource : resource + maybeAbsolutePath.slice(querySplitPos);
31
- }
32
- if (WINDOWS_ABS_PATH_REGEXP.test(maybeAbsolutePath)) {
33
- const querySplitPos = maybeAbsolutePath.indexOf("?");
34
- let resource = querySplitPos === -1 ? maybeAbsolutePath : maybeAbsolutePath.slice(0, querySplitPos);
35
- resource = path2.win32.relative(context, resource);
36
- if (!WINDOWS_ABS_PATH_REGEXP.test(resource)) {
37
- resource = relativePathToRequest(resource.replace(WINDOWS_PATH_SEPARATOR_REGEXP, "/"));
38
- }
39
- return querySplitPos === -1 ? resource : resource + maybeAbsolutePath.slice(querySplitPos);
40
- }
41
- return maybeAbsolutePath;
42
- };
43
- const requestToAbsolute = (context, relativePath) => {
44
- if (relativePath.startsWith("./") || relativePath.startsWith("../"))
45
- return path2.join(context, relativePath);
46
- return relativePath;
47
- };
48
- const contextify = (context, request) => {
49
- return request.split("!").map((r) => absoluteToRequest(context, r)).join("!");
50
- };
51
- const absolutify = (context, request) => {
52
- return request.split("!").map((r) => requestToAbsolute(context, r)).join("!");
53
- };
54
- const utils = {
55
- contextify,
56
- absolutify
57
- };
58
- export {
59
- utils
60
- };
@@ -1,377 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __copyProps = (to, from, except, desc) => {
8
- if (from && typeof from === "object" || typeof from === "function") {
9
- for (let key of __getOwnPropNames(from))
10
- if (!__hasOwnProp.call(to, key) && key !== except)
11
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
- }
13
- return to;
14
- };
15
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
- // If the importer is in node compatibility mode or this is not an ESM
17
- // file that has been converted to a CommonJS file using a Babel-
18
- // compatible transform (i.e. "__esModule" has not been set), then set
19
- // "default" to the CommonJS "module.exports" for node compatibility.
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
- mod
22
- ));
23
- var import_node_fs = __toESM(require("node:fs"));
24
- var import_node_module = __toESM(require("node:module"));
25
- var import_node_querystring = __toESM(require("node:querystring"));
26
- var import_loader_runner = __toESM(require("loader-runner"));
27
- var import_readBuffer = __toESM(require("./readBuffer.cjs"));
28
- var import_serializer = require("./serializer.cjs");
29
- var import_utils = require("./utils.cjs");
30
- const asyncQueue = require("neo-async/queue.js");
31
- const writePipe = import_node_fs.default.createWriteStream(null, { fd: 3 });
32
- const readPipe = import_node_fs.default.createReadStream(null, { fd: 4 });
33
- writePipe.on("finish", onTerminateWrite);
34
- readPipe.on("end", onTerminateRead);
35
- writePipe.on("close", onTerminateWrite);
36
- readPipe.on("close", onTerminateRead);
37
- readPipe.on("error", onError);
38
- writePipe.on("error", onError);
39
- const PARALLEL_JOBS = +process.argv[2] || 20;
40
- let terminated = false;
41
- let nextQuestionId = 0;
42
- const callbackMap = /* @__PURE__ */ Object.create(null);
43
- function onError(error) {
44
- console.error(error);
45
- }
46
- function onTerminateRead() {
47
- terminateRead();
48
- }
49
- function onTerminateWrite() {
50
- terminateWrite();
51
- }
52
- function writePipeWrite(...args) {
53
- if (!terminated) {
54
- writePipe.write(...args);
55
- }
56
- }
57
- function writePipeCork() {
58
- if (!terminated) {
59
- writePipe.cork();
60
- }
61
- }
62
- function writePipeUncork() {
63
- if (!terminated) {
64
- writePipe.uncork();
65
- }
66
- }
67
- function terminateRead() {
68
- terminated = true;
69
- readPipe.removeAllListeners();
70
- }
71
- function terminateWrite() {
72
- terminated = true;
73
- writePipe.removeAllListeners();
74
- }
75
- function terminate() {
76
- terminateRead();
77
- terminateWrite();
78
- }
79
- function toErrorObj(err) {
80
- return {
81
- message: err.message,
82
- details: err.details,
83
- stack: err.stack,
84
- hideStack: err.hideStack
85
- };
86
- }
87
- function toNativeError(obj) {
88
- if (!obj)
89
- return null;
90
- const err = new Error(obj.message);
91
- err.details = obj.details;
92
- err.missing = obj.missing;
93
- return err;
94
- }
95
- function writeJson(data) {
96
- writePipeCork();
97
- process.nextTick(() => {
98
- writePipeUncork();
99
- });
100
- const lengthBuffer = Buffer.alloc(4);
101
- const messageBuffer = Buffer.from(JSON.stringify(data, import_serializer.replacer), "utf-8");
102
- lengthBuffer.writeInt32BE(messageBuffer.length, 0);
103
- writePipeWrite(lengthBuffer);
104
- writePipeWrite(messageBuffer);
105
- }
106
- const queue = asyncQueue(({ id, data }, taskCallback) => {
107
- try {
108
- const resolveWithOptions = (context, request, callback, options) => {
109
- callbackMap[nextQuestionId] = callback;
110
- writeJson({
111
- type: "resolve",
112
- id,
113
- questionId: nextQuestionId,
114
- context,
115
- request,
116
- options
117
- });
118
- nextQuestionId += 1;
119
- };
120
- const buildDependencies = [];
121
- import_loader_runner.default.runLoaders(
122
- {
123
- loaders: data.loaders,
124
- resource: data.resource,
125
- readResource: import_node_fs.default.readFile.bind(import_node_fs.default),
126
- context: {
127
- version: 2,
128
- fs: import_node_fs.default,
129
- loadModule: (request, callback) => {
130
- callbackMap[nextQuestionId] = (error, result) => callback(error, ...result);
131
- writeJson({
132
- type: "loadModule",
133
- id,
134
- questionId: nextQuestionId,
135
- request
136
- });
137
- nextQuestionId += 1;
138
- },
139
- resolve: (context, request, callback) => {
140
- resolveWithOptions(context, request, callback);
141
- },
142
- getResolve: (options) => (context, request, callback) => {
143
- if (callback) {
144
- resolveWithOptions(context, request, callback, options);
145
- } else {
146
- return new Promise((resolve, reject) => {
147
- resolveWithOptions(
148
- context,
149
- request,
150
- (err, result) => {
151
- if (err) {
152
- reject(err);
153
- } else {
154
- resolve(result);
155
- }
156
- },
157
- options
158
- );
159
- });
160
- }
161
- },
162
- // Not an arrow function because it uses this
163
- getOptions() {
164
- const loader = this.loaders[this.loaderIndex];
165
- let { options } = loader;
166
- if (typeof options === "string") {
167
- if (options.substr(0, 1) === "{" && options.substr(-1) === "}") {
168
- try {
169
- options = JSON.parse(options);
170
- } catch (e) {
171
- throw new Error(`Cannot parse string options: ${e.message}`);
172
- }
173
- } else {
174
- options = import_node_querystring.default.parse(options, "&", "=", {
175
- maxKeys: 0
176
- });
177
- }
178
- }
179
- if (options === null || options === void 0) {
180
- options = {};
181
- }
182
- return options;
183
- },
184
- emitWarning: (warning) => {
185
- writeJson({
186
- type: "emitWarning",
187
- id,
188
- data: toErrorObj(warning)
189
- });
190
- },
191
- emitError: (error) => {
192
- writeJson({
193
- type: "emitError",
194
- id,
195
- data: toErrorObj(error)
196
- });
197
- },
198
- exec: (code, filename) => {
199
- const module2 = new import_node_module.default(filename, exports);
200
- module2.paths = import_node_module.default._nodeModulePaths(exports.context);
201
- module2.filename = filename;
202
- module2._compile(code, filename);
203
- return module2.exports;
204
- },
205
- addBuildDependency: (filename) => {
206
- buildDependencies.push(filename);
207
- },
208
- getLogger: (name) => {
209
- function writeLoggerJson(severity, message) {
210
- writeJson({
211
- type: "logger",
212
- id,
213
- data: { severity, name, message }
214
- });
215
- }
216
- writeJson({
217
- type: "getLogger",
218
- id,
219
- data: { name }
220
- });
221
- const loggers = [
222
- "error",
223
- "warn",
224
- "info",
225
- "log",
226
- "debug",
227
- "trace",
228
- "group",
229
- "groupEnd",
230
- "groupCollapsed",
231
- "status",
232
- "clear",
233
- "profile",
234
- "profileEnd"
235
- ];
236
- const fnMap = {};
237
- for (const logger of loggers) {
238
- fnMap[logger] = (...args) => {
239
- writeLoggerJson(logger, args);
240
- };
241
- }
242
- return fnMap;
243
- },
244
- options: {
245
- context: data.optionsContext
246
- },
247
- webpack: true,
248
- "thread-loader": true,
249
- sourceMap: data.sourceMap,
250
- target: data.target,
251
- minimize: data.minimize,
252
- resourceQuery: data.resourceQuery,
253
- rootContext: data.rootContext,
254
- _compilation: data._compilation,
255
- _compiler: data._compiler,
256
- resourcePath: data.resourcePath,
257
- utils: import_utils.utils
258
- }
259
- },
260
- (err, lrResult) => {
261
- const { result, cacheable, fileDependencies, contextDependencies, missingDependencies } = lrResult;
262
- const buffersToSend = [];
263
- const convertedResult = Array.isArray(result) && result.map((item) => {
264
- const isBuffer = Buffer.isBuffer(item);
265
- if (isBuffer) {
266
- buffersToSend.push(item);
267
- return {
268
- buffer: true
269
- };
270
- }
271
- if (typeof item === "string") {
272
- const stringBuffer = Buffer.from(item, "utf-8");
273
- buffersToSend.push(stringBuffer);
274
- return {
275
- buffer: true,
276
- string: true
277
- };
278
- }
279
- return {
280
- data: item
281
- };
282
- });
283
- writeJson({
284
- type: "job",
285
- id,
286
- error: err && toErrorObj(err),
287
- result: {
288
- result: convertedResult,
289
- cacheable,
290
- fileDependencies,
291
- contextDependencies,
292
- missingDependencies,
293
- buildDependencies
294
- },
295
- data: buffersToSend.map((buffer) => buffer.length)
296
- });
297
- buffersToSend.forEach((buffer) => {
298
- writePipeWrite(buffer);
299
- });
300
- setImmediate(taskCallback);
301
- }
302
- );
303
- } catch (e) {
304
- writeJson({
305
- type: "job",
306
- id,
307
- error: toErrorObj(e)
308
- });
309
- taskCallback();
310
- }
311
- }, PARALLEL_JOBS);
312
- function dispose() {
313
- terminate();
314
- queue.kill();
315
- process.exit(0);
316
- }
317
- function onMessage(message) {
318
- try {
319
- const { type, id } = message;
320
- switch (type) {
321
- case "job": {
322
- queue.push(message);
323
- break;
324
- }
325
- case "result": {
326
- const { error, result } = message;
327
- const callback = callbackMap[id];
328
- if (callback) {
329
- const nativeError = toNativeError(error);
330
- callback(nativeError, result);
331
- } else {
332
- console.error(`Worker got unexpected result id ${id}`);
333
- }
334
- delete callbackMap[id];
335
- break;
336
- }
337
- case "warmup": {
338
- const { requires } = message;
339
- requires.forEach((r) => require(r));
340
- break;
341
- }
342
- default: {
343
- console.error(`Worker got unexpected job type ${type}`);
344
- break;
345
- }
346
- }
347
- } catch (e) {
348
- console.error(`Error in worker ${e}`);
349
- }
350
- }
351
- function readNextMessage() {
352
- (0, import_readBuffer.default)(readPipe, 4, (lengthReadError, lengthBuffer) => {
353
- if (lengthReadError) {
354
- console.error(`Failed to communicate with main process (read length) ${lengthReadError}`);
355
- return;
356
- }
357
- const length = lengthBuffer.length && lengthBuffer.readInt32BE(0);
358
- if (length === 0) {
359
- dispose();
360
- return;
361
- }
362
- (0, import_readBuffer.default)(readPipe, length, (messageError, messageBuffer) => {
363
- if (terminated) {
364
- return;
365
- }
366
- if (messageError) {
367
- console.error(`Failed to communicate with main process (read message) ${messageError}`);
368
- return;
369
- }
370
- const messageString = messageBuffer.toString("utf-8");
371
- const message = JSON.parse(messageString, import_serializer.reviver);
372
- onMessage(message);
373
- setImmediate(() => readNextMessage());
374
- });
375
- });
376
- }
377
- readNextMessage();