From 176d1ff2a3b1116603a1fd43daeb5dffdb4de0b6 Mon Sep 17 00:00:00 2001 From: Abimael Martell Date: Thu, 2 Apr 2026 14:44:32 -0700 Subject: [PATCH] Remove auto-generated napi files from version control index.js and index.d.ts are generated by napi-rs. Generate them at publish time via `napi prepublish` instead of checking them in. Co-Authored-By: Claude Opus 4.6 --- .github/workflows/publish.yml | 12 + .gitignore | 4 + napi/index.d.ts | 94 ------ napi/index.js | 584 ---------------------------------- 4 files changed, 16 insertions(+), 678 deletions(-) delete mode 100644 napi/index.d.ts delete mode 100644 napi/index.js diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c403447..73a508a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -76,6 +76,18 @@ jobs: with: path: napi/artifacts + - uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + + - name: Install dependencies + working-directory: napi + run: bun install + + - name: Generate JS bindings + working-directory: napi + run: bunx napi prepublish --skip-gh-release + - name: Collect binaries and publish working-directory: napi run: | diff --git a/.gitignore b/.gitignore index 4cfcba6..0c09176 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,10 @@ Thumbs.db # Build cache **/*.rs.bk +# NAPI generated (regenerated by `napi prepublish` during CI) +napi/index.js +napi/index.d.ts + # Local samples and scripts samples/ scripts/ diff --git a/napi/index.d.ts b/napi/index.d.ts deleted file mode 100644 index 904cb76..0000000 --- a/napi/index.d.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* auto-generated by NAPI-RS */ -/* eslint-disable */ -/** - * Lightweight PDF classification — returns type, page count, and OCR pages. - * Faster than detectPdf as it skips building the full PdfResult. - * Pages in pagesNeedingOcr are 0-indexed. - */ -export declare function classifyPdf(buffer: Buffer): PdfClassification - -/** Fast detection only — no text extraction or markdown. */ -export declare function detectPdf(buffer: Buffer): PdfResult - -/** Extract plain text from a PDF Buffer. */ -export declare function extractText(buffer: Buffer): string - -/** - * Extract text within bounding-box regions from a PDF. - * - * For hybrid OCR: layout model detects regions in rendered images, - * this extracts PDF text within those regions — skipping GPU OCR - * for text-based pages. - * - * Each region result includes `needsOcr` — set when the extracted text - * is unreliable (empty, GID-encoded fonts, garbage, encoding issues). - * - * Coordinates are PDF points with top-left origin. - */ -export declare function extractTextInRegions(buffer: Buffer, pageRegions: Array): Array - -/** Extract text with position information from a PDF Buffer. */ -export declare function extractTextWithPositions(buffer: Buffer, pages?: Array | undefined | null): Array - -/** A page's regions for text extraction: (page_index_0based, bboxes). */ -export interface PageRegions { - page: number - /** Each bbox is [x1, y1, x2, y2] in PDF points, top-left origin. */ - regions: Array> -} - -/** Extracted text for one page's regions. */ -export interface PageRegionTexts { - page: number - regions: Array -} - -/** Lightweight PDF classification result. */ -export interface PdfClassification { - pdfType: string - pageCount: number - /** 0-indexed page numbers that need OCR. */ - pagesNeedingOcr: Array - confidence: number -} - -/** Full PDF processing result with markdown and metadata. */ -export interface PdfResult { - pdfType: string - markdown?: string - pageCount: number - processingTimeMs: number - /** 1-indexed page numbers that need OCR. */ - pagesNeedingOcr: Array - title?: string - confidence: number - isComplexLayout: boolean - pagesWithTables: Array - pagesWithColumns: Array - hasEncodingIssues: boolean -} - -/** Process a PDF from a Buffer: detect type, extract text, and convert to Markdown. */ -export declare function processPdf(buffer: Buffer, pages?: Array | undefined | null): PdfResult - -/** Extracted text for a single region. */ -export interface RegionText { - text: string - /** `true` when the text should not be trusted (empty, GID fonts, garbage, encoding issues). */ - needsOcr: boolean -} - -/** A positioned text item extracted from a PDF. */ -export interface TextItem { - text: string - x: number - y: number - width: number - height: number - font: string - fontSize: number - page: number - isBold: boolean - isItalic: boolean - itemType: string -} diff --git a/napi/index.js b/napi/index.js deleted file mode 100644 index 41fb6d2..0000000 --- a/napi/index.js +++ /dev/null @@ -1,584 +0,0 @@ -// prettier-ignore -/* eslint-disable */ -// @ts-nocheck -/* auto-generated by NAPI-RS */ - -const { readFileSync } = require('node:fs') -let nativeBinding = null -const loadErrors = [] - -const isMusl = () => { - let musl = false - if (process.platform === 'linux') { - musl = isMuslFromFilesystem() - if (musl === null) { - musl = isMuslFromReport() - } - if (musl === null) { - musl = isMuslFromChildProcess() - } - } - return musl -} - -const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-') - -const isMuslFromFilesystem = () => { - try { - return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl') - } catch { - return null - } -} - -const isMuslFromReport = () => { - let report = null - if (typeof process.report?.getReport === 'function') { - process.report.excludeNetwork = true - report = process.report.getReport() - } - if (!report) { - return null - } - if (report.header && report.header.glibcVersionRuntime) { - return false - } - if (Array.isArray(report.sharedObjects)) { - if (report.sharedObjects.some(isFileMusl)) { - return true - } - } - return false -} - -const isMuslFromChildProcess = () => { - try { - return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl') - } catch (e) { - // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false - return false - } -} - -function requireNative() { - if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) { - try { - return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH); - } catch (err) { - loadErrors.push(err) - } - } else if (process.platform === 'android') { - if (process.arch === 'arm64') { - try { - return require('./pdf-inspector.android-arm64.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-android-arm64') - const bindingPackageVersion = require('firecrawl-pdf-inspector-android-arm64/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else if (process.arch === 'arm') { - try { - return require('./pdf-inspector.android-arm-eabi.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-android-arm-eabi') - const bindingPackageVersion = require('firecrawl-pdf-inspector-android-arm-eabi/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`)) - } - } else if (process.platform === 'win32') { - if (process.arch === 'x64') { - if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') { - try { - return require('./pdf-inspector.win32-x64-gnu.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-win32-x64-gnu') - const bindingPackageVersion = require('firecrawl-pdf-inspector-win32-x64-gnu/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - try { - return require('./pdf-inspector.win32-x64-msvc.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-win32-x64-msvc') - const bindingPackageVersion = require('firecrawl-pdf-inspector-win32-x64-msvc/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } - } else if (process.arch === 'ia32') { - try { - return require('./pdf-inspector.win32-ia32-msvc.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-win32-ia32-msvc') - const bindingPackageVersion = require('firecrawl-pdf-inspector-win32-ia32-msvc/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else if (process.arch === 'arm64') { - try { - return require('./pdf-inspector.win32-arm64-msvc.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-win32-arm64-msvc') - const bindingPackageVersion = require('firecrawl-pdf-inspector-win32-arm64-msvc/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`)) - } - } else if (process.platform === 'darwin') { - try { - return require('./pdf-inspector.darwin-universal.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-darwin-universal') - const bindingPackageVersion = require('firecrawl-pdf-inspector-darwin-universal/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - if (process.arch === 'x64') { - try { - return require('./pdf-inspector.darwin-x64.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-darwin-x64') - const bindingPackageVersion = require('firecrawl-pdf-inspector-darwin-x64/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else if (process.arch === 'arm64') { - try { - return require('./pdf-inspector.darwin-arm64.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-darwin-arm64') - const bindingPackageVersion = require('firecrawl-pdf-inspector-darwin-arm64/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`)) - } - } else if (process.platform === 'freebsd') { - if (process.arch === 'x64') { - try { - return require('./pdf-inspector.freebsd-x64.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-freebsd-x64') - const bindingPackageVersion = require('firecrawl-pdf-inspector-freebsd-x64/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else if (process.arch === 'arm64') { - try { - return require('./pdf-inspector.freebsd-arm64.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-freebsd-arm64') - const bindingPackageVersion = require('firecrawl-pdf-inspector-freebsd-arm64/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`)) - } - } else if (process.platform === 'linux') { - if (process.arch === 'x64') { - if (isMusl()) { - try { - return require('./pdf-inspector.linux-x64-musl.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-linux-x64-musl') - const bindingPackageVersion = require('firecrawl-pdf-inspector-linux-x64-musl/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - try { - return require('./pdf-inspector.linux-x64-gnu.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-linux-x64-gnu') - const bindingPackageVersion = require('firecrawl-pdf-inspector-linux-x64-gnu/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } - } else if (process.arch === 'arm64') { - if (isMusl()) { - try { - return require('./pdf-inspector.linux-arm64-musl.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-linux-arm64-musl') - const bindingPackageVersion = require('firecrawl-pdf-inspector-linux-arm64-musl/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - try { - return require('./pdf-inspector.linux-arm64-gnu.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-linux-arm64-gnu') - const bindingPackageVersion = require('firecrawl-pdf-inspector-linux-arm64-gnu/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } - } else if (process.arch === 'arm') { - if (isMusl()) { - try { - return require('./pdf-inspector.linux-arm-musleabihf.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-linux-arm-musleabihf') - const bindingPackageVersion = require('firecrawl-pdf-inspector-linux-arm-musleabihf/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - try { - return require('./pdf-inspector.linux-arm-gnueabihf.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-linux-arm-gnueabihf') - const bindingPackageVersion = require('firecrawl-pdf-inspector-linux-arm-gnueabihf/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } - } else if (process.arch === 'loong64') { - if (isMusl()) { - try { - return require('./pdf-inspector.linux-loong64-musl.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-linux-loong64-musl') - const bindingPackageVersion = require('firecrawl-pdf-inspector-linux-loong64-musl/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - try { - return require('./pdf-inspector.linux-loong64-gnu.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-linux-loong64-gnu') - const bindingPackageVersion = require('firecrawl-pdf-inspector-linux-loong64-gnu/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } - } else if (process.arch === 'riscv64') { - if (isMusl()) { - try { - return require('./pdf-inspector.linux-riscv64-musl.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-linux-riscv64-musl') - const bindingPackageVersion = require('firecrawl-pdf-inspector-linux-riscv64-musl/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - try { - return require('./pdf-inspector.linux-riscv64-gnu.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-linux-riscv64-gnu') - const bindingPackageVersion = require('firecrawl-pdf-inspector-linux-riscv64-gnu/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } - } else if (process.arch === 'ppc64') { - try { - return require('./pdf-inspector.linux-ppc64-gnu.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-linux-ppc64-gnu') - const bindingPackageVersion = require('firecrawl-pdf-inspector-linux-ppc64-gnu/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else if (process.arch === 's390x') { - try { - return require('./pdf-inspector.linux-s390x-gnu.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-linux-s390x-gnu') - const bindingPackageVersion = require('firecrawl-pdf-inspector-linux-s390x-gnu/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`)) - } - } else if (process.platform === 'openharmony') { - if (process.arch === 'arm64') { - try { - return require('./pdf-inspector.openharmony-arm64.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-openharmony-arm64') - const bindingPackageVersion = require('firecrawl-pdf-inspector-openharmony-arm64/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else if (process.arch === 'x64') { - try { - return require('./pdf-inspector.openharmony-x64.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-openharmony-x64') - const bindingPackageVersion = require('firecrawl-pdf-inspector-openharmony-x64/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else if (process.arch === 'arm') { - try { - return require('./pdf-inspector.openharmony-arm.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('firecrawl-pdf-inspector-openharmony-arm') - const bindingPackageVersion = require('firecrawl-pdf-inspector-openharmony-arm/package.json').version - if (bindingPackageVersion !== '0.2.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.2.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`)) - } - } else { - loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`)) - } -} - -nativeBinding = requireNative() - -if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) { - let wasiBinding = null - let wasiBindingError = null - try { - wasiBinding = require('./pdf-inspector.wasi.cjs') - nativeBinding = wasiBinding - } catch (err) { - if (process.env.NAPI_RS_FORCE_WASI) { - wasiBindingError = err - } - } - if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) { - try { - wasiBinding = require('firecrawl-pdf-inspector-wasm32-wasi') - nativeBinding = wasiBinding - } catch (err) { - if (process.env.NAPI_RS_FORCE_WASI) { - if (!wasiBindingError) { - wasiBindingError = err - } else { - wasiBindingError.cause = err - } - loadErrors.push(err) - } - } - } - if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) { - const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error') - error.cause = wasiBindingError - throw error - } -} - -if (!nativeBinding) { - if (loadErrors.length > 0) { - throw new Error( - `Cannot find native binding. ` + - `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` + - 'Please try `npm i` again after removing both package-lock.json and node_modules directory.', - { - cause: loadErrors.reduce((err, cur) => { - cur.cause = err - return cur - }), - }, - ) - } - throw new Error(`Failed to load native binding`) -} - -module.exports = nativeBinding -module.exports.classifyPdf = nativeBinding.classifyPdf -module.exports.detectPdf = nativeBinding.detectPdf -module.exports.extractText = nativeBinding.extractText -module.exports.extractTextInRegions = nativeBinding.extractTextInRegions -module.exports.extractTextWithPositions = nativeBinding.extractTextWithPositions -module.exports.processPdf = nativeBinding.processPdf