@webority/mobile-tools 0.144.1 → 0.145.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.
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=(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)};
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(t){if("ESRCH"!==t.code)throw t}},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/lib/sync.js CHANGED
@@ -1 +1 @@
1
- import{createHash}from"node:crypto";import{existsSync,readdirSync,readFileSync,rmSync,statSync,writeFileSync}from"node:fs";import path from"node:path";import{capture,runInherit}from"./exec.js";import{fail,say}from"./output.js";import{findOnPath,gradleInvocation,npmInvocation,pnpmInvocation}from"./platform.js";import{prependXosShims,xosPath}from"./xos.js";export const STAMP_FILE=path.join("node_modules",".webority-install.json");export const PODS_RECORD=path.join("ios","Pods",".webority-native.json");const INSTALL_FIELDS=["dependencies","devDependencies","optionalDependencies","peerDependencies","bundleDependencies","overrides","resolutions","pnpm","workspaces"];export const lockfileOf=e=>{const s=path.join(e,"pnpm-lock.yaml"),n=path.join(e,"package-lock.json");return existsSync(s)&&existsSync(n)?fail("appConfigInvalid","both pnpm-lock.yaml and package-lock.json exist: delete the one not in use"):existsSync(s)?{manager:"pnpm",file:s}:existsSync(n)?{manager:"npm",file:n}:fail("appConfigInvalid",`no package-lock.json or pnpm-lock.yaml in ${e}`)};const filesUnder=(e,s="")=>readdirSync(e,{withFileTypes:!0}).flatMap(n=>{const o=""===s?n.name:`${s}/${n.name}`;return n.isDirectory()?filesUnder(path.join(e,n.name),o):[o]}).sort();export const installHash=e=>{const{file:s}=lockfileOf(e),n=JSON.parse(readFileSync(path.join(e,"package.json"),"utf8")),o=createHash("sha256");o.update(`lockfile:${path.basename(s)}\0`),o.update(readFileSync(s)),o.update("\0package.json\0"),o.update(JSON.stringify(INSTALL_FIELDS.map(e=>[e,n[e]??null])));const t=path.join(e,"patches");if(existsSync(t))for(const e of filesUnder(t))o.update(`\0patches/${e}\0`),o.update(readFileSync(path.join(t,...e.split("/"))));return o.digest("hex")};export const readStamp=e=>{const s=path.join(e,STAMP_FILE);if(existsSync(s))try{return JSON.parse(readFileSync(s,"utf8"))}catch{return}};const POD_FIX="cd ios && pod install",hasXos=e=>void 0!==findOnPath("xos",process.env,e),installsPods=e=>"darwin"===e||hasXos(e);export const podsStale=e=>{const s=path.join(e,"ios","Podfile.lock"),n=path.join(e,"ios","Pods","Manifest.lock");return!(!existsSync(s)||!existsSync(n))&&!readFileSync(s).equals(readFileSync(n))};const nodeModulesNewerThanPods=e=>{const s=[path.join(e,"node_modules",".modules.yaml"),path.join(e,"node_modules",".pnpm","lock.yaml")].find(e=>existsSync(e)),n=path.join(e,"ios","Pods","Manifest.lock");return!(!s||!existsSync(n))&&statSync(s).mtimeMs>statSync(n).mtimeMs};export const checkSync=(e,s,n=!0)=>{const o=[],t=readStamp(e),{file:a}=lockfileOf(e);if(t?t.hash!==installHash(e)&&o.push(`node_modules is stale: ${path.basename(a)}, package.json or patches/ changed since the last install. Fix: npx mobile-tools sync`):o.push("node_modules has no install stamp (never installed through mobile-tools). Fix: npx mobile-tools sync"),t){const s=changedNativePackages(t.nativePackages??{},nativePackages(e));s.length>0&&o.push(`node_modules native packages changed since the last install: ${s.join(", ")}. Fix: npx mobile-tools sync`)}const i=n&&installsPods(s);return i&&podsStale(e)&&o.push(`ios/Pods is stale: ios/Podfile.lock differs from ios/Pods/Manifest.lock. Fix: ${POD_FIX}`),i&&existsSync(path.join(e,"ios","Podfile.lock"))&&nodeModulesNewerThanPods(e)&&o.push("node_modules changed after the last pod install; run pod install in ios/ (or mobile-tools sync)"),o};export const requireSynced=(e,{pods:s})=>{const n=checkSync(e,process.platform,s);n.length>0&&fail("installStale",n.join("\n"))};export const nativePackages=e=>{const s=path.join(e,"node_modules");if(!existsSync(s))return{};const n=[];for(const e of readdirSync(s,{withFileTypes:!0}))if(!e.name.startsWith(".")&&e.isDirectory())if(e.name.startsWith("@"))for(const o of readdirSync(path.join(s,e.name),{withFileTypes:!0}))o.isDirectory()&&n.push(path.join(s,e.name,o.name));else n.push(path.join(s,e.name));const o={};for(const e of n){const s=path.join(e,"android"),n=path.join(e,"package.json");if(existsSync(s)&&statSync(s).isDirectory()&&existsSync(n))try{const e=JSON.parse(readFileSync(n,"utf8"));e.name&&e.version&&(o[e.name]=e.version)}catch{}}return o};export const changedNativePackages=(e,s)=>[...new Set([...Object.keys(e),...Object.keys(s)])].filter(n=>e[n]!==s[n]).sort();export const writeStamp=e=>{const{manager:s}=lockfileOf(e),n={hash:installHash(e),manager:s,nativePackages:nativePackages(e)};return writeFileSync(path.join(e,STAMP_FILE),`${JSON.stringify(n,null,2)}\n`,"utf8"),n};export const installInvocation=(e,s)=>"pnpm"===e?pnpmInvocation(["install","--frozen-lockfile"],process.env,s,process.execPath):npmInvocation(["ci"],process.env,s,process.execPath);export const localPathPods=e=>{const s=[];let n,o=!1;for(const t of e.split(/\r?\n/)){if(/^\S/.test(t)){o="EXTERNAL SOURCES:"===t,n=void 0;continue}if(!o)continue;const e=/^ {2}"?([^"\s:]+)"?:$/.exec(t);e?n=e[1]:void 0!==n&&/^ {4}:path:/.test(t)&&(s.push(n),n=void 0)}return s};const POD_VERSION_MOVED=/changed the version of the dependency|pod update/,runPod=(e,s,n)=>{const o=capture({file:e,args:s},n);return-1===o.status&&fail("toolFailed",`pod ${s[0]} could not start: ${o.stderr}`),process.stdout.write(o.stdout),process.stderr.write(o.stderr),o};export const ensurePods=(e,s)=>{if(!existsSync(path.join(e,"ios","Podfile")))return;const n=path.join(e,"ios","Pods"),o=path.join(e,PODS_RECORD);let t;if(existsSync(n)?existsSync(path.join(e,"ios","Podfile.lock"))?existsSync(path.join(n,"Manifest.lock"))?podsStale(e)?t="ios/Podfile.lock differs from ios/Pods/Manifest.lock":nodeModulesNewerThanPods(e)?t="node_modules changed after the last pod install":existsSync(o)?readFileSync(o,"utf8")!==JSON.stringify(nativePackages(e))&&(t="native packages changed since the last pod install"):t="no pod install record":t="ios/Pods/Manifest.lock is missing":t="ios/Podfile.lock is missing":t="ios/Pods is missing",void 0===t)return;say(`pods: ${t}; running pod install`);const a=findOnPath("pod",process.env,s);if(!a){const e=hasXos(s)?"check xos doctor --json names its shims folder":"install CocoaPods (brew install cocoapods)";fail("toolMissing",`pod not found on PATH; ${e}, then ${POD_FIX}`)}const i=path.join(e,"ios");let c=runPod(a,["install"],i);if(0!==c.status&&POD_VERSION_MOVED.test(`${c.stdout}${c.stderr}`)){const e=path.join(i,"Podfile.lock"),s=existsSync(e)?localPathPods(readFileSync(e,"utf8")):[];s.length>0&&(say(`pods: updating ${s.length} local pods moved by a package upgrade`),c=runPod(a,["update",...s,"--no-repo-update"],i),0!==c.status&&fail("toolFailed",`pod update failed (exit ${c.status})`))}0!==c.status&&fail("toolFailed",`pod install failed (exit ${c.status})`);const r=path.join(e,"ios","build","ModuleCache.noindex");existsSync(r)&&(rmSync(r,{recursive:!0,force:!0}),say(`sync: removed ${path.relative(e,r)}`)),writeFileSync(o,JSON.stringify(nativePackages(e)),"utf8")};export const sync=(e,s)=>{const{manager:n}=lockfileOf(e),o=readStamp(e)?.nativePackages??nativePackages(e);say("sync: "+("pnpm"===n?"pnpm install --frozen-lockfile":"npm ci")),runInherit(installInvocation(n,s),e,`${n} install`);const t=writeStamp(e).nativePackages,a=changedNativePackages(o,t),i=path.join(e,"android"),c=existsSync(path.join(i,"app",".cxx"))||existsSync(path.join(i,"app","build"));if(a.length>0&&c){say(`sync: native packages changed (${a.join(", ")}): regenerating codegen`),runInherit(gradleInvocation(i,["generateCodegenArtifactsFromSchema"],s,process.env),i,"gradlew generateCodegenArtifactsFromSchema");for(const s of[path.join(i,"app",".cxx"),path.join(i,"app","build","generated","autolinking")])rmSync(s,{recursive:!0,force:!0}),say(`sync: removed ${path.relative(e,s)}`)}installsPods(s)&&existsSync(path.join(e,"ios","Podfile"))&&(hasXos(s)&&prependXosShims(xosPath(process.env,s),e),ensurePods(e,s)),say("sync: done")};
1
+ import{createHash}from"node:crypto";import{existsSync,readdirSync,readFileSync,rmSync,statSync,writeFileSync}from"node:fs";import path from"node:path";import{capture,runInherit}from"./exec.js";import{fail,say}from"./output.js";import{findOnPath,gradleInvocation,npmInvocation,pnpmInvocation}from"./platform.js";import{prependXosShims,xosPath}from"./xos.js";export const STAMP_FILE=path.join("node_modules",".webority-install.json");export const PODS_RECORD=path.join("ios","Pods",".webority-native.json");const INSTALL_FIELDS=["dependencies","devDependencies","optionalDependencies","peerDependencies","bundleDependencies","overrides","resolutions","pnpm","workspaces"];export const lockfileOf=e=>{const s=path.join(e,"pnpm-lock.yaml"),n=path.join(e,"package-lock.json");return existsSync(s)&&existsSync(n)?fail("appConfigInvalid","both pnpm-lock.yaml and package-lock.json exist: delete the one not in use"):existsSync(s)?{manager:"pnpm",file:s}:existsSync(n)?{manager:"npm",file:n}:fail("appConfigInvalid",`no package-lock.json or pnpm-lock.yaml in ${e}`)};const filesUnder=(e,s="")=>readdirSync(e,{withFileTypes:!0}).flatMap(n=>{const o=""===s?n.name:`${s}/${n.name}`;return n.isDirectory()?filesUnder(path.join(e,n.name),o):[o]}).sort();export const installHash=e=>{const{file:s}=lockfileOf(e),n=JSON.parse(readFileSync(path.join(e,"package.json"),"utf8")),o=createHash("sha256");o.update(`lockfile:${path.basename(s)}\0`),o.update(readFileSync(s)),o.update("\0package.json\0"),o.update(JSON.stringify(INSTALL_FIELDS.map(e=>[e,n[e]??null])));const t=path.join(e,"patches");if(existsSync(t))for(const e of filesUnder(t))o.update(`\0patches/${e}\0`),o.update(readFileSync(path.join(t,...e.split("/"))));return o.digest("hex")};export const readStamp=e=>{const s=path.join(e,STAMP_FILE);if(existsSync(s))try{return JSON.parse(readFileSync(s,"utf8"))}catch{return}};const POD_FIX="cd ios && pod install",hasXos=e=>void 0!==findOnPath("xos",process.env,e),installsPods=e=>"darwin"===e||hasXos(e);export const podsStale=e=>{const s=path.join(e,"ios","Podfile.lock"),n=path.join(e,"ios","Pods","Manifest.lock");return!(!existsSync(s)||!existsSync(n))&&!readFileSync(s).equals(readFileSync(n))};const nodeModulesNewerThanPods=e=>{const s=[path.join(e,"node_modules",".modules.yaml"),path.join(e,"node_modules",".pnpm","lock.yaml")].find(e=>existsSync(e)),n=path.join(e,"ios","Pods","Manifest.lock");return!(!s||!existsSync(n))&&statSync(s).mtimeMs>statSync(n).mtimeMs};export const checkSync=(e,s,n=!0)=>{const o=[],t=readStamp(e),{file:a}=lockfileOf(e);if(t?t.hash!==installHash(e)&&o.push(`node_modules is stale: ${path.basename(a)}, package.json or patches/ changed since the last install. Fix: npx mobile-tools sync`):o.push("node_modules has no install stamp (never installed through mobile-tools). Fix: npx mobile-tools sync"),t){const s=changedNativePackages(t.nativePackages??{},nativePackages(e));s.length>0&&o.push(`node_modules native packages changed since the last install: ${s.join(", ")}. Fix: npx mobile-tools sync`)}const i=n&&installsPods(s);return i&&podsStale(e)&&o.push(`ios/Pods is stale: ios/Podfile.lock differs from ios/Pods/Manifest.lock. Fix: ${POD_FIX}`),i&&existsSync(path.join(e,"ios","Podfile.lock"))&&nodeModulesNewerThanPods(e)&&o.push("node_modules changed after the last pod install; run pod install in ios/ (or mobile-tools sync)"),o};export const requireSynced=(e,{pods:s})=>{const n=checkSync(e,process.platform,s);n.length>0&&fail("installStale",n.join("\n"))};export const nativePackages=e=>{const s=path.join(e,"node_modules");if(!existsSync(s))return{};const n=[];for(const e of readdirSync(s,{withFileTypes:!0}))if(!e.name.startsWith(".")&&e.isDirectory())if(e.name.startsWith("@"))for(const o of readdirSync(path.join(s,e.name),{withFileTypes:!0}))o.isDirectory()&&n.push(path.join(s,e.name,o.name));else n.push(path.join(s,e.name));const o={};for(const e of n){const s=path.join(e,"android"),n=path.join(e,"package.json");if(existsSync(s)&&statSync(s).isDirectory()&&existsSync(n))try{const e=JSON.parse(readFileSync(n,"utf8"));e.name&&e.version&&(o[e.name]=e.version)}catch(e){fail("toolFailed",`${n} is not valid package.json, so its native package cannot be read: ${e.message}`)}}return o};export const changedNativePackages=(e,s)=>[...new Set([...Object.keys(e),...Object.keys(s)])].filter(n=>e[n]!==s[n]).sort();export const writeStamp=e=>{const{manager:s}=lockfileOf(e),n={hash:installHash(e),manager:s,nativePackages:nativePackages(e)};return writeFileSync(path.join(e,STAMP_FILE),`${JSON.stringify(n,null,2)}\n`,"utf8"),n};export const installInvocation=(e,s)=>"pnpm"===e?pnpmInvocation(["install","--frozen-lockfile"],process.env,s,process.execPath):npmInvocation(["ci"],process.env,s,process.execPath);export const localPathPods=e=>{const s=[];let n,o=!1;for(const t of e.split(/\r?\n/)){if(/^\S/.test(t)){o="EXTERNAL SOURCES:"===t,n=void 0;continue}if(!o)continue;const e=/^ {2}"?([^"\s:]+)"?:$/.exec(t);e?n=e[1]:void 0!==n&&/^ {4}:path:/.test(t)&&(s.push(n),n=void 0)}return s};const POD_VERSION_MOVED=/changed the version of the dependency|pod update/,runPod=(e,s,n)=>{const o=capture({file:e,args:s},n);return-1===o.status&&fail("toolFailed",`pod ${s[0]} could not start: ${o.stderr}`),process.stdout.write(o.stdout),process.stderr.write(o.stderr),o};export const ensurePods=(e,s)=>{if(!existsSync(path.join(e,"ios","Podfile")))return;const n=path.join(e,"ios","Pods"),o=path.join(e,PODS_RECORD);let t;if(existsSync(n)?existsSync(path.join(e,"ios","Podfile.lock"))?existsSync(path.join(n,"Manifest.lock"))?podsStale(e)?t="ios/Podfile.lock differs from ios/Pods/Manifest.lock":nodeModulesNewerThanPods(e)?t="node_modules changed after the last pod install":existsSync(o)?readFileSync(o,"utf8")!==JSON.stringify(nativePackages(e))&&(t="native packages changed since the last pod install"):t="no pod install record":t="ios/Pods/Manifest.lock is missing":t="ios/Podfile.lock is missing":t="ios/Pods is missing",void 0===t)return;say(`pods: ${t}; running pod install`);const a=findOnPath("pod",process.env,s);if(!a){const e=hasXos(s)?"check xos doctor --json names its shims folder":"install CocoaPods (brew install cocoapods)";fail("toolMissing",`pod not found on PATH; ${e}, then ${POD_FIX}`)}const i=path.join(e,"ios");let c=runPod(a,["install"],i);if(0!==c.status&&POD_VERSION_MOVED.test(`${c.stdout}${c.stderr}`)){const e=path.join(i,"Podfile.lock"),s=existsSync(e)?localPathPods(readFileSync(e,"utf8")):[];s.length>0&&(say(`pods: updating ${s.length} local pods moved by a package upgrade`),c=runPod(a,["update",...s,"--no-repo-update"],i),0!==c.status&&fail("toolFailed",`pod update failed (exit ${c.status})`))}0!==c.status&&fail("toolFailed",`pod install failed (exit ${c.status})`);const r=path.join(e,"ios","build","ModuleCache.noindex");existsSync(r)&&(rmSync(r,{recursive:!0,force:!0}),say(`sync: removed ${path.relative(e,r)}`)),writeFileSync(o,JSON.stringify(nativePackages(e)),"utf8")};export const sync=(e,s)=>{const{manager:n}=lockfileOf(e),o=readStamp(e)?.nativePackages??nativePackages(e);say("sync: "+("pnpm"===n?"pnpm install --frozen-lockfile":"npm ci")),runInherit(installInvocation(n,s),e,`${n} install`);const t=writeStamp(e).nativePackages,a=changedNativePackages(o,t),i=path.join(e,"android"),c=existsSync(path.join(i,"app",".cxx"))||existsSync(path.join(i,"app","build"));if(a.length>0&&c){say(`sync: native packages changed (${a.join(", ")}): regenerating codegen`),runInherit(gradleInvocation(i,["generateCodegenArtifactsFromSchema"],s,process.env),i,"gradlew generateCodegenArtifactsFromSchema");for(const s of[path.join(i,"app",".cxx"),path.join(i,"app","build","generated","autolinking")])rmSync(s,{recursive:!0,force:!0}),say(`sync: removed ${path.relative(e,s)}`)}installsPods(s)&&existsSync(path.join(e,"ios","Podfile"))&&(hasXos(s)&&prependXosShims(xosPath(process.env,s),e),ensurePods(e,s)),say("sync: done")};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/mobile-tools",
3
- "version": "0.144.1",
3
+ "version": "0.145.0",
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",