peachsim 0.1.754 → 0.1.756
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/cli/app-config.ts +4 -29
- package/cli/commands/daemon.ts +117 -116
- package/cli/commands/install-desktop.ts +13 -8
- package/cli/desktop-companion.ts +9 -2
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/agent-identity.cjs +1 -1
- package/dist-lib/agent-sessions.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +8 -5
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cli-constants.cjs +1 -1
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +88 -1
- package/dist-lib/detox/index.cjs +1 -1
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/home-paths.cjs +2 -23
- package/dist-lib/host/bridge-host.cjs +54 -38
- package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +13 -5
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +2551 -2220
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +914 -584
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +1 -1
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/render-mode.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +4 -4
- package/dist-lib/sdk.cjs +1 -1
- package/dist-lib/sdk.mjs +1 -1
- package/dist-lib/skills.cjs +137 -107
- package/dist-lib/swift-compile.cjs +6 -2
- package/dist-lib/swift-compile.mjs +6 -2
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +1 -1
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +6 -2
- package/dist-lib/vite.cjs +10 -4
- package/package.json +1 -1
- package/src/auth/shared-session.ts +9 -4
- package/src/config.ts +92 -0
- package/src/configured-bundle-producer.ts +110 -0
- package/src/desktop-host-delivery.ts +82 -19
- package/src/home-paths.ts +5 -22
- package/src/host/agent-host.ts +4 -1
- package/src/host/replacement-module-handler.ts +8 -2
- package/src/metro-plugin.ts +27 -0
- package/src/swift-compile.ts +4 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! rnx v0.1.
|
|
1
|
+
/*! rnx v0.1.756 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
2
|
let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
|
|
3
3
|
"use strict";
|
|
4
4
|
var __create = Object.create;
|
|
@@ -439,7 +439,11 @@ var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
|
|
|
439
439
|
DatadogCore: [],
|
|
440
440
|
DatadogLogs: ["DatadogCore"],
|
|
441
441
|
DatadogRUM: ["DatadogCore"],
|
|
442
|
-
DatadogTrace: ["DatadogCore"]
|
|
442
|
+
DatadogTrace: ["DatadogCore"],
|
|
443
|
+
AppLovinSDK: [],
|
|
444
|
+
AppsFlyerLib: [],
|
|
445
|
+
FBSDKCoreKit: [],
|
|
446
|
+
FBAudienceNetwork: []
|
|
443
447
|
};
|
|
444
448
|
var OPTIONAL_FRAMEWORKS = new Set(Object.keys(OPTIONAL_FRAMEWORK_DEPENDENCIES));
|
|
445
449
|
var SWIFT_IMPORT = /^\s*(?:@\w+(?:\([^)]*\))?\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?([A-Za-z_][A-Za-z0-9_]*)/;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! rnx v0.1.
|
|
1
|
+
/*! rnx v0.1.756 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
2
|
|
|
3
3
|
// src/swift-compile.ts
|
|
4
4
|
import { execFile as execFile2, execFileSync } from "node:child_process";
|
|
@@ -391,7 +391,11 @@ var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
|
|
|
391
391
|
DatadogCore: [],
|
|
392
392
|
DatadogLogs: ["DatadogCore"],
|
|
393
393
|
DatadogRUM: ["DatadogCore"],
|
|
394
|
-
DatadogTrace: ["DatadogCore"]
|
|
394
|
+
DatadogTrace: ["DatadogCore"],
|
|
395
|
+
AppLovinSDK: [],
|
|
396
|
+
AppsFlyerLib: [],
|
|
397
|
+
FBSDKCoreKit: [],
|
|
398
|
+
FBAudienceNetwork: []
|
|
395
399
|
};
|
|
396
400
|
var OPTIONAL_FRAMEWORKS = new Set(Object.keys(OPTIONAL_FRAMEWORK_DEPENDENCIES));
|
|
397
401
|
var SWIFT_IMPORT = /^\s*(?:@\w+(?:\([^)]*\))?\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?([A-Za-z_][A-Za-z0-9_]*)/;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! rnx v0.1.
|
|
1
|
+
/*! rnx v0.1.756 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
2
|
let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
|
|
3
3
|
"use strict";
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! rnx v0.1.
|
|
1
|
+
/*! rnx v0.1.756 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
2
|
let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
|
|
3
3
|
"use strict";
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! rnx v0.1.
|
|
1
|
+
/*! rnx v0.1.756 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
2
|
let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
|
|
3
3
|
"use strict";
|
|
4
4
|
var __create = Object.create;
|
package/dist-lib/swift.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! rnx v0.1.
|
|
1
|
+
/*! rnx v0.1.756 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
2
|
let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
|
|
3
3
|
"use strict";
|
|
4
4
|
var __defProp = Object.defineProperty;
|
package/dist-lib/vite-swift.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! rnx v0.1.
|
|
1
|
+
/*! rnx v0.1.756 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
2
|
let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
|
|
3
3
|
"use strict";
|
|
4
4
|
var __create = Object.create;
|
|
@@ -831,7 +831,11 @@ var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
|
|
|
831
831
|
DatadogCore: [],
|
|
832
832
|
DatadogLogs: ["DatadogCore"],
|
|
833
833
|
DatadogRUM: ["DatadogCore"],
|
|
834
|
-
DatadogTrace: ["DatadogCore"]
|
|
834
|
+
DatadogTrace: ["DatadogCore"],
|
|
835
|
+
AppLovinSDK: [],
|
|
836
|
+
AppsFlyerLib: [],
|
|
837
|
+
FBSDKCoreKit: [],
|
|
838
|
+
FBAudienceNetwork: []
|
|
835
839
|
};
|
|
836
840
|
var OPTIONAL_FRAMEWORKS = new Set(Object.keys(OPTIONAL_FRAMEWORK_DEPENDENCIES));
|
|
837
841
|
var SWIFT_IMPORT = /^\s*(?:@\w+(?:\([^)]*\))?\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?([A-Za-z_][A-Za-z0-9_]*)/;
|
package/dist-lib/vite.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! rnx v0.1.
|
|
1
|
+
/*! rnx v0.1.756 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
2
|
let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
|
|
3
3
|
"use strict";
|
|
4
4
|
var __create = Object.create;
|
|
@@ -371,6 +371,7 @@ function compileReplacementModule(input) {
|
|
|
371
371
|
return code.slice(token.start + 1, token.end - 1);
|
|
372
372
|
};
|
|
373
373
|
const bridgeNames = /* @__PURE__ */ new Map();
|
|
374
|
+
const bareSpecifiers = /* @__PURE__ */ new Set();
|
|
374
375
|
const declarations = [];
|
|
375
376
|
let needsDefaultInterop = false;
|
|
376
377
|
const bridgeFor = (specifier) => {
|
|
@@ -471,6 +472,7 @@ function compileReplacementModule(input) {
|
|
|
471
472
|
if (specifier !== "react" && specifier !== "react-native" && !JSX_RUNTIME_SPECIFIERS.has(specifier) && !isPeachKitSpecifier(specifier) && !input.runtimePackages.has(specifier)) {
|
|
472
473
|
throw unsupportedSpecifier(specifier);
|
|
473
474
|
}
|
|
475
|
+
bareSpecifiers.add(specifier);
|
|
474
476
|
const bridge = bindings.length > 0 ? bridgeFor(specifier) : null;
|
|
475
477
|
const replacement = bindings.map((binding) => {
|
|
476
478
|
if (binding.imported === null) return `const ${binding.local} = ${bridge};`;
|
|
@@ -493,6 +495,7 @@ function compileReplacementModule(input) {
|
|
|
493
495
|
const preamble = declarations.join(" ");
|
|
494
496
|
return {
|
|
495
497
|
code: preamble ? `${preamble} ${out}` : out,
|
|
498
|
+
bareSpecifiers: [...bareSpecifiers],
|
|
496
499
|
sourceMap: { ...sourceMap, sourcesContent: [input.source] }
|
|
497
500
|
};
|
|
498
501
|
}
|
|
@@ -524,7 +527,7 @@ function sendJavaScript(req, res, source) {
|
|
|
524
527
|
});
|
|
525
528
|
res.end(req.method === "HEAD" ? void 0 : source);
|
|
526
529
|
}
|
|
527
|
-
function
|
|
530
|
+
function resolveReplacementModuleFile(fromFile, specifier) {
|
|
528
531
|
const base = import_node_path3.default.resolve(import_node_path3.default.dirname(fromFile), specifier);
|
|
529
532
|
const candidates = [
|
|
530
533
|
...REPLACEMENT_MODULE_EXTENSIONS.some(
|
|
@@ -629,7 +632,10 @@ async function handleReplacementModuleRequest(req, res, options = {}) {
|
|
|
629
632
|
// so the token, cache key and runtime packages carry over.
|
|
630
633
|
localModuleUrl: (specifier) => {
|
|
631
634
|
const local = new URL(url.href);
|
|
632
|
-
local.searchParams.set(
|
|
635
|
+
local.searchParams.set(
|
|
636
|
+
"path",
|
|
637
|
+
resolveReplacementModuleFile(targetPath, specifier)
|
|
638
|
+
);
|
|
633
639
|
return `${local.pathname}${local.search}`;
|
|
634
640
|
}
|
|
635
641
|
});
|
|
@@ -654,7 +660,7 @@ var import_fs = __toESM(require("fs"), 1);
|
|
|
654
660
|
var import_path = __toESM(require("path"), 1);
|
|
655
661
|
var import_url = require("url");
|
|
656
662
|
|
|
657
|
-
// ../contrast-runtime-delivery/src/
|
|
663
|
+
// ../contrast-runtime-delivery/src/version.ts
|
|
658
664
|
function isValidRuntimeVersion(value) {
|
|
659
665
|
return value.length <= 100 && /^[0-9A-Za-z][0-9A-Za-z._+-]*$/.test(value);
|
|
660
666
|
}
|
package/package.json
CHANGED
|
@@ -177,15 +177,20 @@ export function writeSharedDesktopAuthSession(
|
|
|
177
177
|
) {
|
|
178
178
|
const filepath = getSharedDesktopAuthFilePath()
|
|
179
179
|
mkdirSync(dirname(filepath), { recursive: true })
|
|
180
|
+
const token = session.token.trim()
|
|
181
|
+
// a write of the session already stored (a page echoing what it adopted, or
|
|
182
|
+
// refreshing its user) keeps where that session came from and its account
|
|
183
|
+
const stored = readSharedDesktopAuthSession()
|
|
184
|
+
const same = stored?.token === token ? stored : null
|
|
180
185
|
const normalized: SharedDesktopAuthSession = {
|
|
181
186
|
version: SESSION_VERSION,
|
|
182
|
-
token
|
|
187
|
+
token,
|
|
183
188
|
user: session.user ? normalizeUser(session.user) : null,
|
|
184
189
|
origin: session.origin?.trim() || DEFAULT_ORIGIN,
|
|
185
|
-
source: session.source,
|
|
190
|
+
source: same?.source ?? session.source,
|
|
186
191
|
updatedAt: session.updatedAt || new Date().toISOString(),
|
|
187
|
-
validatedAt: session.validatedAt,
|
|
188
|
-
accountId: session.accountId?.trim() ||
|
|
192
|
+
validatedAt: session.validatedAt ?? same?.validatedAt,
|
|
193
|
+
accountId: session.accountId?.trim() || same?.accountId,
|
|
189
194
|
}
|
|
190
195
|
// readers and directory watchers see a complete session, including replacement writes.
|
|
191
196
|
const temporary = `${filepath}.${process.pid}.${randomUUID()}.tmp`
|
package/src/config.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
// import { defineConfig } from 'peachsim/config'
|
|
5
5
|
// export default defineConfig({ modules: { ... }, env: { ... } })
|
|
6
6
|
|
|
7
|
+
import { isValidRuntimeVersion } from '@contrast/runtime-delivery/version'
|
|
8
|
+
import { isRecord } from './is-record'
|
|
7
9
|
import type { RevenueCatTestStoreConfig } from '@peach/compat/revenuecat-test-store'
|
|
8
10
|
|
|
9
11
|
export type ModuleResolution =
|
|
@@ -54,6 +56,96 @@ export interface PeachConfig<Settings extends Record<string, any> = Record<strin
|
|
|
54
56
|
|
|
55
57
|
export const PEACH_CONFIG_QUERY_PARAM = 'peachConfig'
|
|
56
58
|
|
|
59
|
+
export function collectConfiguredFileModules(config?: PeachConfig): string[] {
|
|
60
|
+
return [
|
|
61
|
+
...new Set(
|
|
62
|
+
['modules', 'turboModules', 'nativeModules', 'nativeViews'].flatMap((key) => {
|
|
63
|
+
const entries: unknown = config && Reflect.get(config, key)
|
|
64
|
+
if (!isRecord(entries)) return []
|
|
65
|
+
return Object.values(entries).flatMap((entry) =>
|
|
66
|
+
isRecord(entry) && typeof entry.file === 'string' ? [entry.file] : [],
|
|
67
|
+
)
|
|
68
|
+
}),
|
|
69
|
+
),
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function isPeachConfig(value: unknown): value is PeachConfig {
|
|
74
|
+
if (!isRecord(value)) return false
|
|
75
|
+
return (
|
|
76
|
+
(value.runtimeVersion === undefined ||
|
|
77
|
+
(typeof value.runtimeVersion === 'string' &&
|
|
78
|
+
value.runtimeVersion === value.runtimeVersion.trim() &&
|
|
79
|
+
isValidRuntimeVersion(value.runtimeVersion))) &&
|
|
80
|
+
[
|
|
81
|
+
'modules',
|
|
82
|
+
'turboModules',
|
|
83
|
+
'nativeModules',
|
|
84
|
+
'nativeViews',
|
|
85
|
+
'env',
|
|
86
|
+
'network',
|
|
87
|
+
'settings',
|
|
88
|
+
'initialState',
|
|
89
|
+
].every((key) => value[key] === undefined || isRecord(value[key]))
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface PeachBundleConfig {
|
|
94
|
+
config: PeachConfig
|
|
95
|
+
runtimePackages: string[]
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const BUNDLE_CONFIG_PREFIX = 'globalThis.__peachBundleConfig='
|
|
99
|
+
export const PEACH_CONFIGURED_FILES_HOOK = '__peachInstallConfiguredFiles'
|
|
100
|
+
|
|
101
|
+
export function readPeachBundleConfig(value: unknown): PeachBundleConfig | null {
|
|
102
|
+
if (value === undefined || value === null) return null
|
|
103
|
+
if (
|
|
104
|
+
!isRecord(value) ||
|
|
105
|
+
!isPeachConfig(value.config) ||
|
|
106
|
+
!Array.isArray(value.runtimePackages) ||
|
|
107
|
+
!value.runtimePackages.every((name) => typeof name === 'string')
|
|
108
|
+
) {
|
|
109
|
+
throw new Error('configured bundle metadata is malformed')
|
|
110
|
+
}
|
|
111
|
+
return { config: value.config, runtimePackages: [...value.runtimePackages] }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function readPeachBundleConfigFooter(source: string): PeachBundleConfig | null {
|
|
115
|
+
const start = source.lastIndexOf('\n' + BUNDLE_CONFIG_PREFIX)
|
|
116
|
+
if (start < 0) return null
|
|
117
|
+
const end = source.indexOf('\n', start + 1)
|
|
118
|
+
const line = source.slice(start + 1, end < 0 ? undefined : end)
|
|
119
|
+
if (!line.endsWith(';')) throw new Error('configured bundle footer is truncated')
|
|
120
|
+
const result = readPeachBundleConfig(
|
|
121
|
+
JSON.parse(line.slice(BUNDLE_CONFIG_PREFIX.length, -1)),
|
|
122
|
+
)
|
|
123
|
+
if (!result) throw new Error('configured bundle footer is empty')
|
|
124
|
+
return result
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function createPeachBundleConfigFooter(config: PeachBundleConfig): string {
|
|
128
|
+
const json = JSON.stringify(config)
|
|
129
|
+
.replace(/\u2028/g, '\\u2028')
|
|
130
|
+
.replace(/\u2029/g, '\\u2029')
|
|
131
|
+
.replace(/<\//g, '<\\/')
|
|
132
|
+
return '\n' + BUNDLE_CONFIG_PREFIX + json + ';'
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function detachPeachBundleConfigFooter(source: string): {
|
|
136
|
+
source: string
|
|
137
|
+
configuredBundle: PeachBundleConfig | null
|
|
138
|
+
} {
|
|
139
|
+
const configuredBundle = readPeachBundleConfigFooter(source)
|
|
140
|
+
if (!configuredBundle) return { source, configuredBundle }
|
|
141
|
+
const start = source.lastIndexOf('\n' + BUNDLE_CONFIG_PREFIX)
|
|
142
|
+
const end = source.indexOf('\n', start + 1)
|
|
143
|
+
return {
|
|
144
|
+
source: source.slice(0, start) + source.slice(end < 0 ? source.length : end),
|
|
145
|
+
configuredBundle,
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
57
149
|
export function defineConfig<Settings extends Record<string, any> = Record<string, any>>(
|
|
58
150
|
config: PeachConfig<Settings>,
|
|
59
151
|
): PeachConfig<Settings> {
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// packages the app's configured native files, never the guest's module factories.
|
|
2
|
+
// the generated prefix runs as ordinary bundle code in browser and workerd tenants.
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import { transform } from 'sucrase'
|
|
6
|
+
import { minify } from 'terser'
|
|
7
|
+
import { compileReplacementModule } from '../../contrast-bundler/src/replacementModule'
|
|
8
|
+
import {
|
|
9
|
+
collectConfiguredFileModules,
|
|
10
|
+
createPeachBundleConfigFooter,
|
|
11
|
+
PEACH_CONFIGURED_FILES_HOOK,
|
|
12
|
+
isPeachConfig,
|
|
13
|
+
} from './config'
|
|
14
|
+
import { resolveReplacementModuleFile } from './host/replacement-module-handler'
|
|
15
|
+
import type { PeachConfig } from './config'
|
|
16
|
+
|
|
17
|
+
export async function produceConfiguredBundle(
|
|
18
|
+
source: string,
|
|
19
|
+
config: PeachConfig | undefined,
|
|
20
|
+
runtimePackages: ReadonlySet<string>,
|
|
21
|
+
): Promise<string> {
|
|
22
|
+
if (!config) return source
|
|
23
|
+
// functions cannot cross JSON. executable native bindings belong in file entries.
|
|
24
|
+
const json = JSON.stringify(config, (_key, value: unknown) => {
|
|
25
|
+
if (
|
|
26
|
+
typeof value === 'function' ||
|
|
27
|
+
typeof value === 'bigint' ||
|
|
28
|
+
typeof value === 'symbol'
|
|
29
|
+
)
|
|
30
|
+
throw new Error(
|
|
31
|
+
'configured bundle values must be JSON; native functions must use file entries',
|
|
32
|
+
)
|
|
33
|
+
return value
|
|
34
|
+
})
|
|
35
|
+
const packagedConfig: unknown = JSON.parse(json)
|
|
36
|
+
if (!isPeachConfig(packagedConfig))
|
|
37
|
+
throw new Error('configured bundle config is malformed')
|
|
38
|
+
const files = new Map<string, string>()
|
|
39
|
+
const neededPackages = new Set<string>()
|
|
40
|
+
const factories: string[] = []
|
|
41
|
+
const visit = (filePath: string): string => {
|
|
42
|
+
const real = fs.realpathSync(filePath)
|
|
43
|
+
const previous = files.get(real)
|
|
44
|
+
if (previous !== undefined) return previous
|
|
45
|
+
const id = 'peach-config-file:' + files.size
|
|
46
|
+
files.set(real, id)
|
|
47
|
+
const compiled = compileReplacementModule({
|
|
48
|
+
filePath: real,
|
|
49
|
+
source: fs.readFileSync(real, 'utf8'),
|
|
50
|
+
runtimePackages,
|
|
51
|
+
localModuleUrl: (specifier) => visit(resolveReplacementModuleFile(real, specifier)),
|
|
52
|
+
})
|
|
53
|
+
const commonJs = transform(compiled.code, { transforms: ['imports'] }).code
|
|
54
|
+
for (const specifier of compiled.bareSpecifiers) neededPackages.add(specifier)
|
|
55
|
+
factories.push(
|
|
56
|
+
JSON.stringify(id) + ':function(require,module,exports){' + commonJs + '\n}',
|
|
57
|
+
)
|
|
58
|
+
return id
|
|
59
|
+
}
|
|
60
|
+
for (const key of ['modules', 'turboModules', 'nativeModules', 'nativeViews']) {
|
|
61
|
+
const entries: unknown = Reflect.get(packagedConfig, key)
|
|
62
|
+
if (!entries || typeof entries !== 'object') continue
|
|
63
|
+
for (const resolution of Object.values(entries)) {
|
|
64
|
+
if (
|
|
65
|
+
resolution &&
|
|
66
|
+
typeof resolution === 'object' &&
|
|
67
|
+
'file' in resolution &&
|
|
68
|
+
typeof resolution.file === 'string'
|
|
69
|
+
) {
|
|
70
|
+
resolution.file = visit(path.resolve(resolution.file))
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const roots = collectConfiguredFileModules(packagedConfig)
|
|
75
|
+
let prefix = ''
|
|
76
|
+
if (roots.length > 0) {
|
|
77
|
+
const code =
|
|
78
|
+
'(function(){const factories={' +
|
|
79
|
+
factories.join(',') +
|
|
80
|
+
'};const cache=Object.create(null);function require(id){if(cache[id])return cache[id].exports;' +
|
|
81
|
+
'const factory=factories[id];if(!factory)throw new Error("missing configured file "+id);' +
|
|
82
|
+
'const module={exports:{}};cache[id]=module;try{factory(require,module,module.exports);' +
|
|
83
|
+
'return module.exports;}catch(error){delete cache[id];throw error;}}' +
|
|
84
|
+
'const loaded=Object.create(null);for(const id of ' +
|
|
85
|
+
JSON.stringify(roots) +
|
|
86
|
+
')loaded[id]=require(id);const install=globalThis[' +
|
|
87
|
+
JSON.stringify(PEACH_CONFIGURED_FILES_HOOK) +
|
|
88
|
+
'];if(typeof install!=="function")throw new Error("runtime cannot install configured bundle files");' +
|
|
89
|
+
'install(loaded);})();'
|
|
90
|
+
const compact = await minify(code, {
|
|
91
|
+
compress: false,
|
|
92
|
+
mangle: false,
|
|
93
|
+
format: { comments: false, beautify: false },
|
|
94
|
+
})
|
|
95
|
+
if (!compact.code || /[\n\r]/.test(compact.code))
|
|
96
|
+
throw new Error('configured bundle prefix must preserve the guest source lines')
|
|
97
|
+
prefix = compact.code
|
|
98
|
+
}
|
|
99
|
+
const footer = createPeachBundleConfigFooter({
|
|
100
|
+
config: packagedConfig,
|
|
101
|
+
runtimePackages: [...neededPackages].sort(),
|
|
102
|
+
})
|
|
103
|
+
const identityStart = source.lastIndexOf('\nglobalThis.__sootsimModulePaths=')
|
|
104
|
+
return (
|
|
105
|
+
prefix +
|
|
106
|
+
(identityStart < 0
|
|
107
|
+
? source + footer
|
|
108
|
+
: source.slice(0, identityStart) + footer + source.slice(identityStart))
|
|
109
|
+
)
|
|
110
|
+
}
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
// peach's binding of the shared runtime-delivery machinery for the native
|
|
2
2
|
// desktop host. the host releases on its own (packages/peach-desktop's Native
|
|
3
|
-
// Desktop Release workflow) and the CLI
|
|
4
|
-
// ~/.peach/desktop/<version>/, exactly as `peach runtime install` manages
|
|
5
|
-
// engine runtime.
|
|
6
|
-
//
|
|
3
|
+
// Desktop Release workflow) and the CLI downloads and verifies each version
|
|
4
|
+
// into ~/.peach/desktop/versions/<version>/, exactly as `peach runtime install` manages
|
|
5
|
+
// the engine runtime. the active version is the one at /Applications/Peach.app,
|
|
6
|
+
// where Spotlight finds it and the CLI, the fleet installer and the app's own
|
|
7
|
+
// updater share it. each channel publishes its own manifest per platform, so
|
|
8
|
+
// the staging and production queues never write the same object.
|
|
7
9
|
|
|
8
10
|
import { spawnSync } from 'node:child_process'
|
|
11
|
+
import fs from 'node:fs'
|
|
12
|
+
import os from 'node:os'
|
|
9
13
|
import path from 'node:path'
|
|
10
14
|
import { createRuntimeDelivery, type RuntimeDelivery } from '@contrast/runtime-delivery'
|
|
11
|
-
import {
|
|
12
|
-
cacheDir,
|
|
13
|
-
desktopHostDir,
|
|
14
|
-
desktopHostsDir,
|
|
15
|
-
ensureRnxHome,
|
|
16
|
-
readActiveDesktopHost,
|
|
17
|
-
writeActiveDesktopHost,
|
|
18
|
-
} from './home-paths.ts'
|
|
15
|
+
import { cacheDir, desktopHostDir, desktopHostsDir, ensureRnxHome } from './home-paths.ts'
|
|
19
16
|
|
|
20
17
|
export const DESKTOP_HOST_CDN_ORIGIN = 'https://r2.rnxsim.com'
|
|
21
18
|
export const DESKTOP_HOST_CHANNELS = ['production', 'staging'] as const
|
|
@@ -33,11 +30,8 @@ export function desktopHostExecutable(): string {
|
|
|
33
30
|
return 'PeachDesktop.app/Contents/MacOS/PeachDesktop'
|
|
34
31
|
}
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const version = readActiveDesktopHost()
|
|
39
|
-
return version ? path.join(desktopHostDir(version), 'PeachDesktop.app') : null
|
|
40
|
-
}
|
|
33
|
+
export const MAC_HOST_APP = '/Applications/Peach.app'
|
|
34
|
+
const HOST_BUNDLE_ID = 'dev.contrast.peach-desktop'
|
|
41
35
|
|
|
42
36
|
// the host's identity: the manifest checksum proves the bytes are the published
|
|
43
37
|
// ones, this proves who signed them
|
|
@@ -60,6 +54,75 @@ function verifyHost(dir: string): void {
|
|
|
60
54
|
}
|
|
61
55
|
}
|
|
62
56
|
|
|
57
|
+
function bundleValue(app: string, key: string): string | null {
|
|
58
|
+
const read = spawnSync(
|
|
59
|
+
'plutil',
|
|
60
|
+
['-extract', key, 'raw', '-o', '-', path.join(app, 'Contents/Info.plist')],
|
|
61
|
+
{ encoding: 'utf8' },
|
|
62
|
+
)
|
|
63
|
+
return read.status === 0 ? read.stdout.trim() : null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** whether `app` is the native host, as opposed to the Electron app, which
|
|
67
|
+
* installs to the same path on a case-insensitive disk. */
|
|
68
|
+
export function isNativeHostBundle(app: string): boolean {
|
|
69
|
+
return (
|
|
70
|
+
process.platform === 'darwin' &&
|
|
71
|
+
bundleValue(app, 'CFBundleIdentifier') === HOST_BUNDLE_ID
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function placedHostVersion(): string | null {
|
|
76
|
+
return isNativeHostBundle(MAC_HOST_APP)
|
|
77
|
+
? bundleValue(MAC_HOST_APP, 'CFBundleVersion')
|
|
78
|
+
: null
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** the active native host's app bundle, or null when none is installed. */
|
|
82
|
+
export function activeDesktopHostApp(): string | null {
|
|
83
|
+
return placedHostVersion() ? MAC_HOST_APP : null
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function run(command: string, args: string[]): void {
|
|
87
|
+
const result = spawnSync(command, args, { encoding: 'utf8' })
|
|
88
|
+
if (result.status !== 0)
|
|
89
|
+
throw new Error(`${command} ${args.join(' ')} failed: ${result.stderr.trim()}`)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// lands a verified cached version at /Applications/Peach.app. the copy is an
|
|
93
|
+
// APFS clone of the cache, so it costs no space, and it swaps in by rename so a
|
|
94
|
+
// failure leaves the previous app in place. an Electron app in the slot moves to
|
|
95
|
+
// ~/Applications, where the CLI still finds it.
|
|
96
|
+
function placeHost(version: string): void {
|
|
97
|
+
if (placedHostVersion() === version) return
|
|
98
|
+
const parent = path.dirname(MAC_HOST_APP)
|
|
99
|
+
const incoming = path.join(parent, `.Peach-incoming-${process.pid}.app`)
|
|
100
|
+
const previous = path.join(parent, `.Peach-previous-${process.pid}.app`)
|
|
101
|
+
run('cp', ['-cR', path.join(desktopHostDir(version), 'PeachDesktop.app'), incoming])
|
|
102
|
+
try {
|
|
103
|
+
if (fs.existsSync(MAC_HOST_APP)) {
|
|
104
|
+
if (isNativeHostBundle(MAC_HOST_APP)) fs.renameSync(MAC_HOST_APP, previous)
|
|
105
|
+
else {
|
|
106
|
+
const electron = path.join(os.homedir(), 'Applications/peach.app')
|
|
107
|
+
if (fs.existsSync(electron))
|
|
108
|
+
throw new Error(
|
|
109
|
+
`${MAC_HOST_APP} holds another app and ${electron} exists; move one aside`,
|
|
110
|
+
)
|
|
111
|
+
fs.mkdirSync(path.dirname(electron), { recursive: true })
|
|
112
|
+
fs.renameSync(MAC_HOST_APP, electron)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
fs.renameSync(incoming, MAC_HOST_APP)
|
|
116
|
+
} catch (err) {
|
|
117
|
+
if (fs.existsSync(previous) && !fs.existsSync(MAC_HOST_APP))
|
|
118
|
+
fs.renameSync(previous, MAC_HOST_APP)
|
|
119
|
+
throw err
|
|
120
|
+
} finally {
|
|
121
|
+
fs.rmSync(incoming, { recursive: true, force: true })
|
|
122
|
+
fs.rmSync(previous, { recursive: true, force: true })
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
63
126
|
function isChannel(value: string): value is DesktopHostChannel {
|
|
64
127
|
return DESKTOP_HOST_CHANNELS.some((channel) => channel === value)
|
|
65
128
|
}
|
|
@@ -98,7 +161,7 @@ export function desktopHostDelivery(channelInput?: string): RuntimeDelivery {
|
|
|
98
161
|
runtimesDir: desktopHostsDir,
|
|
99
162
|
runtimeDir: desktopHostDir,
|
|
100
163
|
cacheDir,
|
|
101
|
-
readActiveRuntime:
|
|
102
|
-
writeActiveRuntime:
|
|
164
|
+
readActiveRuntime: placedHostVersion,
|
|
165
|
+
writeActiveRuntime: placeHost,
|
|
103
166
|
})
|
|
104
167
|
}
|
package/src/home-paths.ts
CHANGED
|
@@ -119,35 +119,18 @@ export function activeRuntimeFile(): string {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
// versioned native desktop hosts, laid out like runtimes: one directory per
|
|
122
|
-
// version
|
|
122
|
+
// version. the active one is the copy at /Applications/Peach.app. they sit
|
|
123
|
+
// apart from the host's own state in ~/.peach/desktop (profiles, window state,
|
|
124
|
+
// the node host's web data), since pruning removes every directory here that is
|
|
125
|
+
// not a kept version.
|
|
123
126
|
export function desktopHostsDir(): string {
|
|
124
|
-
return path.join(rnxHomeDir(), 'desktop')
|
|
127
|
+
return path.join(rnxHomeDir(), 'desktop', 'versions')
|
|
125
128
|
}
|
|
126
129
|
|
|
127
130
|
export function desktopHostDir(version: string): string {
|
|
128
131
|
return path.join(desktopHostsDir(), version)
|
|
129
132
|
}
|
|
130
133
|
|
|
131
|
-
export function readActiveDesktopHost(): string | null {
|
|
132
|
-
try {
|
|
133
|
-
const value = fs
|
|
134
|
-
.readFileSync(path.join(desktopHostsDir(), ACTIVE_RUNTIME_FILE), 'utf8')
|
|
135
|
-
.trim()
|
|
136
|
-
return value.length > 0 ? value : null
|
|
137
|
-
} catch {
|
|
138
|
-
return null
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export function writeActiveDesktopHost(version: string): void {
|
|
143
|
-
fs.mkdirSync(desktopHostsDir(), { recursive: true })
|
|
144
|
-
fs.writeFileSync(
|
|
145
|
-
path.join(desktopHostsDir(), ACTIVE_RUNTIME_FILE),
|
|
146
|
-
`${version}\n`,
|
|
147
|
-
'utf8',
|
|
148
|
-
)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
134
|
export function electronDir(): string {
|
|
152
135
|
return path.join(rnxHomeDir(), 'electron')
|
|
153
136
|
}
|
package/src/host/agent-host.ts
CHANGED
|
@@ -397,12 +397,14 @@ export class AgentHost {
|
|
|
397
397
|
if (sockets.has(sessionId)) {
|
|
398
398
|
return { ok: true, refCount: this.subscriptions.get(sessionId)?.refCount ?? 1 }
|
|
399
399
|
}
|
|
400
|
-
sockets.add(sessionId)
|
|
401
400
|
const existing = this.subscriptions.get(sessionId)
|
|
402
401
|
if (existing) {
|
|
402
|
+
sockets.add(sessionId)
|
|
403
403
|
existing.refCount++
|
|
404
404
|
return { ok: true, refCount: existing.refCount }
|
|
405
405
|
}
|
|
406
|
+
// the socket holds the session only once its events open: a missing FIFO
|
|
407
|
+
// throws here and leaves nothing behind for a retry to count
|
|
406
408
|
const unsubscribe = subscribeAgentEvents(sessionId, (event) => {
|
|
407
409
|
const coalesced = this.coalescePromptEcho(sessionId, event)
|
|
408
410
|
if (coalesced) {
|
|
@@ -427,6 +429,7 @@ export class AgentHost {
|
|
|
427
429
|
}
|
|
428
430
|
}
|
|
429
431
|
})
|
|
432
|
+
sockets.add(sessionId)
|
|
430
433
|
this.subscriptions.set(sessionId, { unsubscribe, refCount: 1 })
|
|
431
434
|
return { ok: true, refCount: 1 }
|
|
432
435
|
}
|
|
@@ -37,7 +37,10 @@ function sendJavaScript(req: IncomingMessage, res: ServerResponse, source: strin
|
|
|
37
37
|
// a relative import resolves the way the app's own files do: the exact path
|
|
38
38
|
// when it names an allowed extension, else each extension in turn, else the
|
|
39
39
|
// directory's index file.
|
|
40
|
-
function
|
|
40
|
+
export function resolveReplacementModuleFile(
|
|
41
|
+
fromFile: string,
|
|
42
|
+
specifier: string,
|
|
43
|
+
): string {
|
|
41
44
|
const base = path.resolve(path.dirname(fromFile), specifier)
|
|
42
45
|
const candidates = [
|
|
43
46
|
...(REPLACEMENT_MODULE_EXTENSIONS.some(
|
|
@@ -170,7 +173,10 @@ export async function handleReplacementModuleRequest(
|
|
|
170
173
|
// so the token, cache key and runtime packages carry over.
|
|
171
174
|
localModuleUrl: (specifier) => {
|
|
172
175
|
const local = new URL(url.href)
|
|
173
|
-
local.searchParams.set(
|
|
176
|
+
local.searchParams.set(
|
|
177
|
+
'path',
|
|
178
|
+
resolveReplacementModuleFile(targetPath, specifier),
|
|
179
|
+
)
|
|
174
180
|
return `${local.pathname}${local.search}`
|
|
175
181
|
},
|
|
176
182
|
})
|