forked from Haleclipse/CodexDesktop-Rebuild
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforge.config.js
More file actions
213 lines (200 loc) · 8.08 KB
/
Copy pathforge.config.js
File metadata and controls
213 lines (200 loc) · 8.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
const { FuseV1Options, FuseVersion } = require("@electron/fuses");
const path = require("path");
const fs = require("fs");
const { main: ensureElectronDist } = require("./scripts/ensure-electron-dist");
function hasRpmDatabase() {
if (process.env.FORGE_LINUX_RPM === "1") return true;
return fs.existsSync("/var/lib/rpm/Packages");
}
const LINUX_DEB_MAKER = {
name: "@electron-forge/maker-deb",
config: {
options: {
name: "codex",
productName: "Codex",
genericName: "AI Coding Assistant",
categories: ["Development", "Utility"],
bin: "Codex",
maintainer: "Cometix Space",
homepage: "https://github.com/Haleclipse/CodexDesktop-Rebuild",
icon: "./resources/electron.png",
},
},
};
const LINUX_RPM_MAKER = {
name: "@electron-forge/maker-rpm",
config: {
options: {
name: "codex",
productName: "Codex",
genericName: "AI Coding Assistant",
categories: ["Development", "Utility"],
bin: "Codex",
license: "Apache-2.0",
homepage: "https://github.com/Haleclipse/CodexDesktop-Rebuild",
icon: "./resources/electron.png",
},
},
};
module.exports = {
packagerConfig: {
name: "Codex",
executableName: "Codex",
appBundleId: "com.openai.codex",
icon: "./resources/electron",
// Build mode is set by prepare-src.js via src/.build-mode marker file.
// "upstream-asar": mac/win — we provide pre-built app.asar, forge skips ASAR packing.
// "linux": forge packs ASAR from src/ content (needs electron-rebuild).
asar: (() => {
try {
return fs.readFileSync(path.join(__dirname, "src", ".build-mode"), "utf-8").trim() === "upstream-asar"
? false
: { unpack: "{**/*.node,**/node-pty/build/Release/spawn-helper,**/node-pty/prebuilds/*/spawn-helper}" };
} catch { return false; }
})(),
ignore: (() => {
let mode = "upstream-asar";
try { mode = fs.readFileSync(path.join(__dirname, "src", ".build-mode"), "utf-8").trim(); } catch {}
return mode === "upstream-asar"
? (filePath) => {
// Allow only package.json + stub main entry (forge validates it)
if (filePath === "") return false;
if (filePath === "/package.json") return false;
if (filePath === "/src" || filePath.startsWith("/src/.vite")) return false;
return true;
}
: (filePath) => {
if (filePath === "") return false;
if (filePath === "/package.json") return false;
const allowed = ["/src/.vite/build", "/src/webview", "/src/skills", "/src/native-menu-locales", "/src/node_modules"];
for (const p of allowed) {
if (p.startsWith(filePath) || filePath.startsWith(p)) return false;
}
return true;
};
})(),
osxSign: process.env.SKIP_SIGN ? undefined : {
identity: process.env.APPLE_IDENTITY,
identityValidation: false,
},
osxNotarize: process.env.SKIP_NOTARIZE ? undefined : {
appleId: process.env.APPLE_ID,
appleIdPassword: process.env.APPLE_PASSWORD,
teamId: process.env.APPLE_TEAM_ID,
},
win32metadata: {
CompanyName: "OpenAI",
ProductName: "Codex",
},
},
rebuildConfig: {},
makers: [
{ name: "@electron-forge/maker-dmg", config: { format: "ULFO", icon: "./resources/electron.icns" } },
{ name: "@electron-forge/maker-zip", platforms: ["darwin"] },
{
name: "@electron-forge/maker-squirrel",
config: {
name: "Codex",
authors: "OpenAI, Cometix Space",
description: "Codex Desktop App",
setupIcon: "./resources/electron.ico",
iconUrl: "https://raw.githubusercontent.com/Haleclipse/CodexDesktop-Rebuild/master/resources/electron.ico",
},
},
{ name: "@electron-forge/maker-zip", platforms: ["win32"] },
LINUX_DEB_MAKER,
...(hasRpmDatabase() ? [LINUX_RPM_MAKER] : []),
{ name: "@electron-forge/maker-zip", platforms: ["linux"] },
],
plugins: [
// No auto-unpack-natives — we provide upstream app.asar.unpacked directly
{
name: "@electron-forge/plugin-fuses",
config: {
version: FuseVersion.V1,
[FuseV1Options.RunAsNode]: true,
[FuseV1Options.EnableCookieEncryption]: false,
[FuseV1Options.EnableNodeOptionsEnvironmentVariable]: true,
[FuseV1Options.EnableNodeCliInspectArguments]: true,
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: false,
[FuseV1Options.OnlyLoadAppFromAsar]: false,
},
},
],
hooks: {
prePackage: async () => {
ensureElectronDist();
},
// Copy everything from the platform dir to the app's Resources:
// - app.asar (repacked by prepare-src with patches applied)
// - app.asar.unpacked/ (upstream native modules, untouched)
// - All other resources (codex CLI, rg, plugins, native, etc.)
//
// Forge's own ASAR packing is disabled (asar: false).
// buildPath points to the app dir — we put app.asar alongside it.
packageAfterCopy: async (config, buildPath, electronVersion, platform, arch) => {
console.log(`\n-- packageAfterCopy: ${platform}-${arch}`);
const resourcesPath = path.dirname(buildPath);
const isLinux = platform === "linux";
const platformKey = platform === "win32" ? "win" : `mac-${arch}`;
const platformDir = path.join(__dirname, "src", platformKey);
if (!fs.existsSync(platformDir)) {
console.log(` [!] src/${platformKey}/ not found`);
return;
}
// Skip _asar (already repacked into app.asar or packed by forge for Linux).
// For Linux: also skip macOS-only binaries and app.asar (forge packs its own).
const skip = new Set(["_asar"]);
const MACOS_ONLY_FILES = new Set([
"node", "node_repl",
"electron.icns", "Assets.car",
"codexTemplate.png", "codexTemplate@2x.png",
"app.asar", "codex-notification.wav",
]);
// cua_node ships Mach-O node/node_repl (apple-darwin); useless on Linux and
// causes Codex CLI "Exec format error" if wired as mcp_servers.node_repl.
// codex-code-mode-host is replaced with a Linux ELF in prepare-src.js before
// forge runs, so it must still be copied (do not add it to MACOS_ONLY_FILES).
const MACOS_ONLY_DIRS = new Set(["native", "app.asar.unpacked", "cua_node"]);
if (isLinux) {
for (const f of MACOS_ONLY_FILES) skip.add(f);
for (const d of MACOS_ONLY_DIRS) skip.add(d);
}
let copied = 0;
const copyDir = (s, d) => {
fs.mkdirSync(d, { recursive: true });
for (const e of fs.readdirSync(s, { withFileTypes: true })) {
const sp = path.join(s, e.name), dp = path.join(d, e.name);
if (e.isDirectory()) copyDir(sp, dp);
else if (!e.isSymbolicLink()) { fs.copyFileSync(sp, dp); copied++; }
}
};
for (const entry of fs.readdirSync(platformDir, { withFileTypes: true })) {
if (skip.has(entry.name)) continue;
if (entry.name.endsWith(".lproj")) continue;
const srcPath = path.join(platformDir, entry.name);
const destPath = path.join(resourcesPath, entry.name);
if (entry.isDirectory()) {
copyDir(srcPath, destPath);
} else if (!entry.isSymbolicLink()) {
fs.copyFileSync(srcPath, destPath);
try { fs.chmodSync(destPath, 0o755); } catch {}
copied++;
}
}
console.log(` [ok] ${copied} files (app.asar + unpacked + resources)`);
if (isLinux) {
const hostPath = path.join(resourcesPath, "codex-code-mode-host");
if (!fs.existsSync(hostPath)) {
throw new Error("Linux package missing codex-code-mode-host (prepare-src should install a Linux ELF)");
}
const { execFileSync } = require("child_process");
const kind = execFileSync("file", ["-b", hostPath], { encoding: "utf-8" }).trim();
if (kind.includes("Mach-O") || !kind.includes("ELF")) {
throw new Error(`Linux package has non-ELF codex-code-mode-host: ${kind}`);
}
console.log(` [ok] codex-code-mode-host is Linux ELF`);
}
},
},
};