fix(api): use createRequire for pdf-parse (CJS-only, exports map blocks deep path)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
admin
2026-05-01 12:40:03 +03:00
parent ca06cd7e58
commit 66c99c7d99
+5 -5
View File
@@ -3,13 +3,13 @@ import { mkdtemp, readFile, readdir, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { promisify } from 'node:util';
import { createRequire } from 'node:module';
import mammoth from 'mammoth';
// pdf-parse имеет auto-test mode в index.js, ломающий ESM. Импортируем функцию напрямую из lib.
// @ts-expect-error пакет без declaration на этом пути
import pdfParseRaw from 'pdf-parse/lib/pdf-parse.js';
const pdfParse: (buf: Buffer) => Promise<{ text: string; numpages: number }> =
pdfParseRaw as unknown as (buf: Buffer) => Promise<{ text: string; numpages: number }>;
// pdf-parse — CJS-only. Прямой ESM-импорт ломается из-за auto-test mode в index.js.
// createRequire даёт CJS loader, в котором module.parent определён → test-mode не активен.
const require = createRequire(import.meta.url);
const pdfParse: (buf: Buffer) => Promise<{ text: string; numpages: number }> = require('pdf-parse');
const execFileP = promisify(execFile);