@cordy/electro-cli 1.2.13 → 1.2.16

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 (2) hide show
  1. package/dist/index.mjs +38 -3
  2. package/package.json +4 -4
package/dist/index.mjs CHANGED
@@ -491,7 +491,7 @@ const cac = (name = "") => new CAC(name);
491
491
 
492
492
  //#endregion
493
493
  //#region package.json
494
- var version$1 = "1.2.13";
494
+ var version$1 = "1.2.16";
495
495
 
496
496
  //#endregion
497
497
  //#region src/dev/logger.ts
@@ -3039,7 +3039,7 @@ async function buildMain(args) {
3039
3039
  id: v.name,
3040
3040
  hasRenderer: !!v.entry,
3041
3041
  features: v.features ?? [],
3042
- webPreferences: v.webPreferences ?? {}
3042
+ webPreferences: sanitizeRuntimeWebPreferences$1(v.webPreferences)
3043
3043
  }));
3044
3044
  await build(createNodeConfig({
3045
3045
  scope: "main",
@@ -3116,6 +3116,11 @@ async function buildPreload(args) {
3116
3116
  };
3117
3117
  await build(baseConfig);
3118
3118
  }
3119
+ function sanitizeRuntimeWebPreferences$1(webPreferences) {
3120
+ const prefs = { ...webPreferences ?? {} };
3121
+ delete prefs.preload;
3122
+ return prefs;
3123
+ }
3119
3124
  /**
3120
3125
  * Flatten renderer HTML output from source-relative paths
3121
3126
  * (e.g., `src/windows/main/index.html`) to `{name}/index.html`.
@@ -3174,6 +3179,8 @@ var DevServer = class {
3174
3179
  nodeFormat = "es";
3175
3180
  mainInitialBuildPromise = null;
3176
3181
  resolveMainInitialBuild = null;
3182
+ preloadInitialBuildPromise = null;
3183
+ resolvePreloadInitialBuild = null;
3177
3184
  logLevel;
3178
3185
  clearScreen;
3179
3186
  rendererOnly;
@@ -3265,6 +3272,7 @@ var DevServer = class {
3265
3272
  }
3266
3273
  const electronTimer = startTimer();
3267
3274
  try {
3275
+ await this.waitForPreloadInitialBuild();
3268
3276
  await this.waitForMainInitialBuild();
3269
3277
  await this.attachElectronProcess();
3270
3278
  step("electron", electronTimer());
@@ -3296,6 +3304,8 @@ var DevServer = class {
3296
3304
  this.preloadWatch = null;
3297
3305
  this.resolveMainInitialBuild = null;
3298
3306
  this.mainInitialBuildPromise = null;
3307
+ this.resolvePreloadInitialBuild = null;
3308
+ this.preloadInitialBuildPromise = null;
3299
3309
  if (this.mainRestartFlushTimer) {
3300
3310
  clearTimeout(this.mainRestartFlushTimer);
3301
3311
  this.mainRestartFlushTimer = null;
@@ -3362,6 +3372,12 @@ var DevServer = class {
3362
3372
  async buildPreload(externals, cjsInteropDeps) {
3363
3373
  const views = (this.config.views ?? []).filter((v) => v.entry);
3364
3374
  const preloadOutDir = resolve(this.outputDir, "preload");
3375
+ this.preloadInitialBuildPromise = new Promise((resolve) => {
3376
+ this.resolvePreloadInitialBuild = () => {
3377
+ resolve();
3378
+ this.resolvePreloadInitialBuild = null;
3379
+ };
3380
+ });
3365
3381
  const input = {};
3366
3382
  for (const view of views) input[view.name] = resolve(this.outputDir, `generated/preload/${view.name}.gen.ts`);
3367
3383
  const firstEntry = Object.values(input)[0];
@@ -3419,6 +3435,7 @@ var DevServer = class {
3419
3435
  closeBundle() {
3420
3436
  if (firstBuild) {
3421
3437
  firstBuild = false;
3438
+ self.resolvePreloadInitialBuild?.();
3422
3439
  return;
3423
3440
  }
3424
3441
  if (self.rendererServer) self.rendererServer.ws.send({ type: "full-reload" });
@@ -3439,7 +3456,7 @@ var DevServer = class {
3439
3456
  id: v.name,
3440
3457
  hasRenderer: !!v.entry,
3441
3458
  features: v.features ?? [],
3442
- webPreferences: v.webPreferences ?? {}
3459
+ webPreferences: sanitizeRuntimeWebPreferences(v.webPreferences)
3443
3460
  }));
3444
3461
  const mainConfig = createNodeConfig({
3445
3462
  scope: "main",
@@ -3503,6 +3520,19 @@ var DevServer = class {
3503
3520
  this.mainInitialBuildPromise = null;
3504
3521
  await Promise.race([promise, timeout]);
3505
3522
  }
3523
+ /**
3524
+ * Wait until the initial preload watch build has completed.
3525
+ * Prevents launching Electron before `window.electro` bridge is injected.
3526
+ */
3527
+ async waitForPreloadInitialBuild() {
3528
+ if (!this.preloadInitialBuildPromise) return;
3529
+ const timeout = setTimeout$1(MAIN_ENTRY_WAIT_TIMEOUT_MS).then(() => {
3530
+ throw new Error(`Preload initial build did not finish in ${MAIN_ENTRY_WAIT_TIMEOUT_MS}ms.`);
3531
+ });
3532
+ const promise = this.preloadInitialBuildPromise;
3533
+ this.preloadInitialBuildPromise = null;
3534
+ await Promise.race([promise, timeout]);
3535
+ }
3506
3536
  async attachElectronProcess() {
3507
3537
  const mainEntry = await this.waitForMainEntry();
3508
3538
  const env = { ELECTRO_DEV: "true" };
@@ -3628,6 +3658,11 @@ async function writeFileIfChanged$1(filePath, content) {
3628
3658
  } catch {}
3629
3659
  await writeFile(filePath, content);
3630
3660
  }
3661
+ function sanitizeRuntimeWebPreferences(webPreferences) {
3662
+ const prefs = { ...webPreferences ?? {} };
3663
+ delete prefs.preload;
3664
+ return prefs;
3665
+ }
3631
3666
 
3632
3667
  //#endregion
3633
3668
  //#region src/commands/dev.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cordy/electro-cli",
3
- "version": "1.2.13",
3
+ "version": "1.2.16",
4
4
  "description": "CLI for @cordy/electro — dev server, build, and code generation commands",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -47,15 +47,15 @@
47
47
  "prepublishOnly": "bun run build"
48
48
  },
49
49
  "peerDependencies": {
50
- "@cordy/electro": "1.2.8",
50
+ "@cordy/electro": "1.2.16",
51
51
  "electron": ">=40.4.1",
52
52
  "vite": ">=8.0.0"
53
53
  },
54
54
  "dependencies": {
55
- "@cordy/electro-generator": "1.2.8"
55
+ "@cordy/electro-generator": "1.2.16"
56
56
  },
57
57
  "devDependencies": {
58
- "@cordy/electro": "1.2.9",
58
+ "@cordy/electro": "1.2.16",
59
59
  "@types/node": "^25.2.3",
60
60
  "cac": "^6.7.14",
61
61
  "electron": "^40.4.1",