// Helper for docker-prep.sh --strip-overrides — remove @bytelyst/* keys from
// pnpm.overrides. Reads: PKG_FILE_ARG (path). Writes: $PKG_FILE_ARG in place.
const fs = require('fs');
const f = process.env.PKG_FILE_ARG;
const p = JSON.parse(fs.readFileSync(f, 'utf8'));
if (p.pnpm && p.pnpm.overrides) {
  const filtered = {};
  for (const k of Object.keys(p.pnpm.overrides)) {
    if (!k.startsWith('@bytelyst/')) filtered[k] = p.pnpm.overrides[k];
  }
  if (Object.keys(filtered).length === 0) delete p.pnpm.overrides;
  else p.pnpm.overrides = filtered;
  if (Object.keys(p.pnpm).length === 0) delete p.pnpm;
  fs.writeFileSync(f, JSON.stringify(p, null, 2) + '\n');
}
