@adea-ai/app-framework 0.30.0 → 0.32.0
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 +26 -11
- package/dist/app/application.js +4 -2
- package/dist/app/create-application.js +4 -3
- package/dist/app/serial-queue.d.ts +5 -0
- package/dist/app/serial-queue.js +14 -0
- package/dist/app/value-guards.d.ts +15 -0
- package/dist/app/value-guards.js +29 -0
- package/dist/appearance/appearance-host.js +6 -0
- package/dist/appearance/appearance-preferences.js +6 -2
- package/dist/appearance/composition.d.ts +1 -1
- package/dist/appearance/custom-theme-import.js +12 -19
- package/dist/appearance/custom-theme-library.d.ts +5 -4
- package/dist/appearance/custom-theme-library.js +20 -2
- package/dist/appearance/editor.js +4 -1
- package/dist/appearance/legacy-imported-theme-token-projection.d.ts +84 -0
- package/dist/appearance/legacy-imported-theme-token-projection.js +142 -0
- package/dist/appearance/theme-record-adapter.js +37 -9
- package/dist/ci/toolchain-identity.js +1 -1
- package/dist/desktop/channel-proof.js +2 -1
- package/dist/desktop/client-asset-stream.js +6 -12
- package/dist/desktop/desktop-host.d.ts +25 -5
- package/dist/desktop/desktop-host.js +75 -20
- package/dist/framework-source.json +1 -1
- package/dist/installer/command-artifact.js +4 -3
- package/dist/installer/command-qualification-command.js +6 -5
- package/dist/installer/hosted-runner.d.ts +9 -2
- package/dist/installer/hosted-runner.js +18 -5
- package/dist/installer/installed-payload.js +20 -46
- package/dist/installer/installer-archive.d.ts +33 -0
- package/dist/installer/installer-archive.js +116 -0
- package/dist/installer/installer-ci-bootstrap.js +10 -6
- package/dist/installer/installer-extraction.js +54 -120
- package/dist/installer/installer-identity.js +33 -111
- package/dist/installer/installer-observation.js +3 -2
- package/dist/installer/installer-process-cleanup.js +7 -46
- package/dist/installer/installer-qualification-command.js +6 -5
- package/dist/installer/installer-upgrade-command.js +5 -5
- package/dist/installer/installer-worker-guard.js +2 -1
- package/dist/native/canonical-path.d.ts +5 -0
- package/dist/native/canonical-path.js +10 -0
- package/dist/native/cef-helper.js +5 -4
- package/dist/native/electrobun-source-patch.js +3 -2
- package/dist/native/{directory-exchange.d.ts → native-rename.d.ts} +2 -0
- package/dist/native/native-rename.js +126 -0
- package/dist/native/native-secret-store.js +2 -6
- package/dist/native/native-utilities.js +4 -4
- package/dist/native/posix-launcher-build.js +1 -1
- package/dist/native/posix-tree-removal.js +2 -2
- package/dist/native/windows-process.d.ts +9 -0
- package/dist/native/windows-process.js +60 -0
- package/dist/release/feed-release-cut.js +2 -1
- package/dist/release/framework-package-publish.js +1 -1
- package/dist/release/framework-update-lock.js +2 -1
- package/dist/release/github-cli.d.ts +18 -0
- package/dist/release/github-cli.js +13 -1
- package/dist/release/github-release-cut.js +3 -2
- package/dist/release/github-release-provenance.js +2 -1
- package/dist/release/github-release-publisher.js +2 -1
- package/dist/release/local-provenance.js +3 -2
- package/dist/release/local-release.js +6 -6
- package/dist/release/qualification-run.d.ts +25 -0
- package/dist/release/qualification-run.js +43 -0
- package/dist/release/release-artifact.js +3 -11
- package/dist/release/release-assets-plan.js +16 -6
- package/dist/release/release-config.js +14 -14
- package/dist/release/release-cut-command.js +14 -4
- package/dist/release/release-cut.js +3 -2
- package/dist/release/release-descriptor-staging.js +13 -27
- package/dist/release/release-finalize.js +2 -1
- package/dist/release/release-publication.js +3 -11
- package/dist/release/release-publish-command.js +15 -6
- package/dist/release/release-qualification.js +3 -2
- package/dist/release/retained-release-build.js +12 -12
- package/dist/shell/app-shell.js +76 -48
- package/dist/shell/app-utilities.d.ts +5 -3
- package/dist/shell/app-utilities.js +15 -7
- package/dist/shell/help-shortcuts.d.ts +4 -0
- package/dist/shell/help-shortcuts.js +38 -7
- package/dist/shell/keyboard-target.d.ts +2 -0
- package/dist/shell/keyboard-target.js +54 -0
- package/dist/shell/settings-sections.d.ts +5 -0
- package/dist/shell/settings-shortcuts.d.ts +10 -0
- package/dist/shell/settings-shortcuts.js +67 -0
- package/dist/update-helper.bundle.js +250 -190
- package/dist/updates/desktop-updater.js +53 -58
- package/dist/updates/packaged-launch-admission.js +3 -2
- package/dist/updates/packaged-release-config.js +6 -5
- package/dist/updates/release-feed.js +9 -9
- package/dist/updates/signed-release.js +5 -5
- package/dist/updates/stable-file.d.ts +18 -0
- package/dist/updates/stable-file.js +54 -1
- package/dist/updates/update-adapter.d.ts +2 -13
- package/dist/updates/update-arm.js +7 -5
- package/dist/updates/update-channel-store.js +7 -9
- package/dist/updates/update-discovery.js +30 -34
- package/dist/updates/update-download-cleanup.js +2 -1
- package/dist/updates/update-download.js +2 -4
- package/dist/updates/update-extraction.js +1 -1
- package/dist/updates/update-generation-lease.js +4 -3
- package/dist/updates/update-handoff-plan.js +3 -2
- package/dist/updates/update-helper.js +8 -6
- package/dist/updates/update-instance-lease.js +3 -2
- package/dist/updates/update-launch-gate.js +12 -25
- package/dist/updates/update-launch.js +3 -2
- package/dist/updates/update-lock.js +3 -2
- package/dist/updates/update-marker.js +3 -2
- package/dist/updates/update-process-fence.js +10 -39
- package/dist/updates/update-process-liveness.js +2 -1
- package/dist/updates/update-resume.js +26 -22
- package/dist/updates/update-retention-marker.js +7 -5
- package/dist/updates/update-retention-plan.js +2 -2
- package/dist/updates/update-retirement.js +40 -39
- package/dist/updates/update-state-store.js +29 -37
- package/dist/updates/update-state.d.ts +8 -3
- package/dist/updates/update-swap-stage.js +6 -5
- package/dist/updates/update-swap.d.ts +1 -1
- package/dist/updates/update-swap.js +8 -6
- package/dist/views/app-help.js +2 -1
- package/dist/views/app-settings.js +5 -2
- package/dist/views/appearance-surface.js +33 -19
- package/package.json +7 -13
- package/src/app/application.tsx +3 -1
- package/src/appearance/appearance-host.tsx +6 -0
- package/src/appearance/appearance-preferences.ts +7 -1
- package/src/appearance/composition.ts +3 -1
- package/src/appearance/custom-theme-import.ts +21 -37
- package/src/appearance/custom-theme-library.ts +21 -5
- package/src/appearance/editor.ts +7 -6
- package/src/appearance/legacy-imported-theme-token-projection.ts +51 -0
- package/src/appearance/theme-record-adapter.ts +58 -11
- package/src/desktop/client-asset-stream.ts +6 -12
- package/src/shell/app-shell.tsx +88 -58
- package/src/shell/app-utilities.tsx +29 -17
- package/src/shell/help-shortcuts.ts +77 -6
- package/src/shell/keyboard-target.ts +74 -0
- package/src/shell/settings-sections.ts +5 -0
- package/src/shell/settings-shortcuts.ts +116 -0
- package/src/updates/update-adapter.ts +2 -14
- package/src/updates/update-state.ts +11 -2
- package/src/views/app-settings.tsx +5 -3
- package/src/views/appearance-surface.tsx +63 -27
- package/dist/native/directory-exchange.js +0 -90
- package/dist/native/exclusive-rename.d.ts +0 -2
- package/dist/native/exclusive-rename.js +0 -52
- package/dist/release/retention-dry-run.d.ts +0 -46
- package/dist/release/retention-dry-run.js +0 -94
- package/dist/updates/update-exclusive-rename.d.ts +0 -3
- package/dist/updates/update-exclusive-rename.js +0 -5
|
@@ -1,19 +1,44 @@
|
|
|
1
1
|
import "./appearance-preferences.js";
|
|
2
2
|
import { customThemeVariantById, customThemeVariants, storedVariantRecord } from "./custom-theme-library.js";
|
|
3
3
|
import { themeRegistry } from "./theme-registry.js";
|
|
4
|
-
import { accentRolesForSelection, themeRecordById, themeRecords } from "@adea-ai/ui/lib/themes";
|
|
4
|
+
import { accentRolesForSelection, themeRecordById, themeRecords, tokensAsHex } from "@adea-ai/ui/lib/themes";
|
|
5
5
|
import { getAccent } from "@adea-ai/ui/lib/accent-presets";
|
|
6
6
|
import { colorToHex, normalizeAccentValue, parseColor } from "@adea-ai/ui/lib/accent-roles";
|
|
7
7
|
import { defaultThemeRecord } from "@adea-ai/ui/lib/theme-projection";
|
|
8
8
|
// src/appearance/theme-record-adapter.ts
|
|
9
9
|
var adeaLight = defaultThemeRecord("light");
|
|
10
10
|
var adeaDark = defaultThemeRecord("dark");
|
|
11
|
+
var MAX_ACCENT_PREVIEWS_PER_THEME = 16;
|
|
12
|
+
var accentRolesByTheme = /* @__PURE__ */ new WeakMap();
|
|
13
|
+
var importedRecordsByVariant = /* @__PURE__ */ new WeakMap();
|
|
11
14
|
/** The published blue preset is the host's default custom accent. */
|
|
12
15
|
var DEFAULT_CUSTOM_ACCENT = getAccent("blue")?.light ?? adeaLight.colors.accent;
|
|
13
16
|
/** Imported themes, re-projected on every registry change. */
|
|
14
17
|
function customThemeRecords() {
|
|
15
18
|
return customThemeVariants().map(storedVariantRecord);
|
|
16
19
|
}
|
|
20
|
+
function importedRecordForPreview(variant) {
|
|
21
|
+
const cached = importedRecordsByVariant.get(variant);
|
|
22
|
+
if (cached) return cached;
|
|
23
|
+
const record = storedVariantRecord(variant);
|
|
24
|
+
importedRecordsByVariant.set(variant, record);
|
|
25
|
+
return record;
|
|
26
|
+
}
|
|
27
|
+
function accentRolesForPreview(theme, key, resolve) {
|
|
28
|
+
if (!key) return resolve();
|
|
29
|
+
const cached = accentRolesByTheme.get(theme);
|
|
30
|
+
if (cached?.has(key)) return cached.get(key) ?? void 0;
|
|
31
|
+
const roles = resolve();
|
|
32
|
+
const byKey = cached ?? /* @__PURE__ */ new Map();
|
|
33
|
+
byKey.delete(key);
|
|
34
|
+
byKey.set(key, roles ?? null);
|
|
35
|
+
if (byKey.size > MAX_ACCENT_PREVIEWS_PER_THEME) {
|
|
36
|
+
const oldest = byKey.keys().next().value;
|
|
37
|
+
if (oldest !== void 0) byKey.delete(oldest);
|
|
38
|
+
}
|
|
39
|
+
accentRolesByTheme.set(theme, byKey);
|
|
40
|
+
return roles;
|
|
41
|
+
}
|
|
17
42
|
/** The built-in catalogue led by the published pair; import lives separately. */
|
|
18
43
|
var appearanceThemeRecords = Object.freeze([
|
|
19
44
|
adeaLight,
|
|
@@ -26,12 +51,14 @@ function allThemeRecords() {
|
|
|
26
51
|
}
|
|
27
52
|
function withAccent(theme, accent, pair) {
|
|
28
53
|
if (accent === "theme") return theme;
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
54
|
+
const roles = accentRolesForPreview(theme, getAccent(accent) ? accent : void 0, () => {
|
|
55
|
+
const variant = themeRegistry().find((candidate) => candidate.id === theme.id);
|
|
56
|
+
if (!variant) return void 0;
|
|
57
|
+
return accentRolesForSelection(accent, theme.appearance, pair, {
|
|
58
|
+
background: variant.colors.background,
|
|
59
|
+
floor: 3,
|
|
60
|
+
variantId: variant.id
|
|
61
|
+
});
|
|
35
62
|
});
|
|
36
63
|
if (!roles) return theme;
|
|
37
64
|
return {
|
|
@@ -51,11 +78,12 @@ function withAccent(theme, accent, pair) {
|
|
|
51
78
|
function appearanceThemeForPreview(variant, accent, pair) {
|
|
52
79
|
const catalogueRecord = themeRecordById(variant.id);
|
|
53
80
|
const importedVariant = catalogueRecord ? void 0 : customThemeVariantById(variant.id);
|
|
54
|
-
return withAccent(catalogueRecord ?? (importedVariant ?
|
|
81
|
+
return withAccent(catalogueRecord ?? (importedVariant ? importedRecordForPreview(importedVariant) : variant.appearance === "dark" ? adeaDark : adeaLight), accent, pair);
|
|
55
82
|
}
|
|
56
83
|
/** Preserve the host's invalid-input behavior while feeding the pure editor. */
|
|
57
84
|
function normalizeCustomAccent(value, background) {
|
|
58
|
-
const
|
|
85
|
+
const canvas = tokensAsHex({ background }).background ?? background;
|
|
86
|
+
const normalized = normalizeAccentValue(value, canvas);
|
|
59
87
|
if (normalized === void 0) return { error: `“${value}” is not a hex color such as ${DEFAULT_CUSTOM_ACCENT}.` };
|
|
60
88
|
const parsed = parseColor(normalized);
|
|
61
89
|
return { value: parsed ? colorToHex({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { delimiter, join } from "node:path";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
2
3
|
import { accessSync, closeSync, constants, mkdirSync, openSync, readFileSync, readSync, realpathSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
3
4
|
import { execFileSync } from "node:child_process";
|
|
4
|
-
import { createHash } from "node:crypto";
|
|
5
5
|
// src/ci/toolchain-identity.ts
|
|
6
6
|
/**
|
|
7
7
|
* Identifies the toolchain cached `vp` tasks run on, so every cache key covers
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isSha256Hex } from "../app/value-guards.js";
|
|
1
2
|
import { containsAsciiControl } from "./string-policy.js";
|
|
2
3
|
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
3
4
|
// src/desktop/channel-proof.ts
|
|
@@ -5,7 +6,7 @@ var separator = "";
|
|
|
5
6
|
var field = (value) => typeof value === "string" && value.length > 0 && value.length <= 128 && !containsAsciiControl(value);
|
|
6
7
|
/** Exact wire input used by Adea's current signed invoke bridge. */
|
|
7
8
|
function legacyProofMessage(input, context = "adea-invoke-v1") {
|
|
8
|
-
if (!field(context) || !field(input.channelId) || !field(input.credentialId) || !field(input.nonce) || !/^\d{1,16}$/.test(input.timestamp) ||
|
|
9
|
+
if (!field(context) || !field(input.channelId) || !field(input.credentialId) || !field(input.nonce) || !/^\d{1,16}$/.test(input.timestamp) || !isSha256Hex(input.bodySha256)) throw new Error("Invalid proof fields");
|
|
9
10
|
return [
|
|
10
11
|
context,
|
|
11
12
|
input.channelId,
|
|
@@ -219,29 +219,23 @@ function createClientAssetStream(path, expected, openAsset = open, limit) {
|
|
|
219
219
|
if (cancelled) return;
|
|
220
220
|
const current = file;
|
|
221
221
|
if (!current) return;
|
|
222
|
-
|
|
222
|
+
const finish = async (last) => {
|
|
223
223
|
const actual = await current.stat();
|
|
224
224
|
if (cancelled) return;
|
|
225
225
|
if (!sameFile(expected, actual)) throw new Error("Client asset changed during request");
|
|
226
226
|
await close();
|
|
227
227
|
if (cancelled) return;
|
|
228
|
+
if (last) controller.enqueue(last);
|
|
228
229
|
controller.close();
|
|
229
|
-
|
|
230
|
-
|
|
230
|
+
};
|
|
231
|
+
if (offset === expected.size) return await finish();
|
|
231
232
|
const buffer = Buffer.allocUnsafe(Math.min(FILE_CHUNK_BYTES, expected.size - offset));
|
|
232
233
|
const { bytesRead } = await current.read(buffer, 0, buffer.length, offset);
|
|
233
234
|
if (cancelled) return;
|
|
234
235
|
if (!bytesRead) throw new Error("Client asset changed during request");
|
|
235
236
|
offset += bytesRead;
|
|
236
|
-
if (offset === expected.size)
|
|
237
|
-
|
|
238
|
-
if (cancelled) return;
|
|
239
|
-
if (!sameFile(expected, actual)) throw new Error("Client asset changed during request");
|
|
240
|
-
await close();
|
|
241
|
-
if (cancelled) return;
|
|
242
|
-
controller.enqueue(buffer.subarray(0, bytesRead));
|
|
243
|
-
controller.close();
|
|
244
|
-
} else controller.enqueue(buffer.subarray(0, bytesRead));
|
|
237
|
+
if (offset === expected.size) await finish(buffer.subarray(0, bytesRead));
|
|
238
|
+
else controller.enqueue(buffer.subarray(0, bytesRead));
|
|
245
239
|
} catch (error) {
|
|
246
240
|
await close().catch(() => {});
|
|
247
241
|
if (!cancelled) controller.error(error);
|
|
@@ -4,6 +4,27 @@ import type { DesktopRenderer } from '../native/renderer-profile';
|
|
|
4
4
|
import type { WindowFrame } from '../native/window-options';
|
|
5
5
|
import type { createServiceRegistry } from '../app/service-registry';
|
|
6
6
|
import { createDesktopStreams } from './desktop-stream';
|
|
7
|
+
/** A WebSocket an app-owned route accepted; `data` is what the route passed to `upgrade`. */
|
|
8
|
+
export type DesktopRouteSocket = {
|
|
9
|
+
readonly data: unknown;
|
|
10
|
+
send(message: string | Uint8Array): number;
|
|
11
|
+
close(code?: number, reason?: string): void;
|
|
12
|
+
};
|
|
13
|
+
/** An app-owned same-origin route. Handlers must apply their own authorization; the host has
|
|
14
|
+
* already refused requests whose Origin is not the window's loopback origin. */
|
|
15
|
+
export type DesktopRoute = {
|
|
16
|
+
prefix: string;
|
|
17
|
+
/** Return a response, or call `context.upgrade` (routes with `websocket` only) and return
|
|
18
|
+
* undefined to accept a WebSocket. */
|
|
19
|
+
handle(request: Request, context: {
|
|
20
|
+
upgrade(data?: unknown): boolean;
|
|
21
|
+
}): Response | undefined | Promise<Response | undefined>;
|
|
22
|
+
websocket?: {
|
|
23
|
+
open?(socket: DesktopRouteSocket): void;
|
|
24
|
+
message?(socket: DesktopRouteSocket, message: string | Buffer): void;
|
|
25
|
+
close?(socket: DesktopRouteSocket, code: number, reason: string): void;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
7
28
|
/** Bind an isolated client server and open a window with a per-window channel. */
|
|
8
29
|
type DesktopHostOptions<Principal, Window extends NativeWindow> = {
|
|
9
30
|
clientRoot: string;
|
|
@@ -32,11 +53,10 @@ type DesktopHostOptions<Principal, Window extends NativeWindow> = {
|
|
|
32
53
|
* callback's responsibility.
|
|
33
54
|
*/
|
|
34
55
|
configureStreams?: (streams: ReturnType<typeof createDesktopStreams<Principal>>) => void;
|
|
35
|
-
/** App-owned same-origin HTTP routes. Handlers must apply their own authorization. */
|
|
36
|
-
routes?: readonly
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}[];
|
|
56
|
+
/** App-owned same-origin HTTP and WebSocket routes. Handlers must apply their own authorization. */
|
|
57
|
+
routes?: readonly DesktopRoute[];
|
|
58
|
+
/** Exact https or loopback origins the client may embed in child frames (at most 8). */
|
|
59
|
+
frameSources?: readonly string[];
|
|
40
60
|
construct(options: SecureWindowOptions): Window;
|
|
41
61
|
frame?: WindowFrame;
|
|
42
62
|
transparent?: boolean;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { errorCode } from "../app/value-guards.js";
|
|
1
2
|
import { createChannelAuthority } from "./channel-handshake.js";
|
|
2
3
|
import { createClientAssetFileLimit, createClientAssetVerificationCache } from "./client-asset-stream.js";
|
|
3
4
|
import { createClientAssetResolver } from "./client-assets.js";
|
|
@@ -18,6 +19,22 @@ var DesktopPortInUseError = class extends Error {
|
|
|
18
19
|
super("Desktop origin port is in use", { cause });
|
|
19
20
|
}
|
|
20
21
|
};
|
|
22
|
+
var FRAME_SOURCE = /^(?:https:\/\/[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*(?::[1-9][0-9]{0,4})?|http:\/\/(?:127\.0\.0\.1|localhost):[1-9][0-9]{0,4})$/;
|
|
23
|
+
/** The asset CSP: no child frames unless the app names exact frame origins. */
|
|
24
|
+
function contentSecurityPolicy(frameSources) {
|
|
25
|
+
const sources = frameSources ?? [];
|
|
26
|
+
if (!Array.isArray(sources) || sources.length > 8 || sources.some((source) => typeof source !== "string" || !FRAME_SOURCE.test(source) || Number(/:([0-9]+)$/.exec(source)?.[1] ?? 443) > 65535)) throw new Error("Invalid desktop frame sources");
|
|
27
|
+
return `frame-src ${sources.length ? [...new Set(sources)].join(" ") : "'none'"}; frame-ancestors 'none'; object-src 'none'; base-uri 'none'`;
|
|
28
|
+
}
|
|
29
|
+
/** Run an app socket handler; a throw closes the socket instead of reaching the server. */
|
|
30
|
+
function routeSocketCall(run, socket) {
|
|
31
|
+
try {
|
|
32
|
+
const result = run();
|
|
33
|
+
if (result instanceof Promise) result.catch(() => socket?.close(1011));
|
|
34
|
+
} catch {
|
|
35
|
+
socket?.close(1011);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
21
38
|
function startDesktopHost(options) {
|
|
22
39
|
return createDesktopHost(options);
|
|
23
40
|
}
|
|
@@ -41,11 +58,17 @@ function createDesktopHost(options, lifecycle) {
|
|
|
41
58
|
verificationCache: clientAssetVerificationCache
|
|
42
59
|
}, options.retainedClientAssets);
|
|
43
60
|
const configuredRoutes = options.routes ?? [];
|
|
44
|
-
if (!Array.isArray(configuredRoutes) || configuredRoutes.length > 32 || configuredRoutes.some((route) => !route || typeof route.prefix !== "string" || !/^\/[a-zA-Z0-9][a-zA-Z0-9._-]*(?:\/[a-zA-Z0-9][a-zA-Z0-9._-]*)*$/.test(route.prefix) || route.prefix.length > 200 || route.prefix === "/__framework" || route.prefix.startsWith("/__framework/") || typeof route.handle !== "function"
|
|
45
|
-
|
|
61
|
+
if (!Array.isArray(configuredRoutes) || configuredRoutes.length > 32 || configuredRoutes.some((route) => !route || typeof route.prefix !== "string" || !/^\/[a-zA-Z0-9][a-zA-Z0-9._-]*(?:\/[a-zA-Z0-9][a-zA-Z0-9._-]*)*$/.test(route.prefix) || route.prefix.length > 200 || route.prefix === "/__framework" || route.prefix.startsWith("/__framework/") || typeof route.handle !== "function" || route.websocket !== void 0 && (typeof route.websocket !== "object" || route.websocket === null || [
|
|
62
|
+
"open",
|
|
63
|
+
"message",
|
|
64
|
+
"close"
|
|
65
|
+
].some((name) => route.websocket[name] !== void 0 && typeof route.websocket[name] !== "function"))) || configuredRoutes.some((route, index) => configuredRoutes.slice(index + 1).some((other) => route.prefix === other.prefix || route.prefix.startsWith(other.prefix + "/") || other.prefix.startsWith(route.prefix + "/")))) throw new Error("Invalid desktop route policy");
|
|
66
|
+
const routes = configuredRoutes.map(({ prefix, handle, websocket }) => ({
|
|
46
67
|
prefix,
|
|
47
|
-
handle
|
|
68
|
+
handle,
|
|
69
|
+
websocket: websocket && { ...websocket }
|
|
48
70
|
}));
|
|
71
|
+
const csp = contentSecurityPolicy(options.frameSources);
|
|
49
72
|
if (options.portFile !== void 0 && (typeof options.portFile !== "string" || !options.portFile)) throw new Error("Invalid desktop port file");
|
|
50
73
|
if (options.initialPort !== void 0 && (!Number.isInteger(options.initialPort) || options.initialPort < 1024 || options.initialPort > 65535)) throw new Error("Invalid initial desktop port");
|
|
51
74
|
let port = options.initialPort ?? 0;
|
|
@@ -59,10 +82,16 @@ function createDesktopHost(options, lifecycle) {
|
|
|
59
82
|
if (options.initialPort !== void 0 && options.initialPort !== savedPort) throw new Error("Saved desktop port does not match initial port");
|
|
60
83
|
port = savedPort;
|
|
61
84
|
} catch (error) {
|
|
62
|
-
if (error
|
|
85
|
+
if (errorCode(error) !== "ENOENT") throw error;
|
|
63
86
|
savePort = true;
|
|
64
87
|
}
|
|
65
88
|
let origin = "";
|
|
89
|
+
let loopbackPolicy;
|
|
90
|
+
const fromLoopbackOrigin = (request) => loopbackPolicy !== void 0 && matchesLoopbackOrigin({
|
|
91
|
+
host: request.headers.get("host"),
|
|
92
|
+
origin: request.headers.get("origin"),
|
|
93
|
+
secFetchSite: request.headers.get("sec-fetch-site")
|
|
94
|
+
}, loopbackPolicy);
|
|
66
95
|
let gateway;
|
|
67
96
|
let streams;
|
|
68
97
|
let grant;
|
|
@@ -74,18 +103,14 @@ function createDesktopHost(options, lifecycle) {
|
|
|
74
103
|
hostname: "127.0.0.1",
|
|
75
104
|
port,
|
|
76
105
|
async fetch(request, connection) {
|
|
77
|
-
if (stopped || !origin || !gateway) return new Response(null, { status: 503 });
|
|
106
|
+
if (stopped || !origin || !loopbackPolicy || !gateway) return new Response(null, { status: 503 });
|
|
78
107
|
const url = new URL(request.url);
|
|
79
|
-
if (url.origin !== origin || request.headers.get("host") !==
|
|
108
|
+
if (url.origin !== origin || request.headers.get("host") !== loopbackPolicy.host) {
|
|
80
109
|
reportRequest("rejected");
|
|
81
110
|
return new Response(null, { status: 403 });
|
|
82
111
|
}
|
|
83
112
|
if (url.pathname === "/__framework/stream") {
|
|
84
|
-
if (!streams || request.method !== "GET" || url.search || !
|
|
85
|
-
host: request.headers.get("host"),
|
|
86
|
-
origin: request.headers.get("origin"),
|
|
87
|
-
secFetchSite: request.headers.get("sec-fetch-site")
|
|
88
|
-
}, createLoopbackPolicy(origin))) return new Response(null, { status: 403 });
|
|
113
|
+
if (!streams || request.method !== "GET" || url.search || !fromLoopbackOrigin(request)) return new Response(null, { status: 403 });
|
|
89
114
|
if (connection.upgrade(request, { data: {} })) return void 0;
|
|
90
115
|
return new Response(null, { status: 400 });
|
|
91
116
|
}
|
|
@@ -103,17 +128,23 @@ function createDesktopHost(options, lifecycle) {
|
|
|
103
128
|
}
|
|
104
129
|
const route = routes.find((value) => url.pathname === value.prefix || url.pathname.startsWith(value.prefix + "/"));
|
|
105
130
|
if (route) {
|
|
106
|
-
if (!
|
|
107
|
-
host: request.headers.get("host"),
|
|
108
|
-
origin: request.headers.get("origin"),
|
|
109
|
-
secFetchSite: request.headers.get("sec-fetch-site")
|
|
110
|
-
}, createLoopbackPolicy(origin))) return new Response(null, { status: 403 });
|
|
131
|
+
if (!fromLoopbackOrigin(request)) return new Response(null, { status: 403 });
|
|
111
132
|
reportRequest("route");
|
|
133
|
+
let upgraded = false;
|
|
134
|
+
const context = { upgrade(data) {
|
|
135
|
+
if (upgraded || !route.websocket || request.method !== "GET") return false;
|
|
136
|
+
upgraded = connection.upgrade(request, { data: { route: {
|
|
137
|
+
handlers: route.websocket,
|
|
138
|
+
data
|
|
139
|
+
} } });
|
|
140
|
+
return upgraded;
|
|
141
|
+
} };
|
|
112
142
|
try {
|
|
113
|
-
const result = await route.handle(request);
|
|
143
|
+
const result = await route.handle(request, context);
|
|
144
|
+
if (upgraded) return void 0;
|
|
114
145
|
return result instanceof Response ? result : new Response(null, { status: 500 });
|
|
115
146
|
} catch {
|
|
116
|
-
return new Response(null, { status: 500 });
|
|
147
|
+
return upgraded ? void 0 : new Response(null, { status: 500 });
|
|
117
148
|
}
|
|
118
149
|
}
|
|
119
150
|
reportRequest(kind);
|
|
@@ -124,7 +155,7 @@ function createDesktopHost(options, lifecycle) {
|
|
|
124
155
|
if (error instanceof ClientResponseLifecycleClosedError) return new Response(null, { status: 503 });
|
|
125
156
|
throw error;
|
|
126
157
|
}
|
|
127
|
-
result.headers.set("content-security-policy",
|
|
158
|
+
result.headers.set("content-security-policy", csp);
|
|
128
159
|
result.headers.set("x-content-type-options", "nosniff");
|
|
129
160
|
result.headers.set("referrer-policy", "no-referrer");
|
|
130
161
|
return result;
|
|
@@ -134,6 +165,17 @@ function createDesktopHost(options, lifecycle) {
|
|
|
134
165
|
backpressureLimit: DESKTOP_STREAM_BACKPRESSURE_LIMIT,
|
|
135
166
|
closeOnBackpressureLimit: true,
|
|
136
167
|
open(socket) {
|
|
168
|
+
const route = socket.data.route;
|
|
169
|
+
if (route) {
|
|
170
|
+
const wrapped = {
|
|
171
|
+
data: route.data,
|
|
172
|
+
send: (message) => socket.send(message),
|
|
173
|
+
close: (code, reason) => socket.close(code, reason)
|
|
174
|
+
};
|
|
175
|
+
route.socket = wrapped;
|
|
176
|
+
routeSocketCall(() => route.handlers.open?.(wrapped), socket);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
137
179
|
socket.data.connection = streams?.accept({
|
|
138
180
|
send: (payload) => sendDesktopStreamPayload(socket, payload),
|
|
139
181
|
close: () => socket.close()
|
|
@@ -141,9 +183,21 @@ function createDesktopHost(options, lifecycle) {
|
|
|
141
183
|
if (!socket.data.connection) socket.close();
|
|
142
184
|
},
|
|
143
185
|
message(socket, message) {
|
|
186
|
+
const route = socket.data.route;
|
|
187
|
+
if (route?.socket) {
|
|
188
|
+
const wrapped = route.socket;
|
|
189
|
+
routeSocketCall(() => route.handlers.message?.(wrapped, message), socket);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
144
192
|
socket.data.connection?.receive(message);
|
|
145
193
|
},
|
|
146
|
-
close(socket) {
|
|
194
|
+
close(socket, code, reason) {
|
|
195
|
+
const route = socket.data.route;
|
|
196
|
+
if (route?.socket) {
|
|
197
|
+
const wrapped = route.socket;
|
|
198
|
+
routeSocketCall(() => route.handlers.close?.(wrapped, code, reason));
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
147
201
|
socket.data.connection?.close();
|
|
148
202
|
}
|
|
149
203
|
}
|
|
@@ -176,6 +230,7 @@ function createDesktopHost(options, lifecycle) {
|
|
|
176
230
|
try {
|
|
177
231
|
if (options.portFile !== void 0 && savePort) publishDesktopPort(options.portFile, server.port);
|
|
178
232
|
origin = `http://127.0.0.1:${server.port}`;
|
|
233
|
+
loopbackPolicy = createLoopbackPolicy(origin);
|
|
179
234
|
const authority = createChannelAuthority();
|
|
180
235
|
if (options.configureStreams) {
|
|
181
236
|
streams = createDesktopStreams({ authority });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.
|
|
1
|
+
{"version":"0.32.0","commit":"9ba046d80699c484a994ff177b2a72b52e4db438"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { errorCode } from "../app/value-guards.js";
|
|
1
2
|
import { safeArchivePath } from "./archive-entry.js";
|
|
2
3
|
import { linuxProcessGroupIsExited } from "./linux-process-group.js";
|
|
3
4
|
import { lstat, mkdir, mkdtemp, readFile, readdir, rm } from "node:fs/promises";
|
|
@@ -146,7 +147,7 @@ function signalProcessGroup(pid, signal) {
|
|
|
146
147
|
try {
|
|
147
148
|
process.kill(-pid, signal);
|
|
148
149
|
} catch (error) {
|
|
149
|
-
if (!processGroupIsGone(error
|
|
150
|
+
if (!processGroupIsGone(errorCode(error))) throw error;
|
|
150
151
|
}
|
|
151
152
|
}
|
|
152
153
|
async function serviceExitStatus(path) {
|
|
@@ -156,7 +157,7 @@ async function serviceExitStatus(path) {
|
|
|
156
157
|
const status = Number(value);
|
|
157
158
|
return status <= 255 ? status : void 0;
|
|
158
159
|
} catch (error) {
|
|
159
|
-
if (error
|
|
160
|
+
if (errorCode(error) === "ENOENT") return void 0;
|
|
160
161
|
throw error;
|
|
161
162
|
}
|
|
162
163
|
}
|
|
@@ -176,7 +177,7 @@ async function processGroupExited(pid, milliseconds) {
|
|
|
176
177
|
try {
|
|
177
178
|
process.kill(-pid, 0);
|
|
178
179
|
} catch (error) {
|
|
179
|
-
if (processGroupIsGone(error
|
|
180
|
+
if (processGroupIsGone(errorCode(error))) return true;
|
|
180
181
|
throw error;
|
|
181
182
|
}
|
|
182
183
|
if (process.platform === "linux" && await linuxProcessGroupIsExited(pid)) return true;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { errorCode } from "../app/value-guards.js";
|
|
1
2
|
import { assertInstallerContext } from "./installer-layout.js";
|
|
2
3
|
import { validateCommandReceipt } from "../release/release-qualification.js";
|
|
3
4
|
import { parseReleaseConfig } from "../release/release-config.js";
|
|
4
|
-
import { planReleaseAssets } from "../release/release-assets-plan.js";
|
|
5
5
|
import { qualifyCommandArtifact } from "./command-artifact.js";
|
|
6
|
+
import { planQualificationRun } from "../release/qualification-run.js";
|
|
6
7
|
import { fileIdentity } from "../release/release-publication.js";
|
|
7
8
|
import { lstat, writeFile } from "node:fs/promises";
|
|
8
9
|
import { join, resolve } from "node:path";
|
|
@@ -16,7 +17,7 @@ async function qualifyCommandArtifactsCommand(options) {
|
|
|
16
17
|
if (!parsed.commandArtifacts.length) return [];
|
|
17
18
|
assertInstallerContext(env, platform, process.platform, process.arch);
|
|
18
19
|
if (env.RELEASE_TAG !== tag) throw new Error("Command artifact release tag mismatch");
|
|
19
|
-
const plan = await
|
|
20
|
+
const plan = await planQualificationRun({
|
|
20
21
|
env,
|
|
21
22
|
config,
|
|
22
23
|
tag
|
|
@@ -28,8 +29,8 @@ async function qualifyCommandArtifactsCommand(options) {
|
|
|
28
29
|
tag,
|
|
29
30
|
sourceSha: plan.sourceSha,
|
|
30
31
|
workflowSha: plan.workflowSha,
|
|
31
|
-
runId:
|
|
32
|
-
runAttempt:
|
|
32
|
+
runId: plan.runId,
|
|
33
|
+
runAttempt: plan.runAttempt
|
|
33
34
|
};
|
|
34
35
|
const receipts = [];
|
|
35
36
|
for (const policy of parsed.commandArtifacts) {
|
|
@@ -39,7 +40,7 @@ async function qualifyCommandArtifactsCommand(options) {
|
|
|
39
40
|
await lstat(destination);
|
|
40
41
|
throw new Error("Command artifact receipt already exists");
|
|
41
42
|
} catch (error) {
|
|
42
|
-
if (error
|
|
43
|
+
if (errorCode(error) !== "ENOENT") throw error;
|
|
43
44
|
}
|
|
44
45
|
const path = join(directory, name);
|
|
45
46
|
const asset = await fileIdentity(path, name);
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* True only on a disposable CI runner: a GitHub-hosted Actions runner, or a GitLab CI job
|
|
3
|
+
* whose configuration declares its executor disposable (a fresh container or VM per job)
|
|
4
|
+
* with `FRAMEWORK_DISPOSABLE_RUNNER=true`. Installer qualification installs software, so a
|
|
5
|
+
* shell executor or developer machine must never set that variable.
|
|
6
|
+
*/
|
|
2
7
|
export declare function isHostedRunner(env: Record<string, string | undefined>): boolean;
|
|
3
|
-
/** Refuse `subject` anywhere but a disposable
|
|
8
|
+
/** Refuse `subject` anywhere but a disposable hosted runner. */
|
|
4
9
|
export declare function assertHostedRunner(env: Record<string, string | undefined>, subject: string): void;
|
|
10
|
+
/** The runner's per-job temporary directory: `RUNNER_TEMP` on GitHub, `TMPDIR` on GitLab. */
|
|
11
|
+
export declare function runnerTemp(env: Record<string, string | undefined>): string | undefined;
|
|
@@ -1,10 +1,23 @@
|
|
|
1
|
+
import { isAbsolute } from "node:path";
|
|
1
2
|
// src/installer/hosted-runner.ts
|
|
2
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* True only on a disposable CI runner: a GitHub-hosted Actions runner, or a GitLab CI job
|
|
5
|
+
* whose configuration declares its executor disposable (a fresh container or VM per job)
|
|
6
|
+
* with `FRAMEWORK_DISPOSABLE_RUNNER=true`. Installer qualification installs software, so a
|
|
7
|
+
* shell executor or developer machine must never set that variable.
|
|
8
|
+
*/
|
|
3
9
|
function isHostedRunner(env) {
|
|
4
|
-
|
|
10
|
+
if (env.CI !== "true") return false;
|
|
11
|
+
if (env.GITHUB_ACTIONS === "true") return env.RUNNER_ENVIRONMENT === "github-hosted";
|
|
12
|
+
return env.GITLAB_CI === "true" && env.FRAMEWORK_DISPOSABLE_RUNNER === "true" && /^[1-9]\d{0,19}$/.test(env.CI_JOB_ID ?? "");
|
|
5
13
|
}
|
|
6
|
-
/** Refuse `subject` anywhere but a disposable
|
|
14
|
+
/** Refuse `subject` anywhere but a disposable hosted runner. */
|
|
7
15
|
function assertHostedRunner(env, subject) {
|
|
8
|
-
if (!isHostedRunner(env)) throw new Error(`${subject} requires a disposable
|
|
16
|
+
if (!isHostedRunner(env)) throw new Error(`${subject} requires a disposable hosted runner`);
|
|
9
17
|
}
|
|
10
|
-
|
|
18
|
+
/** The runner's per-job temporary directory: `RUNNER_TEMP` on GitHub, `TMPDIR` on GitLab. */
|
|
19
|
+
function runnerTemp(env) {
|
|
20
|
+
const path = env.GITHUB_ACTIONS === "true" ? env.RUNNER_TEMP : env.TMPDIR;
|
|
21
|
+
return path && isAbsolute(path) ? path : void 0;
|
|
22
|
+
}
|
|
23
|
+
export { assertHostedRunner, isHostedRunner, runnerTemp };
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { assertSidecarNames, sidecarBundlePath } from "../native/app-bundle.js";
|
|
2
|
+
import { runnerTemp } from "./hosted-runner.js";
|
|
2
3
|
import { assertBuildMetadata, assertInstallerContext, assertPayloadLayout, assertPortableAppName } from "./installer-layout.js";
|
|
4
|
+
import { hashFileAt } from "../updates/stable-file.js";
|
|
3
5
|
import { assertNativeExecutable } from "./native-executable.js";
|
|
6
|
+
import { assertArchiveUnchanged, findArchiveMember, isWithin } from "./installer-archive.js";
|
|
4
7
|
import { lstat, open, realpath, rm } from "node:fs/promises";
|
|
5
|
-
import {
|
|
8
|
+
import { join, resolve } from "node:path";
|
|
6
9
|
import { createHash } from "node:crypto";
|
|
7
10
|
import { Parser } from "tar";
|
|
8
11
|
import { once } from "node:events";
|
|
9
12
|
import { createZstdDecompress } from "node:zlib";
|
|
10
13
|
// src/installer/installed-payload.ts
|
|
11
|
-
function within(root, path) {
|
|
12
|
-
const value = relative(root, path);
|
|
13
|
-
return value !== "" && value !== ".." && !value.startsWith(".." + sep) && !isAbsolute(value);
|
|
14
|
-
}
|
|
15
14
|
function cleanEnv(parent, forceLocal) {
|
|
16
15
|
const env = {};
|
|
17
16
|
for (const name of [
|
|
@@ -135,27 +134,12 @@ async function readMembers(archive, limits, collect) {
|
|
|
135
134
|
}
|
|
136
135
|
async function installed(path, root, limit) {
|
|
137
136
|
const info = await lstat(path);
|
|
138
|
-
if (!info.isFile() || info.isSymbolicLink() || !Number.isSafeInteger(info.size) || info.size < 1 || info.size > limit || !
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
let size = 0;
|
|
145
|
-
for await (const chunk of file.createReadStream({ autoClose: false })) {
|
|
146
|
-
size += chunk.length;
|
|
147
|
-
if (size > before.size) throw new Error("Installed file changed");
|
|
148
|
-
hash.update(chunk);
|
|
149
|
-
}
|
|
150
|
-
const after = await file.stat();
|
|
151
|
-
if (size !== before.size || after.size !== before.size || after.mtimeMs !== before.mtimeMs || after.dev !== before.dev || after.ino !== before.ino) throw new Error("Installed file changed");
|
|
152
|
-
return {
|
|
153
|
-
digest: hash.digest("hex"),
|
|
154
|
-
size
|
|
155
|
-
};
|
|
156
|
-
} finally {
|
|
157
|
-
await file.close();
|
|
158
|
-
}
|
|
137
|
+
if (!info.isFile() || info.isSymbolicLink() || !Number.isSafeInteger(info.size) || info.size < 1 || info.size > limit || !isWithin(root, await realpath(path))) throw new Error("Invalid installed file");
|
|
138
|
+
const { size, sha256 } = await hashFileAt(path, info, "Installed file changed");
|
|
139
|
+
return {
|
|
140
|
+
digest: sha256,
|
|
141
|
+
size
|
|
142
|
+
};
|
|
159
143
|
}
|
|
160
144
|
async function assertRuntimeBinary(path, platform) {
|
|
161
145
|
const info = await lstat(path), file = await open(path, "r");
|
|
@@ -173,7 +157,7 @@ async function verifyInstalledPayload(options) {
|
|
|
173
157
|
const sidecars = assertSidecarNames(options.sidecars ?? [], options.platform).map((name) => sidecarBundlePath(name, options.platform));
|
|
174
158
|
if (!/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(options.version) || options.version.length > 64) throw new Error("Invalid installed version");
|
|
175
159
|
const profile = await realpath(options.profile), root = await realpath(options.installedRoot), archive = resolve(options.archive);
|
|
176
|
-
if (!(await lstat(profile)).isDirectory() || !(await lstat(root)).isDirectory() || !
|
|
160
|
+
if (!(await lstat(profile)).isDirectory() || !(await lstat(root)).isDirectory() || !isWithin(profile, root)) throw new Error("Installed root escapes isolated profile");
|
|
177
161
|
const { archiveInfo, entries } = await listArchive(archive, options.platform, env);
|
|
178
162
|
assertPayloadLayout({
|
|
179
163
|
platform: options.platform,
|
|
@@ -198,16 +182,11 @@ async function verifyInstalledPayload(options) {
|
|
|
198
182
|
const metadata = name === "Resources/version.json" || name === "Resources/build.json";
|
|
199
183
|
const limit = metadata ? 1048576 : name === `${bin}/bun${suffix}` || sidecars.includes(name) ? 268435456 : 67108864;
|
|
200
184
|
const expected = `${prefix}/${name}`;
|
|
201
|
-
const candidates = entries.filter((entry) => {
|
|
202
|
-
const normalized = entry.replace(/^\.\//, "").replaceAll("\\", "/");
|
|
203
|
-
return options.platform === "windows-x64" ? normalized.toLowerCase() === expected.toLowerCase() : normalized === expected;
|
|
204
|
-
});
|
|
205
|
-
if (candidates.length !== 1) throw new Error("Archive member missing or ambiguous");
|
|
206
185
|
return {
|
|
207
186
|
name,
|
|
208
187
|
metadata,
|
|
209
188
|
limit,
|
|
210
|
-
path:
|
|
189
|
+
path: findArchiveMember(entries, expected, options.platform, "Archive member missing or ambiguous")
|
|
211
190
|
};
|
|
212
191
|
});
|
|
213
192
|
const members = await readMembers(archive, new Map(selected.map(({ path, limit }) => [path, limit])), new Set(selected.filter(({ metadata }) => metadata).map(({ path }) => path)));
|
|
@@ -223,8 +202,7 @@ async function verifyInstalledPayload(options) {
|
|
|
223
202
|
assertBuildMetadata(JSON.parse(member.bytes.toString("utf8")), options.renderer);
|
|
224
203
|
}
|
|
225
204
|
}
|
|
226
|
-
|
|
227
|
-
if (!after.isFile() || after.isSymbolicLink() || after.dev !== archiveInfo.dev || after.ino !== archiveInfo.ino || after.size !== archiveInfo.size || after.mtimeMs !== archiveInfo.mtimeMs) throw new Error("Staged archive changed during verification");
|
|
205
|
+
await assertArchiveUnchanged(archive, archiveInfo, "Staged archive changed during verification");
|
|
228
206
|
return { files };
|
|
229
207
|
}
|
|
230
208
|
/** Extract only the candidate Bun executable to an isolated profile for guard preflight. */
|
|
@@ -232,9 +210,10 @@ async function extractCandidateRuntime(options) {
|
|
|
232
210
|
const env = options.env ?? process.env;
|
|
233
211
|
assertInstallerContext(env, options.platform, process.platform, process.arch);
|
|
234
212
|
assertPortableAppName(options.appName);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
213
|
+
const temp = runnerTemp(env);
|
|
214
|
+
if (!temp) throw new Error("Missing runner temp directory");
|
|
215
|
+
const tempRoot = await realpath(temp), profile = await realpath(options.profile), archive = resolve(options.archive);
|
|
216
|
+
if (!isWithin(tempRoot, profile) || !(await lstat(profile)).isDirectory()) throw new Error("Runtime profile escapes runner temp");
|
|
238
217
|
const { archiveInfo, tarEnv, entries } = await listArchive(archive, options.platform, env);
|
|
239
218
|
assertPayloadLayout({
|
|
240
219
|
platform: options.platform,
|
|
@@ -244,11 +223,7 @@ async function extractCandidateRuntime(options) {
|
|
|
244
223
|
});
|
|
245
224
|
const prefix = options.platform === "macos-arm64" ? `${options.appName}.app/Contents/MacOS` : `${options.appName.replaceAll(" ", "")}/bin`, suffix = options.platform === "windows-x64" ? ".exe" : "";
|
|
246
225
|
const expected = `${prefix}/bun${suffix}`;
|
|
247
|
-
const
|
|
248
|
-
const normalized = entry.replace(/^\.\//, "").replaceAll("\\", "/");
|
|
249
|
-
return options.platform === "windows-x64" ? normalized.toLowerCase() === expected.toLowerCase() : normalized === expected;
|
|
250
|
-
});
|
|
251
|
-
if (candidates.length !== 1) throw new Error("Runtime archive member missing or ambiguous");
|
|
226
|
+
const member = findArchiveMember(entries, expected, options.platform, "Runtime archive member missing or ambiguous");
|
|
252
227
|
const destination = join(profile, `candidate-bun${suffix}`), output = await open(destination, "wx", 448);
|
|
253
228
|
const spawn = () => Bun.spawn({
|
|
254
229
|
cmd: [
|
|
@@ -257,7 +232,7 @@ async function extractCandidateRuntime(options) {
|
|
|
257
232
|
"-xOf",
|
|
258
233
|
archive,
|
|
259
234
|
"--",
|
|
260
|
-
|
|
235
|
+
member
|
|
261
236
|
],
|
|
262
237
|
env: tarEnv,
|
|
263
238
|
stdout: "pipe",
|
|
@@ -285,8 +260,7 @@ async function extractCandidateRuntime(options) {
|
|
|
285
260
|
}
|
|
286
261
|
if (await child.exited !== 0 || size < 4096) throw new Error("Invalid candidate runtime");
|
|
287
262
|
await errors;
|
|
288
|
-
|
|
289
|
-
if (!after.isFile() || after.isSymbolicLink() || after.dev !== archiveInfo.dev || after.ino !== archiveInfo.ino || after.size !== archiveInfo.size || after.mtimeMs !== archiveInfo.mtimeMs) throw new Error("Staged archive changed during extraction");
|
|
263
|
+
await assertArchiveUnchanged(archive, archiveInfo, "Staged archive changed during extraction");
|
|
290
264
|
const digest = hash.digest("hex");
|
|
291
265
|
await output.sync();
|
|
292
266
|
const copied = await installed(destination, profile, 268435456);
|