@adea-ai/app-framework 0.24.0 → 0.24.1

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 (128) hide show
  1. package/README.md +43 -1
  2. package/dist/framework-source.json +1 -1
  3. package/dist/release/framework-package-publish.js +4 -2
  4. package/dist/shell/app-shell.js +21 -33
  5. package/dist/shell/navigation-drawer.d.ts +12 -0
  6. package/dist/shell/navigation-drawer.js +42 -0
  7. package/package.json +13 -2
  8. package/src/shell/app-shell.tsx +29 -20
  9. package/src/shell/navigation-drawer.tsx +36 -0
  10. package/src/app/create-application.ts +0 -245
  11. package/src/app/service-registry.ts +0 -124
  12. package/src/ci/toolchain-identity.ts +0 -244
  13. package/src/cli/cef-helper-cli.ts +0 -21
  14. package/src/cli/cli-runner.ts +0 -29
  15. package/src/cli/create-application-cli.ts +0 -62
  16. package/src/cli/electrobun-shortcut-patch-cli.ts +0 -24
  17. package/src/cli/framework-update-cli.ts +0 -41
  18. package/src/cli/release-assets-plan-cli.ts +0 -14
  19. package/src/cli/release-cut-cli.ts +0 -41
  20. package/src/cli/release-descriptor-staging-cli.ts +0 -57
  21. package/src/cli/release-finalize-cli.ts +0 -34
  22. package/src/cli/release-promote-cli.ts +0 -31
  23. package/src/cli/release-publish-cli.ts +0 -46
  24. package/src/cli/release-sign-cli.ts +0 -24
  25. package/src/cli/release-step-cli.ts +0 -71
  26. package/src/cli/toolchain-identity-cli.ts +0 -12
  27. package/src/cli/update-helper-cli.ts +0 -12
  28. package/src/cli/windows-runtime-patch-cli.ts +0 -17
  29. package/src/desktop/application-command-client.ts +0 -43
  30. package/src/desktop/channel-handshake.ts +0 -136
  31. package/src/desktop/channel-proof.ts +0 -122
  32. package/src/desktop/desktop-client.ts +0 -303
  33. package/src/desktop/desktop-gateway.ts +0 -189
  34. package/src/desktop/desktop-host.ts +0 -335
  35. package/src/desktop/desktop-stream.ts +0 -324
  36. package/src/desktop/loopback-policy.ts +0 -41
  37. package/src/desktop/open-url-channel.ts +0 -79
  38. package/src/desktop/string-policy.ts +0 -9
  39. package/src/installer/archive-entry.ts +0 -32
  40. package/src/installer/command-artifact.ts +0 -307
  41. package/src/installer/command-qualification-command.ts +0 -75
  42. package/src/installer/hosted-runner.ts +0 -11
  43. package/src/installer/installed-payload.ts +0 -408
  44. package/src/installer/installer-ci-bootstrap.ts +0 -199
  45. package/src/installer/installer-ci-preflight.ts +0 -61
  46. package/src/installer/installer-ci-worker.ts +0 -105
  47. package/src/installer/installer-extraction.ts +0 -367
  48. package/src/installer/installer-fetch-guard.ts +0 -75
  49. package/src/installer/installer-identity.ts +0 -331
  50. package/src/installer/installer-layout.ts +0 -167
  51. package/src/installer/installer-observation.ts +0 -671
  52. package/src/installer/installer-process-cleanup.ts +0 -167
  53. package/src/installer/installer-qualification-command.ts +0 -81
  54. package/src/installer/installer-renderer-evidence.ts +0 -268
  55. package/src/installer/installer-upgrade-command.ts +0 -226
  56. package/src/installer/installer-worker-guard.ts +0 -112
  57. package/src/installer/native-executable.ts +0 -37
  58. package/src/installer/upgrade-asset-download.ts +0 -72
  59. package/src/installer/write-all.ts +0 -19
  60. package/src/native/app-bundle.ts +0 -86
  61. package/src/native/cef-helper.ts +0 -471
  62. package/src/native/desktop-build-hook.ts +0 -21
  63. package/src/native/electrobun-source-patch.ts +0 -107
  64. package/src/native/linux-cef-links.ts +0 -14
  65. package/src/native/native-secret-store.ts +0 -99
  66. package/src/native/native-utilities.ts +0 -166
  67. package/src/native/partitioned-window.ts +0 -62
  68. package/src/native/secure-window.ts +0 -115
  69. package/src/native/sidecar-services.ts +0 -71
  70. package/src/native/sidecar.ts +0 -387
  71. package/src/native/window-bootstrap.ts +0 -77
  72. package/src/native/windows-build-hook-internal.ts +0 -49
  73. package/src/native/windows-build-hook.ts +0 -12
  74. package/src/native/windows-runtime-patch-internal.ts +0 -48
  75. package/src/native/windows-runtime-patch.ts +0 -15
  76. package/src/release/feed-release-cut.ts +0 -110
  77. package/src/release/feed-state.ts +0 -135
  78. package/src/release/framework-package-publish.ts +0 -163
  79. package/src/release/framework-update.ts +0 -196
  80. package/src/release/github-cli.ts +0 -27
  81. package/src/release/github-release-assets.ts +0 -36
  82. package/src/release/github-release-cut.ts +0 -237
  83. package/src/release/github-release-lookup.ts +0 -39
  84. package/src/release/github-release-promotion.ts +0 -112
  85. package/src/release/github-release-provenance.ts +0 -65
  86. package/src/release/github-release-publisher.ts +0 -90
  87. package/src/release/github-release-qualification.ts +0 -144
  88. package/src/release/local-provenance.ts +0 -92
  89. package/src/release/local-release.ts +0 -525
  90. package/src/release/macos-dmg.ts +0 -113
  91. package/src/release/release-artifact.ts +0 -53
  92. package/src/release/release-assets-plan.ts +0 -118
  93. package/src/release/release-config.ts +0 -420
  94. package/src/release/release-cut-command.ts +0 -80
  95. package/src/release/release-cut.ts +0 -133
  96. package/src/release/release-descriptor-staging.ts +0 -242
  97. package/src/release/release-finalize.ts +0 -191
  98. package/src/release/release-promotion-command.ts +0 -36
  99. package/src/release/release-promotion.ts +0 -132
  100. package/src/release/release-publication.ts +0 -213
  101. package/src/release/release-publish-command.ts +0 -163
  102. package/src/release/release-qualification.ts +0 -397
  103. package/src/release/release-staging.ts +0 -87
  104. package/src/release/release-steps.ts +0 -173
  105. package/src/release/retained-release-build.ts +0 -217
  106. package/src/shell/application-menu-commands.ts +0 -6
  107. package/src/shell/application-menu.ts +0 -250
  108. package/src/updates/channel-update-manager.ts +0 -127
  109. package/src/updates/desktop-updater.ts +0 -440
  110. package/src/updates/release-feed.ts +0 -187
  111. package/src/updates/release-location.ts +0 -101
  112. package/src/updates/signed-release.ts +0 -311
  113. package/src/updates/stable-file.ts +0 -32
  114. package/src/updates/update-arm.ts +0 -107
  115. package/src/updates/update-channel-store.ts +0 -86
  116. package/src/updates/update-discovery.ts +0 -113
  117. package/src/updates/update-download.ts +0 -82
  118. package/src/updates/update-exclusive-rename.ts +0 -58
  119. package/src/updates/update-extraction.ts +0 -261
  120. package/src/updates/update-handoff-plan.ts +0 -75
  121. package/src/updates/update-helper.ts +0 -87
  122. package/src/updates/update-launch.ts +0 -33
  123. package/src/updates/update-manager.ts +0 -130
  124. package/src/updates/update-process-fence.ts +0 -125
  125. package/src/updates/update-resume.ts +0 -34
  126. package/src/updates/update-shutdown.ts +0 -37
  127. package/src/updates/update-swap-stage.ts +0 -75
  128. package/src/updates/update-swap.ts +0 -30
@@ -1,331 +0,0 @@
1
- import { createHash } from 'node:crypto'
2
- import { assertNativeExecutable } from './native-executable'
3
- import { lstat, mkdir, mkdtemp, open, readdir, realpath, rm, stat } from 'node:fs/promises'
4
- import { tmpdir } from 'node:os'
5
- import { basename, dirname, isAbsolute, join, relative, resolve, sep, win32 } from 'node:path'
6
- import {
7
- assertInstallerContext,
8
- assertInstallerLayout,
9
- assertPortableAppName,
10
- type InstallerPlatform,
11
- } from './installer-layout'
12
- import type { Artifact } from '../release/release-qualification'
13
-
14
- async function identity(path: string): Promise<Artifact> {
15
- const info = await lstat(path)
16
- if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || !Number.isSafeInteger(info.size))
17
- throw new Error('Invalid installer artifact')
18
- const file = await open(path, 'r')
19
- try {
20
- const before = await file.stat()
21
- if (before.ino !== info.ino || before.dev !== info.dev || before.size !== info.size)
22
- throw new Error('Installer artifact changed')
23
- const hash = createHash('sha256')
24
- let size = 0
25
- for await (const chunk of file.createReadStream({ autoClose: false })) {
26
- size += chunk.length
27
- if (size > before.size) throw new Error('Installer artifact changed')
28
- hash.update(chunk)
29
- }
30
- const after = await file.stat()
31
- if (
32
- size !== before.size ||
33
- after.size !== before.size ||
34
- after.mtimeMs !== before.mtimeMs ||
35
- after.ino !== before.ino ||
36
- after.dev !== before.dev
37
- )
38
- throw new Error('Installer artifact changed')
39
- return { name: basename(path), size, digest: 'sha256:' + hash.digest('hex') }
40
- } finally {
41
- await file.close()
42
- }
43
- }
44
- function environment(parent: Record<string, string | undefined>): Record<string, string> {
45
- const env: Record<string, string> = {}
46
- for (const name of ['PATH', 'SystemRoot', 'WINDIR', 'TEMP', 'TMP', 'TMPDIR', 'LANG', 'LC_ALL'])
47
- if (parent[name]) env[name] = parent[name]!
48
- return env
49
- }
50
- /** Hosted macOS runners intermittently refuse an attach while disk arbitration is busy. */
51
- /** Whether a volume is mounted at a directory; unknown counts as mounted. */
52
- async function volumeAt(mount: string): Promise<boolean> {
53
- try {
54
- const [own, parent] = await Promise.all([stat(mount), stat(dirname(mount))])
55
- return own.dev !== parent.dev
56
- } catch {
57
- return true
58
- }
59
- }
60
- export type ImageAttachIo = {
61
- run(args: string[], env: Record<string, string>): Promise<unknown>
62
- mounted(mount: string): Promise<boolean>
63
- wait(ms: number): Promise<unknown>
64
- }
65
- /**
66
- * Attach a disk image read-only, up to three times. A failed or timed-out attach can still
67
- * have mounted the image, so each failure detaches whatever is mounted before the retry.
68
- */
69
- export async function attachImage(
70
- mount: string,
71
- image: string,
72
- env: Record<string, string>,
73
- io: ImageAttachIo = { run: command, mounted: volumeAt, wait: Bun.sleep }
74
- ) {
75
- for (let attempt = 1; ; attempt++) {
76
- try {
77
- await io.run(
78
- ['/usr/bin/hdiutil', 'attach', '-readonly', '-nobrowse', '-mountpoint', mount, image],
79
- env
80
- )
81
- return
82
- } catch (error) {
83
- if (await io.mounted(mount))
84
- await io.run(['/usr/bin/hdiutil', 'detach', '-force', mount], env)
85
- if (attempt === 3) throw error
86
- await io.wait(5000)
87
- }
88
- }
89
- }
90
- async function command(args: string[], env: Record<string, string>): Promise<string> {
91
- const child = Bun.spawn({
92
- cmd: args,
93
- env,
94
- stdout: 'pipe',
95
- stderr: 'pipe',
96
- signal: AbortSignal.timeout(120_000),
97
- })
98
- const stdout = (async () => {
99
- let size = 0
100
- const chunks: Buffer[] = []
101
- for await (const chunk of child.stdout) {
102
- size += chunk.length
103
- if (size > 8 * 1024 * 1024) {
104
- child.kill()
105
- throw new Error('Installer listing exceeds bound')
106
- }
107
- chunks.push(Buffer.from(chunk))
108
- }
109
- return Buffer.concat(chunks).toString('utf8')
110
- })()
111
- const stderr = (async () => {
112
- for await (const _chunk of child.stderr) {
113
- /* Drain without exposing paths or output. */
114
- }
115
- })()
116
- const [text, , status] = await Promise.all([stdout, stderr, child.exited])
117
- if (status !== 0) throw new Error('Installer inspection command failed')
118
- return text
119
- }
120
- async function extractMember(
121
- tar: string,
122
- installer: string,
123
- member: string,
124
- output: string,
125
- maximum: number,
126
- env: Record<string, string>
127
- ): Promise<number> {
128
- const file = await open(output, 'wx', 0o600)
129
- const spawn = () =>
130
- Bun.spawn({
131
- cmd: [tar, '-xOf', installer, member],
132
- env,
133
- stdout: 'pipe',
134
- stderr: 'pipe',
135
- signal: AbortSignal.timeout(120_000),
136
- })
137
- let child: ReturnType<typeof spawn>
138
- try {
139
- child = spawn()
140
- } catch (error) {
141
- await file.close()
142
- throw error
143
- }
144
- const errors = (async () => {
145
- for await (const _chunk of child.stderr) {
146
- /* Drain without logging installer output. */
147
- }
148
- })()
149
- let count = 0
150
- try {
151
- for await (const chunk of child.stdout) {
152
- count += chunk.length
153
- if (!Number.isSafeInteger(count) || count > maximum)
154
- throw new Error('Installer member exceeds bound')
155
- let offset = 0
156
- while (offset < chunk.length) {
157
- const result = await file.write(chunk, offset, chunk.length - offset)
158
- if (!result.bytesWritten) throw new Error('Cannot read installer member')
159
- offset += result.bytesWritten
160
- }
161
- }
162
- if ((await child.exited) !== 0) throw new Error('Cannot read installer member')
163
- await errors
164
- return count
165
- } catch (error) {
166
- child.kill()
167
- await child.exited
168
- await errors
169
- throw error
170
- } finally {
171
- await file.close()
172
- }
173
- }
174
- async function assertExecutable(path: string, platform: InstallerPlatform): Promise<void> {
175
- const info = await lstat(path)
176
- if (!info.isFile() || info.isSymbolicLink() || info.size < 4096)
177
- throw new Error('Invalid installer executable')
178
- const file = await open(path, 'r')
179
- try {
180
- await assertNativeExecutable(file, info.size, platform, 'installer executable')
181
- } finally {
182
- await file.close()
183
- }
184
- }
185
- function within(root: string, path: string): boolean {
186
- const rel = relative(root, path)
187
- return rel !== '' && rel !== '..' && !rel.startsWith('..' + sep) && !isAbsolute(rel)
188
- }
189
-
190
- /** Inspect a shipped installer without executing it, on a matching disposable runner. */
191
- export async function verifyInstallerPayload(options: {
192
- platform: InstallerPlatform
193
- appName: string
194
- installer: string
195
- archive: string
196
- env?: Record<string, string | undefined>
197
- }): Promise<{ installer: Artifact; archive: Artifact }> {
198
- const parent = options.env ?? process.env
199
- assertInstallerContext(parent, options.platform, process.platform, process.arch)
200
- assertPortableAppName(options.appName)
201
- const installerPath = resolve(options.installer),
202
- archivePath = resolve(options.archive)
203
- const before = { installer: await identity(installerPath), archive: await identity(archivePath) }
204
- if (!Number.isSafeInteger(before.archive.size + 256 * 1024 * 1024))
205
- throw new Error('Installer archive exceeds bound')
206
- const env = environment(parent)
207
- const temporary = await mkdtemp(join(tmpdir(), 'framework-installer-inspect-'))
208
- const mount = join(temporary, 'mount')
209
- // True while the image may be attached; the temporary tree is removed only once it is not.
210
- let mounted = false
211
- try {
212
- if (options.platform === 'macos-arm64') {
213
- await mkdir(mount)
214
- mounted = true
215
- await attachImage(mount, installerPath, env)
216
- try {
217
- const apps = (await readdir(mount)).filter((name) => name.endsWith('.app'))
218
- if (apps.length !== 1) throw new Error('Installer application is missing or ambiguous')
219
- const resources = join(mount, apps[0]!, 'Contents', 'Resources')
220
- const actualRoot = await realpath(mount),
221
- actualApp = await realpath(join(mount, apps[0]!)),
222
- actualResources = await realpath(resources)
223
- if (!within(actualRoot, actualApp) || !within(actualApp, actualResources))
224
- throw new Error('Installer resources escape mounted image')
225
- const plist = join(actualApp, 'Contents', 'Info.plist'),
226
- plistInfo = await lstat(plist)
227
- if (
228
- !plistInfo.isFile() ||
229
- plistInfo.isSymbolicLink() ||
230
- plistInfo.size < 1 ||
231
- plistInfo.size > 1024 * 1024
232
- )
233
- throw new Error('Invalid installer property list')
234
- const executable = (
235
- await command(['/usr/libexec/PlistBuddy', '-c', 'Print :CFBundleExecutable', plist], env)
236
- ).trim()
237
- if (!executable || executable === '.' || executable === '..' || /[\\/]/.test(executable))
238
- throw new Error('Invalid installer executable name')
239
- await assertExecutable(join(actualApp, 'Contents', 'MacOS', executable), options.platform)
240
- const archives = (await readdir(actualResources)).filter((name) =>
241
- name.endsWith('.tar.zst')
242
- )
243
- if (archives.length !== 1) throw new Error('Installer archive is missing or ambiguous')
244
- const embedded = await identity(join(actualResources, archives[0]!))
245
- if (embedded.size !== before.archive.size || embedded.digest !== before.archive.digest)
246
- throw new Error('Installer archive differs from release archive')
247
- } finally {
248
- await command(['/usr/bin/hdiutil', 'detach', mount], env)
249
- mounted = false
250
- }
251
- } else {
252
- const systemRoot = parent.SystemRoot
253
- if (
254
- options.platform === 'windows-x64' &&
255
- (!systemRoot || !/^[A-Za-z]:[\\/]/.test(systemRoot))
256
- )
257
- throw new Error('Missing Windows system directory')
258
- const tar =
259
- options.platform === 'windows-x64' ? win32.join(systemRoot!, 'System32', 'tar.exe') : 'tar'
260
- if (
261
- options.platform === 'windows-x64' &&
262
- !/^bsdtar\s/i.test((await command([tar, '--version'], env)).trim())
263
- )
264
- throw new Error('Windows installer inspection requires system bsdtar')
265
- const names = (await command([tar, '-tf', installerPath], env)).split(/\r?\n/).filter(Boolean)
266
- assertInstallerLayout(options.platform, options.appName, names)
267
- const candidates =
268
- options.platform === 'windows-x64'
269
- ? [`.installer/${options.appName}-Setup.tar.zst`]
270
- : ['installer']
271
- const matches = names.filter((name) =>
272
- candidates.includes(name.replace(/^\.\//, '').replaceAll('\\', '/'))
273
- )
274
- if (matches.length !== 1) throw new Error('Installer archive is missing or ambiguous')
275
- const extracted = join(temporary, 'member')
276
- const count = await extractMember(
277
- tar,
278
- installerPath,
279
- matches[0]!,
280
- extracted,
281
- before.archive.size + 256 * 1024 * 1024,
282
- env
283
- )
284
- if (options.platform === 'windows-x64') {
285
- const setup = names.find(
286
- (name) =>
287
- name.replace(/^\.\//, '').replaceAll('\\', '/').toLowerCase() ===
288
- `${options.appName}-Setup.exe`.toLowerCase()
289
- )
290
- if (!setup) throw new Error('Installer executable is missing')
291
- const executable = join(temporary, 'setup.exe')
292
- await extractMember(tar, installerPath, setup, executable, 256 * 1024 * 1024, env)
293
- await assertExecutable(executable, options.platform)
294
- const embedded = await identity(extracted)
295
- if (embedded.size !== before.archive.size || embedded.digest !== before.archive.digest)
296
- throw new Error('Installer archive differs from release archive')
297
- } else {
298
- await assertExecutable(extracted, options.platform)
299
- const marker = Buffer.from('ELECTROBUN_ARCHIVE_V1')
300
- if (count <= before.archive.size + marker.length)
301
- throw new Error('Installer archive is incomplete')
302
- const file = await open(extracted, 'r')
303
- try {
304
- const position = count - before.archive.size - marker.length,
305
- actual = Buffer.alloc(marker.length)
306
- if (
307
- (await file.read(actual, 0, actual.length, position)).bytesRead !== actual.length ||
308
- !actual.equals(marker)
309
- )
310
- throw new Error('Installer archive marker is missing')
311
- const hash = createHash('sha256')
312
- for await (const chunk of file.createReadStream({
313
- start: position + marker.length,
314
- autoClose: false,
315
- }))
316
- hash.update(chunk)
317
- if ('sha256:' + hash.digest('hex') !== before.archive.digest)
318
- throw new Error('Installer archive differs from release archive')
319
- } finally {
320
- await file.close()
321
- }
322
- }
323
- }
324
- const after = { installer: await identity(installerPath), archive: await identity(archivePath) }
325
- if (JSON.stringify(before) !== JSON.stringify(after))
326
- throw new Error('Installer artifacts changed during inspection')
327
- return before
328
- } finally {
329
- if (!mounted || !(await volumeAt(mount))) await rm(temporary, { recursive: true, force: true })
330
- }
331
- }
@@ -1,167 +0,0 @@
1
- import { containsAsciiControl } from '../desktop/string-policy'
2
- import { assertSidecarNames, sidecarBundlePath } from '../native/app-bundle'
3
- import { assertHostedRunner } from './hosted-runner'
4
-
5
- /** Installer preflight adapted from adea-ai/adea scripts/test-desktop-release-install.mjs,
6
- * commit 6155d18941acbb14d9099bc2a33a50ee9683a068 (Apache-2.0). */
7
- export type InstallerPlatform = 'macos-arm64' | 'windows-x64' | 'linux-x64'
8
- export type InstallerRenderer = 'native' | 'cef'
9
-
10
- /** Native installer execution is only allowed on disposable, matching hosted runners. */
11
- export function assertInstallerContext(
12
- env: Record<string, string | undefined>,
13
- platform: InstallerPlatform,
14
- host: string,
15
- arch: string
16
- ): void {
17
- assertHostedRunner(env, 'Installer execution')
18
- const expected = {
19
- 'macos-arm64': 'darwin/arm64',
20
- 'windows-x64': 'win32/x64',
21
- 'linux-x64': 'linux/x64',
22
- }[platform]
23
- if (!expected || `${host}/${arch}` !== expected)
24
- throw new Error('Installer requires matching native OS and architecture')
25
- }
26
- /** A bundle and installer name usable on macOS, Windows and Linux. */
27
- export function assertPortableAppName(name: string): void {
28
- if (
29
- typeof name !== 'string' ||
30
- !name ||
31
- name !== name.trim() ||
32
- name.length > 80 ||
33
- name.endsWith('.') ||
34
- /^[.]+$/.test(name) ||
35
- /[<>:"/\\|?*]/.test(name) ||
36
- containsAsciiControl(name) ||
37
- /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(name)
38
- )
39
- throw new Error('Invalid portable application name')
40
- }
41
- function paths(entries: readonly string[], fold: boolean): string[] {
42
- if (!Array.isArray(entries) || entries.length > 200000) throw new Error('Invalid archive listing')
43
- // Archive listings commonly contain a harmless root-directory entry.
44
- const normalized = entries
45
- .filter((entry) => entry !== '.' && entry !== './' && entry !== '.\\')
46
- .map((entry) => {
47
- if (typeof entry !== 'string' || !entry || entry.includes('\0'))
48
- throw new Error('Invalid archive path')
49
- const path = entry.replaceAll('\\', '/').replace(/^\.\//, '').replace(/\/$/, '')
50
- if (
51
- !path ||
52
- path.startsWith('/') ||
53
- /^[A-Za-z]:/.test(path) ||
54
- path.split('/').some((part) => part === '..' || part === '' || part === '.')
55
- )
56
- throw new Error('Unsafe archive path')
57
- return fold ? path.toLowerCase() : path
58
- })
59
- if (new Set(normalized).size !== normalized.length) throw new Error('Duplicate archive path')
60
- return normalized
61
- }
62
- /** Check names before extraction. Callers must also reject unsafe links and archive entry types. */
63
- export function assertPayloadLayout(options: {
64
- platform: InstallerPlatform
65
- appName: string
66
- renderer: InstallerRenderer
67
- entries: readonly string[]
68
- /** Sidecar executables the app bundles; each must be present. */
69
- sidecars?: readonly string[]
70
- }): void {
71
- const { platform, appName, renderer } = options
72
- const sidecars = assertSidecarNames(options.sidecars ?? [])
73
- assertPortableAppName(appName)
74
- if (
75
- !['macos-arm64', 'windows-x64', 'linux-x64'].includes(platform) ||
76
- !['native', 'cef'].includes(renderer)
77
- )
78
- throw new Error('Invalid installer profile')
79
- const fold = platform === 'windows-x64'
80
- const entries = paths(options.entries, fold)
81
- const mac = platform === 'macos-arm64'
82
- const root = mac ? `${appName}.app/Contents` : appName.replaceAll(' ', '')
83
- const bin = mac ? `${root}/MacOS` : `${root}/bin`
84
- const resources = `${root}/Resources`
85
- const suffix = platform === 'windows-x64' ? '.exe' : ''
86
- for (const name of [
87
- `${bin}/launcher${suffix}`,
88
- `${bin}/bun${suffix}`,
89
- `${resources}/version.json`,
90
- `${resources}/main.js`,
91
- `${resources}/app/bun/index.js`,
92
- `${resources}/build.json`,
93
- `${resources}/app/client/index.html`,
94
- ...sidecars.map((sidecar) => `${root}/${sidecarBundlePath(sidecar, platform)}`),
95
- ]) {
96
- if (!entries.includes(fold ? name.toLowerCase() : name))
97
- throw new Error(`Payload missing ${name}`)
98
- }
99
- const containsCef = entries.some((name) =>
100
- /(?:^|\/)(?:chromium embedded framework|libcef\.dll|libcef\.so)$/i.test(name)
101
- )
102
- if (containsCef !== (renderer === 'cef'))
103
- throw new Error('Payload does not match selected renderer')
104
- }
105
- /** Check expected installer entries before extraction; links and types require separate validation. */
106
- export function assertInstallerLayout(
107
- platform: InstallerPlatform,
108
- appName: string,
109
- entries: readonly string[]
110
- ): void {
111
- assertPortableAppName(appName)
112
- if (platform !== 'windows-x64' && platform !== 'linux-x64')
113
- throw new Error('Unsupported archive installer platform')
114
- const fold = platform === 'windows-x64'
115
- const names = paths(entries, fold)
116
- // Electrobun strips spaces from the outer archive name, but preserves them
117
- // in the user-facing Windows setup executable and its embedded payload.
118
- const expected = fold
119
- ? [
120
- `${appName}-Setup.exe`,
121
- `.installer/${appName}-Setup.metadata.json`,
122
- `.installer/${appName}-Setup.tar.zst`,
123
- ]
124
- : ['installer', 'README.txt']
125
- for (const name of expected)
126
- if (!names.includes(fold ? name.toLowerCase() : name))
127
- throw new Error(`Installer missing ${name}`)
128
- }
129
-
130
- /** Check the actual packaged renderer metadata, not merely the app's source config. */
131
- export function assertBuildMetadata(value: unknown, renderer: InstallerRenderer): void {
132
- if (
133
- !['native', 'cef'].includes(renderer) ||
134
- typeof value !== 'object' ||
135
- value === null ||
136
- Array.isArray(value)
137
- )
138
- throw new Error('Invalid build metadata')
139
- const config = value as Record<string, unknown>
140
- if (
141
- config.mainProcess !== 'bun' ||
142
- config.defaultRenderer !== renderer ||
143
- !Array.isArray(config.availableRenderers) ||
144
- !config.availableRenderers.includes(renderer) ||
145
- config.availableRenderers.some((item) => item !== 'native' && item !== 'cef') ||
146
- new Set(config.availableRenderers).size !== config.availableRenderers.length
147
- )
148
- throw new Error('Packaged renderer does not match the application profile')
149
- if (renderer === 'native' && config.availableRenderers.includes('cef'))
150
- throw new Error('System webview package must not bundle CEF')
151
- if (renderer === 'cef') {
152
- if (
153
- typeof config.chromiumFlags !== 'object' ||
154
- config.chromiumFlags === null ||
155
- Array.isArray(config.chromiumFlags)
156
- )
157
- throw new Error('Missing CEF security policy')
158
- const flags = config.chromiumFlags as Record<string, unknown>
159
- for (const flag of [
160
- 'disable-web-security',
161
- 'remote-allow-origins',
162
- 'allow-insecure-localhost',
163
- 'remote-debugging-port',
164
- ])
165
- if (flags[flag] !== false) throw new Error(`Unsafe CEF flag: ${flag}`)
166
- }
167
- }