@threenative/runtime-native 0.2.0 → 0.3.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.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { createServer } from 'node:http';
4
- import { execFile, spawn } from 'node:child_process';
4
+ import { execFile, execFileSync, spawn } from 'node:child_process';
5
5
  import { existsSync } from 'node:fs';
6
6
  import { mkdir, mkdtemp, readFile, readdir, rename, rm, stat, writeFile } from 'node:fs/promises';
7
7
  import { createRequire } from 'node:module';
@@ -11,6 +11,7 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
11
11
  import { promisify } from 'node:util';
12
12
  import { PNG } from 'pngjs';
13
13
  import { readAndroidConfig } from './package-android.mjs';
14
+ import { suppressPlayProtectOnAdbInstalls } from './device-preflight.mjs';
14
15
 
15
16
  import {
16
17
  PRODUCTION_EVIDENCE_VERSION,
@@ -243,13 +244,16 @@ async function scaffoldPlatformer(project, tools) {
243
244
  const packageSource = async (name, directory) => [name, await packLocalPackage(directory, packageArchiveRoot)];
244
245
  const localSources = [];
245
246
  if (inRepositoryCheckout) {
246
- localSources.push(await packageSource('@threenative/core', join(repositoryRoot, 'packages/core')));
247
- localSources.push(await packageSource('@threenative/physics', join(repositoryRoot, 'packages/physics')));
248
- localSources.push(await packageSource('@threenative/playtest', join(repositoryRoot, 'packages/playtest')));
249
- localSources.push(await packageSource('@threenative/runtime-native', join(repositoryRoot, 'packages/runtime-native')));
250
- localSources.push(await packageSource('@threenative/ui', join(repositoryRoot, 'packages/ui')));
251
- localSources.push(await packageSource('@threenative/studio', join(repositoryRoot, 'packages/studio')));
252
- localSources.push(await packageSource('create-threenative', join(repositoryRoot, 'packages/create-threenative')));
247
+ for (const workspacePackage of localWorkspacePackages()) {
248
+ localSources.push(
249
+ await packageSource(workspacePackage.name, join(repositoryRoot, workspacePackage.directory)),
250
+ );
251
+ }
252
+ const studioDirectory = join(repositoryRoot, 'packages/studio');
253
+ if (existsSync(join(studioDirectory, 'package.json'))) {
254
+ // Studio is a private cross-checkout extra, not a workspace package in this repository.
255
+ localSources.push(await packageSource('@threenative/studio', studioDirectory));
256
+ }
253
257
  }
254
258
  const args = [
255
259
  tools.scaffoldCli,
@@ -263,6 +267,17 @@ async function scaffoldPlatformer(project, tools) {
263
267
  }
264
268
  }
265
269
 
270
+ function localWorkspacePackages() {
271
+ const output = execFileSync(
272
+ 'pnpm',
273
+ ['exec', 'tsx', join(repositoryRoot, 'scripts/workspace-packages.ts'), '--json'],
274
+ { cwd: repositoryRoot, encoding: 'utf8' },
275
+ );
276
+ const packages = JSON.parse(output);
277
+ if (!Array.isArray(packages)) throw new Error('TN_WORKSPACE_PACKAGE_DERIVATION_INVALID: expected an array.');
278
+ return packages.filter((item) => item && typeof item.name === 'string' && typeof item.directory === 'string');
279
+ }
280
+
266
281
  async function packLocalPackage(directory, destination) {
267
282
  const before = new Set(await readdir(destination));
268
283
  const result = await runCommand('pnpm', ['pack', '--pack-destination', destination], directory);
@@ -273,19 +288,13 @@ async function packLocalPackage(directory, destination) {
273
288
  }
274
289
 
275
290
  function packageSourceFlag(name) {
276
- return name === '@threenative/core'
277
- ? '--core-package'
278
- : name === '@threenative/physics'
279
- ? '--physics-package'
280
- : name === '@threenative/playtest'
281
- ? '--playtest-package'
282
- : name === '@threenative/runtime-native'
283
- ? '--runtime-native-package'
284
- : name === '@threenative/ui'
285
- ? '--ui-package'
286
- : name === '@threenative/studio'
287
- ? '--studio-package'
288
- : '--cli-package';
291
+ if (name === 'create-threenative') return '--cli-package';
292
+ if (name === 'threenative-engine-mcp') return '--engine-mcp-package';
293
+ if (name.startsWith('@threenative/')) {
294
+ const suffix = name.slice('@threenative/'.length);
295
+ return `--threenative-${suffix}-package`;
296
+ }
297
+ throw new Error(`TN_PROD_PACKAGE_FLAG_UNSUPPORTED: ${name}`);
289
298
  }
290
299
 
291
300
  export async function writeRunScenarios(project, options) {
@@ -928,7 +937,6 @@ function parsePlaytestReport(stdout) {
928
937
  try {
929
938
  return JSON.parse(line);
930
939
  } catch {
931
- continue;
932
940
  }
933
941
  }
934
942
  }
@@ -959,7 +967,6 @@ function frameSeriesFromReport(report) {
959
967
  const batch = JSON.parse(line.slice(offset + prefix.length));
960
968
  if (Array.isArray(batch)) series.push(...batch);
961
969
  } catch {
962
- continue;
963
970
  }
964
971
  }
965
972
  return series.length === 0 ? undefined : series;
@@ -1380,6 +1387,12 @@ async function playtestRunnerPath(project, tools) {
1380
1387
  }
1381
1388
 
1382
1389
  async function installAndroidArtifact(apk, device) {
1390
+ // The Play Protect verifier dialog is modal and swallows the install, so an unattended
1391
+ // lane behind it proves nothing. Suppress before the install, as every install lane must.
1392
+ const serial = device ?? String(execFileSync('adb', ['get-serialno'], { encoding: 'utf8' })).trim();
1393
+ suppressPlayProtectOnAdbInstalls(serial, {
1394
+ adb: (adbArgs) => String(execFileSync('adb', ['-s', serial, ...adbArgs], { encoding: 'utf8' })),
1395
+ });
1383
1396
  const args = [...(device === undefined ? [] : ['-s', device]), 'install', '-r', apk];
1384
1397
  const result = await runCommand('adb', args, commandRoot);
1385
1398
  if (result.status !== 0) throw new ProductionEvidenceError('TN_PROD_ANDROID_INSTALL_FAILED', 'Installing the scaffolded Android platformer failed.');
@@ -1512,6 +1525,21 @@ function positiveInteger(value, flag) {
1512
1525
  }
1513
1526
 
1514
1527
  if (process.argv[1] && new URL(`file://${process.argv[1]}`).pathname === new URL(import.meta.url).pathname) {
1528
+ // Gate records are an engine-repository artefact, not something a published install owns. A
1529
+ // package-relative specifier here would ship inside the tarball and die ERR_MODULE_NOT_FOUND on
1530
+ // an installed copy, so the path is resolved against the checkout and its absence is named.
1531
+ const gateRecords = resolve(scriptDirectory, '../../../scripts/gate-records.mjs');
1532
+ if (!existsSync(gateRecords)) {
1533
+ throw new ProductionEvidenceError(
1534
+ 'TN_PROD_GATE_RECORDS_MISSING',
1535
+ `pnpm profile:production records its gate phases through ${gateRecords}, which does not exist. This command runs from a ThreeNative engine checkout, not from an installed @threenative/runtime-native.`,
1536
+ );
1537
+ }
1538
+ const { createGateRecorder } = await import(pathToFileURL(gateRecords).href);
1539
+ const gateRecorder = await createGateRecorder({
1540
+ phase: 'profile-production',
1541
+ command: ['pnpm profile:production', ...process.argv.slice(2)].join(' '),
1542
+ });
1515
1543
  try {
1516
1544
  const result = await runProductionProfile(parseProductionArgs());
1517
1545
  process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
@@ -1521,5 +1549,8 @@ if (process.argv[1] && new URL(`file://${process.argv[1]}`).pathname === new URL
1521
1549
  const message = error instanceof Error ? error.message : String(error);
1522
1550
  process.stderr.write(`${JSON.stringify({ codes: [code], message, status: 'BLOCKED', exitCode: 2 }, null, 2)}\n`);
1523
1551
  process.exitCode = 2;
1552
+ } finally {
1553
+ // main() communicates its own result through process.exitCode; record what actually ran.
1554
+ await gateRecorder.finish(process.exitCode ?? 0);
1524
1555
  }
1525
1556
  }