@webority/mobile-tools 0.139.1 → 0.139.3

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 CHANGED
@@ -98,10 +98,10 @@ npx mobile-tools run --env <Environment> [--platform android|ios] [--device <ser
98
98
  - otherwise the only device;
99
99
  - otherwise asks, on a terminal. Without a terminal it fails with the list.
100
100
  4. Reads the device's ABI and runs `prebuild`.
101
- 5. Computes the native fingerprint and looks for a cached build of this app, variant and ABI with that fingerprint. A hit installs the cached build and skips Gradle. A miss builds it (step 6) and stores the result. `--rebuild` skips the lookup and always builds.
101
+ 5. Computes the native fingerprint, through the app's own `@expo/fingerprint` when it has one, else the copy mobile-tools ships, and looks for a cached build of this app, variant and ABI with that fingerprint. A hit installs the cached build and skips Gradle. A miss builds it (step 6) and stores the result. `--rebuild` skips the lookup and always builds.
102
102
  6. On a miss or with `--rebuild`, builds `:app:assemble<Flavor>Debug` (or `:app:assembleDebug` without flavors) with `-PreactNativeArchitectures=<abi>`, so only one ABI compiles.
103
103
  7. Installs with `adb -s <serial> install -r` on that device only.
104
- 8. Reuses a Metro already serving this app. Otherwise it starts one detached and prints the path of its log; when another project holds 8081, the new Metro takes the next free port. A Metro that mobile-tools started and that stops answering is restarted on the same port.
104
+ 8. Reuses a Metro already serving this app. Otherwise it starts one detached, through the Expo CLI when the app has expo and through `react-native start` when it does not (a profiling run needs expo), and prints the path of its log; when another project holds 8081, the new Metro takes the next free port. A Metro that mobile-tools started and that stops answering is restarted on the same port.
105
105
  9. Sets `adb reverse tcp:8081` (and, for Development, the local API port). It then launches `<applicationId>/<namespace>.MainActivity`.
106
106
 
107
107
  **iOS** (macOS only, for the Simulator):
@@ -270,7 +270,7 @@ cache: no cached builds for <appId>
270
270
 
271
271
  `--json` for `list` prints `{ "dir": "<folder>", "appId": "<appId>", "builds": [{ "appId", "platform", "variant", "abi", "fingerprint", "file", "bytes", "storedAtUtc" }] }`; `--json` for `clear` prints `{ "appId": "<appId>", "removed": <n> }`.
272
272
 
273
- Exit codes: `0` on success; `1` when the fingerprint cannot be computed (`toolFailed`) or the app has no `@expo/fingerprint` (`toolMissing`); `2` for bad flags.
273
+ Exit codes: `0` on success; `1` when the fingerprint cannot be computed (`toolFailed`) or `@expo/fingerprint` cannot be loaded (`toolMissing`); `2` for bad flags.
274
274
 
275
275
  ### `metro restart`
276
276
 
package/lib/cache.js CHANGED
@@ -1 +1 @@
1
- import{createHash}from"node:crypto";import{copyFileSync,cpSync,existsSync,mkdirSync,readdirSync,renameSync,rmSync,statSync}from"node:fs";import{createRequire}from"node:module";import{homedir}from"node:os";import path from"node:path";import{pathToFileURL}from"node:url";import{baseAppId}from"./config.js";import{fail,isJsonOutput,say,sayJson}from"./output.js";import{pathFor}from"./platform.js";import{nativeBuildInputs}from"./prebuild.js";export const CACHE_KEEP=5;const ARTIFACT_SUFFIXES=[".apk",".app"],BYTES_PER_MB=1048576;export const buildCacheDir=(t,e,o)=>{const r=pathFor(e);return"win32"===e?t.LOCALAPPDATA?r.join(t.LOCALAPPDATA,"Webority","mobile-tools","builds"):fail("toolFailed","LOCALAPPDATA is not set; the build cache lives under it"):"darwin"===e?r.join(o,"Library","Caches","Webority","mobile-tools","builds"):r.join(t.XDG_CACHE_HOME||r.join(o,".cache"),"webority","mobile-tools","builds")};const defaultRoot=()=>buildCacheDir(process.env,process.platform,homedir()),resolveOrUndefined=t=>{try{return t()}catch{return}},fingerprintModuleFile=t=>{const e=createRequire(path.join(t,"package.json"));return resolveOrUndefined(()=>e.resolve("@expo/fingerprint"))??resolveOrUndefined(()=>createRequire(e.resolve("expo/package.json")).resolve("@expo/fingerprint"))};export const nativeFingerprint=async(t,e)=>{const o=fingerprintModuleFile(t)??fail("toolMissing","@expo/fingerprint not found in this app (it ships with expo); run npx mobile-tools sync"),r=await(import(pathToFileURL(o).href)),i=r.createProjectHashAsync??r.default?.createProjectHashAsync;let s;try{s=await(i?.(t,{platforms:[e],silent:!0}))}catch(t){return fail("toolFailed",`the native fingerprint could not be computed: ${t.message}`)}return"string"==typeof s&&/^[0-9a-f]{40,64}$/.test(s)?createHash("sha256").update(s).update("\n").update(nativeBuildInputs(t,e)).digest("hex"):fail("toolFailed",`the native fingerprint could not be computed: ${String(s)}`)};const abiDir=(t,e)=>path.join(t,e.appId,e.platform,e.variant,e.abi),artifactName=t=>`${t.fingerprint}${"ios"===t.platform?".app":".apk"}`;export const findCachedBuild=(t,e=defaultRoot())=>{const o=path.join(abiDir(e,t),artifactName(t));return existsSync(o)?o:void 0};const names=t=>existsSync(t)&&statSync(t).isDirectory()?readdirSync(t):[],isArtifact=t=>ARTIFACT_SUFFIXES.some(e=>t.endsWith(e))&&!t.includes(".tmp-"),storedNewestFirst=t=>names(t).filter(isArtifact).map(e=>{const o=path.join(t,e);return{file:o,mtimeMs:statSync(o).mtimeMs}}).sort((t,e)=>e.mtimeMs-t.mtimeMs);export const storeCachedBuild=(t,e,o=defaultRoot())=>{const r=abiDir(o,t);mkdirSync(r,{recursive:!0});const i=path.join(r,artifactName(t)),s=`${i}.tmp-${process.pid}`;rmSync(s,{recursive:!0,force:!0}),statSync(e).isDirectory()?cpSync(e,s,{recursive:!0}):copyFileSync(e,s),rmSync(i,{recursive:!0,force:!0}),renameSync(s,i);for(const t of storedNewestFirst(r).slice(5))rmSync(t.file,{recursive:!0,force:!0});return i};const folderBytes=t=>readdirSync(t,{withFileTypes:!0}).reduce((e,o)=>{const r=path.join(t,o.name);return e+(o.isDirectory()?folderBytes(r):statSync(r).size)},0),listBuilds=(t,e)=>{const o=[];for(const r of names(e))for(const i of names(path.join(e,r)))for(const s of names(path.join(e,r,i))){const n=path.join(e,r,i,s);for(const e of names(n).filter(isArtifact)){const a=path.join(n,e),c=statSync(a);o.push({appId:t,platform:r,variant:i,abi:s,fingerprint:path.parse(e).name,file:a,bytes:c.isDirectory()?folderBytes(a):c.size,storedAtUtc:c.mtime.toISOString()})}}return o.sort((t,e)=>e.storedAtUtc.localeCompare(t.storedAtUtc))};export const cache=async t=>{const e=baseAppId(t.appRoot),o=defaultRoot(),r=path.join(o,e);if("clear"===t.action){const t=listBuilds(e,r).length;return rmSync(r,{recursive:!0,force:!0}),void(isJsonOutput()?sayJson({appId:e,removed:t}):say(`cache: removed ${t} build(s) of ${e}`))}const i=listBuilds(e,r);if(isJsonOutput())sayJson({dir:o,appId:e,builds:i});else if(say(`cache: ${o}`),0!==i.length)for(const t of i){const e=(t.bytes/1048576).toFixed(1);say(`${t.platform} ${t.variant} ${t.abi} ${t.fingerprint.slice(0,12)} ${e} MB ${t.storedAtUtc}`)}else say(`cache: no cached builds for ${e}`)};
1
+ import{createHash}from"node:crypto";import{copyFileSync,cpSync,existsSync,mkdirSync,readdirSync,renameSync,rmSync,statSync}from"node:fs";import{createRequire}from"node:module";import{homedir}from"node:os";import path from"node:path";import{pathToFileURL}from"node:url";import{baseAppId}from"./config.js";import{fail,isJsonOutput,say,sayJson}from"./output.js";import{pathFor}from"./platform.js";import{nativeBuildInputs}from"./prebuild.js";export const CACHE_KEEP=5;const ARTIFACT_SUFFIXES=[".apk",".app"],BYTES_PER_MB=1048576;export const buildCacheDir=(t,e,o)=>{const r=pathFor(e);return"win32"===e?t.LOCALAPPDATA?r.join(t.LOCALAPPDATA,"Webority","mobile-tools","builds"):fail("toolFailed","LOCALAPPDATA is not set; the build cache lives under it"):"darwin"===e?r.join(o,"Library","Caches","Webority","mobile-tools","builds"):r.join(t.XDG_CACHE_HOME||r.join(o,".cache"),"webority","mobile-tools","builds")};const defaultRoot=()=>buildCacheDir(process.env,process.platform,homedir()),resolveOrUndefined=t=>{try{return t()}catch{return}},fingerprintModuleFile=t=>{const e=createRequire(path.join(t,"package.json"));return resolveOrUndefined(()=>e.resolve("@expo/fingerprint"))??resolveOrUndefined(()=>createRequire(e.resolve("expo/package.json")).resolve("@expo/fingerprint"))},loadFingerprintModule=async t=>{const e=fingerprintModuleFile(t);if(e)return await(import(pathToFileURL(e).href));try{return await(import("@expo/fingerprint"))}catch{return fail("toolMissing","@expo/fingerprint could not be loaded; reinstall @webority/mobile-tools")}};export const nativeFingerprint=async(t,e)=>{const o=await loadFingerprintModule(t),r=o.createProjectHashAsync??o.default?.createProjectHashAsync;let i;try{i=await(r?.(t,{platforms:[e],silent:!0}))}catch(t){return fail("toolFailed",`the native fingerprint could not be computed: ${t.message}`)}return"string"==typeof i&&/^[0-9a-f]{40,64}$/.test(i)?createHash("sha256").update(i).update("\n").update(nativeBuildInputs(t,e)).digest("hex"):fail("toolFailed",`the native fingerprint could not be computed: ${String(i)}`)};const abiDir=(t,e)=>path.join(t,e.appId,e.platform,e.variant,e.abi),artifactName=t=>`${t.fingerprint}${"ios"===t.platform?".app":".apk"}`;export const findCachedBuild=(t,e=defaultRoot())=>{const o=path.join(abiDir(e,t),artifactName(t));return existsSync(o)?o:void 0};const names=t=>existsSync(t)&&statSync(t).isDirectory()?readdirSync(t):[],isArtifact=t=>ARTIFACT_SUFFIXES.some(e=>t.endsWith(e))&&!t.includes(".tmp-"),storedNewestFirst=t=>names(t).filter(isArtifact).map(e=>{const o=path.join(t,e);return{file:o,mtimeMs:statSync(o).mtimeMs}}).sort((t,e)=>e.mtimeMs-t.mtimeMs);export const storeCachedBuild=(t,e,o=defaultRoot())=>{const r=abiDir(o,t);mkdirSync(r,{recursive:!0});const i=path.join(r,artifactName(t)),n=`${i}.tmp-${process.pid}`;rmSync(n,{recursive:!0,force:!0}),statSync(e).isDirectory()?cpSync(e,n,{recursive:!0}):copyFileSync(e,n),rmSync(i,{recursive:!0,force:!0}),renameSync(n,i);for(const t of storedNewestFirst(r).slice(5))rmSync(t.file,{recursive:!0,force:!0});return i};const folderBytes=t=>readdirSync(t,{withFileTypes:!0}).reduce((e,o)=>{const r=path.join(t,o.name);return e+(o.isDirectory()?folderBytes(r):statSync(r).size)},0),listBuilds=(t,e)=>{const o=[];for(const r of names(e))for(const i of names(path.join(e,r)))for(const n of names(path.join(e,r,i))){const s=path.join(e,r,i,n);for(const e of names(s).filter(isArtifact)){const a=path.join(s,e),c=statSync(a);o.push({appId:t,platform:r,variant:i,abi:n,fingerprint:path.parse(e).name,file:a,bytes:c.isDirectory()?folderBytes(a):c.size,storedAtUtc:c.mtime.toISOString()})}}return o.sort((t,e)=>e.storedAtUtc.localeCompare(t.storedAtUtc))};export const cache=async t=>{const e=baseAppId(t.appRoot),o=defaultRoot(),r=path.join(o,e);if("clear"===t.action){const t=listBuilds(e,r).length;return rmSync(r,{recursive:!0,force:!0}),void(isJsonOutput()?sayJson({appId:e,removed:t}):say(`cache: removed ${t} build(s) of ${e}`))}const i=listBuilds(e,r);if(isJsonOutput())sayJson({dir:o,appId:e,builds:i});else if(say(`cache: ${o}`),0!==i.length)for(const t of i){const e=(t.bytes/1048576).toFixed(1);say(`${t.platform} ${t.variant} ${t.abi} ${t.fingerprint.slice(0,12)} ${e} MB ${t.storedAtUtc}`)}else say(`cache: no cached builds for ${e}`)};
package/lib/metro.js CHANGED
@@ -1 +1 @@
1
- import{existsSync,mkdirSync,readFileSync,writeFileSync}from"node:fs";import{createRequire}from"node:module";import{createServer}from"node:net";import path from"node:path";import{logDir}from"./buildLog.js";import{capture,startDetached}from"./exec.js";import{fail,say}from"./output.js";export const DEFAULT_METRO_PORT=8081;export const HUNG_PROBE_MS=5e3;const PORT_FREE_WAIT_MS=1e4,TERM_WAIT_MS=5e3,samePath=(e,t)=>{const norm=e=>{const t=path.resolve(e).replace(/[\\/]+$/,"");return"win32"===process.platform?t.toLowerCase():t};return norm(e)===norm(t)};export const classifyStatus=(e,t,r)=>{if(!e.includes("packager-status:running"))return"other";const o=t??/project-root:(.+)/.exec(e)?.[1]?.trim();return o&&samePath(decodeHeaderPath(o),r)?"ours":"other"};const decodeHeaderPath=e=>{try{return decodeURIComponent(e)}catch{return e}},portIsFree=e=>new Promise(t=>{const r=createServer();r.once("error",()=>t(!1)),r.once("listening",()=>r.close(()=>t(!0))),r.listen(e)});export const probeMetro=async(e,t)=>{try{const r=await fetch(`http://localhost:${e}/status`,{signal:AbortSignal.timeout(1e3)});return classifyStatus(await r.text(),r.headers.get("X-React-Native-Project-Root"),t)}catch{return await portIsFree(e)?"free":"other"}};const sleep=e=>new Promise(t=>setTimeout(t,e)),waitForMetro=async(e,t,r)=>{const o=Date.now()+12e4;for(;Date.now()<o;){if("ours"===await probeMetro(e,t))return;await new Promise(e=>setTimeout(e,500))}fail("metroUnavailable",`Metro did not answer on port ${e} within 2 minutes; see ${r}`)};export const METRO_RECORD_FILE="metro.json";export const readMetroRecord=e=>{const t=path.join(logDir(e),"metro.json");if(existsSync(t))try{const e=JSON.parse(readFileSync(t,"utf8"));return"number"==typeof e.port&&"number"==typeof e.pid?e:void 0}catch{return}};const writeMetroRecord=(e,t,r,o)=>{mkdirSync(logDir(e),{recursive:!0});const s={port:t,pid:r,appRoot:e,startedAtUtc:(new Date).toISOString(),mode:o};writeFileSync(path.join(logDir(e),"metro.json"),JSON.stringify(s,null,2))},servedMode=(e,t)=>{const r=readMetroRecord(e);return(r?.port===t?r.mode:void 0)??"development"},withProfilingEnv=(e,t)=>{const r=process.env.WEBORITY_PROFILING;e?process.env.WEBORITY_PROFILING="1":delete process.env.WEBORITY_PROFILING;try{return t()}finally{void 0===r?delete process.env.WEBORITY_PROFILING:process.env.WEBORITY_PROFILING=r}},startMetro=async(e,t,r,o)=>{let s;try{s=createRequire(path.join(e,"package.json")).resolve("expo/bin/cli")}catch{return fail("toolMissing","expo is not installed in this app; run npx mobile-tools sync")}const a=[s,"start","--port",String(t),...o?["--no-dev","--minify"]:[]],n=withProfilingEnv(o,()=>startDetached({file:process.execPath,args:a},e,r));writeMetroRecord(e,t,n,o?"profiling":"development"),say(`metro: started on port ${t}, log ${r}`),await waitForMetro(t,e,r)},answers=async(e,t)=>{try{return await fetch(`http://localhost:${e}/status`,{signal:AbortSignal.timeout(t)}),!0}catch{return!1}},systemTool=e=>path.join(process.env.SystemRoot??"C:/Windows","System32",e),isNodeProcess=e=>{try{process.kill(e,0)}catch{return!1}if("win32"===process.platform){return capture({file:systemTool("tasklist.exe"),args:["/FI",`PID eq ${e}`,"/FO","CSV","/NH"]},process.cwd()).stdout.toLowerCase().includes("node.exe")}return capture({file:"/bin/ps",args:["-p",String(e),"-o","comm="]},process.cwd()).stdout.trim().endsWith("node")},signalGroup=(e,t)=>{try{process.kill(-e,t)}catch{}},stopTree=async e=>{if("win32"===process.platform){const t=capture({file:systemTool("taskkill.exe"),args:["/PID",String(e),"/T","/F"]},process.cwd());if(0!==t.status&&isNodeProcess(e)){const r=`${t.stdout}${t.stderr}`.trim();fail("toolFailed",`taskkill could not stop pid ${e}: ${r}`)}return}signalGroup(e,"SIGTERM");const t=Date.now()+5e3;for(;isNodeProcess(e)&&Date.now()<t;)await sleep(250);isNodeProcess(e)&&signalGroup(e,"SIGKILL")},waitPortFree=async(e,t)=>{const r=Date.now()+1e4;for(;!await portIsFree(e);)Date.now()>=r&&fail("metroUnavailable",`port ${e} is still held 10 s after stopping pid ${t}; stop the holder and rerun`),await sleep(250)};export const ensureMetro=async(e,t,{fixedPort:r,profiling:o})=>{const s=o?"profiling":"development",a=r?8081:8100;for(let r=8081;r<=a;r++){const a=await probeMetro(r,e);if("ours"===a){const t=servedMode(e,r);return t!==s?fail("metroUnavailable",`Metro on port ${r}: stop the running Metro first; it serves ${t} JavaScript`):(say(`metro: reusing the server on port ${r}`),r)}if("other"===a){const s=readMetroRecord(e);if(s?.port===r&&isNodeProcess(s.pid)&&!await answers(r,5e3))return say(`metro: the server on port ${r} (pid ${s.pid}) does not answer; restarting it, log ${t}`),await stopTree(s.pid),await waitPortFree(r,s.pid),await startMetro(e,r,t,o),r}if("free"===a)return await startMetro(e,r,t,o),r}return fail("metroUnavailable",r?"port 8081 is held by another server (the iOS app always looks there); stop it and rerun":"ports 8081-8100 are all held by other servers; stop one and rerun")};export const restartMetro=async e=>{const t=path.join(logDir(e),"metro.log"),r=readMetroRecord(e);if(r&&isNodeProcess(r.pid))return await stopTree(r.pid),say(`metro: stopped pid ${r.pid} on port ${r.port}`),await waitPortFree(r.port,r.pid),await startMetro(e,r.port,t,"profiling"===r.mode),say(`metro: ready on port ${r.port}`),r.port;const o=r?.port??8081,s=await probeMetro(o,e);return"ours"===s?fail("metroUnavailable",`the Metro on port ${o} was not started by mobile-tools; stop it in its own terminal (Ctrl+C), then run mobile-tools metro restart`):"other"===s?fail("metroUnavailable",`port ${o} is held by another server; stop it and rerun`):(await startMetro(e,o,t,!1),say(`metro: ready on port ${o}`),o)};
1
+ import{existsSync,mkdirSync,readFileSync,writeFileSync}from"node:fs";import{createRequire}from"node:module";import{createServer}from"node:net";import path from"node:path";import{logDir}from"./buildLog.js";import{capture,startDetached}from"./exec.js";import{fail,say}from"./output.js";export const DEFAULT_METRO_PORT=8081;export const HUNG_PROBE_MS=5e3;const PORT_FREE_WAIT_MS=1e4,TERM_WAIT_MS=5e3,samePath=(t,e)=>{const norm=t=>{const e=path.resolve(t).replace(/[\\/]+$/,"");return"win32"===process.platform?e.toLowerCase():e};return norm(t)===norm(e)};export const classifyStatus=(t,e,r)=>{if(!t.includes("packager-status:running"))return"other";const o=e??/project-root:(.+)/.exec(t)?.[1]?.trim();return o&&samePath(decodeHeaderPath(o),r)?"ours":"other"};const decodeHeaderPath=t=>{try{return decodeURIComponent(t)}catch{return t}},portIsFree=t=>new Promise(e=>{const r=createServer();r.once("error",()=>e(!1)),r.once("listening",()=>r.close(()=>e(!0))),r.listen(t)});export const probeMetro=async(t,e)=>{try{const r=await fetch(`http://localhost:${t}/status`,{signal:AbortSignal.timeout(1e3)});return classifyStatus(await r.text(),r.headers.get("X-React-Native-Project-Root"),e)}catch{return await portIsFree(t)?"free":"other"}};const sleep=t=>new Promise(e=>setTimeout(e,t)),waitForMetro=async(t,e,r)=>{const o=Date.now()+12e4;for(;Date.now()<o;){if("ours"===await probeMetro(t,e))return;await new Promise(t=>setTimeout(t,500))}fail("metroUnavailable",`Metro did not answer on port ${t} within 2 minutes; see ${r}`)};export const METRO_RECORD_FILE="metro.json";export const readMetroRecord=t=>{const e=path.join(logDir(t),"metro.json");if(existsSync(e))try{const t=JSON.parse(readFileSync(e,"utf8"));return"number"==typeof t.port&&"number"==typeof t.pid?t:void 0}catch{return}};const writeMetroRecord=(t,e,r,o)=>{mkdirSync(logDir(t),{recursive:!0});const s={port:e,pid:r,appRoot:t,startedAtUtc:(new Date).toISOString(),mode:o};writeFileSync(path.join(logDir(t),"metro.json"),JSON.stringify(s,null,2))},servedMode=(t,e)=>{const r=readMetroRecord(t);return(r?.port===e?r.mode:void 0)??"development"},withProfilingEnv=(t,e)=>{const r=process.env.WEBORITY_PROFILING;t?process.env.WEBORITY_PROFILING="1":delete process.env.WEBORITY_PROFILING;try{return e()}finally{void 0===r?delete process.env.WEBORITY_PROFILING:process.env.WEBORITY_PROFILING=r}},startMetro=async(t,e,r,o)=>{const s=createRequire(path.join(t,"package.json")),resolveCli=t=>{try{return s.resolve(t)}catch{return}},i=resolveCli("expo/bin/cli"),a=i?void 0:resolveCli("react-native/cli.js");let n;if(i)n=[i,"start","--port",String(e),...o?["--no-dev","--minify"]:[]];else{if(!a)return fail("toolMissing","neither expo nor react-native is installed in this app; run pnpm install in the app");if(o)return fail("toolMissing","profiling Metro needs the Expo CLI; add expo to the app or run without profiling");n=[a,"start","--port",String(e)]}const p=withProfilingEnv(o,()=>startDetached({file:process.execPath,args:n},t,r));writeMetroRecord(t,e,p,o?"profiling":"development"),say(`metro: started on port ${e}, log ${r}`),await waitForMetro(e,t,r)},answers=async(t,e)=>{try{return await fetch(`http://localhost:${t}/status`,{signal:AbortSignal.timeout(e)}),!0}catch{return!1}},systemTool=t=>path.join(process.env.SystemRoot??"C:/Windows","System32",t),isNodeProcess=t=>{try{process.kill(t,0)}catch{return!1}if("win32"===process.platform){return capture({file:systemTool("tasklist.exe"),args:["/FI",`PID eq ${t}`,"/FO","CSV","/NH"]},process.cwd()).stdout.toLowerCase().includes("node.exe")}return capture({file:"/bin/ps",args:["-p",String(t),"-o","comm="]},process.cwd()).stdout.trim().endsWith("node")},signalGroup=(t,e)=>{try{process.kill(-t,e)}catch{}},stopTree=async t=>{if("win32"===process.platform){const e=capture({file:systemTool("taskkill.exe"),args:["/PID",String(t),"/T","/F"]},process.cwd());if(0!==e.status&&isNodeProcess(t)){const r=`${e.stdout}${e.stderr}`.trim();fail("toolFailed",`taskkill could not stop pid ${t}: ${r}`)}return}signalGroup(t,"SIGTERM");const e=Date.now()+5e3;for(;isNodeProcess(t)&&Date.now()<e;)await sleep(250);isNodeProcess(t)&&signalGroup(t,"SIGKILL")},waitPortFree=async(t,e)=>{const r=Date.now()+1e4;for(;!await portIsFree(t);)Date.now()>=r&&fail("metroUnavailable",`port ${t} is still held 10 s after stopping pid ${e}; stop the holder and rerun`),await sleep(250)};export const ensureMetro=async(t,e,{fixedPort:r,profiling:o})=>{const s=o?"profiling":"development",i=r?8081:8100;for(let r=8081;r<=i;r++){const i=await probeMetro(r,t);if("ours"===i){const e=servedMode(t,r);return e!==s?fail("metroUnavailable",`Metro on port ${r}: stop the running Metro first; it serves ${e} JavaScript`):(say(`metro: reusing the server on port ${r}`),r)}if("other"===i){const s=readMetroRecord(t);if(s?.port===r&&isNodeProcess(s.pid)&&!await answers(r,5e3))return say(`metro: the server on port ${r} (pid ${s.pid}) does not answer; restarting it, log ${e}`),await stopTree(s.pid),await waitPortFree(r,s.pid),await startMetro(t,r,e,o),r}if("free"===i)return await startMetro(t,r,e,o),r}return fail("metroUnavailable",r?"port 8081 is held by another server (the iOS app always looks there); stop it and rerun":"ports 8081-8100 are all held by other servers; stop one and rerun")};export const restartMetro=async t=>{const e=path.join(logDir(t),"metro.log"),r=readMetroRecord(t);if(r&&isNodeProcess(r.pid))return await stopTree(r.pid),say(`metro: stopped pid ${r.pid} on port ${r.port}`),await waitPortFree(r.port,r.pid),await startMetro(t,r.port,e,"profiling"===r.mode),say(`metro: ready on port ${r.port}`),r.port;const o=r?.port??8081,s=await probeMetro(o,t);return"ours"===s?fail("metroUnavailable",`the Metro on port ${o} was not started by mobile-tools; stop it in its own terminal (Ctrl+C), then run mobile-tools metro restart`):"other"===s?fail("metroUnavailable",`port ${o} is held by another server; stop it and rerun`):(await startMetro(t,o,e,!1),say(`metro: ready on port ${o}`),o)};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/mobile-tools",
3
- "version": "0.139.1",
3
+ "version": "0.139.3",
4
4
  "description": "Dev-time CLI for Webority React Native apps: one prebuild, a dependency guard, a device-aware run and per-environment launcher icons, the same on Windows and macOS.",
5
5
  "keywords": [
6
6
  "react-native",
@@ -35,6 +35,7 @@
35
35
  "!**/*.map"
36
36
  ],
37
37
  "dependencies": {
38
+ "@expo/fingerprint": "0.20.14",
38
39
  "sharp": "^0.35.5"
39
40
  },
40
41
  "engines": {