// Validate npm's resolution from only the committed manifests, with no node_modules. import { spawnSync } from 'node:child_process'; import { copyFileSync, mkdtempSync, rmSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { fileURLToPath } from 'node:url'; if (!process.env.npm_execpath) throw new Error('Run npm run test:install.'); const fixture = mkdtempSync(join(tmpdir(), 'webka-install-')); try { for (const file of ['package.json', 'package-lock.json']) { copyFileSync(fileURLToPath(new URL(`../frontend/${file}`, import.meta.url)), join(fixture, file)); } const result = spawnSync(process.execPath, [process.env.npm_execpath, 'ci', '--dry-run', '--ignore-scripts', '--no-audit', '--no-fund'], { cwd: fixture, encoding: 'utf8', timeout: 180000 }); if (result.error || result.status !== 0) { console.error(result.stderr || result.error?.message || 'Clean lockfile validation failed.'); process.exitCode = 1; } else console.log('PASS: npm ci accepts the frontend lockfile without an existing node_modules directory.'); } finally { rmSync(fixture, { recursive: true, force: true }); }