Deepen all 16 pear-platform scaffolds to production APIs.

Expands spawn, argv, preflight, trust, OTA, pipes, and headless UI modules;
bumps to 0.3.1 with fuller tests and registry tier updates.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-05-21 01:35:15 -04:00
co-authored by Cursor
parent 64a2a824b5
commit 83a0ee684c
51 changed files with 982 additions and 178 deletions
+35 -3
View File
@@ -8,7 +8,8 @@ class HyperBareImportMap extends EventEmitter {
constructor (opts = {}) {
super()
this._imports = {}
this._stats = { loaded: 0, resolved: 0 }
this._conditions = opts.conditions || ['bare', 'default']
this._stats = { loaded: 0, resolved: 0, chained: 0 }
}
loadFromPackage (pkg) {
@@ -19,14 +20,37 @@ class HyperBareImportMap extends EventEmitter {
return this._imports
}
_pickTarget (hit) {
if (typeof hit === 'string') return hit
if (!hit || typeof hit !== 'object') return null
for (const c of this._conditions) {
if (hit[c]) return hit[c]
}
return hit.default || hit.bare || null
}
resolve (specifier) {
const hit = this._imports[specifier]
if (!hit) return null
const target = typeof hit === 'string' ? hit : hit.default || hit.bare || null
const target = this._pickTarget(hit)
this._stats.resolved++
return target
}
resolveChain (specifier, depth = 8) {
let cur = String(specifier)
const chain = [cur]
for (let i = 0; i < depth; i++) {
const next = this.resolve(cur)
if (!next || next === cur) break
if (chain.includes(next)) throw new Error('import cycle detected')
chain.push(next)
cur = next
this._stats.chained++
}
return { specifier, target: cur, chain }
}
map () { return { ...this._imports } }
set (specifier, target) {
@@ -34,12 +58,20 @@ class HyperBareImportMap extends EventEmitter {
return target
}
has (specifier) {
return Object.prototype.hasOwnProperty.call(this._imports, specifier)
}
getStats () {
return platformStats(this._stats, PROTOCOL, { entries: Object.keys(this._imports).length })
}
async ready () { return this }
async close () { this._imports = {}; this.emit('closed') }
async close () {
this._imports = {}
this.emit('closed')
}
}
module.exports = { HyperBareImportMap, HyperP2PBareImportMap: HyperBareImportMap, PROTOCOL }
@@ -1,6 +1,6 @@
{
"name": "hyper-bare-import-map",
"version": "0.0.0-scaffold",
"version": "0.3.1",
"description": "package.json imports map for Bare.",
"main": "index.js",
"type": "commonjs",
@@ -4,7 +4,16 @@ const { HyperBareImportMap } = require('../index.js')
test('imports map', async (t) => {
const m = new HyperBareImportMap()
m.loadFromPackage({ imports: { fs: { bare: 'bare-fs' } } })
t.is(m.resolve('fs'), 'bare-fs')
m.loadFromPackage({ imports: { '#app': './app.js' } })
t.is(m.resolve('#app'), './app.js')
await m.close()
})
test('resolveChain', async (t) => {
const m = new HyperBareImportMap()
m.set('#a', '#b')
m.set('#b', './final.js')
const c = m.resolveChain('#a')
t.is(c.target, './final.js')
await m.close()
})