UNPKG

consortium

Version:

Remote control and session sharing CLI for AI coding agents

49 lines (44 loc) 1.78 kB
#!/usr/bin/env node /** * Post-build helper for the bundled Pi permission extension. * * pkgroll emits `dist/pi/ext/consortium-permission/index.cjs` from the * TS source, but does NOT copy the sibling `package.json` (it isn't a * code file). Pi's extension loader needs the manifest to resolve * `main: "index.js"`, so we copy it post-build and additionally alias * `index.cjs` to `index.js` so Pi can `require()` it without any * package.json edits. * * Run from `package.json`: "build": "... && node scripts/copy-pi-ext-pkg.cjs" */ 'use strict'; const fs = require('node:fs'); const path = require('node:path'); const repoRoot = path.resolve(__dirname, '..'); const srcDir = path.join(repoRoot, 'src/pi/ext/consortium-permission'); const distDir = path.join(repoRoot, 'dist/pi/ext/consortium-permission'); if (!fs.existsSync(distDir)) { console.warn(`[copy-pi-ext-pkg] dist dir missing, skipping: ${distDir}`); process.exit(0); } // Copy package.json from src const pkgSrc = path.join(srcDir, 'package.json'); const pkgDest = path.join(distDir, 'package.json'); if (fs.existsSync(pkgSrc)) { fs.copyFileSync(pkgSrc, pkgDest); console.log(`[copy-pi-ext-pkg] wrote ${pkgDest}`); } else { console.warn(`[copy-pi-ext-pkg] source manifest missing: ${pkgSrc}`); } // Alias index.cjs -> index.js so pi's loader (require) finds it as the // manifest's `main`. We hard-link if possible, otherwise copy. const cjs = path.join(distDir, 'index.cjs'); const js = path.join(distDir, 'index.js'); if (fs.existsSync(cjs) && !fs.existsSync(js)) { try { fs.copyFileSync(cjs, js); console.log(`[copy-pi-ext-pkg] aliased ${js} -> ${cjs}`); } catch (err) { console.warn(`[copy-pi-ext-pkg] alias failed: ${err.message}`); } }