| 25 | } |
| 26 | |
| 27 | function npmPack() { |
| 28 | try { |
| 29 | const jsonOut = run('npm', ['pack', '--json', '--silent']); |
| 30 | const arr = JSON.parse(jsonOut); |
| 31 | if (Array.isArray(arr) && arr.length > 0) { |
| 32 | const last = arr[arr.length - 1]; |
| 33 | const file = (last && typeof last === 'object' && last.filename) || (typeof last === 'string' ? last : null); |
| 34 | if (file) return String(file).trim(); |
| 35 | } |
| 36 | // Unexpected JSON shape or empty array; fallback to plain output |
| 37 | const out = run('npm', ['pack', '--silent']).trim(); |
| 38 | const lines = out.split(/\r?\n/); |
| 39 | return lines[lines.length - 1].trim(); |
| 40 | } catch (e) { |
| 41 | // Fallback for environments not supporting --json |
| 42 | const out = run('npm', ['pack', '--silent']).trim(); |
| 43 | const lines = out.split(/\r?\n/); |
| 44 | return lines[lines.length - 1].trim(); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | function main() { |
| 49 | const pkg = JSON.parse(readFileSync(path.join(process.cwd(), 'package.json'), 'utf-8')); |