78 lines
2.3 KiB
JavaScript
78 lines
2.3 KiB
JavaScript
/**
|
|
* Bundle a lean QVAC Bare worker for the current (or env-specified) host.
|
|
*
|
|
* Used for local dev / pear. Electron Forge packaging runs the same logic via
|
|
* `@qvac/sdk/electron-forge` (QvacForgePlugin).
|
|
*
|
|
* Env:
|
|
* PEARDATA_PACKAGE_PLATFORM / PEARDATA_PACKAGE_ARCH — optional target
|
|
* PEARDATA_SKIP_QVAC=1 — no-op exit 0
|
|
*
|
|
* @see https://docs.qvac.tether.io (qvac bundle sdk / electron-forge)
|
|
*/
|
|
'use strict'
|
|
|
|
const path = require('path')
|
|
const fs = require('fs')
|
|
|
|
const root = path.resolve(__dirname, '..')
|
|
|
|
async function main() {
|
|
if (process.env.PEARDATA_SKIP_QVAC === '1') {
|
|
console.log('[build-qvac-worker] skipped (PEARDATA_SKIP_QVAC=1)')
|
|
return
|
|
}
|
|
|
|
let commands
|
|
try {
|
|
commands = await import('@qvac/sdk/commands')
|
|
} catch (err) {
|
|
console.warn(
|
|
'[build-qvac-worker] @qvac/sdk/commands unavailable — install @qvac/sdk for full LLM packaging.',
|
|
err?.message || err
|
|
)
|
|
process.exitCode = 0
|
|
return
|
|
}
|
|
|
|
const platform = process.env.PEARDATA_PACKAGE_PLATFORM || process.platform
|
|
const arch = process.env.PEARDATA_PACKAGE_ARCH || process.arch
|
|
const host = `${platform}-${arch}`
|
|
const configPath = path.join(root, 'qvac.config.json')
|
|
|
|
console.log(`[build-qvac-worker] bundleSdk hosts=${host}`)
|
|
const result = await commands.bundleSdk({
|
|
projectRoot: root,
|
|
hosts: [host],
|
|
...(fs.existsSync(configPath) ? { configPath } : {}),
|
|
})
|
|
|
|
console.log(
|
|
`[build-qvac-worker] ok addons=${(result.addons || []).length} bundle=${result.bundlePath || '(default)'}`
|
|
)
|
|
|
|
// bundleSdk writes absolute file:// imports — rewrite for packaged / CI clients
|
|
require('./rewrite-qvac-worker-entry.cjs').ensurePortableWorkerEntry({ root })
|
|
|
|
if (typeof commands.verifyBundle === 'function') {
|
|
const verify = await commands.verifyBundle({
|
|
projectRoot: root,
|
|
hosts: [host],
|
|
...(result.bundlePath ? { addonsSource: result.bundlePath } : {}),
|
|
})
|
|
if (commands.hasErrors?.(verify)) {
|
|
const msg =
|
|
typeof commands.formatVerifyBundleResult === 'function'
|
|
? commands.formatVerifyBundleResult(verify)
|
|
: JSON.stringify(verify)
|
|
throw new Error(`verifyBundle failed:\n${msg}`)
|
|
}
|
|
console.log('[build-qvac-worker] verifyBundle ok')
|
|
}
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error('[build-qvac-worker] failed:', err)
|
|
process.exit(1)
|
|
})
|