@lvce-editor/main-process 1.0.3 → 1.2.0

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.
@@ -1,10 +1,8 @@
1
1
  import * as Electron from 'electron';
2
- import Electron__default, { app, dialog, clipboard, BrowserWindow, MessageChannelMain, Menu, shell, desktopCapturer, contentTracing, net, netLog, powerSaveBlocker, safeStorage, screen, webContents, WebContentsView } from 'electron';
2
+ import Electron__default, { dialog, app, clipboard, BrowserWindow, MessageChannelMain, Menu, shell, desktopCapturer, contentTracing, net, netLog, powerSaveBlocker, safeStorage, screen, webContents, WebContentsView } from 'electron';
3
3
  import process$1 from 'node:process';
4
4
  import { inspect } from 'node:util';
5
5
  import { spawn } from 'node:child_process';
6
- import { Buffer as Buffer$1 } from 'node:buffer';
7
- import * as _ws from 'ws';
8
6
  import { createWriteStream, readFileSync } from 'node:fs';
9
7
  import * as NodePath from 'node:path';
10
8
  import { dirname, join as join$1 } from 'node:path';
@@ -479,18 +477,6 @@ function requireLodash_debounce () {
479
477
  var lodash_debounceExports = requireLodash_debounce();
480
478
  const debounce = /*@__PURE__*/getDefaultExportFromCjs(lodash_debounceExports);
481
479
 
482
- const list = [
483
- // Native ES errors https://262.ecma-international.org/12.0/#sec-well-known-intrinsic-objects
484
- EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError,
485
- // Built-in errors
486
- globalThis.DOMException,
487
- // Node-specific errors
488
- // https://nodejs.org/api/errors.html
489
- globalThis.AssertionError, globalThis.SystemError]
490
- // Non-native Errors are used with `globalThis` because they might be missing. This filter drops them when undefined.
491
- .filter(Boolean).map(constructor => [constructor.name, constructor]);
492
- const errorConstructors = new Map(list);
493
-
494
480
  const commonProperties = [{
495
481
  property: 'name',
496
482
  enumerable: false
@@ -514,7 +500,6 @@ const toJSON = from => {
514
500
  toJsonWasCalled.delete(from);
515
501
  return json;
516
502
  };
517
- const getErrorConstructor$1 = name => errorConstructors.get(name) ?? Error;
518
503
 
519
504
  // eslint-disable-next-line complexity
520
505
  const destroyCircular = ({
@@ -530,9 +515,6 @@ const destroyCircular = ({
530
515
  if (!to) {
531
516
  if (Array.isArray(from)) {
532
517
  to = [];
533
- } else if (!serialize && isErrorLike(from)) {
534
- const Error = getErrorConstructor$1(from.name);
535
- to = new Error();
536
518
  } else {
537
519
  to = {};
538
520
  }
@@ -588,7 +570,7 @@ const destroyCircular = ({
588
570
  if (typeof from[property] !== 'undefined' && from[property] !== null) {
589
571
  Object.defineProperty(to, property, {
590
572
  value: isErrorLike(from[property]) ? continueDestroyCircular(from[property]) : from[property],
591
- enumerable: forceEnumerable ? true : enumerable,
573
+ enumerable: true ,
592
574
  configurable: true,
593
575
  writable: true
594
576
  });
@@ -664,7 +646,7 @@ let options = {
664
646
  // eslint-disable-line unicorn/prefer-top-level-await
665
647
  const {
666
648
  default: isDevelopment
667
- } = await Promise.resolve().then(function () { return index$1; });
649
+ } = await Promise.resolve().then(function () { return index; });
668
650
  return isDevelopment;
669
651
  })()
670
652
  };
@@ -1698,7 +1680,7 @@ function requireConversions() {
1698
1680
  var b;
1699
1681
  r = x * 3.2406 + y * -1.5372 + z * -0.4986;
1700
1682
  g = x * -0.9689 + y * 1.8758 + z * 0.0415;
1701
- b = x * 0.0557 + y * -0.2040 + z * 1.0570;
1683
+ b = x * 0.0557 + y * -0.204 + z * 1.0570;
1702
1684
 
1703
1685
  // assume sRGB
1704
1686
  r = r > 0.0031308 ? 1.055 * Math.pow(r, 1.0 / 2.4) - 0.055 : r * 12.92;
@@ -3414,7 +3396,6 @@ const NodeWorker$1 = 1;
3414
3396
  const NodeForkedProcess$1 = 2;
3415
3397
  const ElectronUtilityProcess$1 = 3;
3416
3398
  const ElectronMessagePort$1 = 4;
3417
- const WebSocket = 6;
3418
3399
  const RendererProcess2 = 8;
3419
3400
 
3420
3401
  const Two = '2.0';
@@ -3654,7 +3635,7 @@ const getErrorResponse = (message, error, preparePrettyError, logError) => {
3654
3635
  const errorProperty = getErrorProperty(error, prettyError);
3655
3636
  return create$1$2(message, errorProperty);
3656
3637
  };
3657
- const create$7 = (message, result) => {
3638
+ const create$5 = (message, result) => {
3658
3639
  return {
3659
3640
  jsonrpc: Two,
3660
3641
  id: message.id,
@@ -3663,7 +3644,7 @@ const create$7 = (message, result) => {
3663
3644
  };
3664
3645
  const getSuccessResponse = (message, result) => {
3665
3646
  const resultProperty = result ?? null;
3666
- return create$7(message, resultProperty);
3647
+ return create$5(message, resultProperty);
3667
3648
  };
3668
3649
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
3669
3650
  try {
@@ -3775,7 +3756,7 @@ const getPortTuple = () => {
3775
3756
  };
3776
3757
 
3777
3758
  const __dirname = dirname(fileURLToPath(import.meta.url));
3778
- const root = join$1(__dirname, '../../../../..');
3759
+ const root = process.env.LVCE_ROOT || join$1(__dirname, '../../../../..');
3779
3760
 
3780
3761
  const {
3781
3762
  env: env$1,
@@ -3794,6 +3775,9 @@ const getSessionId = () => {
3794
3775
  return process.env.SESSION_ID || `persist:${scheme}`;
3795
3776
  };
3796
3777
  const getSharedProcessPath = () => {
3778
+ if (process.env.LVCE_SHARED_PROCESS_PATH) {
3779
+ return process.env.LVCE_SHARED_PROCESS_PATH;
3780
+ }
3797
3781
  return join$1(root, 'packages', 'shared-process', 'src', 'sharedProcessMain.ts');
3798
3782
  };
3799
3783
 
@@ -4081,27 +4065,6 @@ class VError extends Error {
4081
4065
  }
4082
4066
  }
4083
4067
 
4084
- const walkValue = (value, transferrables, isTransferrable) => {
4085
- if (!value) {
4086
- return;
4087
- }
4088
- if (isTransferrable(value)) {
4089
- transferrables.push(value);
4090
- return;
4091
- }
4092
- if (Array.isArray(value)) {
4093
- for (const item of value) {
4094
- walkValue(item, transferrables, isTransferrable);
4095
- }
4096
- return;
4097
- }
4098
- if (typeof value === 'object') {
4099
- for (const property of Object.values(value)) {
4100
- walkValue(property, transferrables, isTransferrable);
4101
- }
4102
- return;
4103
- }
4104
- };
4105
4068
  const isMessagePort = value => {
4106
4069
  return value && value instanceof MessagePort;
4107
4070
  };
@@ -4126,6 +4089,27 @@ const isTransferrable = value => {
4126
4089
  }
4127
4090
  return false;
4128
4091
  };
4092
+ const walkValue = (value, transferrables, isTransferrable) => {
4093
+ if (!value) {
4094
+ return;
4095
+ }
4096
+ if (isTransferrable(value)) {
4097
+ transferrables.push(value);
4098
+ return;
4099
+ }
4100
+ if (Array.isArray(value)) {
4101
+ for (const item of value) {
4102
+ walkValue(item, transferrables, isTransferrable);
4103
+ }
4104
+ return;
4105
+ }
4106
+ if (typeof value === 'object') {
4107
+ for (const property of Object.values(value)) {
4108
+ walkValue(property, transferrables, isTransferrable);
4109
+ }
4110
+ return;
4111
+ }
4112
+ };
4129
4113
  const getTransferrables = value => {
4130
4114
  const transferrables = [];
4131
4115
  walkValue(value, transferrables, isTransferrable);
@@ -4207,30 +4191,35 @@ const NewLine = '\n';
4207
4191
  const joinLines = lines => {
4208
4192
  return lines.join(NewLine);
4209
4193
  };
4210
- const splitLines = lines => {
4211
- return lines.split(NewLine);
4212
- };
4213
- const isModuleNotFoundMessage = line => {
4214
- return line.includes('[ERR_MODULE_NOT_FOUND]');
4194
+ const RE_AT = /^\s+at/;
4195
+ const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
4196
+ const isNormalStackLine = line => {
4197
+ return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
4215
4198
  };
4216
- const getModuleNotFoundError = stderr => {
4217
- const lines = splitLines(stderr);
4218
- const messageIndex = lines.findIndex(isModuleNotFoundMessage);
4219
- const message = lines[messageIndex];
4199
+ const getDetails = lines => {
4200
+ const index = lines.findIndex(isNormalStackLine);
4201
+ if (index === -1) {
4202
+ return {
4203
+ actualMessage: joinLines(lines),
4204
+ rest: []
4205
+ };
4206
+ }
4207
+ let lastIndex = index - 1;
4208
+ while (++lastIndex < lines.length) {
4209
+ if (!isNormalStackLine(lines[lastIndex])) {
4210
+ break;
4211
+ }
4212
+ }
4220
4213
  return {
4221
- message,
4222
- code: ERR_MODULE_NOT_FOUND
4214
+ actualMessage: lines[index - 1],
4215
+ rest: lines.slice(index, lastIndex)
4223
4216
  };
4224
4217
  };
4225
- const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
4226
- const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
4218
+ const splitLines = lines => {
4219
+ return lines.split(NewLine);
4220
+ };
4227
4221
  const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
4228
4222
  const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
4229
- const RE_AT = /^\s+at/;
4230
- const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
4231
- const isUnhelpfulNativeModuleError = stderr => {
4232
- return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
4233
- };
4234
4223
  const isMessageCodeBlockStartIndex = line => {
4235
4224
  return RE_MESSAGE_CODE_BLOCK_START.test(line);
4236
4225
  };
@@ -4245,51 +4234,46 @@ const getMessageCodeBlock = stderr => {
4245
4234
  const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
4246
4235
  return relevantMessage;
4247
4236
  };
4248
- const getNativeModuleErrorMessage = stderr => {
4249
- const message = getMessageCodeBlock(stderr);
4237
+ const isModuleNotFoundMessage = line => {
4238
+ return line.includes('[ERR_MODULE_NOT_FOUND]');
4239
+ };
4240
+ const getModuleNotFoundError = stderr => {
4241
+ const lines = splitLines(stderr);
4242
+ const messageIndex = lines.findIndex(isModuleNotFoundMessage);
4243
+ const message = lines[messageIndex];
4250
4244
  return {
4251
- message: `Incompatible native node module: ${message}`,
4252
- code: E_INCOMPATIBLE_NATIVE_MODULE
4245
+ message,
4246
+ code: ERR_MODULE_NOT_FOUND
4253
4247
  };
4254
4248
  };
4255
- const isModulesSyntaxError = stderr => {
4249
+ const isModuleNotFoundError = stderr => {
4256
4250
  if (!stderr) {
4257
4251
  return false;
4258
4252
  }
4259
- return stderr.includes('SyntaxError: Cannot use import statement outside a module');
4260
- };
4261
- const getModuleSyntaxError = () => {
4262
- return {
4263
- message: `ES Modules are not supported in electron`,
4264
- code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
4265
- };
4253
+ return stderr.includes('ERR_MODULE_NOT_FOUND');
4266
4254
  };
4267
- const isModuleNotFoundError = stderr => {
4255
+ const isModulesSyntaxError = stderr => {
4268
4256
  if (!stderr) {
4269
4257
  return false;
4270
4258
  }
4271
- return stderr.includes('ERR_MODULE_NOT_FOUND');
4259
+ return stderr.includes('SyntaxError: Cannot use import statement outside a module');
4272
4260
  };
4273
- const isNormalStackLine = line => {
4274
- return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
4261
+ const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
4262
+ const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
4263
+ const isUnhelpfulNativeModuleError = stderr => {
4264
+ return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
4275
4265
  };
4276
- const getDetails = lines => {
4277
- const index = lines.findIndex(isNormalStackLine);
4278
- if (index === -1) {
4279
- return {
4280
- actualMessage: joinLines(lines),
4281
- rest: []
4282
- };
4283
- }
4284
- let lastIndex = index - 1;
4285
- while (++lastIndex < lines.length) {
4286
- if (!isNormalStackLine(lines[lastIndex])) {
4287
- break;
4288
- }
4289
- }
4266
+ const getNativeModuleErrorMessage = stderr => {
4267
+ const message = getMessageCodeBlock(stderr);
4290
4268
  return {
4291
- actualMessage: lines[index - 1],
4292
- rest: lines.slice(index, lastIndex)
4269
+ message: `Incompatible native node module: ${message}`,
4270
+ code: E_INCOMPATIBLE_NATIVE_MODULE
4271
+ };
4272
+ };
4273
+ const getModuleSyntaxError = () => {
4274
+ return {
4275
+ message: `ES Modules are not supported in electron`,
4276
+ code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
4293
4277
  };
4294
4278
  };
4295
4279
  const getHelpfulChildProcessError = (stdout, stderr) => {
@@ -4308,7 +4292,7 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
4308
4292
  rest
4309
4293
  } = getDetails(lines);
4310
4294
  return {
4311
- message: `${actualMessage}`,
4295
+ message: actualMessage,
4312
4296
  code: '',
4313
4297
  stack: rest
4314
4298
  };
@@ -4347,13 +4331,10 @@ const listen$b = ({
4347
4331
  }
4348
4332
  return messagePort;
4349
4333
  };
4350
- const signal$b = messagePort => {
4334
+ const signal$c = messagePort => {
4351
4335
  messagePort.start();
4352
4336
  };
4353
4337
  class IpcChildWithElectronMessagePort extends Ipc {
4354
- constructor(port) {
4355
- super(port);
4356
- }
4357
4338
  getData = getActualDataElectron;
4358
4339
  send(message) {
4359
4340
  this._rawIpc.postMessage(message);
@@ -4375,14 +4356,14 @@ class IpcChildWithElectronMessagePort extends Ipc {
4375
4356
  this._rawIpc.on('close', callback);
4376
4357
  }
4377
4358
  }
4378
- const wrap$i = messagePort => {
4359
+ const wrap$j = messagePort => {
4379
4360
  return new IpcChildWithElectronMessagePort(messagePort);
4380
4361
  };
4381
4362
  const IpcChildWithElectronMessagePort$1 = {
4382
4363
  __proto__: null,
4383
4364
  listen: listen$b,
4384
- signal: signal$b,
4385
- wrap: wrap$i
4365
+ signal: signal$c,
4366
+ wrap: wrap$j
4386
4367
  };
4387
4368
 
4388
4369
  // @ts-ignore
@@ -4410,7 +4391,7 @@ const listen$a = () => {
4410
4391
  }
4411
4392
  return parentPort;
4412
4393
  };
4413
- const signal$a = parentPort => {
4394
+ const signal$b = parentPort => {
4414
4395
  parentPort.postMessage(readyMessage);
4415
4396
  };
4416
4397
  class IpcChildWithElectronUtilityProcess extends Ipc {
@@ -4437,32 +4418,26 @@ class IpcChildWithElectronUtilityProcess extends Ipc {
4437
4418
  this._rawIpc.on('message', callback);
4438
4419
  }
4439
4420
  }
4440
- const wrap$h = parentPort => {
4421
+ const wrap$i = parentPort => {
4441
4422
  return new IpcChildWithElectronUtilityProcess(parentPort);
4442
4423
  };
4443
4424
  const IpcChildWithElectronUtilityProcess$1 = {
4444
4425
  __proto__: null,
4445
4426
  listen: listen$a,
4446
- signal: signal$a,
4447
- wrap: wrap$h
4427
+ signal: signal$b,
4428
+ wrap: wrap$i
4448
4429
  };
4449
- const withResolvers$2 = () => {
4430
+ const withResolvers$1 = () => {
4450
4431
  let _resolve;
4451
4432
  const promise = new Promise(resolve => {
4452
4433
  _resolve = resolve;
4453
4434
  });
4454
4435
  return {
4436
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4455
4437
  resolve: _resolve,
4456
4438
  promise
4457
4439
  };
4458
4440
  };
4459
- const getTransferrablesNode = value => {
4460
- const transferrables = getTransferrables(value);
4461
- if (transferrables.length === 0) {
4462
- throw new Error(`no transferrables found`);
4463
- }
4464
- return transferrables[0];
4465
- };
4466
4441
  const getActualData = (message, handle) => {
4467
4442
  if (handle) {
4468
4443
  return {
@@ -4472,19 +4447,23 @@ const getActualData = (message, handle) => {
4472
4447
  }
4473
4448
  return message;
4474
4449
  };
4450
+ const getTransferrablesNode = value => {
4451
+ const transferrables = getTransferrables(value);
4452
+ if (transferrables.length === 0) {
4453
+ throw new Error(`no transferrables found`);
4454
+ }
4455
+ return transferrables[0];
4456
+ };
4475
4457
  const listen$5 = async () => {
4476
4458
  if (!process.send) {
4477
4459
  throw new Error('process.send must be defined');
4478
4460
  }
4479
4461
  return process;
4480
4462
  };
4481
- const signal$6 = process => {
4463
+ const signal$7 = process => {
4482
4464
  process.send(readyMessage);
4483
4465
  };
4484
4466
  class IpcChildWithNodeForkedProcess extends Ipc {
4485
- constructor(process) {
4486
- super(process);
4487
- }
4488
4467
  getData(message, handle) {
4489
4468
  return getActualData(message, handle);
4490
4469
  }
@@ -4505,14 +4484,14 @@ class IpcChildWithNodeForkedProcess extends Ipc {
4505
4484
  // ignore
4506
4485
  }
4507
4486
  }
4508
- const wrap$c = process => {
4487
+ const wrap$d = process => {
4509
4488
  return new IpcChildWithNodeForkedProcess(process);
4510
4489
  };
4511
4490
  const IpcChildWithNodeForkedProcess$1 = {
4512
4491
  __proto__: null,
4513
4492
  listen: listen$5,
4514
- signal: signal$6,
4515
- wrap: wrap$c
4493
+ signal: signal$7,
4494
+ wrap: wrap$d
4516
4495
  };
4517
4496
  const listen$3 = async () => {
4518
4497
  const {
@@ -4523,13 +4502,10 @@ const listen$3 = async () => {
4523
4502
  }
4524
4503
  return parentPort;
4525
4504
  };
4526
- const signal$4 = parentPort => {
4505
+ const signal$5 = parentPort => {
4527
4506
  parentPort.postMessage(readyMessage);
4528
4507
  };
4529
4508
  class IpcChildWithNodeWorker extends Ipc {
4530
- constructor(port) {
4531
- super(port);
4532
- }
4533
4509
  getData(data) {
4534
4510
  return data;
4535
4511
  }
@@ -4550,14 +4526,14 @@ class IpcChildWithNodeWorker extends Ipc {
4550
4526
  this._rawIpc.close();
4551
4527
  }
4552
4528
  }
4553
- const wrap$a = parentPort => {
4529
+ const wrap$b = parentPort => {
4554
4530
  return new IpcChildWithNodeWorker(parentPort);
4555
4531
  };
4556
4532
  const IpcChildWithNodeWorker$1 = {
4557
4533
  __proto__: null,
4558
4534
  listen: listen$3,
4559
- signal: signal$4,
4560
- wrap: wrap$a
4535
+ signal: signal$5,
4536
+ wrap: wrap$b
4561
4537
  };
4562
4538
  const preloadChannelType = 'port';
4563
4539
  const listen$2 = ({
@@ -4597,16 +4573,14 @@ class IpcChildWithRendererProcess2 extends Ipc {
4597
4573
  this._rawIpc.on('destroyed', callback);
4598
4574
  }
4599
4575
  }
4600
- const wrap$9 = webContents => {
4576
+ const wrap$a = webContents => {
4601
4577
  return new IpcChildWithRendererProcess2(webContents);
4602
4578
  };
4603
4579
  const IpcChildWithRendererProcess2$1 = {
4604
4580
  __proto__: null,
4605
4581
  listen: listen$2,
4606
- wrap: wrap$9
4582
+ wrap: wrap$a
4607
4583
  };
4608
- const Open = 1;
4609
- const Close = 2;
4610
4584
  const addListener = (emitter, type, callback) => {
4611
4585
  if ('addEventListener' in emitter) {
4612
4586
  emitter.addEventListener(type, callback);
@@ -4625,7 +4599,7 @@ const getFirstEvent = (eventEmitter, eventMap) => {
4625
4599
  const {
4626
4600
  resolve,
4627
4601
  promise
4628
- } = withResolvers$2();
4602
+ } = withResolvers$1();
4629
4603
  const listenerMap = Object.create(null);
4630
4604
  const cleanup = value => {
4631
4605
  for (const event of Object.keys(eventMap)) {
@@ -4645,141 +4619,7 @@ const getFirstEvent = (eventEmitter, eventMap) => {
4645
4619
  }
4646
4620
  return promise;
4647
4621
  };
4648
-
4649
- // @ts-ignore
4650
- const getFirstWebSocketEvent = async webSocket => {
4651
- // @ts-ignore
4652
- const {
4653
- WebSocket
4654
- } = await import('ws');
4655
- switch (webSocket.readyState) {
4656
- case WebSocket.OPEN:
4657
- return {
4658
- type: Open,
4659
- event: undefined
4660
- };
4661
- case WebSocket.CLOSED:
4662
- return {
4663
- type: Close,
4664
- event: undefined
4665
- };
4666
- }
4667
- // @ts-ignore
4668
- const {
4669
- type,
4670
- event
4671
- } = await getFirstEvent(webSocket, {
4672
- open: Open,
4673
- close: Close
4674
- });
4675
- return {
4676
- type,
4677
- event
4678
- };
4679
- };
4680
-
4681
- // @ts-ignore
4682
- const isWebSocketOpen = async webSocket => {
4683
- // @ts-ignore
4684
- const {
4685
- WebSocket
4686
- } = await import('ws');
4687
- return webSocket.readyState === WebSocket.OPEN;
4688
- };
4689
-
4690
- // @ts-ignore
4691
- const serialize = message => {
4692
- return JSON.stringify(message);
4693
- };
4694
-
4695
- // @ts-ignore
4696
- const deserialize = message => {
4697
- return JSON.parse(message.toString());
4698
- };
4699
-
4700
- // @ts-ignore
4701
- const handleUpgrade$1 = async (...args) => {
4702
- const module = await Promise.resolve().then(function () { return index; });
4703
- // @ts-ignore
4704
- return module.handleUpgrade(...args);
4705
- };
4706
-
4707
- // @ts-ignore
4708
- const listen$1 = async ({
4709
- request,
4710
- handle
4711
- }) => {
4712
- if (!request) {
4713
- throw new IpcError('request must be defined');
4714
- }
4715
- if (!handle) {
4716
- throw new IpcError('handle must be defined');
4717
- }
4718
- const webSocket = await handleUpgrade$1(request, handle);
4719
- webSocket.pause();
4720
- if (!(await isWebSocketOpen(webSocket))) {
4721
- await getFirstWebSocketEvent(webSocket);
4722
- }
4723
- return webSocket;
4724
- };
4725
- const signal$3 = webSocket => {
4726
- webSocket.resume();
4727
- };
4728
-
4729
- // @ts-ignore
4730
- const wrap$8 = webSocket => {
4731
- return {
4732
- webSocket,
4733
- /**
4734
- * @type {any}
4735
- */
4736
- wrappedListener: undefined,
4737
- // @ts-ignore
4738
- on(event, listener) {
4739
- switch (event) {
4740
- case 'message':
4741
- // @ts-ignore
4742
- const wrappedListener = message => {
4743
- const data = deserialize(message);
4744
- const event = {
4745
- data,
4746
- target: this
4747
- };
4748
- listener(event);
4749
- };
4750
- webSocket.on('message', wrappedListener);
4751
- break;
4752
- case 'close':
4753
- webSocket.on('close', listener);
4754
- break;
4755
- default:
4756
- throw new Error('unknown event listener type');
4757
- }
4758
- },
4759
- // @ts-ignore
4760
- off(event, listener) {
4761
- this.webSocket.off(event, listener);
4762
- },
4763
- // @ts-ignore
4764
- send(message) {
4765
- const stringifiedMessage = serialize(message);
4766
- this.webSocket.send(stringifiedMessage);
4767
- },
4768
- dispose() {
4769
- this.webSocket.close();
4770
- },
4771
- start() {
4772
- throw new Error('start method is deprecated');
4773
- }
4774
- };
4775
- };
4776
- const IpcChildWithWebSocket = {
4777
- __proto__: null,
4778
- listen: listen$1,
4779
- signal: signal$3,
4780
- wrap: wrap$8
4781
- };
4782
- const create$6 = ({
4622
+ const create$7 = ({
4783
4623
  messagePort
4784
4624
  }) => {
4785
4625
  if (!isMessagePortMain(messagePort)) {
@@ -4787,13 +4627,10 @@ const create$6 = ({
4787
4627
  }
4788
4628
  return messagePort;
4789
4629
  };
4790
- const signal$1 = messagePort => {
4630
+ const signal$2 = messagePort => {
4791
4631
  messagePort.start();
4792
4632
  };
4793
4633
  class IpcParentWithElectronMessagePort extends Ipc {
4794
- constructor(port) {
4795
- super(port);
4796
- }
4797
4634
  getData = getActualDataElectron;
4798
4635
  send(message) {
4799
4636
  this._rawIpc.postMessage(message);
@@ -4815,33 +4652,25 @@ class IpcParentWithElectronMessagePort extends Ipc {
4815
4652
  this._rawIpc.on('close', callback);
4816
4653
  }
4817
4654
  }
4818
- const wrap$6 = messagePort => {
4655
+ const wrap$7 = messagePort => {
4819
4656
  return new IpcParentWithElectronMessagePort(messagePort);
4820
4657
  };
4821
4658
  const IpcParentWithElectronMessagePort$1 = {
4822
4659
  __proto__: null,
4823
- create: create$6,
4824
- signal: signal$1,
4825
- wrap: wrap$6
4660
+ create: create$7,
4661
+ signal: signal$2,
4662
+ wrap: wrap$7
4826
4663
  };
4827
4664
  const Exit = 1;
4828
4665
  const Error$2 = 2;
4829
4666
  const Message$1 = 3;
4830
-
4831
- /**
4832
- *
4833
- * @param {any} utilityProcess
4834
- * @returns
4835
- */
4836
- // @ts-ignore
4837
4667
  const getFirstUtilityProcessEvent = async utilityProcess => {
4838
4668
  const {
4839
4669
  resolve,
4840
4670
  promise
4841
- } = withResolvers$2();
4671
+ } = withResolvers$1();
4842
4672
  let stdout = '';
4843
4673
  let stderr = '';
4844
- // @ts-ignore
4845
4674
  const cleanup = value => {
4846
4675
  // @ts-ignore
4847
4676
  utilityProcess.stderr.off('data', handleStdErrData);
@@ -4849,18 +4678,14 @@ const getFirstUtilityProcessEvent = async utilityProcess => {
4849
4678
  utilityProcess.stdout.off('data', handleStdoutData);
4850
4679
  utilityProcess.off('message', handleMessage);
4851
4680
  utilityProcess.off('exit', handleExit);
4852
- // @ts-ignore
4853
4681
  resolve(value);
4854
4682
  };
4855
- // @ts-ignore
4856
4683
  const handleStdErrData = data => {
4857
4684
  stderr += data;
4858
4685
  };
4859
- // @ts-ignore
4860
4686
  const handleStdoutData = data => {
4861
4687
  stdout += data;
4862
4688
  };
4863
- // @ts-ignore
4864
4689
  const handleMessage = event => {
4865
4690
  cleanup({
4866
4691
  type: Message$1,
@@ -4869,7 +4694,6 @@ const getFirstUtilityProcessEvent = async utilityProcess => {
4869
4694
  stderr
4870
4695
  });
4871
4696
  };
4872
- // @ts-ignore
4873
4697
  const handleExit = event => {
4874
4698
  cleanup({
4875
4699
  type: Exit,
@@ -4884,7 +4708,6 @@ const getFirstUtilityProcessEvent = async utilityProcess => {
4884
4708
  utilityProcess.stdout.on('data', handleStdoutData);
4885
4709
  utilityProcess.on('message', handleMessage);
4886
4710
  utilityProcess.on('exit', handleExit);
4887
- // @ts-ignore
4888
4711
  const {
4889
4712
  type,
4890
4713
  event
@@ -4896,9 +4719,7 @@ const getFirstUtilityProcessEvent = async utilityProcess => {
4896
4719
  stderr
4897
4720
  };
4898
4721
  };
4899
-
4900
- // @ts-ignore
4901
- const create$5 = async ({
4722
+ const create$6 = async ({
4902
4723
  path,
4903
4724
  argv = [],
4904
4725
  execArgv = [],
@@ -4961,13 +4782,13 @@ let IpcParentWithElectronUtilityProcess$1 = class IpcParentWithElectronUtilityPr
4961
4782
  this._rawIpc.on('message', callback);
4962
4783
  }
4963
4784
  };
4964
- const wrap$5 = process => {
4785
+ const wrap$6 = process => {
4965
4786
  return new IpcParentWithElectronUtilityProcess$1(process);
4966
4787
  };
4967
4788
  const IpcParentWithElectronUtilityProcess$1$1 = {
4968
4789
  __proto__: null,
4969
- create: create$5,
4970
- wrap: wrap$5
4790
+ create: create$6,
4791
+ wrap: wrap$6
4971
4792
  };
4972
4793
  class ChildProcessError extends Error {
4973
4794
  // @ts-ignore
@@ -5009,10 +4830,7 @@ const fixNodeChildProcessParameters = value => {
5009
4830
  transfer: transfer[0]
5010
4831
  };
5011
4832
  };
5012
-
5013
- // @ts-ignore
5014
4833
  const getFirstNodeChildProcessEvent = async childProcess => {
5015
- // @ts-ignore
5016
4834
  const {
5017
4835
  type,
5018
4836
  event,
@@ -5021,7 +4839,6 @@ const getFirstNodeChildProcessEvent = async childProcess => {
5021
4839
  } = await new Promise((resolve, reject) => {
5022
4840
  let stderr = '';
5023
4841
  let stdout = '';
5024
- // @ts-ignore
5025
4842
  const cleanup = value => {
5026
4843
  if (childProcess.stdout && childProcess.stderr) {
5027
4844
  childProcess.stderr.off('data', handleStdErrData);
@@ -5032,15 +4849,12 @@ const getFirstNodeChildProcessEvent = async childProcess => {
5032
4849
  childProcess.off('error', handleError);
5033
4850
  resolve(value);
5034
4851
  };
5035
- // @ts-ignore
5036
4852
  const handleStdErrData = data => {
5037
4853
  stderr += data;
5038
4854
  };
5039
- // @ts-ignore
5040
4855
  const handleStdoutData = data => {
5041
4856
  stdout += data;
5042
4857
  };
5043
- // @ts-ignore
5044
4858
  const handleMessage = event => {
5045
4859
  cleanup({
5046
4860
  type: Message$1,
@@ -5049,7 +4863,6 @@ const getFirstNodeChildProcessEvent = async childProcess => {
5049
4863
  stderr
5050
4864
  });
5051
4865
  };
5052
- // @ts-ignore
5053
4866
  const handleExit = event => {
5054
4867
  cleanup({
5055
4868
  type: Exit,
@@ -5058,7 +4871,6 @@ const getFirstNodeChildProcessEvent = async childProcess => {
5058
4871
  stderr
5059
4872
  });
5060
4873
  };
5061
- // @ts-ignore
5062
4874
  const handleError = event => {
5063
4875
  cleanup({
5064
4876
  type: Error$2,
@@ -5184,7 +4996,6 @@ const create$1$1 = async ({
5184
4996
  env = process.env,
5185
4997
  execArgv = []
5186
4998
  }) => {
5187
- // @ts-ignore
5188
4999
  string(path);
5189
5000
  const actualArgv = ['--ipc-type=node-worker', ...argv];
5190
5001
  const actualEnv = {
@@ -5199,7 +5010,6 @@ const create$1$1 = async ({
5199
5010
  env: actualEnv,
5200
5011
  execArgv
5201
5012
  });
5202
- // @ts-ignore
5203
5013
  const {
5204
5014
  type,
5205
5015
  event
@@ -5216,9 +5026,6 @@ const create$1$1 = async ({
5216
5026
  return worker;
5217
5027
  };
5218
5028
  class IpcParentWithNodeWorker extends Ipc {
5219
- constructor(worker) {
5220
- super(worker);
5221
- }
5222
5029
  getData(message) {
5223
5030
  return message;
5224
5031
  }
@@ -5232,8 +5039,8 @@ class IpcParentWithNodeWorker extends Ipc {
5232
5039
  } = fixNodeWorkerParameters(message);
5233
5040
  this._rawIpc.postMessage(newValue, transfer);
5234
5041
  }
5235
- dispose() {
5236
- this._rawIpc.terminate();
5042
+ async dispose() {
5043
+ await this._rawIpc.terminate();
5237
5044
  }
5238
5045
  onClose(callback) {
5239
5046
  this._rawIpc.on('exit', callback);
@@ -5257,8 +5064,6 @@ const getModule$3 = method => {
5257
5064
  return IpcChildWithNodeForkedProcess$1;
5258
5065
  case NodeWorker$1:
5259
5066
  return IpcChildWithNodeWorker$1;
5260
- case WebSocket:
5261
- return IpcChildWithWebSocket;
5262
5067
  case ElectronUtilityProcess$1:
5263
5068
  return IpcChildWithElectronUtilityProcess$1;
5264
5069
  case ElectronMessagePort$1:
@@ -7214,55 +7019,9 @@ const isEnvSet = 'ELECTRON_IS_DEV' in env;
7214
7019
  const getFromEnv = Number.parseInt(env.ELECTRON_IS_DEV, 10) === 1;
7215
7020
  const isDev = isEnvSet ? getFromEnv : !Electron__default.app.isPackaged;
7216
7021
 
7217
- const index$1 = {
7218
- __proto__: null,
7219
- default: isDev
7220
- };
7221
-
7222
- // workaround for jest or node bug
7223
- const WebSocketServer = _ws.WebSocketServer ? _ws.WebSocketServer :
7224
- // @ts-ignore
7225
- _ws.default.WebSocketServer;
7226
- const webSocketServer = new WebSocketServer({
7227
- noServer: true
7228
-
7229
- // TODO not sure if ws compress is working at all
7230
- // perMessageDeflate: true
7231
- });
7232
- const withResolvers$1 = () => {
7233
- /**
7234
- * @type {any}
7235
- */
7236
- let _resolve;
7237
- /**
7238
- * @type {any}
7239
- */
7240
- let _reject;
7241
- const promise = new Promise((resolve, reject) => {
7242
- _resolve = resolve;
7243
- _reject = reject;
7244
- });
7245
- return {
7246
- resolve: _resolve,
7247
- reject: _reject,
7248
- promise
7249
- };
7250
- };
7251
- const handleUpgrade = (request, socket) => {
7252
- const {
7253
- promise,
7254
- resolve
7255
- } = withResolvers$1();
7256
- const upgradeCallback = ws => {
7257
- resolve(ws);
7258
- };
7259
- webSocketServer.handleUpgrade(request, socket, Buffer$1.alloc(0), upgradeCallback);
7260
- return promise;
7261
- };
7262
-
7263
7022
  const index = {
7264
7023
  __proto__: null,
7265
- handleUpgrade
7024
+ default: isDev
7266
7025
  };
7267
7026
 
7268
7027
  const Dash = '-';
@@ -7311,8 +7070,12 @@ const getByName = name => {
7311
7070
  return undefined;
7312
7071
  };
7313
7072
 
7314
- const create$1 = IpcParentWithElectronUtilityProcess$1$1.create;
7315
- const wrap = IpcParentWithElectronUtilityProcess$1$1.wrap;
7073
+ const {
7074
+ create: create$1
7075
+ } = IpcParentWithElectronUtilityProcess$1$1;
7076
+ const {
7077
+ wrap
7078
+ } = IpcParentWithElectronUtilityProcess$1$1;
7316
7079
  const effects = ({
7317
7080
  rawIpc,
7318
7081
  name
@@ -7320,7 +7083,9 @@ const effects = ({
7320
7083
  if (!rawIpc.pid) {
7321
7084
  return;
7322
7085
  }
7323
- const pid = rawIpc.pid;
7086
+ const {
7087
+ pid
7088
+ } = rawIpc;
7324
7089
  const formattedName = formatUtilityProcessName(name);
7325
7090
  add(pid, rawIpc, formattedName);
7326
7091
  const cleanup = () => {
@@ -7450,6 +7215,9 @@ const createElectronSession = () => {
7450
7215
  const state$2 = {
7451
7216
  session: undefined
7452
7217
  };
7218
+ const has = () => {
7219
+ return Boolean(state$2.session);
7220
+ };
7453
7221
  const get$1 = () => {
7454
7222
  if (!state$2.session) {
7455
7223
  throw new Error('session is not defined');
@@ -7477,7 +7245,7 @@ const create = ipc => {
7477
7245
  };
7478
7246
 
7479
7247
  const get = () => {
7480
- if (!get$1()) {
7248
+ if (!has()) {
7481
7249
  set$1(createElectronSession());
7482
7250
  }
7483
7251
  return get$1();
package/package.json CHANGED
@@ -1,23 +1,23 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-process",
3
- "version": "1.0.3",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
- "main": "dist/mainProcessMain.js",
6
- "type": "module",
7
5
  "keywords": [
8
6
  "lvce-editor",
9
7
  "electron"
10
8
  ],
11
- "author": "LVCE Editor",
12
- "license": "MIT",
13
9
  "repository": {
14
10
  "type": "git",
15
11
  "url": "https://github.com/lvce-editor/main-process.git"
16
12
  },
13
+ "license": "MIT",
14
+ "author": "LVCE Editor",
15
+ "type": "module",
16
+ "main": "dist/mainProcessMain.js",
17
+ "dependencies": {
18
+ "electron": "35.0.2"
19
+ },
17
20
  "engines": {
18
21
  "node": ">=22"
19
- },
20
- "dependencies": {
21
- "electron": "33.2.1"
22
22
  }
23
23
  }