Pin @uswriting/exiftool and patch exit-0 stderr guard on install.
Postinstall removes upstream guards that mark parseMetadata failed when stderr is non-empty after success; Docker dev image copies patches before npm ci.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
# Dependency patches
|
||||
|
||||
## `@uswriting/exiftool@1.0.9` — stderr vs warnings
|
||||
|
||||
We do **not** use a `patch-package` diff here: the published `dist/*.js` files are one minified line each, so unified diffs are huge and hard to review.
|
||||
|
||||
Instead, `patches/patch-exiftool-stderr.mjs` runs on `postinstall` and removes two **documented** guard strings:
|
||||
|
||||
| Guard | Role |
|
||||
| ----- | ---- |
|
||||
| `READ_STDERR_GUARD` | After exit 0 on **read**, fail if stderr is non-empty |
|
||||
| `WRITE_STDERR_GUARD` | After exit 0 on **write**, fail if stderr is non-empty |
|
||||
|
||||
See the script for exact literals and upstream context.
|
||||
|
||||
When upgrading `@uswriting/exiftool`, run `npm install` and confirm the script still finds both guards (or update the script for the new bundle).
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
Reference in New Issue
Block a user