simcast-host 0.9.0 → 0.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simcast-host",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "The Mac side of simcast: host this Mac's iOS Simulator for Windows, Linux and Mac clients.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -227,10 +227,16 @@ export const CHECKS = [
227
227
  level: 'fail',
228
228
  async check() {
229
229
  const apps = await findXcodeApps();
230
- if (!apps.length) return { ok: false, detail: 'Xcode is not installed.', data: { apps } };
230
+ // The Xcode builds use: xcode-select -p without /Contents/Developer.
231
+ // Without one (or only the Command Line Tools), the newest found.
232
+ const app = /^(.+\.app)\/Contents\/Developer\/?$/.exec((await developerDir()) || '')?.[1];
233
+ const selected = app ? { app, version: xcodeAppVersion(app) } : null;
234
+ if (!apps.length && !selected) return { ok: false, detail: 'Xcode is not installed.', data: { apps } };
231
235
  const newest = apps[0];
232
- const more = apps.length > 1 ? ` (and ${plural(apps.length - 1, 'other')})` : '';
233
- return { ok: true, detail: `${newest.app}${newest.version ? `, version ${newest.version}` : ''}${more}`, data: { apps, newest } };
236
+ const shown = selected || newest;
237
+ const others = apps.filter((a) => a.app !== shown.app).length;
238
+ const more = others ? ` (and ${plural(others, 'other')})` : '';
239
+ return { ok: true, detail: `${shown.app}${shown.version ? `, version ${shown.version}` : ''}${more}`, data: { apps, newest } };
234
240
  },
235
241
  manual: 'Install Xcode from the App Store (or developer.apple.com/xcode), then run simcast-host setup again.',
236
242
  },
@@ -41,20 +41,34 @@ export async function computerName() {
41
41
  return (await probe('scutil', ['--get', 'ComputerName'])) || os.hostname().replace(/\.local$/i, '');
42
42
  }
43
43
 
44
+ // A hardware address we can't wake with: missing, all zeros, or locally
45
+ // administered (bit 0x02 of the first octet), such as the 02:00:00:00:00:00
46
+ // macOS 27 reports to Node for every interface (privacy masking).
47
+ const unusableMac = (mac) => !mac || /^(00:){5}00$/.test(mac) || (parseInt(mac.slice(0, 2), 16) & 0x02) !== 0;
48
+
49
+ // The address in `networksetup -getmacaddress <interface>` output
50
+ // ("Ethernet Address: aa:bb:… (Device: en0)"), else null.
51
+ export function parseMacAddress(output) {
52
+ return /Ethernet Address:\s*([0-9a-f]{2}(?::[0-9a-f]{2}){5})/i.exec(output || '')?.[1].toLowerCase() || null;
53
+ }
54
+
44
55
  // Wake-on-LAN details of the interface a request came in on: the interface in
45
56
  // os.networkInterfaces() whose IPv4 address equals `localAddress`
46
57
  // (req.socket.localAddress; an IPv4-mapped "::ffff:" prefix is removed):
47
58
  // { mac, interface, address, netmask }, else null (an IPv6 or loopback address,
48
- // no such interface, or one without a hardware address).
49
- export function wakeInfo(localAddress, interfaces = os.networkInterfaces()) {
59
+ // no such interface, or no usable hardware address). When Node's MAC is masked,
60
+ // the real one comes from networksetup (ifconfig run by Node is masked too).
61
+ export async function wakeInfo(localAddress, interfaces = os.networkInterfaces(), macOf = (name) => probe('networksetup', ['-getmacaddress', name])) {
50
62
  const address = String(localAddress || '').replace(/^::ffff:/i, '');
51
63
  if (!/^\d{1,3}(\.\d{1,3}){3}$/.test(address)) return null;
52
64
  for (const [name, addrs] of Object.entries(interfaces || {})) {
53
65
  for (const a of addrs || []) {
54
66
  const v4 = a.family === 'IPv4' || a.family === 4;
55
67
  if (!v4 || a.internal || a.address !== address) continue;
56
- if (!a.mac || /^(00:){5}00$/.test(a.mac)) return null;
57
- return { mac: a.mac.toLowerCase(), interface: name, address, netmask: a.netmask || null };
68
+ let mac = a.mac?.toLowerCase();
69
+ if (unusableMac(mac)) mac = parseMacAddress(await macOf(name));
70
+ if (unusableMac(mac)) return null;
71
+ return { mac, interface: name, address, netmask: a.netmask || null };
58
72
  }
59
73
  }
60
74
  return null;
@@ -1,6 +1,5 @@
1
1
  // Expo (dev builds with expo-dev-client). The reference recipe.
2
2
  import fs from 'node:fs';
3
- import { createRequire } from 'node:module';
4
3
  import path from 'node:path';
5
4
  import { LOCKFILES } from '../../common.js';
6
5
  import * as tunnelModule from '../tunnel.js';
@@ -15,18 +14,27 @@ export function detect(src) {
15
14
 
16
15
  export const deps = kit.installJsDeps;
17
16
 
17
+ // Runs in a fresh `node` so nothing is cached between runs: in the agent's own
18
+ // process, Node's module cache and expo-modules-autolinking's memo kept the old
19
+ // hash after a native module was added. argv: src, options as JSON.
20
+ const FINGERPRINT_SCRIPT = `
21
+ const path = require('node:path');
22
+ const [src, opts] = process.argv.slice(1);
23
+ const mod = require('node:module').createRequire(path.join(src, 'package.json'))('@expo/fingerprint');
24
+ const create = mod.createFingerprintAsync || mod.default?.createFingerprintAsync;
25
+ create(src, JSON.parse(opts)).then((r) => process.stdout.write(JSON.stringify({ hash: r?.hash })));
26
+ `;
27
+
18
28
  // Hash of everything that affects the native binary. Uses Expo's own
19
29
  // @expo/fingerprint from the project when available.
20
30
  export async function fingerprint({ src, options: { cng } }) {
31
+ const opts = { platforms: ['ios'] };
32
+ // In prebuild mode, ios/ is generated on the Mac and must not change the hash.
33
+ if (cng) opts.ignorePaths = ['ios/**', 'android/**'];
21
34
  try {
22
- const req = createRequire(path.join(src, 'package.json'));
23
- const mod = req('@expo/fingerprint');
24
- const create = mod.createFingerprintAsync || mod.default?.createFingerprintAsync;
25
- const opts = { platforms: ['ios'] };
26
- // In prebuild mode, ios/ is generated on the Mac and must not change the hash.
27
- if (cng) opts.ignorePaths = ['ios/**', 'android/**'];
28
- const result = await create(src, opts);
29
- if (result?.hash) return { hash: result.hash, source: '@expo/fingerprint' };
35
+ const res = await kit.run(process.execPath, ['-e', FINGERPRINT_SCRIPT, src, JSON.stringify(opts)], { cwd: src, capture: true });
36
+ const hash = res.code === 0 && JSON.parse(res.stdout.toString().trim().split('\n').at(-1)).hash;
37
+ if (hash) return { hash, source: '@expo/fingerprint' };
30
38
  } catch {
31
39
  // fall through to the simple fingerprint
32
40
  }
@@ -113,7 +121,14 @@ export async function launch({ options: { devServerUrl }, sim, info, warn, tunne
113
121
  await sim.openUrl(udid, url);
114
122
  info(`Opened ${url}`);
115
123
  } else {
124
+ // A debug build without expo-dev-client asks React Native's default bundle
125
+ // location, localhost:8081 on the Mac; the tunnel or --direct is elsewhere.
126
+ if (!devClientScheme && devServerUrl && URL.canParse(devServerUrl)) {
127
+ const url = new URL(devServerUrl);
128
+ const hostPort = `${url.hostname}:${url.port || (url.protocol === 'https:' ? '443' : '80')}`;
129
+ await sim.setJsLocation(udid, meta.bundleId, hostPort);
130
+ info(`expo-dev-client isn't installed; the app loads JS from ${hostPort}`);
131
+ }
116
132
  await sim.launch(udid, meta.bundleId);
117
- if (!devClientScheme) warn('expo-dev-client was not detected, so the app was launched without a Metro URL.');
118
133
  }
119
134
  }
@@ -3,9 +3,9 @@ import crypto from 'node:crypto';
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
5
5
  import { LOCKFILES, sha1File } from '../../common.js';
6
- import { agentEnv, runOk } from '../exec.js';
6
+ import { agentEnv, run, runOk } from '../exec.js';
7
7
 
8
- export { agentEnv, runOk };
8
+ export { agentEnv, run, runOk };
9
9
 
10
10
  export function readJson(file) {
11
11
  return JSON.parse(fs.readFileSync(file, 'utf8'));
@@ -2,6 +2,7 @@ import fs from 'node:fs';
2
2
  import http from 'node:http';
3
3
  import os from 'node:os';
4
4
  import path from 'node:path';
5
+ import readline from 'node:readline';
5
6
  import * as tar from 'tar';
6
7
  import { WebSocketServer } from 'ws';
7
8
  import { MIN_CLIENT_PROTOCOL, PROTOCOL, PROTOCOL_HEADER, VERSION, color, heartbeat, isSafeRelPath, isValidProjectId, negotiateProtocol, sha1File } from '../common.js';
@@ -76,7 +77,7 @@ async function info(req, client, cfg) {
76
77
  const developerDir = await findDeveloperDir();
77
78
  const local = String(req.socket.localAddress || '').replace(/^::ffff:/, '');
78
79
  let wake = null;
79
- try { wake = wakeInfo(local) || null; } catch { /* unknown interface */ }
80
+ try { wake = (await wakeInfo(local)) || null; } catch { /* unknown interface */ }
80
81
  return {
81
82
  version: VERSION,
82
83
  macos: await macosVersion(),
@@ -310,6 +311,11 @@ async function simAction(body) {
310
311
  return { ok: true, device: dev };
311
312
  }
312
313
 
314
+ // What `log stream` prints before the app's own lines: simctl spawn's
315
+ // "getpwuid_r did not find a match for uid 501" and the "Filtering the log
316
+ // data using ..." header.
317
+ export const logNoise = (line) => /^getpwuid_r did not find a match for uid \d+/.test(line) || /^Filtering the log data using /.test(line);
318
+
313
319
  async function streamLogs(req, res, query) {
314
320
  const project = query.get('project');
315
321
  const state = isValidProjectId(project) ? loadState(project) : {};
@@ -319,8 +325,11 @@ async function streamLogs(req, res, query) {
319
325
  if (!query.get('all') && state.lastRun?.executable) args.push('--predicate', `process == "${state.lastRun.executable.replace(/"/g, '')}"`);
320
326
  res.writeHead(200, { 'content-type': 'text/plain; charset=utf-8' });
321
327
  const child = spawnTool('xcrun', args);
322
- child.stdout.pipe(res);
323
- child.stderr.pipe(res);
328
+ for (const stream of [child.stdout, child.stderr]) {
329
+ readline.createInterface({ input: stream }).on('line', (line) => {
330
+ if (!logNoise(line) && !res.destroyed) res.write(`${line}\n`);
331
+ });
332
+ }
324
333
  child.on('error', () => res.end());
325
334
  child.on('close', () => res.end());
326
335
  req.on('close', () => child.kill());
package/src/agent/sim.js CHANGED
@@ -82,6 +82,11 @@ export const approveScheme = (udid, scheme, bundleId) => run('xcrun', [
82
82
  'simctl', 'spawn', udid, 'defaults', 'write', 'com.apple.launchservices.schemeapproval',
83
83
  `com.apple.CoreSimulator.CoreSimulatorBridge-->${scheme}`, '-string', bundleId,
84
84
  ]);
85
+ // Where a React Native debug build without expo-dev-client loads its JS from
86
+ // ("host:port"): RCTBundleURLProvider reads RCT_jsLocation from the app's defaults.
87
+ export const setJsLocation = (udid, bundleId, hostPort) => run('xcrun', [
88
+ 'simctl', 'spawn', udid, 'defaults', 'write', bundleId, 'RCT_jsLocation', hostPort,
89
+ ]);
85
90
  export const appearance = (udid, mode) => runOk('xcrun', ['simctl', 'ui', udid, 'appearance', mode]);
86
91
  export const setLocation = (udid, latLon) => runOk('xcrun', ['simctl', 'location', udid, 'set', latLon]);
87
92
  export const clearLocation = (udid) => runOk('xcrun', ['simctl', 'location', udid, 'clear']);
package/src/common.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import crypto from 'node:crypto';
2
2
  import fs from 'node:fs';
3
3
 
4
- export const VERSION = '0.9.0';
4
+ export const VERSION = '0.9.1';
5
5
  // The agent's protocol range: it serves clients of protocol MIN_CLIENT_PROTOCOL
6
6
  // to PROTOCOL, and reports the one it agrees on with each client (see
7
7
  // negotiateProtocol). PROTOCOL must match the Rust core's (crates/core/src/version.rs,