cicy-desktop 2.1.86 → 2.1.87
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.
- package/bin/cicy-desktop +50 -26
- package/package.json +1 -1
package/bin/cicy-desktop
CHANGED
|
@@ -40,41 +40,65 @@ function globalElectronBin() {
|
|
|
40
40
|
return _globalElectronBin;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
// Pinned electron version = the one cicy-desktop is built against (package.json
|
|
44
|
+
// dependency). NEVER install "latest": its native extract-zip prebuild is
|
|
45
|
+
// unpublished for win32-x64 → `npm i -g electron` dies with "Cannot find native
|
|
46
|
+
// binding". 41.x downloads fine.
|
|
47
|
+
const ELECTRON_VERSION = (() => {
|
|
48
|
+
try {
|
|
49
|
+
const pj = require("../package.json");
|
|
50
|
+
const v = (pj.dependencies && pj.dependencies.electron) ||
|
|
51
|
+
(pj.devDependencies && pj.devDependencies.electron) || "";
|
|
52
|
+
return String(v).replace(/^[\^~>=\s]*/, "").trim() || "41.0.3";
|
|
53
|
+
} catch { return "41.0.3"; }
|
|
54
|
+
})();
|
|
55
|
+
|
|
56
|
+
// True iff <electronDir> has a downloaded, runnable binary (path.txt → dist/exe).
|
|
57
|
+
function electronBinaryHealthy(electronDir) {
|
|
58
|
+
if (!electronDir) return false;
|
|
59
|
+
try {
|
|
60
|
+
const exe = fs.readFileSync(path.join(electronDir, "path.txt"), "utf8").trim();
|
|
61
|
+
return !!exe && fs.existsSync(path.join(electronDir, "dist", exe));
|
|
62
|
+
} catch { return false; }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// The GLOBAL electron's package dir for the current npm prefix (null if none).
|
|
66
|
+
function globalElectronDir() {
|
|
67
|
+
try {
|
|
68
|
+
const prefix = execSync("npm prefix -g", { stdio: ["ignore", "pipe", "ignore"] }).toString().trim();
|
|
69
|
+
if (!prefix) return null;
|
|
70
|
+
return isWindows
|
|
71
|
+
? path.join(prefix, "node_modules", "electron") // win: <prefix>\node_modules\electron
|
|
72
|
+
: path.join(prefix, "lib", "node_modules", "electron"); // unix: <prefix>/lib/node_modules/electron
|
|
73
|
+
} catch { return null; }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Make sure a USABLE electron exists before spawning the worker. Prefer a shared
|
|
77
|
+
// GLOBAL electron (downloaded once, survives npx-cache eviction, and
|
|
78
|
+
// resolveElectronSpawn() picks it first). If nothing healthy is found anywhere,
|
|
79
|
+
// auto-install the PINNED version GLOBALLY with the npmmirror mirror — i.e. do the
|
|
80
|
+
// `npm i -g electron@<pin>` step for the user, so a fresh `npx cicy-desktop`
|
|
81
|
+
// self-provisions electron and starts first-try. Runs once per process.
|
|
52
82
|
let _electronEnsured = false;
|
|
53
83
|
function ensureElectron() {
|
|
54
84
|
if (_electronEnsured) return;
|
|
55
85
|
_electronEnsured = true;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (exe && fs.existsSync(path.join(electronDir, "dist", exe))) return; // healthy
|
|
64
|
-
}
|
|
65
|
-
} catch {}
|
|
66
|
-
const installJs = path.join(electronDir, "install.js");
|
|
67
|
-
if (!fs.existsSync(installJs)) return;
|
|
68
|
-
console.log("⚙️ Electron binary missing — repairing via electron/install.js (mirror)…");
|
|
86
|
+
// Already usable (global, or the resolvable bundled/npx copy)? nothing to do.
|
|
87
|
+
if (electronBinaryHealthy(globalElectronDir())) return;
|
|
88
|
+
let bundledDir = null;
|
|
89
|
+
try { bundledDir = path.dirname(require.resolve("electron/package.json", { paths: [PACKAGE_ROOT] })); } catch {}
|
|
90
|
+
if (electronBinaryHealthy(bundledDir)) return;
|
|
91
|
+
// None usable → install the pinned electron globally (with the mirror).
|
|
92
|
+
console.log(`⚙️ No usable Electron — installing electron@${ELECTRON_VERSION} -g (mirror), one-time…`);
|
|
69
93
|
try {
|
|
70
|
-
execSync(`
|
|
71
|
-
cwd: electronDir,
|
|
94
|
+
execSync(`npm i -g electron@${ELECTRON_VERSION} --registry=${NPM_REGISTRY}`, {
|
|
72
95
|
stdio: "inherit",
|
|
73
96
|
env: { ...process.env, ELECTRON_MIRROR, npm_config_registry: NPM_REGISTRY },
|
|
74
97
|
});
|
|
98
|
+
_globalElectronBin = undefined; // bust the memo so resolveElectronSpawn re-finds the new global bin
|
|
75
99
|
} catch (e) {
|
|
76
|
-
console.warn(`⚠️
|
|
77
|
-
console.warn(` Fix manually: set ELECTRON_MIRROR=${ELECTRON_MIRROR} && npm i -g electron
|
|
100
|
+
console.warn(`⚠️ Global electron install failed: ${e.message}`);
|
|
101
|
+
console.warn(` Fix manually: set ELECTRON_MIRROR=${ELECTRON_MIRROR} && npm i -g electron@${ELECTRON_VERSION}`);
|
|
78
102
|
}
|
|
79
103
|
}
|
|
80
104
|
|