Files
OmniRoute/scripts/build/postinstallSupport.mjs
diegosouzapw dd85309e64 fix(ci): hasStandaloneAppBundle dist/->app/ fallback + gate obsidian-plugin e2e
- hasStandaloneAppBundle now accepts the legacy app/ bundle too (mirrors serve
  CLI's dist/->app/ fallback), fixing postinstall-support.test.ts after #3124.
- obsidian-plugin-e2e: #3077 committed the e2e test but NEVER committed its
  dependency obsidian-plugin/src/server.ts (un-ignored but unstaged) nor the
  'obsidian' npm pkg, so it crashed with ERR_MODULE_NOT_FOUND on every fresh
  checkout. Load the runtime values dynamically and skip the suite when absent
  (unit sync logic stays covered by obsidian-plugin-sync.test.ts).
2026-06-03 22:48:24 -03:00

46 lines
1.6 KiB
JavaScript

#!/usr/bin/env node
import { existsSync } from "node:fs";
import { join } from "node:path";
/**
* Detect whether the current install tree contains the published standalone bundle.
* Checks for dist/server.js (Layer 1: renamed from app/server.js).
* Source checkouts will not have dist/ so postinstall skips platform-specific
* native repairs (which only apply to the shipped pre-built bundle).
*
* @param {string} rootDir
* @returns {boolean}
*/
export function hasStandaloneAppBundle(rootDir) {
// The published bundle ships in dist/ (build-output-isolation). Also accept the
// legacy app/ location so an upgrade over a partially-replaced install is still
// detected as a published bundle — mirrors the serve CLI's dist/ -> app/ fallback.
return (
existsSync(join(rootDir, "dist", "server.js")) ||
existsSync(join(rootDir, "app", "server.js"))
);
}
/**
* Returns true when running inside a Termux environment on Android.
*
* Node.js on Termux reports process.platform === "linux" (not "android"),
* so OS-level platform checks are insufficient. Use Termux-specific signals:
* 1. TERMUX_VERSION env var (set by Termux bootstrap, most reliable)
* 2. PREFIX env var containing "com.termux"
* 3. Filesystem probe at /data/data/com.termux (last resort, no env needed)
*
* @param {object} [env] Override process.env for testing.
* @returns {boolean}
*/
export function isTermux(env = process.env) {
if (env.TERMUX_VERSION) return true;
if (typeof env.PREFIX === "string" && env.PREFIX.includes("com.termux")) return true;
try {
return existsSync("/data/data/com.termux");
} catch {
return false;
}
}