/** * Patch @uswriting/exiftool@1.0.9 after install. * * Problem: parseMetadata / writeMetadata fail when ExifTool prints warnings to stderr * even if exit code is 0 (no stdout / no strip bytes returned). * * Fix: remove the two stderr early-return checks in the published bundle. * Upload safety still relies on post-strip re-read + isCleanAfterStrip (app code). * * Upstream: https://github.com/6over3/exiftool (issue: warnings incorrectly treated as errors) * * Re-verify when bumping @uswriting/exiftool: search dist for these exact snippets. */ import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const READ_STDERR_GUARD = 'if(o&&o.trim())return{success:!1,data:void 0,error:o,exitCode:0};'; const WRITE_STDERR_GUARD = 'if(d&&d.trim())return{success:!1,data:void 0,error:d,exitCode:0};'; const packageRoot = path.resolve( path.dirname(fileURLToPath(import.meta.url)), '../node_modules/@uswriting/exiftool/dist' ); const targets = ['esm/index.js', 'cjs/index.cjs']; const patchFile = (relativePath) => { const filePath = path.join(packageRoot, relativePath); if (!fs.existsSync(filePath)) { throw new Error(`patch-exiftool-stderr: missing ${filePath} (is @uswriting/exiftool installed?)`); } const original = fs.readFileSync(filePath, 'utf8'); const alreadyPatched = !original.includes(READ_STDERR_GUARD) && !original.includes(WRITE_STDERR_GUARD); if (alreadyPatched) { return; } if (!original.includes(READ_STDERR_GUARD) || !original.includes(WRITE_STDERR_GUARD)) { throw new Error( `patch-exiftool-stderr: ${relativePath} does not match @uswriting/exiftool@1.0.9; update or remove this script` ); } const patched = original .replaceAll(READ_STDERR_GUARD, '') .replaceAll(WRITE_STDERR_GUARD, ''); fs.writeFileSync(filePath, patched); }; for (const relativePath of targets) { patchFile(relativePath); }