4.5 KiB
4.5 KiB
Package: bare-os-seeder
Former DOCUMENTATION.md §11. Reference index →
11. Package: bare-os-seeder
11.1 packages/bare-os-seeder/package.json
main—./index.jsscripts.start/dev—bare index.js(Pear/Bare entry)dependencies—bare-os-protocol(workspace*),bare-fs,bare-path,b4a,compact-encoding,corestore,hyperdrive,hyperswarm,protomux,safety-catchengines.bare—>=2.0.0pear.name—bare-os-seederpear.stage.include—../../node_modules(hoisted workspace deps) andkernel(vendored tree under the package). The seeder readskernel/only at runtime via**readdir/readFile**(no static imports), so Pear’s static analyzer would otherwise omit it from released bundles —kernel directory missingat runtime meanspear stagedid not shipkernel/; fix by keepingkernelinincludeand re-staging afterrsync/verify-kernel-seeder-parity. Withpear stage --compact,includeis required for non-traced assets (Pear configuration uses the heading “includes”; the manifest field isinclude).pear.stage.ignore—.git,test,coverage,.DS_Store,node_modules/.bin,node_modules/.package-lock.jsonimports—#host-fs,#host-path,#host-fs-promises(preferred in first-party sources); legacy keysfs,fs/promises,path,url,node:url— Bare vs Node shims
11.2 packages/bare-os-seeder/lib/paths.js
Pear-safe path resolution (same idea as Holepunch pear-rti MOUNT / swapDir):
packageRootDir(metaUrl)— Ifimport.meta.urlisfile:,path.dirname(fileURLToPath(...))vianode:url. Ifpear:/ other, triesRTI.mount,Pear.config.swapDir,**Pear.app.dir/Pear.config.dir**,RTI.dir, then**process.cwd()** (with**bare-osos.cwd()**fallback when**process.cwd()**is empty) — first directory that contains akernel/subfolder wins; otherwise the first candidate (seepaths.js).defaultKernelRoot(pkgRoot, metaUrl)—BARE_OS_KERNEL_ROOTorpath.join(pkgRoot, 'kernel')(vendored copy under the seeder package for Pear bundles).defaultSeedCorestorePath(pkgRoot, metaUrl)—BARE_OS_SEED_STOREorpath.join(hostDataRoot(), 'corestore', 'seeder')wherehostDataRoot()isBARE_OS_HOST_DATA(resolved) or~/.bare-os. Signature keepspkgRoot/metaUrlfor callers; defaults do not use them.
11.3 packages/bare-os-seeder/index.js
Paths — Uses ./lib/paths.js for _pkg, corestorePath(), and kernelRoot (no fileURLToPath(import.meta.url) on the hot path for pear:).
stageKernelTree(drive, kernelRoot)
- Recursive
walk(rel)using#host-fs-promises(readdir+readFile). - Drive path mapping:
init.js→/boot/init.jsbin/<name>→/bin/<name>(POSIX slashes)etc/...→/etc/...- Any other file →
/<subRel>with slashes normalized
drive.put(drivePath, b4a.from(raw))for each file.
main()
- Optional
console.clear(). maybeBuildCoreutilsFromSource()— only whenimport.meta.urlstarts withfile:(Node /node index.js): dynamic import of../bare-os-coreutils/build.mjsandawait build(). Under Pear (pear://URLs) this is skipped; the bundle must include an up-to-date vendoredkernel/(runnpm run build -w bare-os-coreutilsbeforepear run).Corestore(corestorePath(), bareOsCorestoreConstructOpts())—lib/corestore-opts.jsforwardstreeCache(maxSize: 8192) to Hypercore 7.12+ storage — thenHyperdrive(store),ready().stageKernelTree.localRAM = Map,buildMbr(drive.key),localRAM.set(0, mbr).Hyperswarm, onconnection:Protomux(socket),setupSeedChannel(mux, localRAM, stream => drive.replicate(stream), { manifestPaths, searchMaxMatches })—manifestPathslists every staged drive path so peers can search and RPC against the live manifest.swarm.join(topicKey()),swarm.join(drive.discoveryKey),flush().- Logs topic prefix hex, full drive key hex, Corestore path.
Entry: main().catch(safetyCatch).