qpdf-node 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,11 +10,12 @@ Extract, merge and split PDF pages from Node.js and (experimentally) the browser
10
10
 
11
11
  No `qpdf` executable is spawned, and the stale third-party `qpdf-wasm` npm package is not used.
12
12
 
13
- > **Status: pre-release (0.2.0).** Not yet published to npm. The release workflow
14
- > (`.github/workflows/release.yml`) is written to publish one package with prebuilt addons for every
15
- > supported platform, but it has not run yet:
16
- > see [Releasing](#releasing) and [Platform support](#platform-support) for what is and is not verified.
17
- > This package replaces the earlier `pdq-node` (Rust/pdq); see
13
+ > **Status: 0.2.1 (prepared, not yet released).** `qpdf-node@0.2.0` is on npm as a single bundled
14
+ > package; 0.2.1 is the first release with per-platform packages (see
15
+ > [0.2.0 versus 0.2.1](#020-versus-021)). The release workflow
16
+ > (`.github/workflows/release.yml`) is written to build and test the prebuilt addons on every
17
+ > supported platform, but has not run for 0.2.1 yet; see [Releasing](#releasing) and [Platform support](#platform-support) for what is and is not
18
+ > verified. This package replaces the earlier `pdq-node` (Rust/pdq); see
18
19
  > [Changes from pdq-node](#changes-from-pdq-node).
19
20
 
20
21
  ## Install
@@ -23,32 +24,56 @@ No `qpdf` executable is spawned, and the stale third-party `qpdf-wasm` npm packa
23
24
  npm install qpdf-node
24
25
  ```
25
26
 
26
- `qpdf-node` is **one package** that contains the JavaScript, the type declarations and the native
27
- addon for every supported platform (see [Platform support](#platform-support)). There are no
28
- platform packages, no `optionalDependencies` and no install scripts, so `--omit=optional`,
29
- `--ignore-scripts` and copying `node_modules` between machines of the same platform all work. The
30
- package is **about 17 MB unpacked and 6-7 MB compressed** (five addons of roughly 3 MB each; the
31
- exact size is printed by `npm pack` and by `pnpm smoke:package`).
27
+ That is the only package you install. You never choose a platform: `qpdf-node` lists one
28
+ platform package per supported system in `optionalDependencies`, each marked with `os`, `cpu` and
29
+ (on Linux) `libc`, so npm, pnpm and yarn download only the one that matches your machine. The
30
+ platform packages (`qpdf-node-darwin-arm64`, `qpdf-node-darwin-x64`, `qpdf-node-linux-x64-gnu`,
31
+ `qpdf-node-linux-arm64-gnu`, `qpdf-node-win32-x64-msvc`) are an implementation detail: they hold the
32
+ native addon and have no API, so do not depend on them directly. There are no install scripts and no
33
+ download at install time.
34
+
35
+ Package sizes (measured on the darwin-arm64 package; the other four are expected to be similar
36
+ since they are built from the same sources, but have not been measured):
37
+
38
+ | Package | Compressed | Unpacked |
39
+ | -------------------------- | ------------ | ------------ |
40
+ | `qpdf-node` (root) | about 31 kB | about 94 kB |
41
+ | one platform package | about 1.0 MB | about 2.6 MB |
42
+ | what `npm install` fetches | about 1.0 MB | about 2.7 MB |
43
+
44
+ The exact sizes are printed by `npm pack` and by `pnpm smoke:packages`.
45
+
46
+ Install without optional dependencies (`--omit=optional`, `--no-optional`) or copy `node_modules`
47
+ between platforms, and the platform package is missing: the loader then fails with an error that
48
+ names the missing package. Reinstall on the target machine.
49
+
50
+ ### 0.2.0 versus 0.2.1
51
+
52
+ - **`qpdf-node@0.2.0`** was published as one self-contained package that bundled all five addons
53
+ (roughly 17 MB unpacked and 6-7 MB compressed, an estimate from five addons of about 3 MB each) and had no `optionalDependencies`. It stays on npm
54
+ unchanged: npm versions are immutable.
55
+ - **`qpdf-node@0.2.1` and later** use the layout above: a JavaScript-only root package plus one small
56
+ platform package per system. Installing is smaller and faster, and the API is identical. Nothing
57
+ in your code changes; just `npm install qpdf-node@latest`.
32
58
 
33
59
  At load time the addon is looked up in this order:
34
60
 
35
61
  1. `build/Release/qpdf_node.node` inside the package directory: a source checkout after
36
62
  `pnpm run build:native`. Published packages do not contain it.
37
- 2. `native/qpdf_node.<target>.node` inside the package, chosen for the running Node.js (the names are
38
- in the table below).
63
+ 2. The platform package for the running Node.js (`qpdf-node-<platform>-<arch>[-abi]`).
39
64
 
40
65
  A file that exists but fails to load is reported as is, and an unsupported platform gets an error
41
- that lists the bundled addons.
66
+ that lists the supported packages.
42
67
 
43
68
  ## Platform support
44
69
 
45
- | Bundled file (`native/`) | OS / CPU | Built on GitHub runner | Notes |
46
- | -------------------------------- | -------------------- | ---------------------- | --------------------------------------------------- |
47
- | `qpdf_node.darwin-arm64.node` | macOS, Apple silicon | `macos-15` | Locally built and tested. Minimum macOS 12. |
48
- | `qpdf_node.darwin-x64.node` | macOS, Intel | `macos-15-intel` | Built by CI only. Minimum macOS 12. |
49
- | `qpdf_node.linux-x64-gnu.node` | Linux x64, glibc | `ubuntu-22.04` | Built by CI only. glibc 2.35 or newer. |
50
- | `qpdf_node.linux-arm64-gnu.node` | Linux arm64, glibc | `ubuntu-22.04-arm` | Built by CI only. glibc 2.35 or newer. |
51
- | `qpdf_node.win32-x64-msvc.node` | Windows x64 | `windows-2022` | Built by CI only. Needs the Microsoft VC++ runtime. |
70
+ | Platform package (installed automatically) | OS / CPU | Built on GitHub runner | Notes |
71
+ | ------------------------------------------ | -------------------- | ---------------------- | --------------------------------------------------- |
72
+ | `qpdf-node-darwin-arm64` | macOS, Apple silicon | `macos-15` | Locally built and tested. Minimum macOS 12. |
73
+ | `qpdf-node-darwin-x64` | macOS, Intel | `macos-15-intel` | Built by CI only. Minimum macOS 12. |
74
+ | `qpdf-node-linux-x64-gnu` | Linux x64, glibc | `ubuntu-22.04` | Built by CI only. glibc 2.35 or newer. |
75
+ | `qpdf-node-linux-arm64-gnu` | Linux arm64, glibc | `ubuntu-22.04-arm` | Built by CI only. glibc 2.35 or newer. |
76
+ | `qpdf-node-win32-x64-msvc` | Windows x64 | `windows-2022` | Built by CI only. Needs the Microsoft VC++ runtime. |
52
77
 
53
78
  **Not supported:** musl Linux (Alpine), 32-bit systems, Windows arm64, FreeBSD. The loader reports
54
79
  these as unsupported (musl is detected and is not mistaken for glibc); build from source there.
@@ -253,20 +278,24 @@ verified in a browser.
253
278
 
254
279
  ## Releasing
255
280
 
256
- The release is **one npm package, `qpdf-node`**, holding the compiled TypeScript and all five
257
- addons in `native/` (see the [table above](#platform-support)). Expect roughly 17 MB unpacked and
258
- 6-7 MB compressed.
259
-
260
- The workspace manifest `packages/node/package.json` is `private`. The published package is staged by
261
- checked-in scripts into `build/npm/qpdf-node`:
262
-
263
- | Command | What it does |
264
- | ----------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
265
- | `pnpm verify:release [--tag vX.Y.Z]` | Checks that package version, `CMakeLists.txt` version, the tag, the repository URL and the workflow's runner list agree. |
266
- | `pnpm stage:addon [--target T] [--addon F] [--out D]` | Copies a built addon to `D/qpdf_node.<T>.node` (defaults: this machine, the built addon, `build/addons`). |
267
- | `pnpm --filter qpdf-node run build:ts && pnpm package:root` | Stages `qpdf-node` into `build/npm`: compiled JS and declarations, `native/` with **all five** addons from `build/addons`, license files, README. Fails if any addon is missing. |
268
- | `pnpm smoke:package --package DIR` | Packs the staged package, checks the tarball contents, installs the tarball into an empty project with no `build/`, runs a PDF operation and checks which addon file loaded. |
269
- | `pnpm publish:package [--dir build/npm] [--dry-run]` | Publishes `qpdf-node` (skipped if that version is already on the registry). |
281
+ Six packages, all at the same version: the five platform packages of the
282
+ [table above](#platform-support) and the root `qpdf-node`. The root lists every platform package in
283
+ `optionalDependencies` at that exact version; npm installs only the one whose `os`, `cpu` and `libc`
284
+ fields match the machine. The root contains no binary, and each platform package contains one
285
+ `qpdf_node.node`, `LICENSE` and `THIRD_PARTY_NOTICES.md` (qpdf's Apache-2.0 license and notices).
286
+
287
+ The workspace manifest `packages/node/package.json` is `private` and does not list the platform
288
+ packages (they are not on the registry before a release, so `pnpm install --frozen-lockfile` could not
289
+ resolve them). Published packages are instead staged by checked-in scripts into `build/npm/`:
290
+
291
+ | Command | What it does |
292
+ | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
293
+ | `pnpm verify:release [--tag vX.Y.Z]` | Checks that package version, `CMakeLists.txt` version, the tag, the repository URL, the root scripts and the workflow's runner list agree. |
294
+ | `pnpm stage:addon [--target T] [--addon F] [--out D]` | Copies a built addon to `D/qpdf_node.<T>.node` (the CI artifact name; defaults: this machine, built addon, `build/addons`). |
295
+ | `pnpm package:platform --all --addons D [--out build/npm]` | Stages all five `qpdf-node-<T>` packages from `D/qpdf_node.<T>.node`; fails if one is missing. `--target T [--addon F]` stages one. |
296
+ | `pnpm --filter qpdf-node run build:ts && pnpm package:root` | Stages `qpdf-node` (compiled JS, declarations, license files, `optionalDependencies`). It contains no binary. |
297
+ | `pnpm smoke:packages --root DIR --platform DIR` | Packs the root and one platform package, installs both into an empty project with no `build/`, runs a PDF operation and checks the addon was loaded from the platform package. |
298
+ | `pnpm publish:packages [--dir build/npm] [--dry-run]` | Publishes the five platform packages first and `qpdf-node` last; skips versions already on the registry. |
270
299
 
271
300
  To cut a release: bump `version` in `packages/node/package.json` **and** `project(... VERSION ...)` in
272
301
  `CMakeLists.txt`, merge, then push the tag `vX.Y.Z`. The workflow `release.yml` then:
@@ -274,18 +303,20 @@ To cut a release: bump `version` in `packages/node/package.json` **and** `projec
274
303
  1. `prepare`: `pnpm check` and `verify:release`.
275
304
  2. `build-native` (one job per platform, in parallel): `pnpm build`, `pnpm test` against the built
276
305
  addon, then uploads the addon as `qpdf_node.<target>.node` (artifact `addon-<target>`).
277
- 3. `package`: downloads all five addons, builds the TypeScript and stages the single `qpdf-node`
278
- package (artifact `qpdf-node`).
279
- 4. `test-artifacts` (per platform, Node.js 20): downloads that package, packs it, installs the tarball
280
- into an empty project and runs `smoke:package`. This proves the package layout and the loader on
281
- each supported runner, not just the build.
282
- 5. `publish`: publishes `qpdf-node`. A failure in any earlier job stops the release before anything is
283
- published. Versions with a prerelease suffix (`0.3.0-rc.1`) are published under the `next` dist-tag.
306
+ 3. `package`: downloads all five addons, builds the TypeScript and stages the five platform packages
307
+ and the root package (artifact `npm-packages`).
308
+ 4. `test-artifacts` (per platform, Node.js 20): downloads the packages, packs the root and that
309
+ platform's package, installs both into an empty project and runs `smoke:packages`. This proves the
310
+ package layout and the loader on each supported runner, not just the build.
311
+ 5. `publish`: publishes the five platform packages, then `qpdf-node`. A failure in any earlier job
312
+ stops the release before anything is published. If a publish fails part-way, fix the cause and
313
+ re-run the job: versions already published are skipped. Versions with a prerelease suffix
314
+ (`0.3.0-rc.1`) are published under the `next` dist-tag.
284
315
  6. `wasm-build` runs independently (see [WebAssembly build](#webassembly-build)); it is not part of
285
- the npm package.
316
+ the npm packages.
286
317
 
287
- Running the workflow by hand (Actions, "Run workflow") does steps 1-4 and `npm publish --dry-run`.
288
- It publishes nothing and needs no npm credentials.
318
+ Running the workflow by hand (Actions, "Run workflow") does steps 1-4 and `npm publish --dry-run` of
319
+ all six packages. It publishes nothing and needs no npm credentials.
289
320
 
290
321
  The staged `repository`, `homepage` and `bugs` fields point at `taoche/qpdf-node`
291
322
  (`QPDF_NODE_REPOSITORY_URL` or `GITHUB_REPOSITORY` overrides `repository`). npm provenance requires the
@@ -294,11 +325,12 @@ published `repository` to match the repository that runs the workflow.
294
325
  ### What was and was not validated locally
295
326
 
296
327
  Validated on macOS arm64: `pnpm install --frozen-lockfile`, `pnpm check`, `pnpm build`, `pnpm test`,
297
- `verify:release`, `stage:addon`, `package:root`, `npm pack --dry-run`, `publish:package --dry-run`, and
298
- `smoke:package` (the tarball installed into an empty project; the addon loads from
299
- `node_modules/qpdf-node/native/qpdf_node.darwin-arm64.node`). Locally the other four addon files were
300
- stand-in copies of the arm64 addon, so the package size printed locally (about 13 MB unpacked, 5 MB
301
- compressed) is not the real one, and only the darwin-arm64 selection was exercised end to end. The
328
+ `verify:release`, `stage:addon`, `package:platform --all`, `package:root`, `publish:packages --dry-run`
329
+ (all six packages), and `smoke:packages` (root and `qpdf-node-darwin-arm64` tarballs installed into an
330
+ empty project; the addon loads from `node_modules/qpdf-node-darwin-arm64/qpdf_node.node`). Installing
331
+ only the root tarball, with its five platform packages redirected to local tarballs, installed just the
332
+ darwin-arm64 one, which shows npm's `os`/`cpu` selection. Locally the other four addon files were
333
+ stand-in copies of the arm64 addon, so only the darwin-arm64 selection was exercised end to end. The
302
334
  loader's choice for the other targets and for musl is covered by unit tests with a fake file system.
303
335
 
304
336
  **Not validated locally:** the Linux, Windows and macOS x64 builds, the per-runner tarball smoke
@@ -311,19 +343,19 @@ manual "Run workflow" dry run before pushing a tag.
311
343
 
312
344
  ### npm credentials
313
345
 
314
- Only `qpdf-node` is published. Two options:
315
-
316
- - **Token (needed for the first publish).** Create a granular access token on npmjs.com that may
317
- publish `qpdf-node` (for a package that does not exist yet, npm needs a token allowed to create new
318
- packages, for example scoped to all packages, which you can narrow afterwards) and store it as the
319
- repository secret `NPM_TOKEN`. The workflow passes it only to the publish step as `NODE_AUTH_TOKEN`;
320
- npm does not print it. Use an account with 2FA enforced for publishing "authorization only", or an
321
- automation token, since CI cannot enter a one-time password.
322
- - **Trusted publishing (recommended after the first release).** In the package's settings on npmjs.com,
323
- add a GitHub Actions trusted publisher: this repository and workflow file `release.yml`. Trusted
324
- publishers can only be added to packages that already exist, hence the token for the first release.
325
- The publish job has `id-token: write` and runs Node.js 24 (npm 11.5.1 or newer, as trusted
326
- publishing requires); once configured, delete `NPM_TOKEN`. On tag pushes the scripts pass
346
+ All five platform packages and `qpdf-node` must be publishable by the workflow. Two options:
347
+
348
+ - **Token (needed for the first publish of the platform packages).** The platform package names do not
349
+ exist yet, so the token must be allowed to create new packages (for example a granular token
350
+ with read/write on all packages, which you can narrow afterwards) and also publish `qpdf-node`.
351
+ Store it as the repository secret `NPM_TOKEN`. The workflow passes it only to the publish step as
352
+ `NODE_AUTH_TOKEN`; npm does not print it. Use an account with 2FA enforced for publishing
353
+ "authorization only", or an automation token, since CI cannot enter a one-time password.
354
+ - **Trusted publishing (recommended after the first release).** In each package's settings on
355
+ npmjs.com, add a GitHub Actions trusted publisher: this repository and workflow file `release.yml`.
356
+ Trusted publishers can only be added to packages that already exist, hence the token for the first
357
+ release. The publish job has `id-token: write` and runs Node.js 24 (npm 11.5.1 or newer, as
358
+ trusted publishing requires); once configured, delete `NPM_TOKEN`. On tag pushes the scripts pass
327
359
  `--provenance`.
328
360
 
329
361
  The workflow does not create a GitHub release and uses no other secrets.
@@ -372,8 +404,9 @@ native/node/ N-API addon (node-addon-api): addon.cc, CMakeLists.tx
372
404
  native/wasm/ Emscripten module: wasm_bindings.cc, qpdf-worker.mjs, smoke-test.mjs
373
405
  packages/node/ The "qpdf-node" TypeScript wrapper (src/native-loader.ts finds the addon) and tests
374
406
  scripts/ generate-third-party-notices.mjs; release scripts (release-lib, stage-addon,
375
- package-root, smoke-test-package, verify-release, publish-package)
376
- .github/workflows/ release.yml: build the five addons, stage, test and publish the one package
407
+ package-platform, package-root, smoke-test-packages, verify-release,
408
+ publish-packages)
409
+ .github/workflows/ release.yml: build the five addons, stage, test and publish six packages
377
410
  ```
378
411
 
379
412
  ## License
@@ -6,9 +6,9 @@ export interface RuntimePlatform {
6
6
  /** Only meaningful on Linux: the C library this Node.js process runs on. */
7
7
  libc: "glibc" | "musl" | undefined;
8
8
  }
9
- export declare const supportedAddonFileNames: readonly string[];
10
- /** The bundled addon's file name for `runtime`, or undefined when no prebuilt exists. */
11
- export declare function bundledAddonFileName(runtime: RuntimePlatform): string | undefined;
9
+ export declare const supportedPlatformPackages: readonly string[];
10
+ /** The npm package holding the addon for `runtime`, or undefined when no prebuilt exists. */
11
+ export declare function platformPackageName(runtime: RuntimePlatform): string | undefined;
12
12
  export declare function detectRuntimePlatform(): RuntimePlatform;
13
13
  export interface NativeLoaderEnvironment {
14
14
  /** Directory of the loader's own file (`src/` or `dist/`). */
@@ -21,8 +21,7 @@ export interface NativeLoaderEnvironment {
21
21
  * Loads the addon. Order:
22
22
  * 1. `build/Release/qpdf_node.node` next to the package, if present: a source checkout
23
23
  * after `pnpm run build:native`. Published packages do not contain it.
24
- * 2. `native/qpdf_node.<target>.node` in the package for this runtime: every supported
25
- * platform's addon is bundled in the one published package.
24
+ * 2. The platform package for this runtime (an optional dependency of qpdf-node).
26
25
  * A file that exists but fails to load (wrong architecture, missing system library) is
27
26
  * reported as is, never silently replaced by another binary.
28
27
  */
@@ -1,35 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.supportedAddonFileNames = void 0;
4
- exports.bundledAddonFileName = bundledAddonFileName;
3
+ exports.supportedPlatformPackages = void 0;
4
+ exports.platformPackageName = platformPackageName;
5
5
  exports.detectRuntimePlatform = detectRuntimePlatform;
6
6
  exports.loadNativeBinding = loadNativeBinding;
7
7
  exports.loadNativeBindingForCurrentProcess = loadNativeBindingForCurrentProcess;
8
8
  const node_fs_1 = require("node:fs");
9
9
  const node_path_1 = require("node:path");
10
- /** Prebuilt targets, keyed by `${platform}-${arch}` (plus `-glibc` on Linux), to their addon file names. */
11
- const bundledAddonFileNames = {
12
- "darwin-arm64": "qpdf_node.darwin-arm64.node",
13
- "darwin-x64": "qpdf_node.darwin-x64.node",
14
- "linux-x64-glibc": "qpdf_node.linux-x64-gnu.node",
15
- "linux-arm64-glibc": "qpdf_node.linux-arm64-gnu.node",
16
- "win32-x64": "qpdf_node.win32-x64-msvc.node",
10
+ /** Prebuilt targets, as `${platform}-${arch}` (plus `-gnu` / `-msvc`) package suffixes. */
11
+ const platformPackageNames = {
12
+ "darwin-arm64": "qpdf-node-darwin-arm64",
13
+ "darwin-x64": "qpdf-node-darwin-x64",
14
+ "linux-x64-glibc": "qpdf-node-linux-x64-gnu",
15
+ "linux-arm64-glibc": "qpdf-node-linux-arm64-gnu",
16
+ "win32-x64": "qpdf-node-win32-x64-msvc",
17
17
  };
18
- exports.supportedAddonFileNames = Object.values(bundledAddonFileNames);
18
+ exports.supportedPlatformPackages = Object.values(platformPackageNames);
19
19
  /** Path of the addon that `pnpm run build:native` writes, relative to `dist/` or `src/`. */
20
20
  function developmentAddonPath(directory) {
21
21
  return (0, node_path_1.join)(directory, "..", "build", "Release", "qpdf_node.node");
22
22
  }
23
- /** Path of a bundled addon inside the published package, relative to `dist/`. */
24
- function bundledAddonPath(directory, addonFileName) {
25
- return (0, node_path_1.join)(directory, "..", "native", addonFileName);
26
- }
27
- /** The bundled addon's file name for `runtime`, or undefined when no prebuilt exists. */
28
- function bundledAddonFileName(runtime) {
23
+ /** The npm package holding the addon for `runtime`, or undefined when no prebuilt exists. */
24
+ function platformPackageName(runtime) {
29
25
  const key = runtime.platform === "linux"
30
26
  ? `linux-${runtime.arch}-${runtime.libc ?? "unknown"}`
31
27
  : `${runtime.platform}-${runtime.arch}`;
32
- return bundledAddonFileNames[key];
28
+ return platformPackageNames[key];
33
29
  }
34
30
  function detectRuntimePlatform() {
35
31
  return {
@@ -59,12 +55,21 @@ function describeRuntime(runtime) {
59
55
  const libc = runtime.platform === "linux" ? `, libc=${runtime.libc ?? "unknown"}` : "";
60
56
  return `platform=${runtime.platform}, arch=${runtime.arch}${libc}`;
61
57
  }
58
+ function isModuleNotFound(error, moduleName) {
59
+ if (typeof error !== "object" || error === null) {
60
+ return false;
61
+ }
62
+ const { code, message } = error;
63
+ // A missing dependency *of* the addon also has this code; only the addon itself counts.
64
+ return (code === "MODULE_NOT_FOUND" &&
65
+ typeof message === "string" &&
66
+ message.split("\n")[0]?.includes(`'${moduleName}'`) === true);
67
+ }
62
68
  /**
63
69
  * Loads the addon. Order:
64
70
  * 1. `build/Release/qpdf_node.node` next to the package, if present: a source checkout
65
71
  * after `pnpm run build:native`. Published packages do not contain it.
66
- * 2. `native/qpdf_node.<target>.node` in the package for this runtime: every supported
67
- * platform's addon is bundled in the one published package.
72
+ * 2. The platform package for this runtime (an optional dependency of qpdf-node).
68
73
  * A file that exists but fails to load (wrong architecture, missing system library) is
69
74
  * reported as is, never silently replaced by another binary.
70
75
  */
@@ -73,24 +78,23 @@ function loadNativeBinding(environment) {
73
78
  if (environment.fileExists(developmentAddon)) {
74
79
  return environment.requireModule(developmentAddon);
75
80
  }
76
- const addonFileName = bundledAddonFileName(environment.runtime);
77
- if (addonFileName === undefined) {
81
+ const packageName = platformPackageName(environment.runtime);
82
+ if (packageName === undefined) {
78
83
  throw new Error(`qpdf-node has no prebuilt native addon for this platform. ${describeRuntime(environment.runtime)}. ` +
79
- `Bundled addons: ${exports.supportedAddonFileNames.join(", ")}. ` +
84
+ `Supported packages: ${exports.supportedPlatformPackages.join(", ")}. ` +
80
85
  "To use another platform, build the addon from source (see the qpdf-node README).");
81
86
  }
82
- const addonPath = bundledAddonPath(environment.directory, addonFileName);
83
- if (!environment.fileExists(addonPath)) {
84
- throw new Error(`qpdf-node could not find its bundled native addon ${addonFileName} ` +
85
- `(${describeRuntime(environment.runtime)}, expected at ${addonPath}). ` +
86
- "The published package contains it: reinstall qpdf-node. " +
87
- "In a source checkout, run `pnpm run build:native` instead.");
88
- }
89
87
  try {
90
- return environment.requireModule(addonPath);
88
+ return environment.requireModule(packageName);
91
89
  }
92
90
  catch (error) {
93
- throw new Error(`qpdf-node found its bundled native addon ${addonFileName} but could not load it ` +
91
+ if (isModuleNotFound(error, packageName)) {
92
+ throw new Error(`qpdf-node could not find its native addon package ${packageName} ` +
93
+ `(${describeRuntime(environment.runtime)}). It is installed as an optional dependency of qpdf-node: ` +
94
+ "reinstall without --omit=optional / --no-optional, and do not copy node_modules between platforms. " +
95
+ "In a source checkout, run `pnpm run build:native` instead.", { cause: error });
96
+ }
97
+ throw new Error(`qpdf-node found its native addon package ${packageName} but could not load it ` +
94
98
  `(${describeRuntime(environment.runtime)}): ${String(error)}`, { cause: error });
95
99
  }
96
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qpdf-node",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Node.js native addon (C++ N-API) for extracting, merging and splitting PDF pages, built on qpdf.",
5
5
  "keywords": [
6
6
  "pdf",
@@ -22,12 +22,18 @@
22
22
  "types": "dist/index.d.ts",
23
23
  "files": [
24
24
  "dist",
25
- "native",
26
25
  "LICENSE",
27
26
  "THIRD_PARTY_NOTICES.md",
28
27
  "README.md"
29
28
  ],
30
29
  "engines": {
31
30
  "node": ">=20"
31
+ },
32
+ "optionalDependencies": {
33
+ "qpdf-node-darwin-arm64": "0.2.1",
34
+ "qpdf-node-darwin-x64": "0.2.1",
35
+ "qpdf-node-linux-x64-gnu": "0.2.1",
36
+ "qpdf-node-linux-arm64-gnu": "0.2.1",
37
+ "qpdf-node-win32-x64-msvc": "0.2.1"
32
38
  }
33
39
  }
Binary file
Binary file
Binary file