-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforge.config.ts
More file actions
121 lines (117 loc) · 4.54 KB
/
forge.config.ts
File metadata and controls
121 lines (117 loc) · 4.54 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
import type { ForgeConfig } from '@electron-forge/shared-types';
import { MakerDMG } from '@electron-forge/maker-dmg';
import { MakerZIP } from '@electron-forge/maker-zip';
import { VitePlugin } from '@electron-forge/plugin-vite';
import { FusesPlugin } from '@electron-forge/plugin-fuses';
import { FuseV1Options, FuseVersion } from '@electron/fuses';
import path from 'node:path';
import fs from 'node:fs';
const config: ForgeConfig = {
packagerConfig: {
asar: {
// Unpack better-sqlite3 so its native .node binary is not inside the ASAR
// archive (native addons cannot be loaded from within an ASAR).
unpack: '**/node_modules/better-sqlite3/**',
},
icon: 'assets/icons/icon',
extraResource: ['app-update.yml'],
appBundleId: 'ai.polyphon.app',
appCategoryType: 'public.app-category.productivity',
darwinDarkModeSupport: true,
// Signing and notarization — active when APPLE_SIGNING_IDENTITY is set (CI only).
// Local builds remain unsigned. Never use safeStorage: it requires a persistent
// signed keychain entry and breaks when the signing identity changes.
...(process.env.APPLE_SIGNING_IDENTITY && {
osxSign: {
identity: process.env.APPLE_SIGNING_IDENTITY,
optionsForFile: (filePath: string) => ({
entitlements: filePath.includes('Helper')
? 'entitlements.inherit.plist'
: 'entitlements.plist',
}),
},
osxNotarize: {
appleId: process.env.APPLE_ID!,
appleIdPassword: process.env.APPLE_APP_SPECIFIC_PASSWORD!,
teamId: process.env.APPLE_TEAM_ID!,
},
}),
},
// Skip Forge's built-in native module rebuild. better-sqlite3 is built with
// the SQLCipher amalgamation in the postinstall script (build-sqlcipher.mjs
// --mode=electron) using electron-rebuild with the --sqlite3 extra arg.
// Letting Forge rebuild it here would overwrite the SQLCipher binary with a
// stock SQLite build.
rebuildConfig: { onlyModules: [] },
hooks: {
// The Forge Vite plugin only packages the Vite build output — node_modules
// are not included. Native modules can't be bundled by Vite, so we copy
// better-sqlite3 and its runtime deps into the build directory so they end
// up in app.asar (and app.asar.unpacked for the .node binary via asarUnpack).
// We also swap in the Electron-ABI binary (saved to prebuilt-electron/ by
// build-sqlcipher.mjs --mode=electron) since postinstall runs electron then
// node mode, leaving the Node-ABI binary in build/Release/ for Vitest.
packageAfterCopy: async (_config, buildPath) => {
const nmSrc = path.join(__dirname, 'node_modules');
const nmDest = path.join(buildPath, 'node_modules');
// Copy better-sqlite3 and its runtime dependencies
for (const pkg of ['better-sqlite3', 'bindings', 'file-uri-to-path']) {
await fs.promises.cp(
path.join(nmSrc, pkg),
path.join(nmDest, pkg),
{ recursive: true },
);
}
// Swap in the Electron-ABI binary (overwrite the Node-ABI binary that
// postinstall left in build/Release/ for Vitest)
const electronBinary = path.join(nmSrc, 'better-sqlite3', 'prebuilt-electron', 'better_sqlite3.node');
const destBinary = path.join(nmDest, 'better-sqlite3', 'build', 'Release', 'better_sqlite3.node');
await fs.promises.copyFile(electronBinary, destBinary);
},
},
makers: [
new MakerZIP({}, ['darwin']),
new MakerDMG({
icon: 'assets/icons/icon.icns',
format: 'ULFO',
additionalDMGOptions: {
window: {
position: { x: 400, y: 200 },
size: { width: 540, height: 380 },
},
},
}, ['darwin']),
],
plugins: [
new VitePlugin({
build: [
{
entry: 'src/main/index.ts',
config: 'vite.main.config.ts',
target: 'main',
},
{
entry: 'src/main/preload.ts',
config: 'vite.preload.config.ts',
target: 'preload',
},
],
renderer: [
{
name: 'main_window',
config: 'vite.renderer.config.ts',
},
],
}),
new FusesPlugin({
version: FuseVersion.V1,
[FuseV1Options.RunAsNode]: false,
[FuseV1Options.EnableCookieEncryption]: false,
[FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
[FuseV1Options.EnableNodeCliInspectArguments]: false,
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
[FuseV1Options.OnlyLoadAppFromAsar]: true,
}),
],
};
export default config;