From 100e7ac93a3b8309327b4c41b87922fcf02de9ca Mon Sep 17 00:00:00 2001 From: Geordan Gesink Date: Tue, 13 Jan 2026 15:07:59 +0100 Subject: [PATCH 1/7] add mobile Pear global --- index.mobile.js | 1 + package.json | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 index.mobile.js diff --git a/index.mobile.js b/index.mobile.js new file mode 100644 index 0000000..54cf673 --- /dev/null +++ b/index.mobile.js @@ -0,0 +1 @@ +global.Pear = {isMobile: true} \ No newline at end of file diff --git a/package.json b/package.json index 3a8b79e..90a059b 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "teardown.js", "terminal.js", "transform.js", - "tryboot.js" + "tryboot.js", + "index.mobile.js" ], "keywords": [ "pear", @@ -57,6 +58,9 @@ "bare": "bare-module" } }, + "exports": { + "./mobile": "./index.mobile.js" + }, "dependencies": { "pear-constants": "^1.0.0", "pear-errors": "^1.0.0", @@ -68,7 +72,8 @@ "pear-ref": "^1.0.2", "pear-run": "^1.0.8", "pear-updates": "^1.0.1", - "pear-wakeups": "^1.0.0" + "pear-wakeups": "^1.0.0", + "which-runtime": "^1.3.2" }, "devDependencies": { "bare-fs": "^4.3.3", From 9f3a8eb7a900f2c252d628dc26dad811167fa9ac Mon Sep 17 00:00:00 2001 From: Geordan Gesink Date: Tue, 13 Jan 2026 15:13:18 +0100 Subject: [PATCH 2/7] lint --- index.mobile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.mobile.js b/index.mobile.js index 54cf673..429da55 100644 --- a/index.mobile.js +++ b/index.mobile.js @@ -1 +1 @@ -global.Pear = {isMobile: true} \ No newline at end of file +global.Pear = { isMobile: true } From bb9b5b67ec7cb63aa25f63c9395262e145feda78 Mon Sep 17 00:00:00 2001 From: Geordan Gesink Date: Wed, 14 Jan 2026 22:24:56 +0100 Subject: [PATCH 3/7] pear-mobile condition --- package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 90a059b..29316e0 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,10 @@ } }, "exports": { - "./mobile": "./index.mobile.js" + ".": { + "pear-mobile": "./index.mobile.js", + "default": "./index.js" + } }, "dependencies": { "pear-constants": "^1.0.0", From d14d7a9224b970fab788e13beba3a02fe89478e5 Mon Sep 17 00:00:00 2001 From: Geordan Gesink Date: Mon, 19 Jan 2026 22:31:31 +0100 Subject: [PATCH 4/7] add bare logger --- index.mobile.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.mobile.js b/index.mobile.js index 429da55..f8f7f8c 100644 --- a/index.mobile.js +++ b/index.mobile.js @@ -1 +1,4 @@ +const SystemLog = require('bare-system-logger') +const Console = require('bare-console') +global.console = new Console(new SystemLog()) global.Pear = { isMobile: true } From 79d587f6d7edb108b1934915d4f7c98b9180ea1b Mon Sep 17 00:00:00 2001 From: Geordan Gesink Date: Mon, 19 Jan 2026 22:32:04 +0100 Subject: [PATCH 5/7] add packages --- package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package.json b/package.json index 29316e0..c489b0b 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,8 @@ } }, "dependencies": { + "bare-console": "^6.1.0", + "bare-system-logger": "^1.0.2", "pear-constants": "^1.0.0", "pear-errors": "^1.0.0", "pear-gracedown": "^1.0.0", From 23e5034703a09c62133ac9aee9a6237a39eab2bf Mon Sep 17 00:00:00 2001 From: Geordan Gesink Date: Sun, 1 Feb 2026 00:30:46 -0600 Subject: [PATCH 6/7] app pear mobile worklet wrapper --- index.mobile.js | 126 +++++++++++++++++++++++++++++++++++++++++++++++- package.json | 9 +++- 2 files changed, 132 insertions(+), 3 deletions(-) diff --git a/index.mobile.js b/index.mobile.js index f8f7f8c..ab84954 100644 --- a/index.mobile.js +++ b/index.mobile.js @@ -1,4 +1,128 @@ const SystemLog = require('bare-system-logger') const Console = require('bare-console') global.console = new Console(new SystemLog()) -global.Pear = { isMobile: true } +const Module = require('bare-module') +const { startsWithWindowsDriveLetter } = require('bare-module-resolve') +const path = require('bare-path') +const fs = require('bare-fs') +const crypto = require('bare-crypto') +const { fileURLToPath, pathToFileURL } = require('bare-url') + +let bundle = Bare.argv.pop() +const filename = Bare.argv.pop() +const assets = null // TODO: support assets + +load() +async function load() { + if (assets !== null) { + let url + + if (startsWithWindowsDriveLetter(assets)) { + url = null + } else { + url = URL.parse(assets) + } + + if (url === null) url = pathToFileURL(assets) + + assets = fileURLToPath(url) + } + + let url + + if (startsWithWindowsDriveLetter(filename)) { + url = null + } else { + url = URL.parse(filename) + } + console.log(url) + if (url === null) url = pathToFileURL(filename) + + if (bundle === null) bundle = Module.protocol.read(url) + else bundle = Buffer.from(bundle) + + if (assets !== null && path.extname(url.href) === '.bundle') { + const bundle = Bundle.from(bundle) + + if (bundle.id !== null && bundle.assets.length > 0) { + const id = crypto.createHash('blake2b256').update(bundle.id).digest('hex') + + const root = path.join(assets, id) + + const tmp = fs.existsSync(root) ? null : path.join(assets, 'tmp') + + if (tmp !== null) { + fs.rmSync(tmp, { recursive: true, force: true }) + fs.mkdirSync(tmp, { recursive: true }) + } + + bundle = await unpack(bundle, { files: false, assets: true }, (key) => { + if (tmp !== null) { + const target = path.join(tmp, key) + + fs.mkdirSync(path.dirname(target), { recursive: true }) + fs.writeFileSync(target, bundle.read(key)) + } + + return pathToFileURL(path.join(root, key)).href + }) + + if (tmp !== null) fs.renameSync(tmp, root) + } + } + + const cache = Object.create(null) // use clean cache to avoid id collisions + + Module.load(url, bundle, {cache}) +} + + +const goodbye = require('graceful-goodbye') + +global.Pear = {} +global.Pear.test = "test" +global.Pear.isMobile = true + +console.log('logging bare api', Bare) +global.Pear.versions = () => { return { runtimes: { bare: Bare.versions.bare }, engines: {}}} +global.Pear.exit = (code) => Bare.exit(code) +global.Pear.argv = Bare.argv +global.Pear.pid = Bare.pid +global.Pear.exitCode = Bare.exitCode +global.Pear.teardown = goodbye +global.Pear.checkpoint = null // +global.Pear.app = null // need stage create config from im pear-state + +// eg: +// id, +// startId, +// key, +// links, +// alias, +// env, +// gui, +// assets, +// options, +// checkpoint, +// checkout, +// flags, +// dev, +// stage, +// storage, +// name, +// main, +// args, +// channel, +// release, +// applink, +// query, +// fragment, +// link, +// linkData, +// entrypoint, +// route, +// routes, +// dir, +// dht, +// prerunning, +// version diff --git a/package.json b/package.json index c489b0b..d1a4cdc 100644 --- a/package.json +++ b/package.json @@ -62,11 +62,16 @@ ".": { "pear-mobile": "./index.mobile.js", "default": "./index.js" - } + }, + "./wrapper": "./index.mobile.js" }, "dependencies": { "bare-console": "^6.1.0", + "bare-crypto": "^1.13.0", + "bare-module-resolve": "^1.12.1", "bare-system-logger": "^1.0.2", + "bare-url": "^2.3.2", + "graceful-goodbye": "^1.3.3", "pear-constants": "^1.0.0", "pear-errors": "^1.0.0", "pear-gracedown": "^1.0.0", @@ -81,7 +86,7 @@ "which-runtime": "^1.3.2" }, "devDependencies": { - "bare-fs": "^4.3.3", + "bare-fs": "^4.5.3", "bare-module": "^5.0.3", "bare-os": "^3.6.2", "bare-path": "^3.0.0", From bed727465656675aabb2c5cda855ee2cd2333b94 Mon Sep 17 00:00:00 2001 From: Geordan Gesink Date: Tue, 3 Feb 2026 16:30:06 -0600 Subject: [PATCH 7/7] api class --- index.mobile.js | 120 ++++++++++++++++++++++++++++-------------------- 1 file changed, 69 insertions(+), 51 deletions(-) diff --git a/index.mobile.js b/index.mobile.js index ab84954..34e29c2 100644 --- a/index.mobile.js +++ b/index.mobile.js @@ -7,12 +7,81 @@ const path = require('bare-path') const fs = require('bare-fs') const crypto = require('bare-crypto') const { fileURLToPath, pathToFileURL } = require('bare-url') +const os = require('bare-os') +const goodbye = require('graceful-goodbye') let bundle = Bare.argv.pop() const filename = Bare.argv.pop() const assets = null // TODO: support assets +class API { + constructor (){ + this.isMobile = true + this.argv = Bare.argv + this.pid = Bare.pid + this.exitCode = Bare.exitCode + this.app = {} // need to adjust + + this.app.startId = crypto.randomBytes(16).toString('hex') // ID for the thread + this.app.id = null // `${client.id}@${startId}` + + } + + checkpoint (state) { + global.Pear.app.checkpoint = state + // return ref.track(this.#ipc.checkpoint(state)) // TODO: find equivalent + } + + versions () { + return { runtimes: { bare: Bare.versions.bare }, engines: {}} + } + + exit () { + return os.kill(Bare.pid, 'SIGTERM') + } + + teardown (callback, position){ + return goodbye(callback, position) + } +} + +// eg: +// id, +// startId, +// key, +// links, +// alias, +// env, +// gui, +// assets, +// options, +// checkpoint, +// checkout, +// flags, +// dev, +// stage, +// storage, +// name, +// main, +// args, +// channel, +// release, +// applink, +// query, +// fragment, +// link, +// linkData, +// entrypoint, +// route, +// routes, +// dir, +// dht, +// prerunning, +// version + +global.Pear = new API() load() + async function load() { if (assets !== null) { let url @@ -75,54 +144,3 @@ async function load() { Module.load(url, bundle, {cache}) } - - -const goodbye = require('graceful-goodbye') - -global.Pear = {} -global.Pear.test = "test" -global.Pear.isMobile = true - -console.log('logging bare api', Bare) -global.Pear.versions = () => { return { runtimes: { bare: Bare.versions.bare }, engines: {}}} -global.Pear.exit = (code) => Bare.exit(code) -global.Pear.argv = Bare.argv -global.Pear.pid = Bare.pid -global.Pear.exitCode = Bare.exitCode -global.Pear.teardown = goodbye -global.Pear.checkpoint = null // -global.Pear.app = null // need stage create config from im pear-state - -// eg: -// id, -// startId, -// key, -// links, -// alias, -// env, -// gui, -// assets, -// options, -// checkpoint, -// checkout, -// flags, -// dev, -// stage, -// storage, -// name, -// main, -// args, -// channel, -// release, -// applink, -// query, -// fragment, -// link, -// linkData, -// entrypoint, -// route, -// routes, -// dir, -// dht, -// prerunning, -// version