// Verify the BUILT worklet bundle carries every browser file favela-surface serves.
//
// ⛔ WHY THIS EXISTS. favela-surface used to fill its /static/ map by reading its own static/ directory
// at boot. On a desktop that directory is on disk. In this app the surface runs from worklet.bundle,
// and bare-pack packs only what the module graph IMPORTS — a directory read at runtime is invisible to
// it. So readdirSync failed inside the bundle, the try/catch turned that into an empty list, and every
// /static/*.js on the phone was a 404:
//
// composer.js never ran, so a photo posted from the phone was ONE level with no pyramid. A 2,645,504
// byte photo then had no level under bsky's 2,000,000 ceiling and the bridge withheld
// it — the post reached bsky with no image while Mastodon (no ceiling) showed it.
// the @-picker, explore's three.js, the anproto client — all silently absent the same way.
//
// Nothing reported it: a module script that 404s is a page that quietly does nothing. favela-surface now
// imports static/ as text modules so bare-pack sees them; this reads the ARTIFACT so a regression fails
// the build instead of a handset.
//
// Usage: bare scripts/verify-bundle-static.mjs [path/to/worklet.bundle]
import fs from 'bare-fs'
import path from 'bare-path'
import process from 'bare-process'
import b4a from 'b4a'
import Bundle from 'bare-bundle'
const bundlePath = process.argv[2] || 'android/app/src/main/assets/worklet.bundle'
const staticDir = path.resolve('node_modules/favela-surface/static')
const bundle = Bundle.from(fs.readFileSync(bundlePath))
const files = fs.readdirSync(staticDir).filter((f) => f.endsWith('.js')).sort()
if (!files.length) {
console.error('verify-bundle-static: no .js files in ' + staticDir + ' — wrong directory, not a pass')
process.exit(1)
}
const missing = []
const differ = []
for (const f of files) {
const key = '/node_modules/favela-surface/static/' + f
if (!bundle.exists(key)) { missing.push(f); continue }
if (!b4a.equals(bundle.read(key), fs.readFileSync(path.join(staticDir, f)))) differ.push(f)
}
if (missing.length || differ.length) {
if (missing.length) console.error('verify-bundle-static: NOT in ' + bundlePath + ': ' + missing.join(', '))
if (differ.length) console.error('verify-bundle-static: bytes DIFFER from static/: ' + differ.join(', '))
process.exit(1)
}
console.log('verify-bundle-static: all ' + files.length + ' favela-surface static files are in ' + bundlePath)