@lvce-editor/main-process 6.24.0 → 6.25.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.
@@ -9,6 +9,7 @@ import { mkdirSync, createWriteStream, readFileSync, openAsBlob, existsSync, wri
9
9
  import * as NodePath from 'node:path';
10
10
  import { dirname, join as join$1, isAbsolute } from 'node:path';
11
11
  import { homedir, tmpdir } from 'node:os';
12
+ import { readFile } from 'node:fs/promises';
12
13
  import { pbkdf2Sync, createDecipheriv, createHash } from 'node:crypto';
13
14
  import { DatabaseSync } from 'node:sqlite';
14
15
  import { MessageChannel } from 'node:worker_threads';
@@ -796,11 +797,15 @@ const isProduction = false;
796
797
  const homeDirectory = homedir();
797
798
 
798
799
  const xdgCache = env.XDG_CACHE_HOME || (homeDirectory ? join(homeDirectory, '.cache') : undefined);
800
+ const xdgConfig = env.XDG_CONFIG_HOME || (homeDirectory ? join(homeDirectory, '.config') : undefined);
799
801
  const xdgData = env.XDG_DATA_HOME || (homeDirectory ? join(homeDirectory, '.local', 'share') : undefined);
800
802
  join(xdgData || tmpdir(), applicationName);
801
803
  const xdgState = env.XDG_STATE_HOME || (homeDirectory ? join(homeDirectory, '.local', 'state') : undefined);
802
804
  const logsDir = join(xdgState || tmpdir(), applicationName, 'logs');
803
805
  const chromeUserDataPath = xdgCache ? join(xdgCache, applicationName, 'userdata') : '';
806
+ const getArgvConfigPath = () => {
807
+ return join(xdgConfig || tmpdir(), applicationName, 'argv.json');
808
+ };
804
809
 
805
810
  const useIpcForResponse = true;
806
811
  const getSessionId = () => {
@@ -1598,7 +1603,7 @@ const Array$1 = 3;
1598
1603
  const String$1 = 4;
1599
1604
  const Boolean$1 = 5;
1600
1605
  const Function$1 = 6;
1601
- const Null = 7;
1606
+ const Null$1 = 7;
1602
1607
  const Unknown$1 = 8;
1603
1608
  const getType = value => {
1604
1609
  switch (typeof value) {
@@ -1610,7 +1615,7 @@ const getType = value => {
1610
1615
  return String$1;
1611
1616
  case 'object':
1612
1617
  if (value === null) {
1613
- return Null;
1618
+ return Null$1;
1614
1619
  }
1615
1620
  if (Array.isArray(value)) {
1616
1621
  return Array$1;
@@ -2814,7 +2819,7 @@ const execute$1 = (command, ...args) => {
2814
2819
  return fn(...args);
2815
2820
  };
2816
2821
 
2817
- const Two$1 = '2.0';
2822
+ const Two$2 = '2.0';
2818
2823
  const callbacks = Object.create(null);
2819
2824
  const set$2 = (id, fn) => {
2820
2825
  callbacks[id] = fn;
@@ -2850,7 +2855,7 @@ const create$2$1 = (method, params) => {
2850
2855
  } = registerPromise$1();
2851
2856
  const message = {
2852
2857
  id,
2853
- jsonrpc: Two$1,
2858
+ jsonrpc: Two$2,
2854
2859
  method,
2855
2860
  params
2856
2861
  };
@@ -3097,7 +3102,7 @@ const create$1$1 = (id, error) => {
3097
3102
  return {
3098
3103
  error,
3099
3104
  id,
3100
- jsonrpc: Two$1
3105
+ jsonrpc: Two$2
3101
3106
  };
3102
3107
  };
3103
3108
  const getErrorResponse = (id, error, preparePrettyError, logError) => {
@@ -3109,7 +3114,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
3109
3114
  const create$9 = (message, result) => {
3110
3115
  return {
3111
3116
  id: message.id,
3112
- jsonrpc: Two$1,
3117
+ jsonrpc: Two$2,
3113
3118
  result: result ?? null
3114
3119
  };
3115
3120
  };
@@ -3126,7 +3131,7 @@ const getErrorResponseSimple = (id, error) => {
3126
3131
  message: error.message
3127
3132
  },
3128
3133
  id,
3129
- jsonrpc: Two$1
3134
+ jsonrpc: Two$2
3130
3135
  };
3131
3136
  };
3132
3137
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
@@ -3223,11 +3228,11 @@ const invokeAndTransfer$1 = (ipc, method, ...params) => {
3223
3228
  return invokeHelper$1(ipc, method, params);
3224
3229
  };
3225
3230
 
3226
- const Two = '2.0';
3231
+ const Two$1 = '2.0';
3227
3232
 
3228
3233
  const create$8 = (method, params) => {
3229
3234
  return {
3230
- jsonrpc: Two,
3235
+ jsonrpc: Two$1,
3231
3236
  method,
3232
3237
  params
3233
3238
  };
@@ -3236,7 +3241,7 @@ const create$8 = (method, params) => {
3236
3241
  const create$7 = (id, method, params) => {
3237
3242
  const message = {
3238
3243
  id,
3239
- jsonrpc: Two,
3244
+ jsonrpc: Two$1,
3240
3245
  method,
3241
3246
  params
3242
3247
  };
@@ -3408,13 +3413,13 @@ const create$3 = async ({
3408
3413
  const commandMapRef = Object.create(null);
3409
3414
 
3410
3415
  const Dash = '-';
3411
- const Space$2 = ' ';
3416
+ const Space$3 = ' ';
3412
3417
 
3413
3418
  const firstLetterLowerCase = string => {
3414
3419
  return string[0].toLowerCase() + string.slice(1);
3415
3420
  };
3416
3421
  const camelCase = string => {
3417
- const parts = string.split(Space$2);
3422
+ const parts = string.split(Space$3);
3418
3423
  const lowerParts = parts.map(firstLetterLowerCase);
3419
3424
  return lowerParts.join(Dash);
3420
3425
  };
@@ -3490,7 +3495,10 @@ const getPortTuple = () => {
3490
3495
  };
3491
3496
  };
3492
3497
 
3493
- const getSharedProcessArgv = isProduction => {
3498
+ const getSharedProcessArgv = argv => {
3499
+ return argv.slice(1);
3500
+ };
3501
+ const getSharedProcessExecArgv = isProduction => {
3494
3502
  return [];
3495
3503
  };
3496
3504
 
@@ -3553,13 +3561,14 @@ const launchSharedProcess = async ({
3553
3561
  }) => {
3554
3562
  mark(WillStartSharedProcess);
3555
3563
  const sharedProcessPath = getSharedProcessPath();
3556
- const execArgv = getSharedProcessArgv();
3564
+ const argv = getSharedProcessArgv(getArgv());
3565
+ const execArgv = getSharedProcessExecArgv();
3557
3566
  const fullEnv = {
3558
3567
  ...process.env,
3559
3568
  ...env
3560
3569
  };
3561
3570
  const sharedProcessRpc = await createElectronUtilityProcessRpc({
3562
- argv: [],
3571
+ argv,
3563
3572
  commandMap: commandMapRef,
3564
3573
  env: fullEnv,
3565
3574
  execArgv,
@@ -3654,7 +3663,7 @@ const CliForwardToSharedProcess = {
3654
3663
  };
3655
3664
 
3656
3665
  const SharedProcess = 4;
3657
- const None = 0;
3666
+ const None$1 = 0;
3658
3667
 
3659
3668
  const on = (event, listener) => {
3660
3669
  app.on(event, listener);
@@ -3687,7 +3696,7 @@ const getCliModuleId = parsedArgs => {
3687
3696
  if (arg0 === Install || arg0 === List || arg0 === Link || arg0 === Unlink || parsedArgs[Status] || parsedArgs[Version] || parsedArgs[Help] || parsedArgs[Web] || parsedArgs[BuiltinSelfTest]) {
3688
3697
  return SharedProcess;
3689
3698
  }
3690
- return None;
3699
+ return None$1;
3691
3700
  };
3692
3701
 
3693
3702
  const getModule$3 = moduleId => {
@@ -4278,6 +4287,378 @@ const hydrate = async (isLinux, chromeUserDataPath, argv) => {
4278
4287
  const {
4279
4288
  argv
4280
4289
  } = process;
4290
+ const getInsertionIndex = () => {
4291
+ if (argv[0].endsWith('dist/electron') || argv[0].endsWith('dist\\electron.exe')) {
4292
+ return 2;
4293
+ }
4294
+ return 1;
4295
+ };
4296
+ const prepend = argumentsToPrepend => {
4297
+ argv.splice(getInsertionIndex(), 0, ...argumentsToPrepend);
4298
+ };
4299
+
4300
+ const CurlyOpen$1 = '{'.charCodeAt(0);
4301
+ const CurlyClose$1 = '}'.charCodeAt(0);
4302
+ const SquareOpen$1 = '['.charCodeAt(0);
4303
+ const SquareClose$1 = ']'.charCodeAt(0);
4304
+ const DoubleQuote$1 = '"'.charCodeAt(0);
4305
+ const Comma$1$1 = ','.charCodeAt(0);
4306
+ const Zero = '0'.charCodeAt(0);
4307
+ const One = '1'.charCodeAt(0);
4308
+ const Two = '2'.charCodeAt(0);
4309
+ const Three = '3'.charCodeAt(0);
4310
+ const Four = '4'.charCodeAt(0);
4311
+ const Five = '5'.charCodeAt(0);
4312
+ const Six = '6'.charCodeAt(0);
4313
+ const Seven = '7'.charCodeAt(0);
4314
+ const Eight = '8'.charCodeAt(0);
4315
+ const Nine = '9'.charCodeAt(0);
4316
+ const Dot = '.'.charCodeAt(0);
4317
+ const CarriageReturn = '\r'.charCodeAt(0);
4318
+ const LineFeed = '\n'.charCodeAt(0);
4319
+ const Space$2 = ' '.charCodeAt(0);
4320
+ const Tab$2 = '\t'.charCodeAt(0);
4321
+ const Slash$1$1 = '/'.charCodeAt(0);
4322
+ const Star$2 = '*'.charCodeAt(0);
4323
+ const None = 0;
4324
+ const CurlyOpen = 1;
4325
+ const CurlyClose = 2;
4326
+ const Eof = 3;
4327
+ const SquareOpen = 4;
4328
+ const SquareClose = 5;
4329
+ const DoubleQuote = 6;
4330
+ const Comma$2 = 7;
4331
+ const Numeric = 8;
4332
+ const Slash$2 = 9;
4333
+ const Literal = 10;
4334
+ const createScanner = text => {
4335
+ let offset = 0;
4336
+ const length = text.length;
4337
+ const scanValue = () => {
4338
+ while (offset < length) {
4339
+ const code = text.charCodeAt(offset);
4340
+ switch (code) {
4341
+ case CurlyOpen$1:
4342
+ offset++;
4343
+ return CurlyOpen;
4344
+ case CurlyClose$1:
4345
+ offset++;
4346
+ return CurlyClose;
4347
+ case SquareOpen$1:
4348
+ offset++;
4349
+ return SquareOpen;
4350
+ case SquareClose$1:
4351
+ offset++;
4352
+ return SquareClose;
4353
+ case DoubleQuote$1:
4354
+ offset++;
4355
+ return DoubleQuote;
4356
+ case Comma$1$1:
4357
+ offset++;
4358
+ return Comma$2;
4359
+ case Zero:
4360
+ case One:
4361
+ case Two:
4362
+ case Three:
4363
+ case Four:
4364
+ case Five:
4365
+ case Six:
4366
+ case Seven:
4367
+ case Eight:
4368
+ case Nine:
4369
+ case Dot:
4370
+ offset++;
4371
+ return Numeric;
4372
+ case CarriageReturn:
4373
+ case LineFeed:
4374
+ case Tab$2:
4375
+ case Space$2:
4376
+ offset++;
4377
+ break;
4378
+ case Slash$1$1:
4379
+ return Slash$2;
4380
+ default:
4381
+ return Literal;
4382
+ }
4383
+ }
4384
+ return Eof;
4385
+ };
4386
+ const scanString = () => {
4387
+ while (offset < length) {
4388
+ const code = text.charCodeAt(offset);
4389
+ if (code === DoubleQuote$1) {
4390
+ break;
4391
+ }
4392
+ offset++;
4393
+ }
4394
+ offset++;
4395
+ const start = offset;
4396
+ while (offset < length) {
4397
+ const code = text.charCodeAt(offset);
4398
+ if (code === DoubleQuote$1) {
4399
+ break;
4400
+ }
4401
+ offset++;
4402
+ }
4403
+ const result = text.slice(start, offset);
4404
+ offset++;
4405
+ return result;
4406
+ };
4407
+ const scanPropertyName = () => {
4408
+ return scanString();
4409
+ };
4410
+ const scanPropertyColon = () => {
4411
+ text.charCodeAt(offset);
4412
+ offset++;
4413
+ };
4414
+ const goBack = delta => {
4415
+ offset -= delta;
4416
+ };
4417
+ const scanNumber = () => {
4418
+ const start = offset;
4419
+ outer: while (offset < length) {
4420
+ const code = text.charCodeAt(offset);
4421
+ switch (code) {
4422
+ case Zero:
4423
+ case One:
4424
+ case Two:
4425
+ case Three:
4426
+ case Four:
4427
+ case Five:
4428
+ case Six:
4429
+ case Seven:
4430
+ case Eight:
4431
+ case Nine:
4432
+ case Dot:
4433
+ break;
4434
+ default:
4435
+ break outer;
4436
+ }
4437
+ offset++;
4438
+ }
4439
+ const result = text.slice(start, offset);
4440
+ return result;
4441
+ };
4442
+ const scanLiteral = () => {
4443
+ const start = offset;
4444
+ outer: while (offset < length) {
4445
+ const code = text.charCodeAt(offset);
4446
+ switch (code) {
4447
+ case LineFeed:
4448
+ case CarriageReturn:
4449
+ case Tab$2:
4450
+ case Space$2:
4451
+ case Comma$1$1:
4452
+ break outer;
4453
+ }
4454
+ offset++;
4455
+ }
4456
+ const result = text.slice(start, offset);
4457
+ return result;
4458
+ };
4459
+ const scanBlockComment = () => {
4460
+ while (offset < length) {
4461
+ if (text.charCodeAt(offset) === Star$2 && text.charCodeAt(offset + 1) === Slash$1$1) {
4462
+ break;
4463
+ }
4464
+ offset++;
4465
+ }
4466
+ };
4467
+ const scanLineComment = () => {
4468
+ while (offset < length) {
4469
+ const code = text.charCodeAt(offset);
4470
+ if (code === LineFeed) {
4471
+ break;
4472
+ }
4473
+ offset++;
4474
+ }
4475
+ };
4476
+ const scanComment = () => {
4477
+ const code = text.charCodeAt(offset);
4478
+ switch (code) {
4479
+ case Star$2:
4480
+ return scanBlockComment();
4481
+ case Slash$1$1:
4482
+ return scanLineComment();
4483
+ }
4484
+ };
4485
+ return {
4486
+ scanValue,
4487
+ scanPropertyName,
4488
+ scanPropertyColon,
4489
+ scanString,
4490
+ scanNumber,
4491
+ goBack,
4492
+ scanLiteral,
4493
+ scanComment,
4494
+ getOffset() {
4495
+ return offset;
4496
+ }
4497
+ };
4498
+ };
4499
+ const parseComment = scanner => {
4500
+ scanner.scanComment();
4501
+ };
4502
+ const True = 'true';
4503
+ const False = 'false';
4504
+ const Null = 'null';
4505
+ const parseLiteral = scanner => {
4506
+ const rawValue = scanner.scanLiteral();
4507
+ switch (rawValue) {
4508
+ case True:
4509
+ return true;
4510
+ case False:
4511
+ return false;
4512
+ case Null:
4513
+ return null;
4514
+ default:
4515
+ return undefined;
4516
+ }
4517
+ };
4518
+ const parseNumber = scanner => {
4519
+ scanner.goBack(1);
4520
+ const rawValue = scanner.scanNumber();
4521
+ const value = Number.parseFloat(rawValue);
4522
+ return value;
4523
+ };
4524
+ const parsePropertyColon = scanner => {
4525
+ scanner.scanPropertyColon();
4526
+ };
4527
+ const parsePropertyName = scanner => {
4528
+ const propertyName = scanner.scanPropertyName();
4529
+ return propertyName;
4530
+ };
4531
+ const parseString = scanner => {
4532
+ scanner.goBack(1);
4533
+ const value = scanner.scanString();
4534
+ return value;
4535
+ };
4536
+ const parseObject = scanner => {
4537
+ const object = {};
4538
+ outer: while (true) {
4539
+ const token = scanner.scanValue();
4540
+ switch (token) {
4541
+ case Eof:
4542
+ case None:
4543
+ case CurlyClose:
4544
+ break outer;
4545
+ case DoubleQuote:
4546
+ scanner.goBack(1);
4547
+ const propertyName = parsePropertyName(scanner);
4548
+ parsePropertyColon(scanner);
4549
+ const value = parseValue(scanner);
4550
+ object[propertyName] = value;
4551
+ case Comma$2:
4552
+ break;
4553
+ case Slash$2:
4554
+ parseComment(scanner);
4555
+ break;
4556
+ case Literal:
4557
+ parseLiteral(scanner);
4558
+ break;
4559
+ }
4560
+ }
4561
+ return object;
4562
+ };
4563
+ const parseArray = scanner => {
4564
+ const array = [];
4565
+ outer: while (true) {
4566
+ const token = scanner.scanValue();
4567
+ switch (token) {
4568
+ case Eof:
4569
+ case None:
4570
+ case SquareClose:
4571
+ break outer;
4572
+ case Slash$2:
4573
+ scanner.scanComment();
4574
+ break;
4575
+ case Comma$2:
4576
+ break;
4577
+ default:
4578
+ scanner.goBack(1);
4579
+ const value = parseValue(scanner);
4580
+ array.push(value);
4581
+ break;
4582
+ }
4583
+ }
4584
+ return array;
4585
+ };
4586
+ const parseValue = scanner => {
4587
+ const token = scanner.scanValue();
4588
+ switch (token) {
4589
+ case CurlyOpen:
4590
+ return parseObject(scanner);
4591
+ case DoubleQuote:
4592
+ return parseString(scanner);
4593
+ case Numeric:
4594
+ return parseNumber(scanner);
4595
+ case SquareOpen:
4596
+ return parseArray(scanner);
4597
+ case Literal:
4598
+ return parseLiteral(scanner);
4599
+ case Slash$2:
4600
+ parseComment(scanner);
4601
+ return parseValue(scanner);
4602
+ default:
4603
+ return undefined;
4604
+ }
4605
+ };
4606
+ const parse = text => {
4607
+ const scanner = createScanner(text);
4608
+ const result = parseValue(scanner);
4609
+ return result;
4610
+ };
4611
+
4612
+ // @ts-ignore
4613
+ const appliedEnvironmentVariable = 'LVCE_ARGV_CONFIG_APPLIED';
4614
+ const keyPattern = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
4615
+ const getArgument = (key, value) => {
4616
+ return `--${key}=${value}`;
4617
+ };
4618
+ const getArgumentsForValue = (key, value) => {
4619
+ if (value === true) {
4620
+ return [`--${key}`];
4621
+ }
4622
+ if (value === false) {
4623
+ return [];
4624
+ }
4625
+ if (typeof value === 'string' || typeof value === 'number') {
4626
+ return [getArgument(key, value)];
4627
+ }
4628
+ if (Array.isArray(value) && value.every(item => typeof item === 'string' || typeof item === 'number')) {
4629
+ return value.map(item => getArgument(key, item));
4630
+ }
4631
+ throw new TypeError(`Invalid argv.json value for "${key}": expected a boolean, string, number, or array of strings and numbers`);
4632
+ };
4633
+ const parseArgvConfig = content => {
4634
+ const config = parse(content);
4635
+ if (!config || typeof config !== 'object' || Array.isArray(config)) {
4636
+ throw new TypeError('Invalid argv.json: expected an object');
4637
+ }
4638
+ const argumentsFromConfig = [];
4639
+ for (const [key, value] of Object.entries(config)) {
4640
+ if (!keyPattern.test(key)) {
4641
+ throw new TypeError(`Invalid argv.json key "${key}"`);
4642
+ }
4643
+ argumentsFromConfig.push(...getArgumentsForValue(key, value));
4644
+ }
4645
+ return argumentsFromConfig;
4646
+ };
4647
+ const load = async (path, env = process.env) => {
4648
+ if (env[appliedEnvironmentVariable] === '1') {
4649
+ return [];
4650
+ }
4651
+ env[appliedEnvironmentVariable] = '1';
4652
+ try {
4653
+ const content = await readFile(path, 'utf8');
4654
+ return parseArgvConfig(content);
4655
+ } catch (error) {
4656
+ if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
4657
+ return [];
4658
+ }
4659
+ throw error;
4660
+ }
4661
+ };
4281
4662
 
4282
4663
  const accessControlAllowOrigin = 'access-control-allow-origin';
4283
4664
  const getCorsResponseHeaders = (responseHeaders = {}) => {
@@ -7504,6 +7885,8 @@ const setStackTraceLimit = value => {
7504
7885
  // @ts-ignore
7505
7886
  performance.mark('code/start');
7506
7887
  const main = async () => {
7888
+ const configArguments = await load(getArgvConfigPath());
7889
+ prepend(configArguments);
7507
7890
  Object.assign(commandMapRef, commandMap);
7508
7891
  setStackTraceLimit(20);
7509
7892
  on$1('uncaughtExceptionMonitor', handleUncaughtExceptionMonitor);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-process",
3
- "version": "6.24.0",
3
+ "version": "6.25.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "electron"