learning_ai_common_plat/scripts/_docker-prep-inject.js
saravanakumardb1 a418a23e56 feat(scripts): canonical hardened docker-prep + sync tooling (Phase B7)
Promotes docker-prep.sh to canonical home in common-plat with full Phase B
hardening from the docker-build-optimization-roadmap:

- B1: --dry-run mode (lists actions, no side effects)
- B2: idempotency guard (refuses to run if *.bak exists, --force to bypass)
- B5: trap-based auto-restore on error (--keep to disable)
- B6: standardized header + usage block
- B7: canonical home + sync + drift-check (mirrors npmrc.template pattern)
- B8: --strip-overrides for safety-net cleanup
- New: --check mode for CI-friendly state verification
- New: auto-discovers package.json files with @bytelyst/* deps
- New: portable sed -i (BSD on macOS, GNU on Linux)
- New: preserves .docker-deps/.gitkeep on clear (fixes earlier regression)
- New: 2 small JS helpers (_docker-prep-*.js) avoid bash 3.2 heredoc quirks

Verified on clock + peakpulse: dry-run, pack, check, idempotency guard,
restore, and post-restore git status all clean.
2026-05-27 03:48:46 -07:00

10 lines
473 B
JavaScript

// Helper for docker-prep.sh — inject pnpm.overrides for @bytelyst/* tarballs.
// Reads: PKG_FILE_ARG (path), OVERRIDES_ARG (JSON object string)
// 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'));
p.pnpm = p.pnpm || {};
p.pnpm.overrides = Object.assign({}, p.pnpm.overrides || {}, JSON.parse(process.env.OVERRIDES_ARG));
fs.writeFileSync(f, JSON.stringify(p, null, 2) + '\n');