@threenative/runtime-native 0.2.0 → 0.3.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/NOTICE +2 -0
- package/README.md +63 -0
- package/android/README.md +2 -2
- package/android/app/build.gradle.kts +177 -30
- package/android/app/src/main/AndroidManifest.xml +8 -1
- package/android/app/src/main/java/com/mystral/engine/MystralActivity.java +190 -2
- package/android/app/src/main/java/com/mystral/engine/TnUiOverlay.java +261 -0
- package/android/app/src/main/res/values/branding.xml +12 -0
- package/android/app/src/main/res/values/themes.xml +2 -0
- package/android/gradle.properties +1 -1
- package/package.json +44 -8
- package/scripts/asset-preflight.mjs +442 -0
- package/scripts/bundle.mjs +178 -48
- package/scripts/check-source-list.mjs +90 -0
- package/scripts/device-preflight.mjs +456 -0
- package/scripts/install-prebuilt.mjs +326 -30
- package/scripts/package-android.mjs +414 -23
- package/scripts/package-desktop.mjs +132 -12
- package/scripts/package-ios.mjs +249 -25
- package/scripts/physical-device-evidence.mjs +644 -0
- package/scripts/production-evidence.mjs +101 -2
- package/scripts/profile-production.mjs +544 -115
- package/scripts/qualify-physical-mobile.mjs +1327 -0
- package/scripts/verify-starter-desktop.mjs +140 -16
- package/scripts/xvfb.sh +68 -0
|
@@ -1,17 +1,76 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { createHash } from 'node:crypto';
|
|
4
|
-
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
4
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
5
|
import { dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
9
9
|
const packageVersion = JSON.parse(readFileSync(join(packageRoot, 'package.json'), 'utf8')).version;
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
export const RELEASE_REPOSITORY = 'ThreeNativeHQ/threenative';
|
|
11
|
+
|
|
12
|
+
/** Every asset a packaged consumer or native release workflow may request. */
|
|
13
|
+
export const PREBUILT_ASSET_NAMES = Object.freeze({
|
|
14
|
+
'android-arm64-v8a-runtime': 'threenative-runtime-android-arm64-v8a.so',
|
|
15
|
+
'android-arm64-v8a-runtime-v8': 'threenative-runtime-android-arm64-v8a-v8.so',
|
|
16
|
+
'android-arm64-v8a-sdl3': 'threenative-sdl3-android-arm64-v8a.so',
|
|
17
|
+
'android-arm64-v8a-v8': 'threenative-v8-android-arm64-v8a.so',
|
|
18
|
+
'android-arm64-v8a-libcxx': 'threenative-libcxx-android-arm64-v8a.so',
|
|
19
|
+
'android-arm64-v8a-v8-snapshot': 'threenative-v8-snapshot-android-arm64-v8a.bin',
|
|
20
|
+
'android-sdl3-aar': 'threenative-sdl3-android.aar',
|
|
21
|
+
'android-x86_64-runtime': 'threenative-runtime-android-x86_64.so',
|
|
22
|
+
'android-x86_64-runtime-v8': 'threenative-runtime-android-x86_64-v8.so',
|
|
23
|
+
'android-x86_64-sdl3': 'threenative-sdl3-android-x86_64.so',
|
|
24
|
+
'android-x86_64-v8': 'threenative-v8-android-x86_64.so',
|
|
25
|
+
'android-x86_64-libcxx': 'threenative-libcxx-android-x86_64.so',
|
|
26
|
+
'android-x86_64-v8-snapshot': 'threenative-v8-snapshot-android-x86_64.bin',
|
|
27
|
+
'darwin-arm64': 'threenative-runtime-darwin-arm64',
|
|
28
|
+
'darwin-arm64-tools': 'threenative-tools-darwin-arm64',
|
|
29
|
+
'ios-simulator-arm64': 'threenative-ios-simulator-arm64.zip',
|
|
30
|
+
'linux-x64': 'threenative-runtime-linux-x64',
|
|
31
|
+
'linux-x64-tools': 'threenative-tools-linux-x64',
|
|
32
|
+
'win32-x64': 'threenative-runtime-win32-x64.exe',
|
|
33
|
+
'win32-x64-tools': 'threenative-tools-win32-x64.exe',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/** Every key a packaged consumer or native release workflow may request. */
|
|
37
|
+
export const PREBUILT_KEYS = Object.freeze(Object.keys(PREBUILT_ASSET_NAMES));
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Rows this repository builds and verifies on every release run but does not publish.
|
|
41
|
+
*
|
|
42
|
+
* Only macOS. Gatekeeper hard-refuses an unsigned, un-notarized bundle downloaded from the web, so
|
|
43
|
+
* a macOS asset without an Apple Developer Program identity is not a shippable artifact — it is a
|
|
44
|
+
* support ticket. Windows is different: an unsigned executable runs, SmartScreen only warns, so
|
|
45
|
+
* `win32-x64` ships unsigned rather than waiting on a certificate.
|
|
46
|
+
*
|
|
47
|
+
* The row keeps building and verifying on every release run — a row that stops compiling rots
|
|
48
|
+
* silently — it is simply not advertised as downloadable, which is the narrowing PRD-262 allows in
|
|
49
|
+
* place of building every claimed row. Publishing it again is one entry, once the Apple identity
|
|
50
|
+
* exists. Status and cost of every platform's signing inputs: `docs/RELEASE-SIGNING.md`.
|
|
51
|
+
*/
|
|
52
|
+
export const UNPUBLISHED_PREBUILT_KEYS = Object.freeze(['darwin-arm64', 'darwin-arm64-tools']);
|
|
53
|
+
|
|
54
|
+
/** The exact cohort a release publishes and a consumer may download. */
|
|
55
|
+
export const PUBLISHED_PREBUILT_KEYS = Object.freeze(
|
|
56
|
+
PREBUILT_KEYS.filter((key) => !UNPUBLISHED_PREBUILT_KEYS.includes(key)),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const supported = new Set(['darwin-arm64', 'linux-x64', 'win32-x64']);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The desktop runtime dispatches `threenative build --target desktop` to a `mystral-tools` helper
|
|
63
|
+
* sitting beside its own executable (`src/cli/tool_dispatch.cpp:52`). A consumer that installs only
|
|
64
|
+
* the runtime gets `build tool helper is missing` and exit 127, so the helper is a published
|
|
65
|
+
* release asset of its own and is installed beside the runtime by the same atomic install.
|
|
66
|
+
*/
|
|
67
|
+
export function toolsKey(key) {
|
|
68
|
+
return supported.has(key) ? `${key}-tools` : undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function toolsFilename(platform = process.platform) {
|
|
72
|
+
return platform === 'win32' ? 'mystral-tools.exe' : 'mystral-tools';
|
|
73
|
+
}
|
|
15
74
|
|
|
16
75
|
export function platformKey(platform = process.platform, arch = process.arch) {
|
|
17
76
|
const key = `${platform}-${arch}`;
|
|
@@ -31,10 +90,20 @@ export function verifyChecksum(contents, expected, key) {
|
|
|
31
90
|
}
|
|
32
91
|
|
|
33
92
|
function releaseFromManifest(manifest, key) {
|
|
34
|
-
|
|
93
|
+
if (UNPUBLISHED_PREBUILT_KEYS.includes(key)) {
|
|
94
|
+
const error = new Error(
|
|
95
|
+
`No prebuilt release is published for '${key}'. This platform builds from an engine checkout until its release credentials exist; see PRD-262.`,
|
|
96
|
+
);
|
|
97
|
+
error.code = 'PREBUILT_RELEASE_UNPUBLISHED';
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
const release = manifest?.artifacts?.[key];
|
|
35
101
|
if (!release?.url || !release?.sha256) {
|
|
36
102
|
throw new Error(`No prebuilt release asset is recorded for '${key}'.`);
|
|
37
103
|
}
|
|
104
|
+
if (typeof release.sha256 !== 'string' || !/^[a-f0-9]{64}$/u.test(release.sha256)) {
|
|
105
|
+
throw new Error(`Invalid prebuilt SHA-256 for '${key}'.`);
|
|
106
|
+
}
|
|
38
107
|
const url = new URL(release.url);
|
|
39
108
|
if (url.protocol !== 'https:' && process.env.THREENATIVE_ALLOW_INSECURE_PREBUILT !== '1') {
|
|
40
109
|
throw new Error(`Prebuilt release URL for '${key}' must use HTTPS.`);
|
|
@@ -42,15 +111,165 @@ function releaseFromManifest(manifest, key) {
|
|
|
42
111
|
return release;
|
|
43
112
|
}
|
|
44
113
|
|
|
114
|
+
function isLoopbackFixture(url) {
|
|
115
|
+
return process.env.THREENATIVE_ALLOW_INSECURE_PREBUILT === '1' &&
|
|
116
|
+
url.protocol === 'http:' && ['127.0.0.1', '[::1]', 'localhost'].includes(url.hostname) &&
|
|
117
|
+
!url.username && !url.password;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function validateManifestEnvelope(manifest, options) {
|
|
121
|
+
if (manifest?.schemaVersion !== 1) throw new Error('Unsupported or missing prebuilt manifest schemaVersion.');
|
|
122
|
+
const version = options.version ?? packageVersion;
|
|
123
|
+
if (manifest.version !== version) {
|
|
124
|
+
throw new Error(`Prebuilt manifest version mismatch: expected ${version}, received ${manifest.version}.`);
|
|
125
|
+
}
|
|
126
|
+
if (typeof manifest.sourceSha !== 'string' || !/^[a-f0-9]{40}$/u.test(manifest.sourceSha)) {
|
|
127
|
+
throw new Error('Prebuilt manifest must record a full source SHA.');
|
|
128
|
+
}
|
|
129
|
+
if (options.sourceSha !== undefined && manifest.sourceSha !== options.sourceSha) {
|
|
130
|
+
throw new Error(`Prebuilt source SHA mismatch: expected ${options.sourceSha}, received ${manifest.sourceSha}.`);
|
|
131
|
+
}
|
|
132
|
+
if (!manifest.artifacts || typeof manifest.artifacts !== 'object' || Array.isArray(manifest.artifacts)) {
|
|
133
|
+
throw new Error('Prebuilt manifest artifacts must be an object.');
|
|
134
|
+
}
|
|
135
|
+
return version;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function validateManifestArtifact(manifest, key, version) {
|
|
139
|
+
if (!Object.hasOwn(PREBUILT_ASSET_NAMES, key)) throw new Error(`Unknown prebuilt release key '${key}'.`);
|
|
140
|
+
const release = releaseFromManifest(manifest, key);
|
|
141
|
+
if (!Number.isSafeInteger(release.size) || release.size <= 0) {
|
|
142
|
+
throw new Error(`Prebuilt release size for '${key}' must be a positive integer.`);
|
|
143
|
+
}
|
|
144
|
+
const expectedUrl = `${releaseManifestUrl(version).replace('/prebuilt-lock.json', '')}/${PREBUILT_ASSET_NAMES[key]}`;
|
|
145
|
+
const url = new URL(release.url);
|
|
146
|
+
if (release.url !== expectedUrl && !isLoopbackFixture(url)) {
|
|
147
|
+
throw new Error(`Prebuilt release URL for '${key}' must match version ${version}: ${expectedUrl}.`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Validate the entire advertised cohort before selecting even one consumer artifact. */
|
|
152
|
+
export function validateReleaseManifest(manifest, options = {}) {
|
|
153
|
+
const version = validateManifestEnvelope(manifest, options);
|
|
154
|
+
// iOS retains its separate release gate; it is not a prerequisite for a non-iOS consumer.
|
|
155
|
+
const requiredKeys = options.requiredKeys ??
|
|
156
|
+
PUBLISHED_PREBUILT_KEYS.filter((key) => !key.startsWith('ios-'));
|
|
157
|
+
for (const key of requiredKeys) releaseFromManifest(manifest, key);
|
|
158
|
+
for (const key of Object.keys(manifest.artifacts)) validateManifestArtifact(manifest, key, version);
|
|
159
|
+
return manifest;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** The release workflow uses this same validator, including its existing iOS requirement. */
|
|
163
|
+
export function generateReleaseManifest(directory, { repository, tag, sourceSha }) {
|
|
164
|
+
if (repository !== RELEASE_REPOSITORY) {
|
|
165
|
+
throw new Error(`Prebuilt releases must be published by ${RELEASE_REPOSITORY}, received ${repository}.`);
|
|
166
|
+
}
|
|
167
|
+
if (tag !== `runtime-native-v${packageVersion}`) {
|
|
168
|
+
throw new Error(`Prebuilt release tag must be runtime-native-v${packageVersion}, received ${tag}.`);
|
|
169
|
+
}
|
|
170
|
+
const published = PUBLISHED_PREBUILT_KEYS.map((key) => [key, PREBUILT_ASSET_NAMES[key]]);
|
|
171
|
+
const expected = published.map(([, name]) => name).sort();
|
|
172
|
+
const actual = readdirSync(directory).sort();
|
|
173
|
+
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
|
|
174
|
+
throw new Error(`Incomplete prebuilt release matrix: expected ${expected.join(', ')}; received ${actual.join(', ')}.`);
|
|
175
|
+
}
|
|
176
|
+
const artifacts = Object.fromEntries(published.map(([key, name]) => {
|
|
177
|
+
const contents = readFileSync(join(directory, name));
|
|
178
|
+
if (contents.length === 0) throw new Error(`Prebuilt release asset '${key}' is empty.`);
|
|
179
|
+
return [key, { sha256: sha256(contents), size: contents.length,
|
|
180
|
+
url: `${releaseManifestUrl().replace('/prebuilt-lock.json', '')}/${name}` }];
|
|
181
|
+
}));
|
|
182
|
+
return validateReleaseManifest({ schemaVersion: 1, version: packageVersion, sourceSha, artifacts },
|
|
183
|
+
{ sourceSha, requiredKeys: PUBLISHED_PREBUILT_KEYS });
|
|
184
|
+
}
|
|
185
|
+
|
|
45
186
|
export function readRelease(manifestPath, key) {
|
|
46
187
|
if (!existsSync(manifestPath)) {
|
|
47
|
-
|
|
188
|
+
const error = new Error(`No prebuilt release manifest exists for '${key}'; this target remains OPEN.`);
|
|
189
|
+
error.code = 'PREBUILT_RELEASE_MISSING';
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
193
|
+
// Explicit artifact-only local pins predate the envelope. Never downgrade a partially
|
|
194
|
+
// specified candidate, and never allow this compatibility path for a remote default lock.
|
|
195
|
+
if (manifest && ['schemaVersion', 'version', 'sourceSha'].some((field) => Object.hasOwn(manifest, field))) {
|
|
196
|
+
validateReleaseManifest(manifest);
|
|
48
197
|
}
|
|
49
|
-
return releaseFromManifest(
|
|
198
|
+
return releaseFromManifest(manifest, key);
|
|
50
199
|
}
|
|
51
200
|
|
|
52
201
|
export function releaseManifestUrl(version = packageVersion) {
|
|
53
|
-
return `https://github.com/
|
|
202
|
+
return `https://github.com/${RELEASE_REPOSITORY}/releases/download/runtime-native-v${encodeURIComponent(version)}/prebuilt-lock.json`;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function writeInstallStatus(status, statusPath = join(packageRoot, 'prebuilt', 'install-status.json')) {
|
|
206
|
+
mkdirSync(dirname(statusPath), { recursive: true });
|
|
207
|
+
const temporary = `${statusPath}.${randomUUID()}.tmp`;
|
|
208
|
+
try {
|
|
209
|
+
writeFileSync(temporary, `${JSON.stringify(status, null, 2)}\n`, { flag: 'wx' });
|
|
210
|
+
renameSync(temporary, statusPath);
|
|
211
|
+
return statusPath;
|
|
212
|
+
} finally {
|
|
213
|
+
rmSync(temporary, { force: true });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function createInstallPlan(options) {
|
|
218
|
+
const platform = options.platform ?? process.platform;
|
|
219
|
+
const key = `${platform}-${options.arch ?? process.arch}`;
|
|
220
|
+
const filename = platform === 'win32' ? 'threenative-runtime.exe' : 'threenative-runtime';
|
|
221
|
+
const output = resolve(options.output ?? join(packageRoot, 'prebuilt', key, filename));
|
|
222
|
+
const statusPath = resolve(options.statusPath ?? (options.output
|
|
223
|
+
? join(dirname(output), 'install-status.json')
|
|
224
|
+
: join(packageRoot, 'prebuilt', 'install-status.json')));
|
|
225
|
+
if (output === statusPath) throw new Error('Prebuilt output and install status paths must differ.');
|
|
226
|
+
const toolsOutput = join(dirname(output), toolsFilename(platform));
|
|
227
|
+
if (toolsOutput === output) throw new Error('Prebuilt runtime and build tool helper paths must differ.');
|
|
228
|
+
return { platform, key, output, statusPath, toolsOutput, toolsKey: toolsKey(key),
|
|
229
|
+
status: { key, url: options.manifestPath ?? process.env.THREENATIVE_PREBUILT_MANIFEST ??
|
|
230
|
+
options.manifestUrl ?? releaseManifestUrl(), version: packageVersion } };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function beginInstall(plan, arch) {
|
|
234
|
+
rmSync(plan.output, { force: true });
|
|
235
|
+
rmSync(plan.toolsOutput, { force: true });
|
|
236
|
+
rmSync(plan.statusPath, { force: true });
|
|
237
|
+
writeInstallStatus({ ...plan.status, ok: false, reason: 'installing' }, plan.statusPath);
|
|
238
|
+
platformKey(plan.platform, arch);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function publishBinary(target, contents, platform) {
|
|
242
|
+
const temporary = `${target}.${randomUUID()}.tmp`;
|
|
243
|
+
try {
|
|
244
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
245
|
+
writeFileSync(temporary, contents, { flag: 'wx' });
|
|
246
|
+
if (platform !== 'win32') chmodSync(temporary, 0o755);
|
|
247
|
+
renameSync(temporary, target);
|
|
248
|
+
} finally {
|
|
249
|
+
rmSync(temporary, { force: true });
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// The success marker is written only once both binaries are in place: a desktop build that finds
|
|
254
|
+
// the runtime but not the helper dies inside the packager with exit 127, which is exactly the
|
|
255
|
+
// stale-success shape this install exists to prevent.
|
|
256
|
+
function publishInstall(plan, contents, toolsContents) {
|
|
257
|
+
publishBinary(plan.output, contents, plan.platform);
|
|
258
|
+
publishBinary(plan.toolsOutput, toolsContents, plan.platform);
|
|
259
|
+
writeInstallStatus({ ...plan.status, ok: true, reason: 'installed', sha256: sha256(contents),
|
|
260
|
+
toolsSha256: sha256(toolsContents) }, plan.statusPath);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function recordInstallFailure(plan, error) {
|
|
264
|
+
try {
|
|
265
|
+
rmSync(plan.output, { force: true });
|
|
266
|
+
rmSync(plan.toolsOutput, { force: true });
|
|
267
|
+
writeInstallStatus({ ...plan.status, ok: false,
|
|
268
|
+
reason: error instanceof Error ? error.message : String(error) }, plan.statusPath);
|
|
269
|
+
} catch (statusError) {
|
|
270
|
+
rmSync(plan.statusPath, { force: true });
|
|
271
|
+
throw new Error(`Could not invalidate prebuilt install for '${plan.key}': ${statusError instanceof Error ? statusError.message : String(statusError)}`, { cause: error });
|
|
272
|
+
}
|
|
54
273
|
}
|
|
55
274
|
|
|
56
275
|
async function fetchRelease(manifestUrl, key) {
|
|
@@ -58,11 +277,22 @@ async function fetchRelease(manifestUrl, key) {
|
|
|
58
277
|
if (url.protocol !== 'https:' && process.env.THREENATIVE_ALLOW_INSECURE_PREBUILT !== '1') {
|
|
59
278
|
throw new Error(`Prebuilt release manifest for '${key}' must use HTTPS.`);
|
|
60
279
|
}
|
|
61
|
-
|
|
280
|
+
let response;
|
|
281
|
+
try {
|
|
282
|
+
response = await fetch(url);
|
|
283
|
+
} catch (error) {
|
|
284
|
+
throw new Error(
|
|
285
|
+
`Prebuilt release manifest fetch failed for '${key}' at ${url.href}: ${error instanceof Error ? error.message : String(error)}`,
|
|
286
|
+
);
|
|
287
|
+
}
|
|
62
288
|
if (!response.ok) {
|
|
63
|
-
|
|
289
|
+
const error = new Error(
|
|
290
|
+
`Prebuilt release manifest fetch failed for '${key}' at ${url.href}: HTTP ${response.status}.`,
|
|
291
|
+
);
|
|
292
|
+
if (response.status === 404) error.code = 'PREBUILT_RELEASE_MISSING';
|
|
293
|
+
throw error;
|
|
64
294
|
}
|
|
65
|
-
return releaseFromManifest(await response.json(), key);
|
|
295
|
+
return releaseFromManifest(validateReleaseManifest(await response.json()), key);
|
|
66
296
|
}
|
|
67
297
|
|
|
68
298
|
export async function downloadReleaseArtifact(key, options = {}) {
|
|
@@ -70,23 +300,77 @@ export async function downloadReleaseArtifact(key, options = {}) {
|
|
|
70
300
|
const release = manifestPath
|
|
71
301
|
? readRelease(resolve(manifestPath), key)
|
|
72
302
|
: await fetchRelease(options.manifestUrl ?? releaseManifestUrl(), key);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
303
|
+
let response;
|
|
304
|
+
try {
|
|
305
|
+
response = await fetch(release.url);
|
|
306
|
+
} catch (error) {
|
|
307
|
+
throw new Error(
|
|
308
|
+
`Prebuilt release fetch failed for '${key}' at ${release.url}: ${error instanceof Error ? error.message : String(error)}`,
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
if (!response.ok) {
|
|
312
|
+
throw new Error(`Prebuilt release fetch failed for '${key}' at ${release.url}: HTTP ${response.status}.`);
|
|
313
|
+
}
|
|
314
|
+
let contents;
|
|
315
|
+
try {
|
|
316
|
+
contents = Buffer.from(await response.arrayBuffer());
|
|
317
|
+
} catch (error) {
|
|
318
|
+
throw new Error(`Prebuilt release body failed for '${key}' at ${release.url}: ${error instanceof Error ? error.message : String(error)}`);
|
|
319
|
+
}
|
|
76
320
|
verifyChecksum(contents, release.sha256, key);
|
|
321
|
+
if (contents.length === 0 || (release.size !== undefined && contents.length !== release.size)) {
|
|
322
|
+
throw new Error(`Prebuilt release size verification failed for '${key}': received ${contents.length} bytes.`);
|
|
323
|
+
}
|
|
77
324
|
return contents;
|
|
78
325
|
}
|
|
79
326
|
|
|
327
|
+
/** Reuse only a complete install for this exact package, platform and manifest selection. */
|
|
328
|
+
function isVerifiedInstall(plan, options) {
|
|
329
|
+
try {
|
|
330
|
+
const status = JSON.parse(readFileSync(plan.statusPath, 'utf8'));
|
|
331
|
+
if (status.ok !== true || status.key !== plan.key ||
|
|
332
|
+
status.version !== plan.status.version || status.url !== plan.status.url) return false;
|
|
333
|
+
// A caller can replace a local lock without changing its path. That explicit pin must
|
|
334
|
+
// still authorize these bytes, and a missing/invalid pin must never be bypassed by cache.
|
|
335
|
+
const manifestPath = options.manifestPath ?? process.env.THREENATIVE_PREBUILT_MANIFEST;
|
|
336
|
+
const pinned = manifestPath ? readRelease(resolve(manifestPath), plan.key) : undefined;
|
|
337
|
+
if (pinned && pinned.sha256 !== status.sha256) return false;
|
|
338
|
+
const contents = readFileSync(plan.output);
|
|
339
|
+
if (contents.length === 0 || (pinned?.size !== undefined && contents.length !== pinned.size)) return false;
|
|
340
|
+
verifyChecksum(contents, status.sha256, plan.key);
|
|
341
|
+
// A cached runtime without its verified helper is not a reusable desktop install.
|
|
342
|
+
if (typeof status.toolsSha256 !== 'string') return false;
|
|
343
|
+
const pinnedTools = manifestPath ? readRelease(resolve(manifestPath), plan.toolsKey) : undefined;
|
|
344
|
+
if (pinnedTools && pinnedTools.sha256 !== status.toolsSha256) return false;
|
|
345
|
+
const tools = readFileSync(plan.toolsOutput);
|
|
346
|
+
if (tools.length === 0 || (pinnedTools?.size !== undefined && tools.length !== pinnedTools.size)) return false;
|
|
347
|
+
verifyChecksum(tools, status.toolsSha256, plan.toolsKey);
|
|
348
|
+
return true;
|
|
349
|
+
} catch {
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
80
354
|
export async function installPrebuilt(options = {}) {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
355
|
+
const plan = createInstallPlan(options);
|
|
356
|
+
try {
|
|
357
|
+
// Packaging may reuse verified bytes offline. Explicit install/retry keeps its original
|
|
358
|
+
// invalidation semantics, including removing an earlier binary on a failed retry.
|
|
359
|
+
if (options.reuse === true) {
|
|
360
|
+
platformKey(plan.platform, options.arch);
|
|
361
|
+
if (isVerifiedInstall(plan, options)) return plan.output;
|
|
362
|
+
}
|
|
363
|
+
// A failed retry must not leave an earlier binary usable or its old success marker intact.
|
|
364
|
+
beginInstall(plan, options.arch);
|
|
365
|
+
const contents = await downloadReleaseArtifact(plan.key, options);
|
|
366
|
+
const toolsContents = await downloadReleaseArtifact(plan.toolsKey, options);
|
|
367
|
+
publishInstall(plan, contents, toolsContents);
|
|
368
|
+
console.log(`Installed verified ThreeNative runtime and build tool helper for '${plan.key}'.`);
|
|
369
|
+
return plan.output;
|
|
370
|
+
} catch (error) {
|
|
371
|
+
recordInstallFailure(plan, error);
|
|
372
|
+
throw error;
|
|
373
|
+
}
|
|
90
374
|
}
|
|
91
375
|
|
|
92
376
|
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
@@ -94,9 +378,21 @@ if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1]
|
|
|
94
378
|
if (sourceCheckout) {
|
|
95
379
|
console.log('ThreeNative runtime source checkout detected; prebuilt install is deferred to package testing.');
|
|
96
380
|
} else {
|
|
97
|
-
installPrebuilt()
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
381
|
+
installPrebuilt()
|
|
382
|
+
.catch((error) => {
|
|
383
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
384
|
+
// An unpublished release is a packaging-state fact, not a broken download. The web game
|
|
385
|
+
// this install carries must not lose node_modules/.bin over an optional native binary;
|
|
386
|
+
// the native lanes fail closed later, on the missing binary itself.
|
|
387
|
+
if (error instanceof Error &&
|
|
388
|
+
['PREBUILT_RELEASE_MISSING', 'PREBUILT_RELEASE_UNPUBLISHED'].includes(error.code)) {
|
|
389
|
+
console.warn(
|
|
390
|
+
`No prebuilt release is published for v${packageVersion} (${reason}). Continuing without the native runtime; desktop and device lanes fail closed on the missing binary.`,
|
|
391
|
+
);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
console.error(reason);
|
|
395
|
+
process.exitCode = 1;
|
|
396
|
+
});
|
|
101
397
|
}
|
|
102
398
|
}
|