diff --git a/README.md b/README.md index ef2aa5a..5fcad73 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ npm install -S pdf-to-img NodeJS (using ESM Modules): ```js -const { promises: fs } = require("node:fs"); -const { pdf } = require("pdf-to-img"); +import { promises as fs } from "node:fs"; +import { pdf } from "pdf-to-img"; async function main() { let counter = 1; @@ -45,8 +45,9 @@ main(); If your app does not support ESM modules, just change the import: ```diff - const { promises: fs } = require("node:fs"); -- const { pdf } = require("pdf-to-img"); ++ const { promises: fs } = require("node:fs"); +- import { promises as fs } from "node:fs"; +- import { pdf } from "pdf-to-img"; async function main() { + const { pdf } = await import("pdf-to-img"); diff --git a/bin/cli.mjs b/bin/cli.mjs index 2bc44ee..0f39a6c 100644 --- a/bin/cli.mjs +++ b/bin/cli.mjs @@ -1,7 +1,6 @@ #!/usr/bin/env node // @ts-check -/* eslint-disable import/extensions */ import { promises as fs } from "node:fs"; import { parseArgs } from "node:util"; import { join } from "node:path"; diff --git a/src/index.ts b/src/index.ts index 3fcea5f..e813338 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,14 @@ -import "./polyfill"; // do this before pdfjs - +import "./polyfill.js"; // do this before pdfjs +import { createRequire } from "node:module"; import path from "node:path"; import * as pdfjs from "pdfjs-dist/legacy/build/pdf.mjs"; import type { DocumentInitParameters } from "pdfjs-dist/types/src/display/api.js"; import { NodeCanvasFactory } from "./canvasFactory.js"; import { parseInput } from "./parseInput.js"; -const pdfjsPath = path.dirname(require.resolve("pdfjs-dist/package.json")); +const pdfjsPath = path.dirname( + createRequire(import.meta.url).resolve("pdfjs-dist/package.json") +); /** required since k-yle/pdf-to-img#58, the objects from pdfjs are weirdly structured */ const sanitize = (x: object) => { diff --git a/vitest.config.ts b/vitest.config.ts index ef3f763..49ed429 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -5,7 +5,7 @@ export default defineConfig({ setupFiles: ["./tests/setupTests.ts"], coverage: { provider: "v8", - exclude: ["node_modules", "bin", ".eslintrc.js"], + exclude: ["node_modules", "bin", ".eslintrc.cjs"], }, testTimeout: 30_000, },