@adea-ai/app-framework 0.36.1 → 0.37.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.
- package/README.md +2 -0
- package/dist/appearance/appearance-host.js +2 -1
- package/dist/appearance/custom-theme-import.js +3 -1
- package/dist/appearance/custom-theme-library.d.ts +6 -185
- package/dist/appearance/custom-theme-library.js +3 -621
- package/dist/appearance/theme-library-mutation.d.ts +42 -0
- package/dist/appearance/theme-library-mutation.js +172 -0
- package/dist/appearance/theme-library-schema.d.ts +108 -0
- package/dist/appearance/theme-library-schema.js +189 -0
- package/dist/appearance/theme-library-store.d.ts +61 -0
- package/dist/appearance/theme-library-store.js +268 -0
- package/dist/appearance/theme-record-adapter.js +3 -1
- package/dist/appearance/theme-registry.js +2 -1
- package/dist/appearance/window-surface.d.ts +19 -0
- package/dist/appearance/window-surface.js +68 -1
- package/dist/cli/update-helper-cli.js +1 -1
- package/dist/cli/windows-installer-build-cli.d.ts +2 -0
- package/dist/cli/windows-installer-build-cli.js +14 -0
- package/dist/desktop/desktop-client.d.ts +1 -1
- package/dist/framework-source.json +1 -1
- package/dist/installer/installed-payload.js +2 -2
- package/dist/installer/{installer-archive.js → installer-archive-members.js} +2 -2
- package/dist/installer/installer-extraction.js +2 -2
- package/dist/installer/installer-fetch-guard.d.ts +1 -1
- package/dist/installer/installer-identity.js +2 -2
- package/dist/installer/installer-observation.d.ts +1 -1
- package/dist/installer/installer-observation.js +2 -2
- package/dist/installer/installer-upgrade-command.d.ts +2 -2
- package/dist/installer/installer-upgrade-command.js +5 -5
- package/dist/installer/linux-process-group.js +1 -1
- package/dist/installer/upgrade-asset-download.d.ts +1 -1
- package/dist/installer/upgrade-asset-download.js +2 -2
- package/dist/native/installer-archive.d.ts +42 -0
- package/dist/native/installer-archive.js +172 -0
- package/dist/native/posix-tree-removal.d.ts +1 -1
- package/dist/native/window-surface-store.d.ts +16 -0
- package/dist/native/window-surface-store.js +69 -0
- package/dist/native/windows-extractor-build.d.ts +95 -0
- package/dist/native/windows-extractor-build.js +326 -0
- package/dist/release/feed-release-cut.d.ts +1 -1
- package/dist/release/feed-state.d.ts +2 -2
- package/dist/release/feed-state.js +3 -3
- package/dist/release/github-release-cut.js +1 -1
- package/dist/release/github-release-promotion.js +1 -1
- package/dist/release/github-release-publisher.js +1 -1
- package/dist/release/github-release-qualification.js +1 -1
- package/dist/release/local-release.d.ts +2 -2
- package/dist/release/local-release.js +3 -3
- package/dist/release/release-artifact.d.ts +1 -1
- package/dist/release/release-artifact.js +2 -2
- package/dist/release/release-assets-plan.js +1 -1
- package/dist/release/release-config.d.ts +1 -1
- package/dist/release/release-config.js +1 -1
- package/dist/release/release-descriptor-staging.js +3 -3
- package/dist/release/release-finalize.js +1 -1
- package/dist/release/release-promotion.js +1 -1
- package/dist/release/release-publication.d.ts +1 -1
- package/dist/release/release-publication.js +2 -2
- package/dist/release/release-publish-command.js +2 -2
- package/dist/update-helper.bundle.js +18 -18
- package/dist/updates/channel-update-manager.d.ts +3 -3
- package/dist/updates/channel-update-manager.js +2 -2
- package/dist/updates/desktop-updater.d.ts +10 -83
- package/dist/updates/desktop-updater.js +14 -217
- package/dist/updates/{packaged-release-config.js → feed/packaged-release-config.js} +5 -5
- package/dist/updates/{release-feed.js → feed/release-feed.js} +2 -2
- package/dist/updates/{release-location.js → feed/release-location.js} +2 -2
- package/dist/updates/{release-version.js → feed/release-version.js} +1 -1
- package/dist/updates/{signed-release.js → feed/signed-release.js} +2 -2
- package/dist/updates/{update-discovery.js → feed/update-discovery.js} +1 -1
- package/dist/updates/helper/launch-gate-recovery.d.ts +8 -0
- package/dist/updates/{update-resume.js → helper/launch-gate-recovery.js} +13 -423
- package/dist/updates/helper/resume-staging.d.ts +22 -0
- package/dist/updates/helper/resume-staging.js +180 -0
- package/dist/updates/{update-helper.d.ts → helper/update-helper.d.ts} +1 -1
- package/dist/updates/{update-helper.js → helper/update-helper.js} +9 -9
- package/dist/updates/{update-resume.d.ts → helper/update-resume.d.ts} +4 -10
- package/dist/updates/helper/update-resume.js +252 -0
- package/dist/updates/{update-shutdown.js → helper/update-shutdown.js} +2 -2
- package/dist/updates/{update-arm.d.ts → install/update-arm.d.ts} +2 -2
- package/dist/updates/{update-arm.js → install/update-arm.js} +9 -9
- package/dist/updates/{update-download-cleanup.d.ts → install/update-download-cleanup.d.ts} +1 -1
- package/dist/updates/{update-download-cleanup.js → install/update-download-cleanup.js} +3 -3
- package/dist/updates/{update-download.d.ts → install/update-download.d.ts} +2 -2
- package/dist/updates/{update-download.js → install/update-download.js} +3 -3
- package/dist/updates/{update-extraction.d.ts → install/update-extraction.d.ts} +2 -2
- package/dist/updates/{update-extraction.js → install/update-extraction.js} +6 -6
- package/dist/updates/{update-handoff-plan.d.ts → install/update-handoff-plan.d.ts} +2 -2
- package/dist/updates/{update-handoff-plan.js → install/update-handoff-plan.js} +5 -5
- package/dist/updates/{update-marker.js → install/update-marker.js} +2 -2
- package/dist/updates/{update-swap-stage.d.ts → install/update-swap-stage.d.ts} +2 -2
- package/dist/updates/{update-swap-stage.js → install/update-swap-stage.js} +7 -6
- package/dist/updates/{update-swap.d.ts → install/update-swap.d.ts} +1 -1
- package/dist/updates/{update-swap.js → install/update-swap.js} +5 -5
- package/dist/updates/install-target.d.ts +8 -0
- package/dist/updates/install-target.js +27 -0
- package/dist/updates/{launch-environment.js → launch/launch-environment.js} +1 -1
- package/dist/updates/{packaged-launch-admission.js → launch/packaged-launch-admission.js} +4 -4
- package/dist/updates/{packaged-update-startup.d.ts → launch/packaged-update-startup.d.ts} +3 -3
- package/dist/updates/{packaged-update-startup.js → launch/packaged-update-startup.js} +10 -7
- package/dist/updates/{update-launch-gate.d.ts → launch/update-launch-gate.d.ts} +1 -1
- package/dist/updates/{update-launch-gate.js → launch/update-launch-gate.js} +9 -9
- package/dist/updates/{update-launch.d.ts → launch/update-launch.d.ts} +1 -1
- package/dist/updates/{update-launch.js → launch/update-launch.js} +2 -2
- package/dist/updates/{linux-process-state.js → locks/linux-process-state.js} +1 -1
- package/dist/updates/{native-file-lock.js → locks/native-file-lock.js} +1 -1
- package/dist/updates/{stable-file.js → locks/stable-file.js} +2 -2
- package/dist/updates/{update-download-lock.js → locks/update-download-lock.js} +1 -1
- package/dist/updates/{update-generation-lease.js → locks/update-generation-lease.js} +3 -3
- package/dist/updates/{update-inherited-launch-lease.d.ts → locks/update-inherited-launch-lease.d.ts} +1 -1
- package/dist/updates/{update-inherited-launch-lease.js → locks/update-inherited-launch-lease.js} +2 -2
- package/dist/updates/{update-instance-lease.js → locks/update-instance-lease.js} +2 -2
- package/dist/updates/{update-lock.js → locks/update-lock.js} +2 -2
- package/dist/updates/{update-process-fence.js → locks/update-process-fence.js} +3 -3
- package/dist/updates/{update-process-liveness.js → locks/update-process-liveness.js} +2 -2
- package/dist/updates/retained-client-assets.d.ts +60 -0
- package/dist/updates/retained-client-assets.js +116 -0
- package/dist/updates/retention/retention-cleanup.d.ts +103 -0
- package/dist/updates/retention/retention-cleanup.js +439 -0
- package/dist/updates/retention/retention-prune-progress.d.ts +27 -0
- package/dist/updates/retention/retention-prune-progress.js +203 -0
- package/dist/updates/retention/retirement-inventory.d.ts +93 -0
- package/dist/updates/retention/retirement-inventory.js +373 -0
- package/dist/updates/retention/retirement-records.d.ts +75 -0
- package/dist/updates/retention/retirement-records.js +309 -0
- package/dist/updates/{update-retention-marker.d.ts → retention/update-retention-marker.d.ts} +1 -1
- package/dist/updates/{update-retention-marker.js → retention/update-retention-marker.js} +3 -3
- package/dist/updates/{update-retention-plan.d.ts → retention/update-retention-plan.d.ts} +1 -1
- package/dist/updates/{update-retention-plan.js → retention/update-retention-plan.js} +2 -2
- package/dist/updates/{update-retention-sync.d.ts → retention/update-retention-sync.d.ts} +1 -1
- package/dist/updates/{update-retention-sync.js → retention/update-retention-sync.js} +2 -2
- package/dist/updates/retention/update-retirement.d.ts +26 -0
- package/dist/updates/retention/update-retirement.js +205 -0
- package/dist/updates/update-adapter.js +1 -1
- package/dist/updates/update-channel-store.d.ts +1 -1
- package/dist/updates/update-channel-store.js +2 -2
- package/dist/updates/update-manager.d.ts +4 -4
- package/dist/updates/update-manager.js +5 -5
- package/dist/updates/update-services.d.ts +15 -0
- package/dist/updates/update-services.js +77 -0
- package/dist/updates/update-state-store.d.ts +2 -2
- package/dist/updates/update-state-store.js +2 -2
- package/dist/views/appearance-surface.js +3 -1
- package/package.json +42 -29
- package/src/appearance/custom-theme-library.ts +42 -956
- package/src/appearance/theme-library-mutation.ts +288 -0
- package/src/appearance/theme-library-schema.ts +347 -0
- package/src/appearance/theme-library-store.ts +379 -0
- package/src/appearance/window-surface.ts +91 -5
- package/src/updates/update-adapter.ts +1 -1
- package/templates/application/src/bun/index.ts +15 -0
- package/templates/application/src/web/main.tsx +13 -1
- package/dist/updates/update-retirement.d.ts +0 -205
- package/dist/updates/update-retirement.js +0 -1485
- /package/dist/installer/{installer-archive.d.ts → installer-archive-members.d.ts} +0 -0
- /package/dist/updates/{packaged-release-config.d.ts → feed/packaged-release-config.d.ts} +0 -0
- /package/dist/updates/{release-feed.d.ts → feed/release-feed.d.ts} +0 -0
- /package/dist/updates/{release-location.d.ts → feed/release-location.d.ts} +0 -0
- /package/dist/updates/{release-version.d.ts → feed/release-version.d.ts} +0 -0
- /package/dist/updates/{signed-release.d.ts → feed/signed-release.d.ts} +0 -0
- /package/dist/updates/{update-discovery.d.ts → feed/update-discovery.d.ts} +0 -0
- /package/dist/updates/{update-shutdown.d.ts → helper/update-shutdown.d.ts} +0 -0
- /package/dist/updates/{update-marker.d.ts → install/update-marker.d.ts} +0 -0
- /package/dist/updates/{launch-environment.d.ts → launch/launch-environment.d.ts} +0 -0
- /package/dist/updates/{packaged-launch-admission.d.ts → launch/packaged-launch-admission.d.ts} +0 -0
- /package/dist/updates/{linux-process-state.d.ts → locks/linux-process-state.d.ts} +0 -0
- /package/dist/updates/{native-file-lock.d.ts → locks/native-file-lock.d.ts} +0 -0
- /package/dist/updates/{stable-file.d.ts → locks/stable-file.d.ts} +0 -0
- /package/dist/updates/{update-download-lock.d.ts → locks/update-download-lock.d.ts} +0 -0
- /package/dist/updates/{update-generation-lease.d.ts → locks/update-generation-lease.d.ts} +0 -0
- /package/dist/updates/{update-instance-lease.d.ts → locks/update-instance-lease.d.ts} +0 -0
- /package/dist/updates/{update-lock.d.ts → locks/update-lock.d.ts} +0 -0
- /package/dist/updates/{update-process-fence.d.ts → locks/update-process-fence.d.ts} +0 -0
- /package/dist/updates/{update-process-liveness.d.ts → locks/update-process-liveness.d.ts} +0 -0
- /package/src/updates/{release-version.ts → feed/release-version.ts} +0 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { FFIType, dlopen, read } from "bun:ffi";
|
|
3
|
+
import { closeSync, constants, fstatSync, openSync, readFileSync } from "node:fs";
|
|
4
|
+
// src/native/installer-archive.ts
|
|
5
|
+
/** The extractor only accepts hashes of this shape when it names the tar. */
|
|
6
|
+
var SAFE_HASH = /^[A-Za-z0-9_-]+$/;
|
|
7
|
+
/** Identifier and channel become path components under Application Support. */
|
|
8
|
+
var SAFE_COMPONENT = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
9
|
+
/** Electrobun's record of an update it has staged; present means "hands off". */
|
|
10
|
+
var PREPARED_UPDATE_RECORD = ".electrobun-prepared-update.json";
|
|
11
|
+
/** `ENOENT` is 2 on both Linux and macOS. */
|
|
12
|
+
var ENOENT = 2;
|
|
13
|
+
var nativeOps;
|
|
14
|
+
var cstring = (value) => Buffer.from(`${value}\0`);
|
|
15
|
+
/** `AT_SYMLINK_NOFOLLOW` differs between macOS and Linux. */
|
|
16
|
+
var AT_SYMLINK_NOFOLLOW = process.platform === "darwin" ? 32 : 256;
|
|
17
|
+
var F_OK = 0;
|
|
18
|
+
/** libc `openat`/`unlinkat`/`faccessat` through Bun's FFI, or null when unavailable. */
|
|
19
|
+
function loadNativeOps() {
|
|
20
|
+
if (nativeOps !== void 0) return nativeOps;
|
|
21
|
+
try {
|
|
22
|
+
const library = dlopen(process.platform === "darwin" ? "libSystem.B.dylib" : "libc.so.6", {
|
|
23
|
+
openat: {
|
|
24
|
+
args: [
|
|
25
|
+
FFIType.i32,
|
|
26
|
+
FFIType.cstring,
|
|
27
|
+
FFIType.i32
|
|
28
|
+
],
|
|
29
|
+
returns: FFIType.i32
|
|
30
|
+
},
|
|
31
|
+
unlinkat: {
|
|
32
|
+
args: [
|
|
33
|
+
FFIType.i32,
|
|
34
|
+
FFIType.cstring,
|
|
35
|
+
FFIType.i32
|
|
36
|
+
],
|
|
37
|
+
returns: FFIType.i32
|
|
38
|
+
},
|
|
39
|
+
faccessat: {
|
|
40
|
+
args: [
|
|
41
|
+
FFIType.i32,
|
|
42
|
+
FFIType.cstring,
|
|
43
|
+
FFIType.i32,
|
|
44
|
+
FFIType.i32
|
|
45
|
+
],
|
|
46
|
+
returns: FFIType.i32
|
|
47
|
+
},
|
|
48
|
+
[process.platform === "darwin" ? "__error" : "__errno_location"]: {
|
|
49
|
+
args: [],
|
|
50
|
+
returns: FFIType.ptr
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const errnoLocation = library.symbols[process.platform === "darwin" ? "__error" : "__errno_location"];
|
|
54
|
+
const errno = () => {
|
|
55
|
+
const location = errnoLocation();
|
|
56
|
+
return location ? read.i32(location) : void 0;
|
|
57
|
+
};
|
|
58
|
+
const openAt = (dirFd, name, flags) => library.symbols.openat(dirFd, cstring(name), flags);
|
|
59
|
+
nativeOps = {
|
|
60
|
+
openAt,
|
|
61
|
+
unlinkAt: (dirFd, name) => library.symbols.unlinkat(dirFd, cstring(name), 0),
|
|
62
|
+
probe: (dirFd, name) => {
|
|
63
|
+
if (library.symbols.faccessat(dirFd, cstring(name), F_OK, AT_SYMLINK_NOFOLLOW) === 0) return "present";
|
|
64
|
+
const accessErrno = errno();
|
|
65
|
+
const open = openAt(dirFd, name, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
|
|
66
|
+
if (open >= 0) {
|
|
67
|
+
closeSync(open);
|
|
68
|
+
return "present";
|
|
69
|
+
}
|
|
70
|
+
const openErrno = errno();
|
|
71
|
+
return accessErrno === ENOENT && openErrno === ENOENT ? "absent" : "unknown";
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
} catch {
|
|
75
|
+
nativeOps = null;
|
|
76
|
+
}
|
|
77
|
+
return nativeOps;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Remove the installer's retained payload tar for the running build.
|
|
81
|
+
*/
|
|
82
|
+
function retireInstallerArchive(options) {
|
|
83
|
+
const held = [];
|
|
84
|
+
try {
|
|
85
|
+
const versionFile = join(options.resourcesDir, "version.json");
|
|
86
|
+
let raw;
|
|
87
|
+
try {
|
|
88
|
+
raw = readFileSync(versionFile, "utf8");
|
|
89
|
+
} catch {
|
|
90
|
+
return {
|
|
91
|
+
state: "skipped",
|
|
92
|
+
reason: "not a packaged install"
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const identity = JSON.parse(raw);
|
|
96
|
+
if (typeof identity !== "object" || identity === null) return {
|
|
97
|
+
state: "skipped",
|
|
98
|
+
reason: "unreadable version identity"
|
|
99
|
+
};
|
|
100
|
+
const { identifier, channel, hash } = identity;
|
|
101
|
+
if (typeof identifier !== "string" || typeof channel !== "string" || typeof hash !== "string" || !SAFE_COMPONENT.test(identifier) || !SAFE_COMPONENT.test(channel) || !SAFE_HASH.test(hash)) return {
|
|
102
|
+
state: "skipped",
|
|
103
|
+
reason: "unsafe version identity"
|
|
104
|
+
};
|
|
105
|
+
const ops = options.ops === void 0 ? loadNativeOps() : options.ops;
|
|
106
|
+
const { O_RDONLY, O_DIRECTORY, O_NOFOLLOW, O_NONBLOCK } = constants;
|
|
107
|
+
if (!ops || O_DIRECTORY === void 0 || O_NOFOLLOW === void 0 || O_NONBLOCK === void 0) return {
|
|
108
|
+
state: "skipped",
|
|
109
|
+
reason: "descriptor-relative file operations are unavailable"
|
|
110
|
+
};
|
|
111
|
+
const chain = [
|
|
112
|
+
identifier,
|
|
113
|
+
channel,
|
|
114
|
+
"self-extraction"
|
|
115
|
+
];
|
|
116
|
+
let dirFd = openSync(options.applicationSupportDir, O_RDONLY | O_DIRECTORY | O_NONBLOCK);
|
|
117
|
+
held.push(dirFd);
|
|
118
|
+
let walked = options.applicationSupportDir;
|
|
119
|
+
for (const name of chain) {
|
|
120
|
+
walked = join(walked, name);
|
|
121
|
+
const next = ops.openAt(dirFd, name, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_NONBLOCK);
|
|
122
|
+
if (next < 0) return {
|
|
123
|
+
state: "skipped",
|
|
124
|
+
reason: "install directory is missing or not a real directory"
|
|
125
|
+
};
|
|
126
|
+
held.push(next);
|
|
127
|
+
dirFd = next;
|
|
128
|
+
}
|
|
129
|
+
options.afterDirectoryVerified?.();
|
|
130
|
+
if (ops.probe(dirFd, PREPARED_UPDATE_RECORD) !== "absent") return {
|
|
131
|
+
state: "skipped",
|
|
132
|
+
reason: "a prepared update record exists or cannot be ruled out"
|
|
133
|
+
};
|
|
134
|
+
const name = `${hash}.tar`;
|
|
135
|
+
const fileFd = ops.openAt(dirFd, name, O_RDONLY | O_NOFOLLOW | O_NONBLOCK);
|
|
136
|
+
if (fileFd < 0) switch (ops.probe(dirFd, name)) {
|
|
137
|
+
case "absent": return { state: "absent" };
|
|
138
|
+
case "present": return {
|
|
139
|
+
state: "skipped",
|
|
140
|
+
reason: "not a regular file"
|
|
141
|
+
};
|
|
142
|
+
default: return {
|
|
143
|
+
state: "skipped",
|
|
144
|
+
reason: "the archive could not be inspected"
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
held.push(fileFd);
|
|
148
|
+
if (!fstatSync(fileFd).isFile()) return {
|
|
149
|
+
state: "skipped",
|
|
150
|
+
reason: "not a regular file"
|
|
151
|
+
};
|
|
152
|
+
options.beforeUnlink?.();
|
|
153
|
+
if (ops.unlinkAt(dirFd, name) !== 0) return {
|
|
154
|
+
state: "skipped",
|
|
155
|
+
reason: "could not remove the archive"
|
|
156
|
+
};
|
|
157
|
+
return {
|
|
158
|
+
state: "removed",
|
|
159
|
+
path: join(walked, name)
|
|
160
|
+
};
|
|
161
|
+
} catch (error) {
|
|
162
|
+
return {
|
|
163
|
+
state: "skipped",
|
|
164
|
+
reason: error instanceof Error ? error.message : "unexpected failure"
|
|
165
|
+
};
|
|
166
|
+
} finally {
|
|
167
|
+
for (const fd of held) try {
|
|
168
|
+
closeSync(fd);
|
|
169
|
+
} catch {}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
export { loadNativeOps, retireInstallerArchive };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { createServiceRegistry } from '../app/service-registry';
|
|
2
|
+
import type { WindowSurface } from '../appearance/window-surface';
|
|
3
|
+
/** The persisted surface; a missing, unreadable or unknown record is `theme`. */
|
|
4
|
+
export declare function readWindowSurface(stateFile: string): WindowSurface;
|
|
5
|
+
/** Whether the window is created see-through: only the frosted surface, only on macOS. */
|
|
6
|
+
export declare function windowSurfaceTransparent(surface: WindowSurface, platform: string): boolean;
|
|
7
|
+
/** Persist the surface atomically, readable by this user only. */
|
|
8
|
+
export declare function writeWindowSurface(stateFile: string, surface: WindowSurface): void;
|
|
9
|
+
/** Register `shell.window-surface`, which persists `{ surface }` and answers `{ surface, appliesOnRestart }`. */
|
|
10
|
+
export declare function registerWindowSurfaceService<Principal>(options: {
|
|
11
|
+
services: ReturnType<typeof createServiceRegistry<Principal>>;
|
|
12
|
+
stateFile: string;
|
|
13
|
+
authorize(principal: Principal): boolean | Promise<boolean>;
|
|
14
|
+
/** The surface the running window was created with; default: the persisted one at registration. */
|
|
15
|
+
current?: WindowSurface;
|
|
16
|
+
}): () => void;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { dirname, join } from "node:path";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
// src/native/window-surface-store.ts
|
|
5
|
+
/**
|
|
6
|
+
* The native half of the appearance editor's glass setting. Electrobun 2.0.5 sets window
|
|
7
|
+
* transparency at creation only, so the host reads the persisted surface at startup and a
|
|
8
|
+
* change applies on the next launch. The web side persists each choice through the
|
|
9
|
+
* `shell.window-surface` service (see `createWindowSurfaceMirror`).
|
|
10
|
+
*/
|
|
11
|
+
var SURFACES = [
|
|
12
|
+
"theme",
|
|
13
|
+
"frosted",
|
|
14
|
+
"opaque"
|
|
15
|
+
];
|
|
16
|
+
var isWindowSurface = (value) => SURFACES.includes(value);
|
|
17
|
+
/** The persisted surface; a missing, unreadable or unknown record is `theme`. */
|
|
18
|
+
function readWindowSurface(stateFile) {
|
|
19
|
+
try {
|
|
20
|
+
const surface = JSON.parse(readFileSync(stateFile, "utf8"))?.windowSurface;
|
|
21
|
+
return isWindowSurface(surface) ? surface : "theme";
|
|
22
|
+
} catch {
|
|
23
|
+
return "theme";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Whether the window is created see-through: only the frosted surface, only on macOS. */
|
|
27
|
+
function windowSurfaceTransparent(surface, platform) {
|
|
28
|
+
return platform === "darwin" && surface === "frosted";
|
|
29
|
+
}
|
|
30
|
+
/** Persist the surface atomically, readable by this user only. */
|
|
31
|
+
function writeWindowSurface(stateFile, surface) {
|
|
32
|
+
if (!isWindowSurface(surface)) throw new Error("Invalid window surface");
|
|
33
|
+
mkdirSync(dirname(stateFile), {
|
|
34
|
+
recursive: true,
|
|
35
|
+
mode: 448
|
|
36
|
+
});
|
|
37
|
+
const temporary = join(dirname(stateFile), `.window-surface-${randomUUID()}.tmp`);
|
|
38
|
+
try {
|
|
39
|
+
writeFileSync(temporary, `${JSON.stringify({ windowSurface: surface })}\n`, {
|
|
40
|
+
mode: 384,
|
|
41
|
+
flag: "wx"
|
|
42
|
+
});
|
|
43
|
+
renameSync(temporary, stateFile);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
rmSync(temporary, { force: true });
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Register `shell.window-surface`, which persists `{ surface }` and answers `{ surface, appliesOnRestart }`. */
|
|
50
|
+
function registerWindowSurfaceService(options) {
|
|
51
|
+
const { services, stateFile, authorize } = options;
|
|
52
|
+
const current = options.current ?? readWindowSurface(stateFile);
|
|
53
|
+
return services.register("shell.window-surface", {
|
|
54
|
+
parse(value) {
|
|
55
|
+
const record = value;
|
|
56
|
+
if (typeof value !== "object" || value === null || Array.isArray(value) || Object.keys(value).length !== 1 || !isWindowSurface(record?.surface)) throw new Error("Invalid input");
|
|
57
|
+
return record.surface;
|
|
58
|
+
},
|
|
59
|
+
authorize: (principal) => authorize(principal),
|
|
60
|
+
run(_principal, surface) {
|
|
61
|
+
writeWindowSurface(stateFile, surface);
|
|
62
|
+
return {
|
|
63
|
+
surface,
|
|
64
|
+
appliesOnRestart: surface !== current
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
export { readWindowSurface, registerWindowSurfaceService, windowSurfaceTransparent, writeWindowSurface };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Electrobun 2.0.5's Windows installer runs `extractor.exe`, whose shortcut code this
|
|
3
|
+
* framework patches (electrobun-windows-shortcut-com.patch). A stable Windows build
|
|
4
|
+
* rebuilds that extractor from the pinned source with the pinned Zig toolchain and points
|
|
5
|
+
* Electrobun at a copy of its devkit holding the rebuilt binary.
|
|
6
|
+
*/
|
|
7
|
+
export declare const ELECTROBUN_VERSION = "2.0.5";
|
|
8
|
+
/** The Zig release Electrobun 2.0.5 builds with (its src/shared/build-dependencies.ts). */
|
|
9
|
+
export declare const ZIG_VERSION = "0.17.0";
|
|
10
|
+
/**
|
|
11
|
+
* Zig builds for the build host's own CPU unless told otherwise, and some Windows runners
|
|
12
|
+
* have AVX-512 while others do not; a native build then dies with STATUS_ILLEGAL_INSTRUCTION
|
|
13
|
+
* on another machine. Every Windows binary targets a fixed baseline instead.
|
|
14
|
+
*/
|
|
15
|
+
export declare const ZIG_WINDOWS_TARGET: readonly ['-Dtarget=x86_64-windows-gnu', '-Dcpu=x86_64_v2'];
|
|
16
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
17
|
+
/** The extractor's name in a pinned Electrobun 2.0.5 Windows x64 devkit manifest. */
|
|
18
|
+
export declare function validateWindowsDevkitManifest(manifest: unknown): string;
|
|
19
|
+
/** A PE32+ x64 executable that keeps the Windows GUI subsystem (no console window). */
|
|
20
|
+
export declare function assertWindowsX64GuiExecutable(bytes: Uint8Array): void;
|
|
21
|
+
/**
|
|
22
|
+
* Copy the official devkit (hardlinks where possible) to `patchedCoreRoot` and replace only
|
|
23
|
+
* its extractor with `builtExtractor`. The official cached extractor must not change and the
|
|
24
|
+
* copy must hold the built bytes.
|
|
25
|
+
*/
|
|
26
|
+
export declare function installPatchedExtractor(options: {
|
|
27
|
+
officialCoreRoot: string;
|
|
28
|
+
patchedCoreRoot: string;
|
|
29
|
+
builtExtractor: string;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
extractorName: string;
|
|
32
|
+
officialSha256: string;
|
|
33
|
+
builtSha256: string;
|
|
34
|
+
}>;
|
|
35
|
+
/** A process the build runs; `capture` returns trimmed stdout. */
|
|
36
|
+
export type WindowsBuildCommand = (command: string, args: readonly string[], options?: {
|
|
37
|
+
cwd?: string;
|
|
38
|
+
env?: Env;
|
|
39
|
+
capture?: boolean;
|
|
40
|
+
}) => string;
|
|
41
|
+
type SpawnResult = {
|
|
42
|
+
status: number | null;
|
|
43
|
+
stdout?: string;
|
|
44
|
+
stderr?: string;
|
|
45
|
+
error?: Error;
|
|
46
|
+
};
|
|
47
|
+
/** Run a command with bounded output; a non-zero exit throws with its stderr. */
|
|
48
|
+
export declare function runBuildCommand(command: string, args: readonly string[], options?: {
|
|
49
|
+
cwd?: string;
|
|
50
|
+
env?: Env;
|
|
51
|
+
capture?: boolean;
|
|
52
|
+
spawnProcess?: (command: string, args: readonly string[], options: object) => SpawnResult;
|
|
53
|
+
}): string;
|
|
54
|
+
type FetchResponse = {
|
|
55
|
+
ok: boolean;
|
|
56
|
+
body: ReadableStream<Uint8Array> | null;
|
|
57
|
+
url: string;
|
|
58
|
+
};
|
|
59
|
+
/** Download the pinned Zig archive from ziglang.org and check its size and SHA-256. */
|
|
60
|
+
export declare function downloadPinnedZig(archivePath: string, options?: {
|
|
61
|
+
fetch?: (url: string, init: {
|
|
62
|
+
redirect: 'follow';
|
|
63
|
+
}) => Promise<FetchResponse>;
|
|
64
|
+
expectedSize?: number;
|
|
65
|
+
expectedSha256?: string;
|
|
66
|
+
}): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Build a stable Windows x64 installer whose extractor carries the framework's shortcut
|
|
69
|
+
* patch: prepare Electrobun's devkit, fetch and patch the pinned source, build and test the
|
|
70
|
+
* extractor with the pinned Zig, swap it into a copy of the devkit, then run
|
|
71
|
+
* `electrobun build --env=stable` against that copy. Runs only on a disposable Windows x64
|
|
72
|
+
* CI runner (`CI=true`) and removes its scratch state, success or failure. Resolves the
|
|
73
|
+
* installer path.
|
|
74
|
+
*/
|
|
75
|
+
export declare function buildPatchedWindowsInstaller(options: {
|
|
76
|
+
/** The Electrobun project directory (its `electrobun.config.ts`). */
|
|
77
|
+
appRoot: string;
|
|
78
|
+
appName: string;
|
|
79
|
+
env?: Env;
|
|
80
|
+
platform?: string;
|
|
81
|
+
arch?: string;
|
|
82
|
+
/** Where scratch state goes; defaults to `RUNNER_TEMP`, then the system temp directory. */
|
|
83
|
+
scratchParent?: string;
|
|
84
|
+
runCommand?: WindowsBuildCommand;
|
|
85
|
+
fetch?: (url: string, init: {
|
|
86
|
+
redirect: 'follow';
|
|
87
|
+
}) => Promise<FetchResponse>;
|
|
88
|
+
zigArchiveSize?: number;
|
|
89
|
+
zigArchiveSha256?: string;
|
|
90
|
+
/** Replaces the pinned-patch apply step; tests only. */
|
|
91
|
+
applyPatch?: (sourceRoot: string) => void;
|
|
92
|
+
now?: () => number;
|
|
93
|
+
logStage?: (message: string) => void;
|
|
94
|
+
}): Promise<string>;
|
|
95
|
+
export {};
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { ELECTROBUN_COMMIT, PINNED_SHORTCUT_PATCH, SHORTCUT_PATCH_PATH, applyElectrobunPatch } from "./electrobun-source-patch.js";
|
|
2
|
+
import { electrobunArtifacts } from "../release/release-steps.js";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
import { copyFileSync, createReadStream, createWriteStream, existsSync, linkSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, unlinkSync } from "node:fs";
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
import { Readable } from "node:stream";
|
|
9
|
+
import { pipeline } from "node:stream/promises";
|
|
10
|
+
import { performance } from "node:perf_hooks";
|
|
11
|
+
// src/native/windows-extractor-build.ts
|
|
12
|
+
/**
|
|
13
|
+
* Electrobun 2.0.5's Windows installer runs `extractor.exe`, whose shortcut code this
|
|
14
|
+
* framework patches (electrobun-windows-shortcut-com.patch). A stable Windows build
|
|
15
|
+
* rebuilds that extractor from the pinned source with the pinned Zig toolchain and points
|
|
16
|
+
* Electrobun at a copy of its devkit holding the rebuilt binary.
|
|
17
|
+
*/
|
|
18
|
+
var ELECTROBUN_VERSION = "2.0.5";
|
|
19
|
+
/** The Zig release Electrobun 2.0.5 builds with (its src/shared/build-dependencies.ts). */
|
|
20
|
+
var ZIG_VERSION = "0.17.0";
|
|
21
|
+
/**
|
|
22
|
+
* Zig builds for the build host's own CPU unless told otherwise, and some Windows runners
|
|
23
|
+
* have AVX-512 while others do not; a native build then dies with STATUS_ILLEGAL_INSTRUCTION
|
|
24
|
+
* on another machine. Every Windows binary targets a fixed baseline instead.
|
|
25
|
+
*/
|
|
26
|
+
var ZIG_WINDOWS_TARGET = ["-Dtarget=x86_64-windows-gnu", "-Dcpu=x86_64_v2"];
|
|
27
|
+
var ZIG_WINDOWS_X64_URL = `https://ziglang.org/download/${ZIG_VERSION}/zig-x86_64-windows-${ZIG_VERSION}.zip`;
|
|
28
|
+
/** From ziglang.org's download index. */
|
|
29
|
+
var ZIG_WINDOWS_X64_SHA256 = "b5663f69581dcf391293fbf16c06cb80d81d806545ce618b4d0bab7f0eb8c428";
|
|
30
|
+
var ZIG_WINDOWS_X64_SIZE = 100268137;
|
|
31
|
+
var ELECTROBUN_SOURCE_URL = "https://github.com/blackboardsh/electrobun.git";
|
|
32
|
+
/** The extractor's name in a pinned Electrobun 2.0.5 Windows x64 devkit manifest. */
|
|
33
|
+
function validateWindowsDevkitManifest(manifest) {
|
|
34
|
+
const value = manifest;
|
|
35
|
+
if (value?.schemaVersion !== 1 || value.product?.name !== "electrobun" || value.product?.version !== "2.0.5" || value.target?.os !== "win" || value.target?.arch !== "x64" || value.layout?.runtime?.extractor !== "extractor.exe") throw new Error("Hutch core does not match the pinned Electrobun 2.0.5 Windows x64 devkit");
|
|
36
|
+
return "extractor.exe";
|
|
37
|
+
}
|
|
38
|
+
/** A PE32+ x64 executable that keeps the Windows GUI subsystem (no console window). */
|
|
39
|
+
function assertWindowsX64GuiExecutable(bytes) {
|
|
40
|
+
const buffer = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes);
|
|
41
|
+
if (buffer.length < 256 || buffer.toString("ascii", 0, 2) !== "MZ") throw new Error("Patched Electrobun extractor is not a valid PE executable");
|
|
42
|
+
const peOffset = buffer.readUInt32LE(60);
|
|
43
|
+
if (peOffset < 64 || peOffset + 94 > buffer.length || buffer.toString("ascii", peOffset, peOffset + 4) !== "PE\0\0") throw new Error("Patched Electrobun extractor has an invalid PE header");
|
|
44
|
+
if (buffer.readUInt16LE(peOffset + 4) !== 34404) throw new Error("Patched Electrobun extractor is not Windows x64");
|
|
45
|
+
const optionalHeader = peOffset + 24;
|
|
46
|
+
if (buffer.readUInt16LE(optionalHeader) !== 523) throw new Error("Patched Electrobun extractor does not use the PE32+ format");
|
|
47
|
+
if (buffer.readUInt16LE(optionalHeader + 68) !== 2) throw new Error("Patched Electrobun extractor must retain the Windows GUI subsystem");
|
|
48
|
+
}
|
|
49
|
+
async function sha256File(path) {
|
|
50
|
+
const hash = createHash("sha256");
|
|
51
|
+
for await (const chunk of createReadStream(path)) hash.update(chunk);
|
|
52
|
+
return hash.digest("hex");
|
|
53
|
+
}
|
|
54
|
+
function hardlinkOrCopy(source, destination) {
|
|
55
|
+
try {
|
|
56
|
+
linkSync(source, destination);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
const code = error.code ?? "";
|
|
59
|
+
if (![
|
|
60
|
+
"EACCES",
|
|
61
|
+
"EMLINK",
|
|
62
|
+
"EPERM",
|
|
63
|
+
"EXDEV",
|
|
64
|
+
"ENOTSUP"
|
|
65
|
+
].includes(code)) throw error;
|
|
66
|
+
copyFileSync(source, destination);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function copyTree(source, destination) {
|
|
70
|
+
for (const entry of readdirSync(source)) {
|
|
71
|
+
const from = join(source, entry);
|
|
72
|
+
const to = join(destination, entry);
|
|
73
|
+
const info = lstatSync(from);
|
|
74
|
+
if (info.isSymbolicLink()) throw new Error("Electrobun core must not contain symbolic links");
|
|
75
|
+
if (info.isDirectory()) {
|
|
76
|
+
mkdirSync(to);
|
|
77
|
+
copyTree(from, to);
|
|
78
|
+
} else if (info.isFile()) hardlinkOrCopy(from, to);
|
|
79
|
+
else throw new Error("Electrobun core contains an unsupported filesystem object");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Copy the official devkit (hardlinks where possible) to `patchedCoreRoot` and replace only
|
|
84
|
+
* its extractor with `builtExtractor`. The official cached extractor must not change and the
|
|
85
|
+
* copy must hold the built bytes.
|
|
86
|
+
*/
|
|
87
|
+
async function installPatchedExtractor(options) {
|
|
88
|
+
const { officialCoreRoot, patchedCoreRoot, builtExtractor } = options;
|
|
89
|
+
const extractorName = validateWindowsDevkitManifest(JSON.parse(readFileSync(join(officialCoreRoot, "native-devkit.json"), "utf8")));
|
|
90
|
+
const officialExtractor = join(officialCoreRoot, extractorName);
|
|
91
|
+
const patchedExtractor = join(patchedCoreRoot, extractorName);
|
|
92
|
+
if (!lstatSync(officialExtractor).isFile()) throw new Error("Pinned Electrobun core extractor is missing");
|
|
93
|
+
const builtBytes = readFileSync(builtExtractor);
|
|
94
|
+
assertWindowsX64GuiExecutable(builtBytes);
|
|
95
|
+
const officialSha256 = await sha256File(officialExtractor);
|
|
96
|
+
const builtSha256 = createHash("sha256").update(builtBytes).digest("hex");
|
|
97
|
+
if (existsSync(patchedCoreRoot)) throw new Error("Patched Electrobun core destination already exists");
|
|
98
|
+
mkdirSync(patchedCoreRoot, { recursive: true });
|
|
99
|
+
copyTree(officialCoreRoot, patchedCoreRoot);
|
|
100
|
+
unlinkSync(patchedExtractor);
|
|
101
|
+
copyFileSync(builtExtractor, patchedExtractor);
|
|
102
|
+
if (await sha256File(officialExtractor) !== officialSha256) throw new Error("Building the patched core modified the official cached Electrobun extractor");
|
|
103
|
+
if (await sha256File(patchedExtractor) !== builtSha256) throw new Error("Patched Electrobun core does not contain the built extractor bytes");
|
|
104
|
+
return {
|
|
105
|
+
extractorName,
|
|
106
|
+
officialSha256,
|
|
107
|
+
builtSha256
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** Run a command with bounded output; a non-zero exit throws with its stderr. */
|
|
111
|
+
function runBuildCommand(command, args, options = {}) {
|
|
112
|
+
const result = (options.spawnProcess ?? ((cmd, argv, spawnOptions) => spawnSync(cmd, [...argv], spawnOptions)))(command, args, {
|
|
113
|
+
cwd: options.cwd,
|
|
114
|
+
env: options.env,
|
|
115
|
+
encoding: "utf8",
|
|
116
|
+
maxBuffer: 8388608,
|
|
117
|
+
stdio: options.capture ? [
|
|
118
|
+
"ignore",
|
|
119
|
+
"pipe",
|
|
120
|
+
"pipe"
|
|
121
|
+
] : "inherit"
|
|
122
|
+
});
|
|
123
|
+
if (result.error) throw result.error;
|
|
124
|
+
if (result.status !== 0) {
|
|
125
|
+
const detail = result.stderr?.trim();
|
|
126
|
+
throw new Error(`${command} exited with status ${result.status}${detail ? `: ${detail}` : ""}`);
|
|
127
|
+
}
|
|
128
|
+
return options.capture ? (result.stdout ?? "").trim() : "";
|
|
129
|
+
}
|
|
130
|
+
/** Download the pinned Zig archive from ziglang.org and check its size and SHA-256. */
|
|
131
|
+
async function downloadPinnedZig(archivePath, options = {}) {
|
|
132
|
+
const response = await (options.fetch ?? ((url, init) => fetch(url, init)))(ZIG_WINDOWS_X64_URL, { redirect: "follow" });
|
|
133
|
+
if (!response.ok || !response.body) throw new Error(`Could not download pinned Zig ${ZIG_VERSION}`);
|
|
134
|
+
if (new URL(response.url).hostname !== "ziglang.org") throw new Error("Pinned Zig download redirected away from ziglang.org");
|
|
135
|
+
await pipeline(Readable.fromWeb(response.body), createWriteStream(archivePath, { flags: "wx" }));
|
|
136
|
+
if (statSync(archivePath).size !== (options.expectedSize ?? ZIG_WINDOWS_X64_SIZE)) throw new Error("Pinned Zig Windows archive has an unexpected size");
|
|
137
|
+
if (await sha256File(archivePath) !== (options.expectedSha256 ?? ZIG_WINDOWS_X64_SHA256)) throw new Error("Pinned Zig Windows archive failed its official SHA-256 check");
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Build a stable Windows x64 installer whose extractor carries the framework's shortcut
|
|
141
|
+
* patch: prepare Electrobun's devkit, fetch and patch the pinned source, build and test the
|
|
142
|
+
* extractor with the pinned Zig, swap it into a copy of the devkit, then run
|
|
143
|
+
* `electrobun build --env=stable` against that copy. Runs only on a disposable Windows x64
|
|
144
|
+
* CI runner (`CI=true`) and removes its scratch state, success or failure. Resolves the
|
|
145
|
+
* installer path.
|
|
146
|
+
*/
|
|
147
|
+
async function buildPatchedWindowsInstaller(options) {
|
|
148
|
+
const env = options.env ?? process.env;
|
|
149
|
+
const runCommand = options.runCommand ?? ((command, args, runOptions) => runBuildCommand(command, args, runOptions));
|
|
150
|
+
const now = options.now ?? (() => performance.now());
|
|
151
|
+
const logStage = options.logStage ?? ((message) => console.log(message));
|
|
152
|
+
if ((options.platform ?? process.platform) !== "win32" || (options.arch ?? process.arch) !== "x64") throw new Error("The patched Electrobun installer build requires a native Windows x64 runner");
|
|
153
|
+
if (env.CI !== "true") throw new Error("The patched Electrobun installer build requires a disposable CI runner");
|
|
154
|
+
const appRoot = resolve(options.appRoot);
|
|
155
|
+
const [installerName] = electrobunArtifacts(options.appName, "windows-x64");
|
|
156
|
+
const parent = options.scratchParent ?? env.RUNNER_TEMP ?? tmpdir();
|
|
157
|
+
const scratch = mkdtempSync(join(parent, "framework-electrobun-extractor-"));
|
|
158
|
+
let stage;
|
|
159
|
+
let started = 0;
|
|
160
|
+
const finishStage = () => {
|
|
161
|
+
if (stage) logStage(`Windows installer stage ${stage}: ${Math.round(now() - started)} ms`);
|
|
162
|
+
};
|
|
163
|
+
const startStage = (name) => {
|
|
164
|
+
finishStage();
|
|
165
|
+
stage = name;
|
|
166
|
+
started = now();
|
|
167
|
+
};
|
|
168
|
+
try {
|
|
169
|
+
startStage("hutch-prepare");
|
|
170
|
+
const hutchHome = join(scratch, "hutch");
|
|
171
|
+
mkdirSync(hutchHome);
|
|
172
|
+
const childEnv = {
|
|
173
|
+
...env,
|
|
174
|
+
HUTCH_HOME: hutchHome
|
|
175
|
+
};
|
|
176
|
+
runCommand("bun", [
|
|
177
|
+
"x",
|
|
178
|
+
"--bun",
|
|
179
|
+
"electrobun",
|
|
180
|
+
"prepare"
|
|
181
|
+
], {
|
|
182
|
+
cwd: appRoot,
|
|
183
|
+
env: childEnv
|
|
184
|
+
});
|
|
185
|
+
startStage("source-and-patch");
|
|
186
|
+
const sourceRoot = join(scratch, "electrobun-source");
|
|
187
|
+
runCommand("git", ["init", sourceRoot]);
|
|
188
|
+
runCommand("git", [
|
|
189
|
+
"-C",
|
|
190
|
+
sourceRoot,
|
|
191
|
+
"remote",
|
|
192
|
+
"add",
|
|
193
|
+
"origin",
|
|
194
|
+
ELECTROBUN_SOURCE_URL
|
|
195
|
+
]);
|
|
196
|
+
runCommand("git", [
|
|
197
|
+
"-C",
|
|
198
|
+
sourceRoot,
|
|
199
|
+
"fetch",
|
|
200
|
+
"--depth=1",
|
|
201
|
+
"origin",
|
|
202
|
+
ELECTROBUN_COMMIT
|
|
203
|
+
]);
|
|
204
|
+
runCommand("git", [
|
|
205
|
+
"-C",
|
|
206
|
+
sourceRoot,
|
|
207
|
+
"checkout",
|
|
208
|
+
"--detach",
|
|
209
|
+
"FETCH_HEAD"
|
|
210
|
+
]);
|
|
211
|
+
if (runCommand("git", [
|
|
212
|
+
"-C",
|
|
213
|
+
sourceRoot,
|
|
214
|
+
"rev-parse",
|
|
215
|
+
"HEAD"
|
|
216
|
+
], { capture: true }) !== "d06abc9edf0b4e55116129cabbfe17bf89e11791") throw new Error("Fetched Electrobun source does not match the pinned upstream commit");
|
|
217
|
+
(options.applyPatch ?? ((root) => applyElectrobunPatch(root, SHORTCUT_PATCH_PATH, PINNED_SHORTCUT_PATCH)))(sourceRoot);
|
|
218
|
+
startStage("zig-download-and-verification");
|
|
219
|
+
const archivePath = join(scratch, "zig-windows-x64.zip");
|
|
220
|
+
const zigRoot = join(scratch, "zig-toolchain");
|
|
221
|
+
mkdirSync(zigRoot);
|
|
222
|
+
await downloadPinnedZig(archivePath, {
|
|
223
|
+
...options.fetch ? { fetch: options.fetch } : {},
|
|
224
|
+
...options.zigArchiveSize === void 0 ? {} : { expectedSize: options.zigArchiveSize },
|
|
225
|
+
...options.zigArchiveSha256 === void 0 ? {} : { expectedSha256: options.zigArchiveSha256 }
|
|
226
|
+
});
|
|
227
|
+
startStage("zig-extraction-and-verification");
|
|
228
|
+
const systemRoot = env.SystemRoot ?? env.WINDIR;
|
|
229
|
+
if (!systemRoot) throw new Error("Windows system directory is unavailable");
|
|
230
|
+
const bsdtar = join(systemRoot, "System32", "tar.exe");
|
|
231
|
+
if (!/^bsdtar\s/i.test(runCommand(bsdtar, ["--version"], { capture: true }))) throw new Error("Windows extractor build requires the qualified system bsdtar");
|
|
232
|
+
runCommand(bsdtar, [
|
|
233
|
+
"-xf",
|
|
234
|
+
archivePath,
|
|
235
|
+
"-C",
|
|
236
|
+
zigRoot
|
|
237
|
+
]);
|
|
238
|
+
const zig = join(zigRoot, `zig-x86_64-windows-${ZIG_VERSION}`, "zig.exe");
|
|
239
|
+
if (runCommand(zig, ["version"], { capture: true }) !== "0.17.0") throw new Error("Downloaded Zig executable does not report the pinned version");
|
|
240
|
+
const extractorRoot = join(sourceRoot, "package", "src", "extractor");
|
|
241
|
+
const zigEnv = {
|
|
242
|
+
...childEnv,
|
|
243
|
+
ZIG_LOCAL_CACHE_DIR: join(scratch, "zig-local-cache"),
|
|
244
|
+
ZIG_GLOBAL_CACHE_DIR: join(scratch, "zig-global-cache")
|
|
245
|
+
};
|
|
246
|
+
startStage("shortcut-helper");
|
|
247
|
+
const shortcutTestHelper = join(scratch, "shortcut-test-helper.exe");
|
|
248
|
+
runCommand(zig, [
|
|
249
|
+
"cc",
|
|
250
|
+
"-target",
|
|
251
|
+
"x86_64-windows-gnu",
|
|
252
|
+
"-mcpu=x86_64_v2",
|
|
253
|
+
"-O2",
|
|
254
|
+
"-municode",
|
|
255
|
+
"-DELECTROBUN_WINDOWS_SHORTCUT_TESTING=1",
|
|
256
|
+
"-Werror=incompatible-pointer-types",
|
|
257
|
+
"windows_shortcut.c",
|
|
258
|
+
"windows_shortcut_test_helper.c",
|
|
259
|
+
"-lole32",
|
|
260
|
+
"-o",
|
|
261
|
+
shortcutTestHelper
|
|
262
|
+
], {
|
|
263
|
+
cwd: extractorRoot,
|
|
264
|
+
env: zigEnv
|
|
265
|
+
});
|
|
266
|
+
if (!existsSync(shortcutTestHelper)) throw new Error("Windows shortcut test helper was not built");
|
|
267
|
+
startStage("shortcut-tests");
|
|
268
|
+
runCommand(zig, [
|
|
269
|
+
"build",
|
|
270
|
+
"test",
|
|
271
|
+
"-Doptimize=ReleaseFast",
|
|
272
|
+
...ZIG_WINDOWS_TARGET
|
|
273
|
+
], {
|
|
274
|
+
cwd: extractorRoot,
|
|
275
|
+
env: {
|
|
276
|
+
...zigEnv,
|
|
277
|
+
ELECTROBUN_WINDOWS_SHORTCUT_TEST_HELPER: shortcutTestHelper
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
startStage("extractor-build");
|
|
281
|
+
runCommand(zig, [
|
|
282
|
+
"build",
|
|
283
|
+
"-Doptimize=ReleaseFast",
|
|
284
|
+
...ZIG_WINDOWS_TARGET
|
|
285
|
+
], {
|
|
286
|
+
cwd: extractorRoot,
|
|
287
|
+
env: zigEnv
|
|
288
|
+
});
|
|
289
|
+
const builtExtractor = join(extractorRoot, "zig-out", "bin", "extractor.exe");
|
|
290
|
+
assertWindowsX64GuiExecutable(readFileSync(builtExtractor));
|
|
291
|
+
startStage("patched-core");
|
|
292
|
+
const patched = await installPatchedExtractor({
|
|
293
|
+
officialCoreRoot: join(hutchHome, "releases", "electrobun", ELECTROBUN_VERSION, "windows-x64"),
|
|
294
|
+
patchedCoreRoot: join(scratch, "patched-electrobun-core"),
|
|
295
|
+
builtExtractor
|
|
296
|
+
});
|
|
297
|
+
startStage("installer-package");
|
|
298
|
+
runCommand("bun", [
|
|
299
|
+
"x",
|
|
300
|
+
"--bun",
|
|
301
|
+
"electrobun",
|
|
302
|
+
"build",
|
|
303
|
+
"--env=stable"
|
|
304
|
+
], {
|
|
305
|
+
cwd: appRoot,
|
|
306
|
+
env: {
|
|
307
|
+
...childEnv,
|
|
308
|
+
HUTCH_ELECTROBUN_DEVKIT_ROOT: join(scratch, "patched-electrobun-core")
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
const installer = join(appRoot, "artifacts", installerName);
|
|
312
|
+
if (!existsSync(installer)) throw new Error("Patched Electrobun build did not produce the Windows installer ZIP");
|
|
313
|
+
console.log(`Built Electrobun ${ELECTROBUN_VERSION} source ${ELECTROBUN_COMMIT}; Zig ${ZIG_VERSION}; extractor SHA-256 ${patched.builtSha256}`);
|
|
314
|
+
return installer;
|
|
315
|
+
} finally {
|
|
316
|
+
try {
|
|
317
|
+
finishStage();
|
|
318
|
+
} finally {
|
|
319
|
+
rmSync(scratch, {
|
|
320
|
+
recursive: true,
|
|
321
|
+
force: true
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
export { ELECTROBUN_VERSION, ZIG_VERSION, ZIG_WINDOWS_TARGET, assertWindowsX64GuiExecutable, buildPatchedWindowsInstaller, downloadPinnedZig, installPatchedExtractor, runBuildCommand, validateWindowsDevkitManifest };
|