@cordy/electro-cli 1.2.1 → 1.2.2

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 +39 -2
  2. package/package.json +4 -4
package/dist/index.mjs CHANGED
@@ -490,7 +490,7 @@ const cac = (name = "") => new CAC(name);
490
490
 
491
491
  //#endregion
492
492
  //#region package.json
493
- var version$1 = "1.2.1";
493
+ var version$1 = "1.2.2";
494
494
 
495
495
  //#endregion
496
496
  //#region src/dev/logger.ts
@@ -838,6 +838,43 @@ function resolveSourcemap$1(mode) {
838
838
  if (mode === "none") return false;
839
839
  return true;
840
840
  }
841
+ /**
842
+ * Vite plugin: rewrite static ESM `import { X } from "electron"` into CJS require().
843
+ *
844
+ * Electron's npm package is CJS. Node's ESM-CJS interop cannot detect all
845
+ * named exports, so `import { Menu } from "electron"` fails at runtime.
846
+ * This plugin post-processes the rendered chunk and replaces such imports
847
+ * with `createRequire`-based require() calls.
848
+ */
849
+ function electronCjsCompat() {
850
+ return {
851
+ name: "electro:electron-cjs-compat",
852
+ renderChunk(code) {
853
+ const re = /^import\s+(.+?)\s+from\s+"(electron(?:\/\w+)?)"\s*;\s*$/gm;
854
+ if (!re.test(code)) return null;
855
+ re.lastIndex = 0;
856
+ let result = code;
857
+ let match;
858
+ while ((match = re.exec(code)) !== null) {
859
+ const [full, clause, specifier] = match;
860
+ const named = clause.match(/\{([^}]+)\}/)?.[1];
861
+ const def = clause.match(/^(\w+)/);
862
+ const hasDefault = def && !clause.startsWith("{");
863
+ const tag = specifier.replace(/\//g, "_");
864
+ const lines = [`import { createRequire as __cr_${tag} } from "node:module";`, `var __${tag} = __cr_${tag}(import.meta.url)("${specifier}");`];
865
+ if (hasDefault && !named) lines.push(`var ${def[1]} = __${tag};`);
866
+ if (hasDefault && named) lines.push(`var ${def[1].replace(/,\s*$/, "").trim()} = __${tag};`);
867
+ if (named) for (const n of named.split(",").map((s) => s.trim()).filter(Boolean)) {
868
+ const alias = n.match(/^(\w+)\s+as\s+(\w+)$/);
869
+ if (alias) lines.push(`var ${alias[2]} = __${tag}.${alias[1]};`);
870
+ else lines.push(`var ${n} = __${tag}.${n};`);
871
+ }
872
+ result = result.replace(full, lines.join("\n"));
873
+ }
874
+ return result;
875
+ }
876
+ };
877
+ }
841
878
  function createNodeConfig(opts) {
842
879
  const resolveConditions = opts.scope === "preload" ? [
843
880
  "node",
@@ -848,7 +885,7 @@ function createNodeConfig(opts) {
848
885
  const config = {
849
886
  configFile: false,
850
887
  root: opts.root,
851
- plugins: opts.plugins ?? [],
888
+ plugins: [electronCjsCompat(), ...opts.plugins ?? []],
852
889
  customLogger: opts.customLogger,
853
890
  envPrefix,
854
891
  define: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cordy/electro-cli",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
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.1",
50
+ "@cordy/electro": "1.2.2",
51
51
  "electron": ">=40.4.1",
52
52
  "vite": ">=8.0.0"
53
53
  },
54
54
  "dependencies": {
55
- "@cordy/electro-generator": "1.2.1"
55
+ "@cordy/electro-generator": "1.2.2"
56
56
  },
57
57
  "devDependencies": {
58
- "@cordy/electro": "1.2.1",
58
+ "@cordy/electro": "1.2.2",
59
59
  "@types/node": "^25.2.3",
60
60
  "cac": "^6.7.14",
61
61
  "electron": "^40.4.1",