@webority/mobile-tools 0.119.0 → 0.120.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/lib/build.js CHANGED
@@ -1 +1 @@
1
- import{existsSync,readdirSync}from"node:fs";import path from"node:path";import{buildOrFail,logDir,logStamp}from"./buildLog.js";import{gradleOutputDir,gradleTask,loadToolsConfig,mappingFile,resolveIosProjectName}from"./config.js";import{fail,isJsonOutput,say,sayJson}from"./output.js";import{gradleInvocation}from"./platform.js";import{prebuild}from"./prebuild.js";import{ensurePods,requireSynced}from"./sync.js";import{prependXosShims,xosPath,xosSimulatorBuild}from"./xos.js";const buildAndroid=async(o,a,i)=>{const{appRoot:r,env:s}=o;requireSynced(r);const t=loadToolsConfig(r),e=path.join(r,"android");existsSync(path.join(e,"app","build.gradle"))||fail("appConfigInvalid",`android/app/build.gradle not found in ${r}`),prebuild({appRoot:r,env:s,platform:"android",otaTest:o.otaTest});const l=gradleTask(s,t.flavors,a,i),n=path.join(logDir(r),`gradle-${s}-${logStamp()}.log`);await buildOrFail(gradleInvocation(e,[`:app:${l}`,...o.gradleArgs],process.platform,process.env),e,n,`gradle ${l}`);const p=gradleOutputDir(r,s,t.flavors,a,i),d=existsSync(p)?readdirSync(p,{withFileTypes:!0}).filter(o=>o.isFile()&&o.name.endsWith(`.${a}`)).map(o=>path.resolve(p,o.name)).sort():[];0===d.length&&fail("artifactMissing",`the build produced no ${a} in ${p}`);const g=mappingFile(r,s,t.flavors);return{artifacts:d,mapping:"release"===i&&existsSync(g)?g:null,log:n}},buildIos=async(o,a)=>{o.gradleArgs.length>0&&fail("badInput","Gradle arguments after -- apply to apk and aab builds only");const{appRoot:i,env:r}=o,s=xosPath(process.env,process.platform);requireSynced(i);const t=loadToolsConfig(i),e=resolveIosProjectName(i,t)??fail("appConfigInvalid",`no ios/ folder in ${i}`);prebuild({appRoot:i,env:r,platform:"ios",otaTest:o.otaTest}),prependXosShims(s,i),ensurePods(i,process.platform);const l="release"===a?"Release":"Debug",n=path.join(logDir(i),`xos-${r}-${logStamp()}.log`);return{artifacts:[await xosSimulatorBuild(s,{appRoot:i,projectName:e,configuration:l,arch:o.arch??"x86_64"},n)],mapping:null,log:n}};export const build=async o=>{const a=o.debug?"debug":"release",i="ios-sim"===o.artifact?await buildIos(o,a):await buildAndroid(o,o.artifact,a);if(isJsonOutput())sayJson({artifacts:i.artifacts,mapping:i.mapping,log:i.log});else{for(const o of i.artifacts)say(`build: ${o}`);null!==i.mapping&&say(`build: mapping ${i.mapping}`)}};
1
+ import{existsSync,readdirSync}from"node:fs";import path from"node:path";import{buildOrFail,logDir,logStamp}from"./buildLog.js";import{gradleOutputDir,gradleTask,loadToolsConfig,mappingFile,resolveIosProjectName}from"./config.js";import{fail,isJsonOutput,say,sayJson}from"./output.js";import{gradleInvocation}from"./platform.js";import{prebuild}from"./prebuild.js";import{ensurePods,requireSynced}from"./sync.js";import{prependXosShims,xosPath,xosSimulatorBuild}from"./xos.js";const buildAndroid=async(o,a,i)=>{const{appRoot:r,env:s}=o;requireSynced(r,"android");const t=loadToolsConfig(r),e=path.join(r,"android");existsSync(path.join(e,"app","build.gradle"))||fail("appConfigInvalid",`android/app/build.gradle not found in ${r}`),prebuild({appRoot:r,env:s,platform:"android",otaTest:o.otaTest});const n=gradleTask(s,t.flavors,a,i),l=path.join(logDir(r),`gradle-${s}-${logStamp()}.log`);await buildOrFail(gradleInvocation(e,[`:app:${n}`,...o.gradleArgs],process.platform,process.env),e,l,`gradle ${n}`);const p=gradleOutputDir(r,s,t.flavors,a,i),d=existsSync(p)?readdirSync(p,{withFileTypes:!0}).filter(o=>o.isFile()&&o.name.endsWith(`.${a}`)).map(o=>path.resolve(p,o.name)).sort():[];0===d.length&&fail("artifactMissing",`the build produced no ${a} in ${p}`);const g=mappingFile(r,s,t.flavors);return{artifacts:d,mapping:"release"===i&&existsSync(g)?g:null,log:l}},buildIos=async(o,a)=>{o.gradleArgs.length>0&&fail("badInput","Gradle arguments after -- apply to apk and aab builds only");const{appRoot:i,env:r}=o,s=xosPath(process.env,process.platform);requireSynced(i,"ios");const t=loadToolsConfig(i),e=resolveIosProjectName(i,t)??fail("appConfigInvalid",`no ios/ folder in ${i}`);prebuild({appRoot:i,env:r,platform:"ios",otaTest:o.otaTest}),prependXosShims(s,i),ensurePods(i,process.platform);const n="release"===a?"Release":"Debug",l=path.join(logDir(i),`xos-${r}-${logStamp()}.log`);return{artifacts:[await xosSimulatorBuild(s,{appRoot:i,projectName:e,configuration:n,arch:o.arch??"x86_64"},l)],mapping:null,log:l}};export const build=async o=>{const a=o.debug?"debug":"release",i="ios-sim"===o.artifact?await buildIos(o,a):await buildAndroid(o,o.artifact,a);if(isJsonOutput())sayJson({artifacts:i.artifacts,mapping:i.mapping,log:i.log});else{for(const o of i.artifacts)say(`build: ${o}`);null!==i.mapping&&say(`build: mapping ${i.mapping}`)}};
package/lib/run.js CHANGED
@@ -1 +1 @@
1
- import{existsSync,readdirSync,readFileSync,statSync}from"node:fs";import path from"node:path";import{buildOrFail,logDir,logStamp}from"./buildLog.js";import{findCachedBuild,nativeFingerprint,storeCachedBuild}from"./cache.js";import{applicationId,baseAppId,gradleOutputDir,gradleTask,loadToolsConfig,localApiPort,variantName}from"./config.js";import{connectLocalEmulators,describeDevice,listAndroidDevices,pickDevice}from"./devices.js";import{capture}from"./exec.js";import{appBundleId,describeAppleDevice,listAppleDevices}from"./ios.js";import{ensureMetro}from"./metro.js";import{fail,say}from"./output.js";import{adbPath,gradleInvocation,requireDarwin,XCRUN}from"./platform.js";import{prebuild}from"./prebuild.js";import{requireSynced}from"./sync.js";export const readNamespace=e=>/^\s*namespace\s*=?\s*["']([^"']+)["']/m.exec(e)?.[1];export const ABI_PATTERN=/^(arm64-v8a|armeabi-v7a|x86_64|x86)$/;export const chooseApk=(e,a)=>{const i=e.filter(e=>e.endsWith(".apk")).sort();return i.find(e=>e.includes(a))??i.find(e=>e.includes("universal"))??i[0]};const adbOrFail=(e,a,i)=>{const t=capture({file:e,args:a},i);return 0!==t.status?fail("toolFailed",`adb ${a.join(" ")} failed: ${(t.stderr||t.stdout).trim()}`):t.stdout};export const installFailure=e=>/Failure \[[^\]]*\]/.exec(e)?.[0];const UNINSTALL_FIRST=/INSTALL_FAILED_(UPDATE_INCOMPATIBLE|VERSION_DOWNGRADE)/;export const installFailureReason=(e,a,i,t)=>{const r=installFailure(`${e}\n${a}`);if(void 0!==r)return UNINSTALL_FIRST.test(r)?`${r}; run \`adb -s ${i} uninstall ${t}\` (this deletes the app's data), then run again`:r;return[e.trim(),a.trim()].filter(Boolean).join("\n")||"adb gave no reason; check the device is still listed by `adb devices`, then run again"};const installOrFail=(e,a,i,t,r)=>{const s=capture({file:e,args:["-s",a,"install","-r","-t",i]},r);0===s.status&&void 0===installFailure(`${s.stderr}\n${s.stdout}`)||fail("toolFailed",`adb install on ${a} failed: ${installFailureReason(s.stderr,s.stdout,a,t)}`)},elapsedSeconds=e=>((Date.now()-e)/1e3).toFixed(1),cachedBuild=(e,a,i)=>{const t=e.fingerprint.slice(0,12),r=a?void 0:findCachedBuild(e);if(r)return say(`cache: hit ${t} (fingerprint ${i} s), installing the cached build`),r;say(a?"cache: skipped (--rebuild), building":`cache: miss ${t} (fingerprint ${i} s), building`)},DEVICE_METRO_PORT=8081,DEV_HOST_ENTRY=/^\s*<string name="debug_http_host">[^<]*<\/string>\s*$\n?/m;export const withDevHost=(e,a)=>{const i=e.includes("</map>")?e.replace(DEV_HOST_ENTRY,""):"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n<map>\n</map>\n";return void 0===a?i:i.replace("</map>",` <string name="debug_http_host">${a}</string>\n</map>`)};const pointAppAtMetro=(e,a,i,t,r)=>{const s=`shared_prefs/${i}_preferences.xml`;adbOrFail(e,["-s",a,"shell","am","force-stop",i],r);const o=capture({file:e,args:["-s",a,"shell","run-as",i,"cat",s]},r),n=8081===t?void 0:`localhost:${t}`,l=withDevHost(0===o.status?o.stdout:"",n),p=Buffer.from(l,"utf8").toString("base64"),d=capture({file:e,args:["-s",a,"shell",`run-as ${i} sh -c 'mkdir -p shared_prefs && echo ${p} | base64 -d > ${s}'`]},r);0!==d.status&&void 0!==n&&fail("toolFailed",`could not point ${i} at Metro port ${t}: ${(d.stderr||d.stdout).trim()}`),adbOrFail(e,["-s",a,"reverse",`tcp:${t}`,`tcp:${t}`],r)},runAndroid=async e=>{const{appRoot:a,env:i}=e,t=loadToolsConfig(a),r=path.join(a,"android"),s=path.join(r,"app","build.gradle");existsSync(s)||fail("appConfigInvalid",`android/app/build.gradle not found in ${a}`);const o=readNamespace(readFileSync(s,"utf8"))??fail("appConfigInvalid","android/app/build.gradle declares no namespace"),n=adbPath(process.env,process.platform);await connectLocalEmulators(n,a);const l=listAndroidDevices(n,a),p=await pickDevice(l,e.device,describeDevice,!0===process.stdin.isTTY);ABI_PATTERN.test(p.abi)||fail("deviceNotFound",`${describeDevice(p)} reports an ABI this build cannot target: "${p.abi}"`),say(`run: ${describeDevice(p)}`);const d=prebuild({appRoot:a,env:i,platform:"android"}),c=Date.now(),u=await nativeFingerprint(a,"android"),f={appId:baseAppId(a),platform:"android",variant:variantName(i,t.flavors,"debug"),abi:p.abi,fingerprint:u};let m=cachedBuild(f,e.rebuild,elapsedSeconds(c));if(void 0===m){const e=gradleTask(i,t.flavors,"apk","debug"),s=logDir(a);await buildOrFail(gradleInvocation(r,[`:app:${e}`,`-PreactNativeArchitectures=${p.abi}`],process.platform,process.env),r,path.join(s,`gradle-${i}-${logStamp()}.log`),`gradle ${e}`);const o=gradleOutputDir(a,i,t.flavors,"apk","debug"),n=existsSync(o)?chooseApk(readdirSync(o),p.abi):void 0;n||fail("artifactMissing",`the build produced no APK in ${o}`),m=path.join(o,n),storeCachedBuild(f,m),say(`cache: stored ${u.slice(0,12)}`)}const h=applicationId(d.APP_ID,i);say(`run: installing ${path.basename(m)} on ${p.serial}`),installOrFail(n,p.serial,m,h,a);const b=await ensureMetro(a,path.join(logDir(a),"metro.log"),{fixedPort:!1,profiling:e.profiling});if(pointAppAtMetro(n,p.serial,h,b,a),8081!==b&&say(`run: ${h} loads from Metro on port ${b}; port 8081 belongs to another app`),"Development"===i){const e=localApiPort(String(d.BASE_URL),t);void 0!==e&&(adbOrFail(n,["-s",p.serial,"reverse",`tcp:${e}`,`tcp:${e}`],a),say(`run: device localhost:${e} reaches this machine's API`))}adbOrFail(n,["-s",p.serial,"shell","am","start","-n",`${h}/${o}.MainActivity`],a),say(`run: launched ${h} on ${p.model||p.serial}`)},runIos=async e=>{requireDarwin(process.platform,"run --platform ios");const{appRoot:a,env:i}=e;e.rebuild&&fail("badInput","--rebuild applies to Android; an iOS run installs the app --app names");const t=e.app??fail("badInput","run --platform ios installs a simulator app built with xOS Tools: on a host with xos run npx mobile-tools build --env <Env> --artifact ios-sim --debug, bring the .app here, then pass --app <path>"),r=path.resolve(a,t);r.endsWith(".app")&&existsSync(r)&&statSync(r).isDirectory()||fail("badInput",`--app must be a simulator .app folder: ${t}`);const s=await pickDevice(listAppleDevices(a),e.device,describeAppleDevice,!0===process.stdin.isTTY);say(`run: ${describeAppleDevice(s)}`);const o=prebuild({appRoot:a,env:i,platform:"ios"}),n=applicationId(o.APP_ID,i),l=appBundleId(r,a);l!==n&&fail("appConfigInvalid",`${r} is ${l}, but --env ${i} runs ${n}: build the simulator app for ${i}`),await ensureMetro(a,path.join(logDir(a),"metro.log"),{fixedPort:!0,profiling:e.profiling});const p=[["simctl","install",s.udid,r],["simctl","launch",s.udid,n]];for(const e of p){const i=capture({file:XCRUN,args:e},a);0!==i.status&&fail("toolFailed",`xcrun ${e.slice(0,3).join(" ")} failed: ${(i.stderr||i.stdout).trim()}`)}say(`run: launched ${n} on ${s.name}`)};export const run=async e=>{"android"===e.platform&&void 0!==e.app&&fail("badInput","--app installs a simulator app; an Android run builds its own"),requireSynced(e.appRoot),"ios"===e.platform?await runIos(e):await runAndroid(e)};
1
+ import{existsSync,readdirSync,readFileSync,statSync}from"node:fs";import path from"node:path";import{buildOrFail,logDir,logStamp}from"./buildLog.js";import{findCachedBuild,nativeFingerprint,storeCachedBuild}from"./cache.js";import{applicationId,baseAppId,gradleOutputDir,gradleTask,loadToolsConfig,localApiPort,variantName}from"./config.js";import{connectLocalEmulators,describeDevice,listAndroidDevices,pickDevice}from"./devices.js";import{capture}from"./exec.js";import{appBundleId,describeAppleDevice,listAppleDevices}from"./ios.js";import{ensureMetro}from"./metro.js";import{fail,say}from"./output.js";import{adbPath,gradleInvocation,requireDarwin,XCRUN}from"./platform.js";import{prebuild}from"./prebuild.js";import{requireSynced}from"./sync.js";export const readNamespace=e=>/^\s*namespace\s*=?\s*["']([^"']+)["']/m.exec(e)?.[1];export const ABI_PATTERN=/^(arm64-v8a|armeabi-v7a|x86_64|x86)$/;export const chooseApk=(e,a)=>{const i=e.filter(e=>e.endsWith(".apk")).sort();return i.find(e=>e.includes(a))??i.find(e=>e.includes("universal"))??i[0]};const adbOrFail=(e,a,i)=>{const t=capture({file:e,args:a},i);return 0!==t.status?fail("toolFailed",`adb ${a.join(" ")} failed: ${(t.stderr||t.stdout).trim()}`):t.stdout};export const installFailure=e=>/Failure \[[^\]]*\]/.exec(e)?.[0];const UNINSTALL_FIRST=/INSTALL_FAILED_(UPDATE_INCOMPATIBLE|VERSION_DOWNGRADE)/;export const installFailureReason=(e,a,i,t)=>{const r=installFailure(`${e}\n${a}`);if(void 0!==r)return UNINSTALL_FIRST.test(r)?`${r}; run \`adb -s ${i} uninstall ${t}\` (this deletes the app's data), then run again`:r;return[e.trim(),a.trim()].filter(Boolean).join("\n")||"adb gave no reason; check the device is still listed by `adb devices`, then run again"};const installOrFail=(e,a,i,t,r)=>{const s=capture({file:e,args:["-s",a,"install","-r","-t",i]},r);0===s.status&&void 0===installFailure(`${s.stderr}\n${s.stdout}`)||fail("toolFailed",`adb install on ${a} failed: ${installFailureReason(s.stderr,s.stdout,a,t)}`)},elapsedSeconds=e=>((Date.now()-e)/1e3).toFixed(1),cachedBuild=(e,a,i)=>{const t=e.fingerprint.slice(0,12),r=a?void 0:findCachedBuild(e);if(r)return say(`cache: hit ${t} (fingerprint ${i} s), installing the cached build`),r;say(a?"cache: skipped (--rebuild), building":`cache: miss ${t} (fingerprint ${i} s), building`)},DEVICE_METRO_PORT=8081,DEV_HOST_ENTRY=/^\s*<string name="debug_http_host">[^<]*<\/string>\s*$\n?/m;export const withDevHost=(e,a)=>{const i=e.includes("</map>")?e.replace(DEV_HOST_ENTRY,""):"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n<map>\n</map>\n";return void 0===a?i:i.replace("</map>",` <string name="debug_http_host">${a}</string>\n</map>`)};const pointAppAtMetro=(e,a,i,t,r)=>{const s=`shared_prefs/${i}_preferences.xml`;adbOrFail(e,["-s",a,"shell","am","force-stop",i],r);const o=capture({file:e,args:["-s",a,"shell","run-as",i,"cat",s]},r),n=8081===t?void 0:`localhost:${t}`,l=withDevHost(0===o.status?o.stdout:"",n),p=Buffer.from(l,"utf8").toString("base64"),d=capture({file:e,args:["-s",a,"shell",`run-as ${i} sh -c 'mkdir -p shared_prefs && echo ${p} | base64 -d > ${s}'`]},r);0!==d.status&&void 0!==n&&fail("toolFailed",`could not point ${i} at Metro port ${t}: ${(d.stderr||d.stdout).trim()}`),adbOrFail(e,["-s",a,"reverse",`tcp:${t}`,`tcp:${t}`],r)},runAndroid=async e=>{const{appRoot:a,env:i}=e,t=loadToolsConfig(a),r=path.join(a,"android"),s=path.join(r,"app","build.gradle");existsSync(s)||fail("appConfigInvalid",`android/app/build.gradle not found in ${a}`);const o=readNamespace(readFileSync(s,"utf8"))??fail("appConfigInvalid","android/app/build.gradle declares no namespace"),n=adbPath(process.env,process.platform);await connectLocalEmulators(n,a);const l=listAndroidDevices(n,a),p=await pickDevice(l,e.device,describeDevice,!0===process.stdin.isTTY);ABI_PATTERN.test(p.abi)||fail("deviceNotFound",`${describeDevice(p)} reports an ABI this build cannot target: "${p.abi}"`),say(`run: ${describeDevice(p)}`);const d=prebuild({appRoot:a,env:i,platform:"android"}),c=Date.now(),u=await nativeFingerprint(a,"android"),f={appId:baseAppId(a),platform:"android",variant:variantName(i,t.flavors,"debug"),abi:p.abi,fingerprint:u};let m=cachedBuild(f,e.rebuild,elapsedSeconds(c));if(void 0===m){const e=gradleTask(i,t.flavors,"apk","debug"),s=logDir(a);await buildOrFail(gradleInvocation(r,[`:app:${e}`,`-PreactNativeArchitectures=${p.abi}`],process.platform,process.env),r,path.join(s,`gradle-${i}-${logStamp()}.log`),`gradle ${e}`);const o=gradleOutputDir(a,i,t.flavors,"apk","debug"),n=existsSync(o)?chooseApk(readdirSync(o),p.abi):void 0;n||fail("artifactMissing",`the build produced no APK in ${o}`),m=path.join(o,n),storeCachedBuild(f,m),say(`cache: stored ${u.slice(0,12)}`)}const h=applicationId(d.APP_ID,i);say(`run: installing ${path.basename(m)} on ${p.serial}`),installOrFail(n,p.serial,m,h,a);const b=await ensureMetro(a,path.join(logDir(a),"metro.log"),{fixedPort:!1,profiling:e.profiling});if(pointAppAtMetro(n,p.serial,h,b,a),8081!==b&&say(`run: ${h} loads from Metro on port ${b}; port 8081 belongs to another app`),"Development"===i){const e=localApiPort(String(d.BASE_URL),t);void 0!==e&&(adbOrFail(n,["-s",p.serial,"reverse",`tcp:${e}`,`tcp:${e}`],a),say(`run: device localhost:${e} reaches this machine's API`))}adbOrFail(n,["-s",p.serial,"shell","am","start","-n",`${h}/${o}.MainActivity`],a),say(`run: launched ${h} on ${p.model||p.serial}`)},runIos=async e=>{requireDarwin(process.platform,"run --platform ios");const{appRoot:a,env:i}=e;e.rebuild&&fail("badInput","--rebuild applies to Android; an iOS run installs the app --app names");const t=e.app??fail("badInput","run --platform ios installs a simulator app built with xOS Tools: on a host with xos run npx mobile-tools build --env <Env> --artifact ios-sim --debug, bring the .app here, then pass --app <path>"),r=path.resolve(a,t);r.endsWith(".app")&&existsSync(r)&&statSync(r).isDirectory()||fail("badInput",`--app must be a simulator .app folder: ${t}`);const s=await pickDevice(listAppleDevices(a),e.device,describeAppleDevice,!0===process.stdin.isTTY);say(`run: ${describeAppleDevice(s)}`);const o=prebuild({appRoot:a,env:i,platform:"ios"}),n=applicationId(o.APP_ID,i),l=appBundleId(r,a);l!==n&&fail("appConfigInvalid",`${r} is ${l}, but --env ${i} runs ${n}: build the simulator app for ${i}`),await ensureMetro(a,path.join(logDir(a),"metro.log"),{fixedPort:!0,profiling:e.profiling});const p=[["simctl","install",s.udid,r],["simctl","launch",s.udid,n]];for(const e of p){const i=capture({file:XCRUN,args:e},a);0!==i.status&&fail("toolFailed",`xcrun ${e.slice(0,3).join(" ")} failed: ${(i.stderr||i.stdout).trim()}`)}say(`run: launched ${n} on ${s.name}`)};export const run=async e=>{"android"===e.platform&&void 0!==e.app&&fail("badInput","--app installs a simulator app; an Android run builds its own"),requireSynced(e.appRoot,e.platform),"ios"===e.platform?await runIos(e):await runAndroid(e)};
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{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 n=path.join(e,"pnpm-lock.yaml"),s=path.join(e,"package-lock.json");return existsSync(n)&&existsSync(s)?fail("appConfigInvalid","both pnpm-lock.yaml and package-lock.json exist: delete the one not in use"):existsSync(n)?{manager:"pnpm",file:n}:existsSync(s)?{manager:"npm",file:s}:fail("appConfigInvalid",`no package-lock.json or pnpm-lock.yaml in ${e}`)};const filesUnder=(e,n="")=>readdirSync(e,{withFileTypes:!0}).flatMap(s=>{const o=""===n?s.name:`${n}/${s.name}`;return s.isDirectory()?filesUnder(path.join(e,s.name),o):[o]}).sort();export const installHash=e=>{const{file:n}=lockfileOf(e),s=JSON.parse(readFileSync(path.join(e,"package.json"),"utf8")),o=createHash("sha256");o.update(`lockfile:${path.basename(n)}\0`),o.update(readFileSync(n)),o.update("\0package.json\0"),o.update(JSON.stringify(INSTALL_FIELDS.map(e=>[e,s[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 n=path.join(e,STAMP_FILE);if(existsSync(n))try{return JSON.parse(readFileSync(n,"utf8"))}catch{return}};const POD_FIX="cd ios && pod install";export const podsStale=e=>{const n=path.join(e,"ios","Podfile.lock"),s=path.join(e,"ios","Pods","Manifest.lock");return!(!existsSync(n)||!existsSync(s))&&!readFileSync(n).equals(readFileSync(s))};const nodeModulesNewerThanPods=e=>{const n=[path.join(e,"node_modules",".modules.yaml"),path.join(e,"node_modules",".pnpm","lock.yaml")].find(e=>existsSync(e)),s=path.join(e,"ios","Pods","Manifest.lock");return!(!n||!existsSync(s))&&statSync(n).mtimeMs>statSync(s).mtimeMs};export const checkSync=(e,n)=>{const s=[],o=readStamp(e),{file:t}=lockfileOf(e);if(o?o.hash!==installHash(e)&&s.push(`node_modules is stale: ${path.basename(t)}, package.json or patches/ changed since the last install. Fix: npx mobile-tools sync`):s.push("node_modules has no install stamp (never installed through mobile-tools). Fix: npx mobile-tools sync"),o){const n=changedNativePackages(o.nativePackages??{},nativePackages(e));n.length>0&&s.push(`node_modules native packages changed since the last install: ${n.join(", ")}. Fix: npx mobile-tools sync`)}return void 0!==findOnPath("xos",process.env,n)&&podsStale(e)&&s.push(`ios/Pods is stale: ios/Podfile.lock differs from ios/Pods/Manifest.lock. Fix: ${POD_FIX}`),void 0!==findOnPath("xos",process.env,n)&&existsSync(path.join(e,"ios","Podfile.lock"))&&nodeModulesNewerThanPods(e)&&s.push("node_modules changed after the last pod install; run pod install in ios/ (or mobile-tools sync)"),s};export const requireSynced=e=>{const n=checkSync(e,process.platform);n.length>0&&fail("installStale",n.join("\n"))};export const nativePackages=e=>{const n=path.join(e,"node_modules");if(!existsSync(n))return{};const s=[];for(const e of readdirSync(n,{withFileTypes:!0}))if(!e.name.startsWith(".")&&e.isDirectory())if(e.name.startsWith("@"))for(const o of readdirSync(path.join(n,e.name),{withFileTypes:!0}))o.isDirectory()&&s.push(path.join(n,e.name,o.name));else s.push(path.join(n,e.name));const o={};for(const e of s){const n=path.join(e,"android"),s=path.join(e,"package.json");if(existsSync(n)&&statSync(n).isDirectory()&&existsSync(s))try{const e=JSON.parse(readFileSync(s,"utf8"));e.name&&e.version&&(o[e.name]=e.version)}catch{}}return o};export const changedNativePackages=(e,n)=>[...new Set([...Object.keys(e),...Object.keys(n)])].filter(s=>e[s]!==n[s]).sort();export const writeStamp=e=>{const{manager:n}=lockfileOf(e),s={hash:installHash(e),manager:n,nativePackages:nativePackages(e)};return writeFileSync(path.join(e,STAMP_FILE),`${JSON.stringify(s,null,2)}\n`,"utf8"),s};export const installInvocation=(e,n)=>"pnpm"===e?pnpmInvocation(["install","--frozen-lockfile"],process.env,n,process.execPath):npmInvocation(["ci"],process.env,n,process.execPath);export const ensurePods=(e,n)=>{if(!existsSync(path.join(e,"ios","Podfile")))return;const s=path.join(e,"ios","Pods"),o=path.join(e,PODS_RECORD);let t;if(existsSync(s)?existsSync(path.join(e,"ios","Podfile.lock"))?existsSync(path.join(s,"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 i=findOnPath("pod",process.env,n);i||fail("toolMissing",`pod not found on PATH; check xos doctor --json names its shims folder, then ${POD_FIX}`),runInherit({file:i,args:["install"]},path.join(e,"ios"),"pod install");const a=path.join(e,"ios","build","ModuleCache.noindex");existsSync(a)&&(rmSync(a,{recursive:!0,force:!0}),say(`sync: removed ${path.relative(e,a)}`)),writeFileSync(o,JSON.stringify(nativePackages(e)),"utf8")};export const sync=(e,n)=>{const{manager:s}=lockfileOf(e),o=readStamp(e)?.nativePackages??nativePackages(e);say("sync: "+("pnpm"===s?"pnpm install --frozen-lockfile":"npm ci")),runInherit(installInvocation(s,n),e,`${s} install`);const t=writeStamp(e).nativePackages,i=changedNativePackages(o,t),a=path.join(e,"android"),c=existsSync(path.join(a,"app",".cxx"))||existsSync(path.join(a,"app","build"));if(i.length>0&&c){say(`sync: native packages changed (${i.join(", ")}): regenerating codegen`),runInherit(gradleInvocation(a,["generateCodegenArtifactsFromSchema"],n,process.env),a,"gradlew generateCodegenArtifactsFromSchema");for(const n of[path.join(a,"app",".cxx"),path.join(a,"app","build","generated","autolinking")])rmSync(n,{recursive:!0,force:!0}),say(`sync: removed ${path.relative(e,n)}`)}void 0!==findOnPath("xos",process.env,n)&&existsSync(path.join(e,"ios","Podfile"))&&(prependXosShims(xosPath(process.env,n),e),ensurePods(e,n)),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{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 n=path.join(e,"pnpm-lock.yaml"),s=path.join(e,"package-lock.json");return existsSync(n)&&existsSync(s)?fail("appConfigInvalid","both pnpm-lock.yaml and package-lock.json exist: delete the one not in use"):existsSync(n)?{manager:"pnpm",file:n}:existsSync(s)?{manager:"npm",file:s}:fail("appConfigInvalid",`no package-lock.json or pnpm-lock.yaml in ${e}`)};const filesUnder=(e,n="")=>readdirSync(e,{withFileTypes:!0}).flatMap(s=>{const o=""===n?s.name:`${n}/${s.name}`;return s.isDirectory()?filesUnder(path.join(e,s.name),o):[o]}).sort();export const installHash=e=>{const{file:n}=lockfileOf(e),s=JSON.parse(readFileSync(path.join(e,"package.json"),"utf8")),o=createHash("sha256");o.update(`lockfile:${path.basename(n)}\0`),o.update(readFileSync(n)),o.update("\0package.json\0"),o.update(JSON.stringify(INSTALL_FIELDS.map(e=>[e,s[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 n=path.join(e,STAMP_FILE);if(existsSync(n))try{return JSON.parse(readFileSync(n,"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 n=path.join(e,"ios","Podfile.lock"),s=path.join(e,"ios","Pods","Manifest.lock");return!(!existsSync(n)||!existsSync(s))&&!readFileSync(n).equals(readFileSync(s))};const nodeModulesNewerThanPods=e=>{const n=[path.join(e,"node_modules",".modules.yaml"),path.join(e,"node_modules",".pnpm","lock.yaml")].find(e=>existsSync(e)),s=path.join(e,"ios","Pods","Manifest.lock");return!(!n||!existsSync(s))&&statSync(n).mtimeMs>statSync(s).mtimeMs};export const checkSync=(e,n,s=!0)=>{const o=[],t=readStamp(e),{file:i}=lockfileOf(e);if(t?t.hash!==installHash(e)&&o.push(`node_modules is stale: ${path.basename(i)}, 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 n=changedNativePackages(t.nativePackages??{},nativePackages(e));n.length>0&&o.push(`node_modules native packages changed since the last install: ${n.join(", ")}. Fix: npx mobile-tools sync`)}const a=s&&installsPods(n);return a&&podsStale(e)&&o.push(`ios/Pods is stale: ios/Podfile.lock differs from ios/Pods/Manifest.lock. Fix: ${POD_FIX}`),a&&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,n)=>{const s=checkSync(e,process.platform,"ios"===n);s.length>0&&fail("installStale",s.join("\n"))};export const nativePackages=e=>{const n=path.join(e,"node_modules");if(!existsSync(n))return{};const s=[];for(const e of readdirSync(n,{withFileTypes:!0}))if(!e.name.startsWith(".")&&e.isDirectory())if(e.name.startsWith("@"))for(const o of readdirSync(path.join(n,e.name),{withFileTypes:!0}))o.isDirectory()&&s.push(path.join(n,e.name,o.name));else s.push(path.join(n,e.name));const o={};for(const e of s){const n=path.join(e,"android"),s=path.join(e,"package.json");if(existsSync(n)&&statSync(n).isDirectory()&&existsSync(s))try{const e=JSON.parse(readFileSync(s,"utf8"));e.name&&e.version&&(o[e.name]=e.version)}catch{}}return o};export const changedNativePackages=(e,n)=>[...new Set([...Object.keys(e),...Object.keys(n)])].filter(s=>e[s]!==n[s]).sort();export const writeStamp=e=>{const{manager:n}=lockfileOf(e),s={hash:installHash(e),manager:n,nativePackages:nativePackages(e)};return writeFileSync(path.join(e,STAMP_FILE),`${JSON.stringify(s,null,2)}\n`,"utf8"),s};export const installInvocation=(e,n)=>"pnpm"===e?pnpmInvocation(["install","--frozen-lockfile"],process.env,n,process.execPath):npmInvocation(["ci"],process.env,n,process.execPath);export const ensurePods=(e,n)=>{if(!existsSync(path.join(e,"ios","Podfile")))return;const s=path.join(e,"ios","Pods"),o=path.join(e,PODS_RECORD);let t;if(existsSync(s)?existsSync(path.join(e,"ios","Podfile.lock"))?existsSync(path.join(s,"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 i=findOnPath("pod",process.env,n);if(!i){const e=hasXos(n)?"check xos doctor --json names its shims folder":"install CocoaPods (brew install cocoapods)";fail("toolMissing",`pod not found on PATH; ${e}, then ${POD_FIX}`)}runInherit({file:i,args:["install"]},path.join(e,"ios"),"pod install");const a=path.join(e,"ios","build","ModuleCache.noindex");existsSync(a)&&(rmSync(a,{recursive:!0,force:!0}),say(`sync: removed ${path.relative(e,a)}`)),writeFileSync(o,JSON.stringify(nativePackages(e)),"utf8")};export const sync=(e,n)=>{const{manager:s}=lockfileOf(e),o=readStamp(e)?.nativePackages??nativePackages(e);say("sync: "+("pnpm"===s?"pnpm install --frozen-lockfile":"npm ci")),runInherit(installInvocation(s,n),e,`${s} install`);const t=writeStamp(e).nativePackages,i=changedNativePackages(o,t),a=path.join(e,"android"),c=existsSync(path.join(a,"app",".cxx"))||existsSync(path.join(a,"app","build"));if(i.length>0&&c){say(`sync: native packages changed (${i.join(", ")}): regenerating codegen`),runInherit(gradleInvocation(a,["generateCodegenArtifactsFromSchema"],n,process.env),a,"gradlew generateCodegenArtifactsFromSchema");for(const n of[path.join(a,"app",".cxx"),path.join(a,"app","build","generated","autolinking")])rmSync(n,{recursive:!0,force:!0}),say(`sync: removed ${path.relative(e,n)}`)}installsPods(n)&&existsSync(path.join(e,"ios","Podfile"))&&(hasXos(n)&&prependXosShims(xosPath(process.env,n),e),ensurePods(e,n)),say("sync: done")};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/mobile-tools",
3
- "version": "0.119.0",
3
+ "version": "0.120.1",
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",