@threenative/runtime-native 0.3.2 → 0.3.4
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 +236 -1
- package/android/app/build.gradle.kts +37 -2
- package/android/app/src/main/java/com/mystral/engine/MystralActivity.java +97 -1
- package/android/app/src/main/java/com/mystral/engine/TnUiOverlay.java +170 -8
- package/android/build.gradle.kts +1 -1
- package/android/gradle/wrapper/gradle-wrapper.properties +2 -2
- package/package.json +17 -4
- package/scripts/asset-manifest.mjs +209 -0
- package/scripts/asset-preflight.mjs +137 -6
- package/scripts/bundle.mjs +25 -5
- package/scripts/check-android-16kb-alignment.mjs +413 -0
- package/scripts/desktop-distribution.mjs +1084 -0
- package/scripts/inspect-container-brand.mjs +748 -0
- package/scripts/inspect-macos-icon.mjs +169 -0
- package/scripts/install-prebuilt.mjs +6 -3
- package/scripts/package-android.mjs +478 -32
- package/scripts/package-desktop.mjs +191 -15
- package/scripts/package-ios.mjs +83 -41
- package/scripts/physical-device-evidence.mjs +135 -1
- package/scripts/production-evidence.mjs +43 -12
- package/scripts/profile-production.mjs +735 -159
- package/scripts/qualify-physical-mobile.mjs +286 -69
- package/scripts/verify-starter-consumer.mjs +782 -0
- package/scripts/verify-starter-desktop-base.mjs +458 -0
- package/scripts/verify-starter-desktop.mjs +27 -220
- package/scripts/verify-windows-installer.mjs +63 -0
- package/scripts/windows-installer.mjs +181 -0
- package/scripts/windows-installer.nsi +114 -0
- package/scripts/xvfb.sh +48 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import {
|
|
4
|
+
lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync,
|
|
5
|
+
} from 'node:fs';
|
|
6
|
+
import { tmpdir } from 'node:os';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { PNG } from 'pngjs';
|
|
9
|
+
|
|
10
|
+
const INVALID = 'TN_NATIVE_STARTER_CONTAINER_MACOS_ICON_INVALID';
|
|
11
|
+
const MISMATCH = 'TN_NATIVE_STARTER_CONTAINER_ICON_MISMATCH';
|
|
12
|
+
const PNG_SIGNATURE = Buffer.from('89504e470d0a1a0a', 'hex');
|
|
13
|
+
const GENERATED_NAMES = [16, 32, 128, 256, 512].flatMap((size) => [
|
|
14
|
+
`icon_${size}x${size}.png`, `icon_${size}x${size}@2x.png`,
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
function assertIcns(bytes) {
|
|
18
|
+
if (bytes.length < 16 || bytes.toString('ascii', 0, 4) !== 'icns' ||
|
|
19
|
+
bytes.readUInt32BE(4) !== bytes.length) {
|
|
20
|
+
throw new Error(`${INVALID}: the packaged icon is not a complete, nonempty ICNS file.`);
|
|
21
|
+
}
|
|
22
|
+
for (let offset = 8; offset < bytes.length;) {
|
|
23
|
+
if (offset + 8 > bytes.length) throw new Error(`${INVALID}: truncated ICNS element.`);
|
|
24
|
+
const size = bytes.readUInt32BE(offset + 4);
|
|
25
|
+
if (size <= 8 || size > bytes.length - offset) {
|
|
26
|
+
throw new Error(`${INVALID}: invalid ICNS element length.`);
|
|
27
|
+
}
|
|
28
|
+
offset += size;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function iconTool(run, command, args) {
|
|
33
|
+
const result = run(command, args, { encoding: 'utf8', timeout: 30_000, maxBuffer: 1024 * 1024 });
|
|
34
|
+
if (result.error || result.status !== 0) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`${INVALID}: ${command} could not inspect the icon (${result.error?.message ?? result.status ?? 'no exit status'}). Run the brand verifier on macOS with iconutil and sips available; metadata alone is not icon proof.`,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function pngImage(path, pixels) {
|
|
42
|
+
const bytes = readFileSync(path);
|
|
43
|
+
// Bound the decoder by the representation's dimensions, not by untrusted IHDR allocation sizes.
|
|
44
|
+
if (bytes.length < 33 || bytes.length > 32 * 1024 * 1024 ||
|
|
45
|
+
!bytes.subarray(0, 8).equals(PNG_SIGNATURE) || bytes.readUInt32BE(8) !== 13 ||
|
|
46
|
+
bytes.toString('ascii', 12, 16) !== 'IHDR' ||
|
|
47
|
+
bytes.readUInt32BE(16) !== pixels || bytes.readUInt32BE(20) !== pixels) {
|
|
48
|
+
throw new Error(`${INVALID}: ${path} is not a ${pixels}x${pixels} PNG representation.`);
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
return PNG.sync.read(bytes);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
throw new Error(`${INVALID}: cannot decode ${path}: ${error.message}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Compare decoded RGBA, never PNG encoding, ancillary metadata, or a source-hash assertion. */
|
|
58
|
+
export function assertIconPixels(actual, expected, name) {
|
|
59
|
+
for (const image of [actual, expected]) {
|
|
60
|
+
if (!image || !Number.isInteger(image.width) || !Number.isInteger(image.height) ||
|
|
61
|
+
image.width < 1 || image.width > 1024 || image.height < 1 || image.height > 1024 ||
|
|
62
|
+
!Buffer.isBuffer(image.data) || image.data.length !== image.width * image.height * 4) {
|
|
63
|
+
throw new Error(`${INVALID}: ${name} has no complete decoded RGBA image.`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (actual.width !== expected.width || actual.height !== expected.height) {
|
|
67
|
+
throw new Error(`${MISMATCH}: decoded macOS icon ${name} dimensions differ from app.icon.`);
|
|
68
|
+
}
|
|
69
|
+
// Converters may discard hidden RGB beneath zero alpha. Canonicalize only invisible pixels;
|
|
70
|
+
// every visible channel, including partial transparency, must still match exactly.
|
|
71
|
+
const canonical = Buffer.from(actual.data);
|
|
72
|
+
for (let offset = 0; offset < canonical.length; offset += 4) {
|
|
73
|
+
const alpha = actual.data[offset + 3];
|
|
74
|
+
if (alpha !== expected.data[offset + 3] || (alpha !== 0 &&
|
|
75
|
+
!actual.data.subarray(offset, offset + 3).equals(expected.data.subarray(offset, offset + 3)))) {
|
|
76
|
+
throw new Error(`${MISMATCH}: decoded macOS icon ${name} differs from app.icon.`);
|
|
77
|
+
}
|
|
78
|
+
if (alpha === 0) canonical.fill(0, offset, offset + 3);
|
|
79
|
+
}
|
|
80
|
+
return createHash('sha256').update(canonical).digest('hex');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Compare at the same conversion boundary. iconutil can normalize even visible colour values
|
|
84
|
+
// while encoding/decoding ICNS. Resized source PNG pixels alone are therefore not its output.
|
|
85
|
+
// Build the reference independently from app.icon with the packager's existing recipe, then
|
|
86
|
+
// decode both ICNS files. Exact visible RGBA comparison remains unchanged; no tolerance is added.
|
|
87
|
+
function referenceIconset(source, scratch, run) {
|
|
88
|
+
const inputs = join(scratch, 'reference.iconset');
|
|
89
|
+
mkdirSync(inputs);
|
|
90
|
+
for (const name of GENERATED_NAMES) {
|
|
91
|
+
const match = /^icon_(\d+)x\1(@2x)?\.png$/u.exec(name);
|
|
92
|
+
const pixels = String(Number(match[1]) * (match[2] ? 2 : 1));
|
|
93
|
+
const target = join(inputs, name);
|
|
94
|
+
iconTool(run, 'sips', ['-z', pixels, pixels, source, '--out', target]);
|
|
95
|
+
pngImage(target, Number(pixels));
|
|
96
|
+
}
|
|
97
|
+
const reference = join(scratch, 'reference.icns');
|
|
98
|
+
iconTool(run, 'iconutil', ['-c', 'icns', inputs, '-o', reference]);
|
|
99
|
+
assertIcns(readFileSync(reference));
|
|
100
|
+
const decoded = join(scratch, 'reference-decoded.iconset');
|
|
101
|
+
iconTool(run, 'iconutil', ['-c', 'iconset', '-o', decoded, reference]);
|
|
102
|
+
if (!lstatSync(decoded).isDirectory() || lstatSync(decoded).isSymbolicLink()) {
|
|
103
|
+
throw new Error(`${INVALID}: iconutil did not produce a reference iconset directory.`);
|
|
104
|
+
}
|
|
105
|
+
return decoded;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Read back every iconutil representation of the final .icns. The packager's PNG -> sips ->
|
|
110
|
+
* iconutil round trip is independently repeated for the authored source, then compared at decoded
|
|
111
|
+
* RGBA. Compression/metadata differences cannot pass for artwork or reject identical artwork. Authored .icns inputs must remain byte-identical and still
|
|
112
|
+
* decode successfully. This proves artifact content, not Finder/Dock appearance or a GUI launch.
|
|
113
|
+
* `run` is the same command-boundary seam used by desktop-distribution.mjs; production uses the OS.
|
|
114
|
+
*/
|
|
115
|
+
export function inspectMacosIcon(icon, source, { run = spawnSync } = {}) {
|
|
116
|
+
const bytes = readFileSync(icon);
|
|
117
|
+
assertIcns(bytes);
|
|
118
|
+
const authoredIcns = source.endsWith('.icns'); // Match buildIcon's existing copy-vs-convert rule.
|
|
119
|
+
if (authoredIcns && !bytes.equals(readFileSync(source))) {
|
|
120
|
+
throw new Error(`${MISMATCH}: the packaged ICNS differs from the authored ICNS.`);
|
|
121
|
+
}
|
|
122
|
+
const scratch = mkdtempSync(join(tmpdir(), 'threenative-icon-inspection-'));
|
|
123
|
+
try {
|
|
124
|
+
const decoded = join(scratch, 'actual.iconset');
|
|
125
|
+
iconTool(run, 'iconutil', ['-c', 'iconset', '-o', decoded, icon]);
|
|
126
|
+
if (!lstatSync(decoded).isDirectory() || lstatSync(decoded).isSymbolicLink()) {
|
|
127
|
+
throw new Error(`${INVALID}: iconutil did not produce an iconset directory.`);
|
|
128
|
+
}
|
|
129
|
+
const entries = readdirSync(decoded, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
130
|
+
if (entries.length === 0 || entries.length > 32) {
|
|
131
|
+
throw new Error(`${INVALID}: iconutil produced no bounded set of icon representations.`);
|
|
132
|
+
}
|
|
133
|
+
if (!authoredIcns && GENERATED_NAMES.some((name) => !entries.some((entry) => entry.name === name))) {
|
|
134
|
+
throw new Error(`${INVALID}: the converted icon is missing a size or scale generated by the packager.`);
|
|
135
|
+
}
|
|
136
|
+
const references = authoredIcns ? undefined : referenceIconset(source, scratch, run);
|
|
137
|
+
const representations = [];
|
|
138
|
+
for (const entry of entries) {
|
|
139
|
+
const match = /^icon_(\d+)x\1(@2x)?\.png$/u.exec(entry.name);
|
|
140
|
+
const pixels = match ? Number(match[1]) * (match[2] ? 2 : 1) : 0;
|
|
141
|
+
if (!entry.isFile() || !match || pixels < 1 || pixels > 1024) {
|
|
142
|
+
throw new Error(`${INVALID}: unexpected iconutil output ${entry.name}.`);
|
|
143
|
+
}
|
|
144
|
+
const actual = pngImage(join(decoded, entry.name), pixels);
|
|
145
|
+
let expected = actual;
|
|
146
|
+
if (references !== undefined) {
|
|
147
|
+
const reference = join(references, entry.name);
|
|
148
|
+
const info = lstatSync(reference);
|
|
149
|
+
if (!info.isFile() || info.isSymbolicLink()) {
|
|
150
|
+
throw new Error(`${INVALID}: unexpected reference output ${entry.name}.`);
|
|
151
|
+
}
|
|
152
|
+
expected = pngImage(reference, pixels);
|
|
153
|
+
}
|
|
154
|
+
representations.push({
|
|
155
|
+
name: entry.name,
|
|
156
|
+
width: actual.width,
|
|
157
|
+
height: actual.height,
|
|
158
|
+
rgbaSha256: assertIconPixels(actual, expected, entry.name),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return { method: 'iconutil-decoded-rgba', representations };
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (error.message?.startsWith('TN_')) throw error;
|
|
164
|
+
throw new Error(`${INVALID}: could not read iconutil output: ${error.message}`);
|
|
165
|
+
} finally {
|
|
166
|
+
// Never modify the signed app or put scratch resources inside the distributed container.
|
|
167
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { createHash, randomUUID } from 'node:crypto';
|
|
4
|
-
import { chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
5
|
import { dirname, join, resolve } from 'node:path';
|
|
6
|
-
import { fileURLToPath
|
|
6
|
+
import { fileURLToPath } 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;
|
|
@@ -419,7 +419,10 @@ export async function installPrebuilt(options = {}) {
|
|
|
419
419
|
}
|
|
420
420
|
}
|
|
421
421
|
|
|
422
|
-
|
|
422
|
+
// Real paths on both sides: pnpm runs this hook through a symlinked `node_modules` path, and a
|
|
423
|
+
// plain comparison with the module's real URL silently skipped the install.
|
|
424
|
+
if (process.argv[1] && existsSync(process.argv[1]) &&
|
|
425
|
+
realpathSync(fileURLToPath(import.meta.url)) === realpathSync(process.argv[1])) {
|
|
423
426
|
const sourceCheckout = existsSync(join(packageRoot, 'src')) && existsSync(join(packageRoot, 'CMakeLists.txt'));
|
|
424
427
|
if (sourceCheckout) {
|
|
425
428
|
console.log('ThreeNative runtime source checkout detected; prebuilt install is deferred to package testing.');
|