@threenative/runtime-native 0.3.8 → 0.3.10

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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threenative/runtime-native",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "ThreeNative-owned native host for desktop and Android",
5
5
  "keywords": [
6
6
  "threenative",
@@ -76,19 +76,19 @@
76
76
  ],
77
77
  "devDependencies": {
78
78
  "@dimforge/rapier3d-compat": "0.19.3",
79
- "@types/three": "0.185.3",
79
+ "@types/three": "0.187.0",
80
80
  "publint": "0.3.22",
81
- "three": "0.185.1",
81
+ "three": "0.187.0",
82
82
  "vitest": "4.1.10",
83
- "@threenative/playtest": "0.3.8"
83
+ "@threenative/playtest": "0.3.10"
84
84
  },
85
85
  "dependencies": {
86
86
  "pngjs": "7.0.0",
87
87
  "esbuild": "0.27.0",
88
88
  "typescript": "npm:@typescript/typescript6@6.0.2",
89
- "@threenative/assets": "0.3.9",
90
- "@threenative/three-native": "0.3.8",
91
- "@threenative/core": "0.3.8"
89
+ "@threenative/core": "0.3.10",
90
+ "@threenative/assets": "0.3.11",
91
+ "@threenative/three-native": "0.3.10"
92
92
  },
93
93
  "scripts": {
94
94
  "deps:download": "node scripts/download-deps.mjs",
@@ -151,9 +151,18 @@ export async function bundleNativeEngine({ entry, outfile, boot = true, define =
151
151
  const declaration = coreIndex.statements.find((node) => ts.isExportDeclaration(node) &&
152
152
  !node.isTypeOnly && node.exportClause && ts.isNamedExports(node.exportClause) &&
153
153
  node.exportClause.elements.some((item) => !item.isTypeOnly && item.name.text === name));
154
- if (!declaration?.moduleSpecifier)
154
+ // A value core declares in the barrel itself (`export const version`) re-exports from no
155
+ // module, so reading it as unbound refused every game that names the engine version it runs.
156
+ const local = declaration === undefined && coreIndex.statements.some((node) => {
157
+ const exported = node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) === true;
158
+ if (!exported) return false;
159
+ if (ts.isVariableStatement(node))
160
+ return node.declarationList.declarations.some((item) => ts.isIdentifier(item.name) && item.name.text === name);
161
+ return (ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)) && node.name?.text === name;
162
+ });
163
+ if (!local && !declaration?.moduleSpecifier)
155
164
  throw new Error(`TN_NATIVE_ENGINE_UNBOUND: @threenative/core:${name}`);
156
- const source = JSON.stringify(resolve(core, "src", declaration.moduleSpecifier.text));
165
+ const source = JSON.stringify(resolve(core, "src", local ? "index.ts" : declaration.moduleSpecifier.text));
157
166
  if (name === "defineGame") return `import { defineGame as coreDefineGame } from ${source};
158
167
  import { platform } from ${JSON.stringify(resolve(player, "core-host.mjs"))};
159
168
  export function defineGame(options) { return coreDefineGame({ ...options, platform: options.platform ?? platform }); }`;
@@ -125,6 +125,32 @@ export function androidSigningGradleEnvironment(signing, environment = process.e
125
125
  };
126
126
  }
127
127
 
128
+ // Gradle 8.13, the wrapper this project pins, runs on JDK 23 or earlier. On a newer one it stops with
129
+ // the bare version string as its only message ("27.0.1.0.3" on JDK 27).
130
+ const ANDROID_GRADLE_NEWEST_JDK = 23;
131
+
132
+ /**
133
+ * The environment Gradle needs, decided where the tools can be measured: the SDK at the default path
134
+ * that `doctor` and `findAndroidBuildTool` already read, and a JDK Gradle can run on.
135
+ */
136
+ export function androidGradleEnvironment(environment = process.env, { home = homedir() } = {}) {
137
+ if (environment.ANDROID_HOME || environment.ANDROID_SDK_ROOT) return environment;
138
+ const sdk = join(home, 'Android', 'Sdk');
139
+ return existsSync(sdk) ? { ...environment, ANDROID_HOME: sdk } : environment;
140
+ }
141
+
142
+ /** Gradle on a JDK it cannot read prints only the version string, so a failure names the JDK itself. */
143
+ export function androidGradleFailure(status, environment = process.env, spawn = spawnSync) {
144
+ const java = environment.JAVA_HOME ? join(environment.JAVA_HOME, 'bin', 'java') : 'java';
145
+ const probe = spawn(java, ['-version'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], timeout: 5_000 });
146
+ const major = /version "(\d+)/u.exec(`${probe?.stdout ?? ''}${probe?.stderr ?? ''}`)?.[1];
147
+ const jdk =
148
+ major !== undefined && Number(major) > ANDROID_GRADLE_NEWEST_JDK
149
+ ? ` TN_ANDROID_JDK_UNSUPPORTED: ${java} is JDK ${major}, and Android builds run on JDK ${ANDROID_GRADLE_NEWEST_JDK} or earlier. Install JDK 17 and set JAVA_HOME to it.`
150
+ : '';
151
+ return `Gradle exited with code ${status ?? 'unknown'}.${jdk}`;
152
+ }
153
+
128
154
  /** Locate an Android build tool on `PATH`, then in the SDK's `build-tools/<version>/`. */
129
155
  export function findAndroidBuildTool(name, environment = process.env) {
130
156
  const suffix = process.platform === 'win32' ? '.bat' : '';
@@ -1152,19 +1178,17 @@ export async function packageAndroid(
1152
1178
  ];
1153
1179
  const args = process.platform === 'win32' ? baseArgs : [gradlew, ...baseArgs];
1154
1180
  const spawn = options.spawnSync ?? spawnSync;
1181
+ const gradleEnvironment = androidGradleEnvironment(environment);
1155
1182
  const result = spawn(command, args, {
1156
1183
  cwd: androidRoot,
1157
1184
  encoding: 'utf8',
1158
1185
  // The signing values reach Gradle only as project properties from the game's environment; the
1159
1186
  // keystore path was resolved against the consumer project above. Nothing here logs them.
1160
- ...(signing === undefined
1161
- ? {}
1162
- : { env: androidSigningGradleEnvironment(signing, environment) }),
1187
+ env: signing === undefined ? gradleEnvironment : androidSigningGradleEnvironment(signing, gradleEnvironment),
1163
1188
  stdio: 'inherit',
1164
1189
  });
1165
1190
  if (result.error) throw result.error;
1166
- if (result.status !== 0)
1167
- throw new Error(`Gradle exited with code ${result.status ?? 'unknown'}.`);
1191
+ if (result.status !== 0) throw new Error(androidGradleFailure(result.status, gradleEnvironment, spawn));
1168
1192
  const candidates = androidArtifactCandidates(packageRoot, request);
1169
1193
  const artifact = candidates.find((candidate) => existsSync(candidate));
1170
1194
  if (artifact === undefined) {
@@ -317,10 +317,16 @@ function verifyOwnedDesktop({ frames, project, artifact, artifactDirectory, logP
317
317
  steps: [{ kind: 'wait', waitTicks: 1, label: 'native-smoke' }],
318
318
  assert: { diagnostics: { runtimeReady: true, noConsoleErrors: true, noRuntimeDiagnostics: true } },
319
319
  artifacts: { screenshots: 'after' } }));
320
- const result = run(process.execPath, [cli, scenario, '--target', 'desktop', '--project', project,
321
- '--artifacts', captures, '--executable', artifact, '--host-arg', '--windowed'], {
320
+ const runner = [cli, scenario, '--target', 'desktop', '--project', project,
321
+ '--artifacts', captures, '--executable', artifact, '--host-arg', '--windowed'];
322
+ // The completion window admits only a VSYNC=0 player and, on Linux, a named display. The private
323
+ // Xvfb is that display unless the caller opted into the session's with TN_PLAYTEST_HOST_DISPLAY.
324
+ const linux = process.platform === 'linux';
325
+ const result = run(linux ? 'sh' : process.execPath, linux
326
+ ? [join(dirname(fileURLToPath(import.meta.url)), 'xvfb.sh'), 'env', 'TN_PLAYTEST_HOST_DISPLAY=1', process.execPath, ...runner]
327
+ : runner, {
322
328
  cwd: project, encoding: 'utf8', timeout, maxBuffer: 32 * 1024 * 1024,
323
- env: { ...env, TN_PLAYTEST_COMPLETION_WINDOW_LABEL: 'native-smoke',
329
+ env: { ...env, TN_PLAYER_VSYNC: '0', TN_PLAYTEST_COMPLETION_WINDOW_LABEL: 'native-smoke',
324
330
  TN_PLAYTEST_COMPLETION_WINDOW_MIN_FRAMES: String(frames),
325
331
  TN_PLAYTEST_COMPLETION_WINDOW_TIMEOUT_MS: String(Math.max(1, timeout - 10_000)) },
326
332
  });
@@ -224,13 +224,14 @@ defineRenderTargets(WebGPURenderer.prototype, (renderer) => ({
224
224
  // three's QuadMesh over the engine Mesh (shared with the Wasm back end).
225
225
  export const QuadMesh = defineQuadMesh(globalThis);
226
226
 
227
- // three's TempNode (shared with the Wasm back end): the V8 TSL adapter reads a game node's engine node
227
+ // three's node base (shared with the Wasm back end): the V8 TSL adapter reads a game node's engine node
228
228
  // under `threenative.tslNode`, and each top-level render runs the FRAME nodes' updateBefore first. An
229
- // engine node carries its methods itself; the adapter calls them on the receiver's engine node.
229
+ // engine node carries its methods itself; the adapter calls them on the receiver's engine node. `Node` is
230
+ // r187's name for it and `TempNode` the deprecated alias (r187 src/nodes/core/TempNode.js:39).
230
231
  const tslNode = Symbol.for("threenative.tslNode");
231
232
  const nodeMethods = Object.defineProperties({}, Object.getOwnPropertyDescriptors(globalThis.tsl.float(0)));
232
233
  const tempNodes = defineTempNode(nodeMethods, tslNode, (output) => (tslNode in output ? output[tslNode] : output));
233
- export const { TempNode } = tempNodes;
234
+ export const { Node, TempNode } = tempNodes;
234
235
  // The game's startup render() runs before the player opens its renderer and draws no frame, so its nodes
235
236
  // update on the first render() of a drawn frame.
236
237
  let tempFrame = 0;