@medicomind/rolldown-compression 2.4.2 → 2.5.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # @medicomind/rolldown-compression
2
2
 
3
+ ## 2.5.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`cb1cfe8`](https://github.com/Medico-Mind/rolldown-compression/commit/cb1cfe835554389b92b3b79f9e57480911ed7498) Thanks [@Mnwa](https://github.com/Mnwa)! - Pass each source file to Rust once per batch and share its buffer across compression algorithms, with algorithm settings sent separately.
8
+
9
+ - [`b1fbdfe`](https://github.com/Medico-Mind/rolldown-compression/commit/b1fbdfef82174a8cc8aa8ff3e326d9735c5267b6) Thanks [@Mnwa](https://github.com/Mnwa)! - Use the same Brotli encoder for single-section and parallel compression.
10
+
11
+ - [`f8b39cb`](https://github.com/Medico-Mind/rolldown-compression/commit/f8b39cbbd62cfc3f5ca3805182efd3d58804168c) Thanks [@Mnwa](https://github.com/Mnwa)! - Update the WebAssembly runtime dependency to @napi-rs/wasm-runtime 1.2.4.
12
+
13
+ ## 2.5.1
14
+
15
+ ### Patch Changes
16
+
17
+ - [`87ff2d5`](https://github.com/Medico-Mind/rolldown-compression/commit/87ff2d51ac65a3fcda9abf37bb4bf5d15718da87) Thanks [@Mnwa](https://github.com/Mnwa)! - Remove retention policy
18
+
19
+ - [`63191bf`](https://github.com/Medico-Mind/rolldown-compression/commit/63191bf37d51b8deed07ed6cddc70991be5bd22c) Thanks [@Mnwa](https://github.com/Mnwa)! - Update the WebAssembly runtime dependencies to @napi-rs/wasm-runtime 1.2.3 and emnapi 2.0.0-alpha.5.
20
+
21
+ - [`8fa09dc`](https://github.com/Medico-Mind/rolldown-compression/commit/8fa09dc5159f9a0e5f0dad1321f9084181a392d8) Thanks [@Mnwa](https://github.com/Mnwa)! - Simplify brotli parallel config
22
+
23
+ ## 2.5.0
24
+
25
+ ### Minor Changes
26
+
27
+ - [`4682438`](https://github.com/Medico-Mind/rolldown-compression/commit/4682438766c5b481b18bd5ebfacf231e5da2353c) Thanks [@Mnwa](https://github.com/Mnwa)! - Migrate brotli encoding to `mbrotli`.
28
+
29
+ - **Compressed bytes change for brotli inputs above the split threshold.** The new encoder's sectioned stream trades more ratio for parallelism than the old one did: about 5% against a single stream (5.1% at 8 MiB, 5.8% at 16 MiB, 6.7% at 32 MiB, quality 11 at the default window), in exchange for finishing 3.2x, 6.2x and 10.9x faster on an 18-worker pool. Inputs below the threshold, and all gzip and zstd output, are unchanged.
30
+ - **Brotli output no longer depends on the machine.** How many sections an input is cut into follows `sectionSize` alone, and how many threads work through them is a scheduling decision that leaves the bytes alone. A given input and set of options now compress to identical bytes regardless of core count or `concurrency`, as gzip and zstd already did. The previous caveat about files larger than `threads * sectionSize` differing between machines no longer applies.
31
+ - **`sectionSize` is clamped to 64 KiB - 16 MiB**, the range the new encoder segments in. Its meaning, its `2^(windowBits + 1)` default and the `2 * sectionSize` split threshold are unchanged; previously valid values outside the range are clamped rather than rejected.
32
+ - **Large inputs now use the whole pool.** The section count no longer caps the threads that work on it, so a split file runs on every worker rather than one per section.
33
+ - **Each worker reuses its brotli encoder across files** instead of building one per file, capped by a 4 MiB retention budget. The win depends on consecutive files on a worker sharing an encoder shape: batches of similarly sized files compress about 28% faster in the per-file overhead, while batches of widely varying sizes are unchanged, because the window is re-derived per input and a shape change discards the workspace. The budget is what keeps the reuse from costing memory — at quality 11 a retained workspace is 2.3 MB at window 14 but 62.9 MB at window 22, so without it every worker would hold its high-water mark for the life of the process.
34
+ - `simd-brotli` is now a dev-dependency only; it is kept because `mbrotli` ships no decoder and the round-trip tests need one.
35
+
36
+ The brotli benchmark tables in the README predate this change and have not been re-measured.
37
+
38
+ ### Patch Changes
39
+
40
+ - [`0818b8d`](https://github.com/Medico-Mind/rolldown-compression/commit/0818b8d039ee24529c72b6db5ed453e3e3748368) Thanks [@Mnwa](https://github.com/Mnwa)! - Fix the WebAssembly fallback build by using the same zstd version as native builds while preserving its no-assembly configuration.
41
+
3
42
  ## 2.4.2
4
43
 
5
44
  ### Patch Changes
package/README.md CHANGED
@@ -113,11 +113,22 @@ defineAlgorithm('brotli', { quality: 7, windowBits: 22 })
113
113
  defineAlgorithm('zstd', { level: 12 })
114
114
  ```
115
115
 
116
- `sectionSize` is the target number of bytes each brotli worker thread compresses when a large input is split across the native worker pool; inputs at least twice `sectionSize` take the multithreaded path. It defaults to two windows (`2^(windowBits + 1)` bytes) — 8 MiB and multithreading from 16 MiB at the default window — because sections much smaller than the window lose too many cross-section matches. Smaller sections finish large files faster at a slight cost in compression ratio.
116
+ `sectionSize` is the target number of bytes in each section when a large input is split across the native worker pool; inputs larger than one section are split. It defaults to two windows (`2^(windowBits + 1)` bytes) — 8 MiB at the default window — because sections much smaller than the window lose too many cross-section matches. The encoder segments between 64 KiB and 16 MiB, and values outside that range are clamped to it.
117
117
 
118
- An input is cut into one section per full `sectionSize`, up to one section per worker thread — more sections than there are threads only queue behind each other. A file large enough to hit that cap is therefore split according to the pool size (the machine's core count, or [`concurrency`](#options) when set), so its compressed bytes can differ between machines; smaller inputs are split by length alone and compress identically everywhere. On 100 MiB of real JS at quality 11 with 18 workers, one section per worker compresses 3.1x faster than the previous four-section limit for 0.1% more output.
118
+ Smaller sections finish large files faster and cost ratio. Measured on 31.8 MiB of real JS at quality 9, `windowBits: 22`, against the 4 MiB point:
119
119
 
120
- **`windowBits` is the main speed/ratio dial.** It sets the brotli sliding window (`2^windowBits` bytes) — how far back a match can be found — and, through the `sectionSize` default above, how large a file has to be before it is split across threads. **Lowering it makes compression faster in two ways at once and costs compression ratio**: a smaller window is cheaper to search, *and* it drops the split threshold to `2^(windowBits + 2)` bytes, so big bundles are cut into sections sooner and finish on more cores (`windowBits: 20` splits from 4 MiB instead of 16 MiB). On the [benchmark](#synthetic-benchmark) fixtures, `windowBits: 20` takes brotli quality 11 from 10.08s to 6.48s. Raising it does the reverse: better ratio, less parallelism, slower builds.
120
+ | `sectionSize` | sections in flight | output | vs 4 MiB |
121
+ |---------------|--------------------|--------|----------|
122
+ | 256 KiB | 18 | 6,123,466 | +14.9% |
123
+ | 1 MiB | 18 | 5,686,721 | +6.7% |
124
+ | 2 MiB | 16 | 5,555,631 | +4.3% |
125
+ | 4 MiB | 8 | 5,328,674 | — |
126
+ | 8 MiB (default at `windowBits: 22`) | 4 | 5,244,683 | −1.6% |
127
+ | 16 MiB | 2 | 5,167,925 | −3.0% |
128
+
129
+ **Brotli output is reproducible across machines.** How many sections an input is cut into follows `sectionSize` alone, and how many threads work through them is a scheduling decision that leaves the bytes alone, so a given input and set of options compress to identical bytes regardless of core count or [`concurrency`](#options) — as gzip and zstd already did.
130
+
131
+ **`windowBits` is the other speed/ratio dial.** It sets the brotli sliding window (`2^windowBits` bytes) — how far back a match can be found — and, through the `sectionSize` default above, how large a file has to be before it is split across threads. **Lowering it makes compression faster in two ways at once and costs compression ratio**: a smaller window is cheaper to search, *and* it reduces the default section size to `2^(windowBits + 1)` bytes, so big bundles are cut into sections sooner and finish on more cores (`windowBits: 20` splits inputs larger than 2 MiB instead of 8 MiB). Raising it does the reverse: better ratio, less parallelism, slower builds.
121
132
 
122
133
  The size penalty depends entirely on how far apart your content's repetitions are: it is real on production bundles (repeated vendor copies, inlined assets, source maps), but on those synthetic fixtures — whose matches are nearly all short-range — it stays within 0.1%, and there `windowBits: 20` even came out marginally *smaller*. **Measure your own output before shipping a lower window** — decoders also allocate the window the stream declares, and above 24 bits brotli needs the large-window extension that browsers do not implement, hence the 10–24 range. The default `22` matches `BROTLI_DEFAULT_WINDOW`, i.e. what `node:zlib` and the `brotli` CLI emit.
123
134
 
@@ -125,7 +136,7 @@ The size penalty depends entirely on how far apart your content's repetitions ar
125
136
 
126
137
  - The plugin hooks **`generateBundle`**, while all chunks and assets are still in memory — no filesystem round-trip. Eligible files (filter + threshold) are sent to the native module as **one batched FFI call per build**; results are emitted with `emitFile`.
127
138
  - Compression runs on a rayon thread pool inside the native module (`AsyncTask`), parallel across files *and* algorithms, scheduled most-expensive-first so one large brotli file can't stretch the batch tail. The JS event loop keeps ticking throughout (covered by a test).
128
- - Buffers cross the FFI boundary without base64/string round-trips, and the compression working set lives in native memory — a 500 MB asset does not pressure the JS heap.
139
+ - Each file crosses the FFI boundary once as a buffer, with algorithm settings sent separately. Rust shares that source allocation across algorithms without copying the bytes. Buffers require no base64/string round-trips, and the compression working set lives in native memory — a 500 MB asset does not pressure the JS heap.
129
140
  - A failing task never aborts the batch: per-task errors are aggregated and fail the build with one message.
130
141
  - Already-compressed artifacts (`.gz`, `.br`, `.zst` — ours or pre-existing) are never re-compressed, so chaining plugin instances can't produce `app.js.gz.br`.
131
142
  - Artifact names are checked before anything is written: a name that escapes the output directory, collides with another artifact of the same build, or overwrites a file the build already owns fails the build instead of silently clobbering it.
@@ -247,10 +258,11 @@ Results on an Apple M5 Pro (18 cores), Node 26, default `UV_THREADPOOL_SIZE`:
247
258
  Reading these numbers honestly:
248
259
 
249
260
  - **gzip** and **zstd** are faster per core ([zlib-rs](https://github.com/trifectatechfoundation/zlib-rs), ~2.4x faster per core than node's bundled zlib in our measurements; libzstd) *and* use every core, while `node:zlib` is capped at `UV_THREADPOOL_SIZE` (default 4) threads. The two >16 MiB bundles temper the headline numbers: neither algorithm has a sectioned mode, so each giant file occupies a single thread on both sides and that tail runs at the per-core ratio rather than the thread-count ratio.
250
- - **brotli at quality 11** is the bound on the combined number: the Rust `brotli` crate is at per-core parity with node's C brotli (we measured a 1.01 single-thread ratio), so the speedup is parallelism — every core against `UV_THREADPOOL_SIZE` threads across the many small files, plus the sectioned worker pool (2 x 8 MiB sections) on the >16 MiB bundles that `node:zlib` has to compress one thread per file.
251
- - **The brotli rows are slower than the previous release's tables, by design.** `sectionSize` used to default to one window (4 MiB at `windowBits: 22`), splitting a >16 MiB input into up to 4 sections; it now defaults to two windows (8 MiB), so the fixture set's two ~20 MiB bundles are cut into 2 sections instead of 4 and their tail runs on half as many cores. Brotli quality 11 went from ~6.9s to ~10.2s and the combined scenario from 3.34x to 2.43x. Holding the *current* binding fixed and passing only `sectionSize: 4 * 1024 * 1024` brings quality 11 back to 7.29s (vs 10.08s at the default), so the regression is the new default rather than the rayon worker-pool rewrite that landed alongside it. Pass `sectionSize` explicitly if you want the old wall clock.
252
- - **The ratio this buys is not visible on these fixtures.** The larger default exists because sections much smaller than the window lose cross-section matches, but at quality 11 the same 85 MB comes out **5.450 MB with 8 MiB sections and 5.445 MB with 4 MiB ones** — 0.09%, and in the wrong direction, i.e. block-splitting noise rather than a real gain. The generated fixtures repeat a small vocabulary line by line, so nearly every match is short-range and even a 4 MiB window already finds it. Expect the trade to favor the larger default on real bundles with long-range redundancy (repeated vendor copies, inlined assets, source maps) — and measure your own output before trading wall clock for it.
253
- - The speedup grows with core count and shrinks if you raise `UV_THREADPOOL_SIZE` for the JS side — the benchmark prints both so runs are comparable. The 10-core M1 Pro these tables previously covered landed around 2.4x on the combined scenario, and the 18-core M5 Pro reaches 2.3–2.4x at the current section default (it reached 3.3–3.6x at the old 4 MiB one) against the same 4-thread JS side.
261
+ - **brotli at quality 11** is the bound on the combined number: the Rust encoder is at per-core parity with node's C brotli (we measured a 1.01 single-thread ratio), so the speedup is parallelism — every core against `UV_THREADPOOL_SIZE` threads across the many small files, plus the split worker pool on the >16 MiB bundles that `node:zlib` has to compress one thread per file.
262
+ > [!WARNING]
263
+ > **The brotli rows below predate the `mbrotli` migration and have not been re-measured.** That release replaced the encoder, and a section now costs more ratio to split than it used to. Expect the brotli numbers to have moved substantially in both wall clock and output size; the gzip and zstd rows are unaffected. Re-run `npm run bench` for current figures.
264
+
265
+ - The speedup grows with core count and shrinks if you raise `UV_THREADPOOL_SIZE` for the JS side — the benchmark prints both so runs are comparable. The 10-core M1 Pro these tables previously covered landed around 2.4x on the combined scenario against the same 4-thread JS side.
254
266
  - The two tables above are single runs of each binding, so the small differences *between* them are run-to-run noise, not a PGO effect — see [PGO / BOLT builds](#pgo--bolt-builds) for an interleaved median comparison of the same two binaries.
255
267
 
256
268
  ### PGO / BOLT builds
package/dist/index.cjs CHANGED
@@ -221,7 +221,8 @@ function resolveOutputFileName(filename, fileName, algorithm, source) {
221
221
  }
222
222
  /**
223
223
  * Compress a batch of buffers in the native rayon thread pool, off the JS
224
- * main thread. `tasks[i]` describes how to compress `buffers[i]`.
224
+ * main thread. Each file is passed once and compressed with every algorithm.
225
+ * Results follow file order, then algorithm order within each file.
225
226
  */
226
227
  const compressBuffers = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("../index.js").compressBuffers;
227
228
  //#endregion
@@ -296,7 +297,7 @@ function createLogger(context, logLevel) {
296
297
  };
297
298
  }
298
299
  /**
299
- * Shared batching core: queues per-algorithm tasks, flushes them to the
300
+ * Shared batching core: queues each file once, flushes the files to the
300
301
  * native module and hands successful results to `emit`. Only one batch of
301
302
  * source buffers is referenced at a time once a flush trigger is set.
302
303
  */
@@ -308,17 +309,27 @@ function createBatchRunner({ options, log, emittedNames, isReserved, emit, fail
308
309
  /** Artifact name -> the `source (algorithm)` that claimed it, for collision reporting. */
309
310
  const claimed = /* @__PURE__ */ new Map();
310
311
  const chunkSize = options.chunkSize > 0 ? options.chunkSize : options.stream ? STREAM_DEFAULT_CHUNK_SIZE : 0;
312
+ const algorithms = options.algorithms.map(({ algorithm, level, windowBits, sectionSize }) => ({
313
+ algorithm,
314
+ level,
315
+ windowBits,
316
+ sectionSize
317
+ }));
318
+ const batchOptions = {
319
+ concurrency: options.concurrency,
320
+ skipIfLargerOrEqual: options.skipIfLargerOrEqual
321
+ };
322
+ let pendingFiles = [];
311
323
  let pending = [];
312
324
  let pendingSourceBytes = 0;
313
325
  const flush = async () => {
314
326
  if (pending.length === 0) return;
315
327
  const batch = pending;
328
+ const files = pendingFiles;
316
329
  pending = [];
330
+ pendingFiles = [];
317
331
  pendingSourceBytes = 0;
318
- const results = await compressBuffers(batch.map((artifact) => artifact.task), batch.map((artifact) => artifact.buffer), {
319
- concurrency: options.concurrency,
320
- skipIfLargerOrEqual: options.skipIfLargerOrEqual
321
- });
332
+ const results = await compressBuffers(files, algorithms, batchOptions);
322
333
  for (const [index, result] of results.entries()) {
323
334
  const artifact = batch[index];
324
335
  if (artifact === void 0) continue;
@@ -354,18 +365,14 @@ function createBatchRunner({ options, log, emittedNames, isReserved, emit, fail
354
365
  if (isReserved(outputFileName)) fail(`the artifact "${outputFileName}" for ${fileName} (${algorithm.algorithm}) would overwrite a file this build already owns`);
355
366
  claimed.set(outputFileName, `${fileName} (${algorithm.algorithm})`);
356
367
  pending.push({
357
- task: {
358
- fileName,
359
- algorithm: algorithm.algorithm,
360
- level: algorithm.level,
361
- windowBits: algorithm.windowBits,
362
- sectionSize: algorithm.sectionSize
363
- },
364
- buffer,
365
368
  sourceFileName: fileName,
366
369
  outputFileName
367
370
  });
368
371
  }
372
+ pendingFiles.push({
373
+ fileName,
374
+ data: buffer
375
+ });
369
376
  processedSources.add(fileName);
370
377
  pendingSourceBytes += buffer.byteLength;
371
378
  if (chunkSize > 0 && pendingSourceBytes >= chunkSize) await flush();
package/dist/index.d.cts CHANGED
@@ -10,11 +10,12 @@ interface GzipOptions {
10
10
  }
11
11
  /**
12
12
  * Brotli options. `quality`: 0-11, default 11. `windowBits`: 10-24, default 22.
13
- * `sectionSize`: target bytes per worker thread when large inputs are split
14
- * across the native brotli worker pool; inputs at least twice this size
15
- * take the multithreaded path. Defaults to two windows (`2^(windowBits + 1)`
16
- * bytes), i.e. 8 MiB and multithreading from 16 MiB at the default window. Smaller
17
- * sections finish large files faster at a slight cost in compression ratio.
13
+ * `sectionSize`: target bytes per section when large inputs are split across
14
+ * the native brotli worker pool; inputs larger than one section are split.
15
+ * Defaults to two windows (`2^(windowBits + 1)` bytes), i.e. 8 MiB
16
+ * at the default window. Smaller
17
+ * sections finish large files faster at a cost in compression ratio, and are
18
+ * clamped to the 64 KiB - 16 MiB range the encoder segments in.
18
19
  */
19
20
  interface BrotliOptions {
20
21
  quality?: number;
@@ -137,9 +138,9 @@ interface CompressionOptions {
137
138
  * @example
138
139
  * compression({ algorithms: [defineAlgorithm('brotli', { quality: 9 })] })
139
140
  */
140
- declare function defineAlgorithm(name: 'gzip' | 'gz', options?: GzipOptions): DefineAlgorithmResult;
141
- declare function defineAlgorithm(name: 'brotli' | 'br' | 'brotliCompress', options?: BrotliOptions): DefineAlgorithmResult;
142
- declare function defineAlgorithm(name: 'zstd' | 'zstandard', options?: ZstdOptions): DefineAlgorithmResult;
141
+ export declare function defineAlgorithm(name: 'gzip' | 'gz', options?: GzipOptions): DefineAlgorithmResult;
142
+ export declare function defineAlgorithm(name: 'brotli' | 'br' | 'brotliCompress', options?: BrotliOptions): DefineAlgorithmResult;
143
+ export declare function defineAlgorithm(name: 'zstd' | 'zstandard', options?: ZstdOptions): DefineAlgorithmResult;
143
144
  //#endregion
144
145
  //#region ts/plugin.d.ts
145
146
  /**
@@ -186,6 +187,6 @@ type CompressionPlugin = Plugin<CompressionPluginApi> & VitePluginFields;
186
187
  * ],
187
188
  * })
188
189
  */
189
- declare function compression(options?: CompressionOptions): CompressionPlugin;
190
+ export declare function compression(options?: CompressionOptions): CompressionPlugin;
190
191
  //#endregion
191
- export { type AlgorithmName, type BrotliOptions, type CanonicalAlgorithm, type CompressionOptions, type CompressionPlugin, type CompressionPluginApi, type DefineAlgorithmResult, type FilenameOption, type GzipOptions, type LogLevel, type ZstdOptions, compression, defineAlgorithm };
192
+ export type { AlgorithmName, BrotliOptions, CanonicalAlgorithm, CompressionOptions, CompressionPlugin, CompressionPluginApi, DefineAlgorithmResult, FilenameOption, GzipOptions, LogLevel, ZstdOptions };
package/dist/index.d.mts CHANGED
@@ -10,11 +10,12 @@ interface GzipOptions {
10
10
  }
11
11
  /**
12
12
  * Brotli options. `quality`: 0-11, default 11. `windowBits`: 10-24, default 22.
13
- * `sectionSize`: target bytes per worker thread when large inputs are split
14
- * across the native brotli worker pool; inputs at least twice this size
15
- * take the multithreaded path. Defaults to two windows (`2^(windowBits + 1)`
16
- * bytes), i.e. 8 MiB and multithreading from 16 MiB at the default window. Smaller
17
- * sections finish large files faster at a slight cost in compression ratio.
13
+ * `sectionSize`: target bytes per section when large inputs are split across
14
+ * the native brotli worker pool; inputs larger than one section are split.
15
+ * Defaults to two windows (`2^(windowBits + 1)` bytes), i.e. 8 MiB
16
+ * at the default window. Smaller
17
+ * sections finish large files faster at a cost in compression ratio, and are
18
+ * clamped to the 64 KiB - 16 MiB range the encoder segments in.
18
19
  */
19
20
  interface BrotliOptions {
20
21
  quality?: number;
@@ -137,9 +138,9 @@ interface CompressionOptions {
137
138
  * @example
138
139
  * compression({ algorithms: [defineAlgorithm('brotli', { quality: 9 })] })
139
140
  */
140
- declare function defineAlgorithm(name: 'gzip' | 'gz', options?: GzipOptions): DefineAlgorithmResult;
141
- declare function defineAlgorithm(name: 'brotli' | 'br' | 'brotliCompress', options?: BrotliOptions): DefineAlgorithmResult;
142
- declare function defineAlgorithm(name: 'zstd' | 'zstandard', options?: ZstdOptions): DefineAlgorithmResult;
141
+ export declare function defineAlgorithm(name: 'gzip' | 'gz', options?: GzipOptions): DefineAlgorithmResult;
142
+ export declare function defineAlgorithm(name: 'brotli' | 'br' | 'brotliCompress', options?: BrotliOptions): DefineAlgorithmResult;
143
+ export declare function defineAlgorithm(name: 'zstd' | 'zstandard', options?: ZstdOptions): DefineAlgorithmResult;
143
144
  //#endregion
144
145
  //#region ts/plugin.d.ts
145
146
  /**
@@ -186,6 +187,6 @@ type CompressionPlugin = Plugin<CompressionPluginApi> & VitePluginFields;
186
187
  * ],
187
188
  * })
188
189
  */
189
- declare function compression(options?: CompressionOptions): CompressionPlugin;
190
+ export declare function compression(options?: CompressionOptions): CompressionPlugin;
190
191
  //#endregion
191
- export { type AlgorithmName, type BrotliOptions, type CanonicalAlgorithm, type CompressionOptions, type CompressionPlugin, type CompressionPluginApi, type DefineAlgorithmResult, type FilenameOption, type GzipOptions, type LogLevel, type ZstdOptions, compression, defineAlgorithm };
192
+ export type { AlgorithmName, BrotliOptions, CanonicalAlgorithm, CompressionOptions, CompressionPlugin, CompressionPluginApi, DefineAlgorithmResult, FilenameOption, GzipOptions, LogLevel, ZstdOptions };
package/dist/index.mjs CHANGED
@@ -197,7 +197,8 @@ function resolveOutputFileName(filename, fileName, algorithm, source) {
197
197
  }
198
198
  /**
199
199
  * Compress a batch of buffers in the native rayon thread pool, off the JS
200
- * main thread. `tasks[i]` describes how to compress `buffers[i]`.
200
+ * main thread. Each file is passed once and compressed with every algorithm.
201
+ * Results follow file order, then algorithm order within each file.
201
202
  */
202
203
  const compressBuffers = createRequire(import.meta.url)("../index.js").compressBuffers;
203
204
  //#endregion
@@ -272,7 +273,7 @@ function createLogger(context, logLevel) {
272
273
  };
273
274
  }
274
275
  /**
275
- * Shared batching core: queues per-algorithm tasks, flushes them to the
276
+ * Shared batching core: queues each file once, flushes the files to the
276
277
  * native module and hands successful results to `emit`. Only one batch of
277
278
  * source buffers is referenced at a time once a flush trigger is set.
278
279
  */
@@ -284,17 +285,27 @@ function createBatchRunner({ options, log, emittedNames, isReserved, emit, fail
284
285
  /** Artifact name -> the `source (algorithm)` that claimed it, for collision reporting. */
285
286
  const claimed = /* @__PURE__ */ new Map();
286
287
  const chunkSize = options.chunkSize > 0 ? options.chunkSize : options.stream ? STREAM_DEFAULT_CHUNK_SIZE : 0;
288
+ const algorithms = options.algorithms.map(({ algorithm, level, windowBits, sectionSize }) => ({
289
+ algorithm,
290
+ level,
291
+ windowBits,
292
+ sectionSize
293
+ }));
294
+ const batchOptions = {
295
+ concurrency: options.concurrency,
296
+ skipIfLargerOrEqual: options.skipIfLargerOrEqual
297
+ };
298
+ let pendingFiles = [];
287
299
  let pending = [];
288
300
  let pendingSourceBytes = 0;
289
301
  const flush = async () => {
290
302
  if (pending.length === 0) return;
291
303
  const batch = pending;
304
+ const files = pendingFiles;
292
305
  pending = [];
306
+ pendingFiles = [];
293
307
  pendingSourceBytes = 0;
294
- const results = await compressBuffers(batch.map((artifact) => artifact.task), batch.map((artifact) => artifact.buffer), {
295
- concurrency: options.concurrency,
296
- skipIfLargerOrEqual: options.skipIfLargerOrEqual
297
- });
308
+ const results = await compressBuffers(files, algorithms, batchOptions);
298
309
  for (const [index, result] of results.entries()) {
299
310
  const artifact = batch[index];
300
311
  if (artifact === void 0) continue;
@@ -330,18 +341,14 @@ function createBatchRunner({ options, log, emittedNames, isReserved, emit, fail
330
341
  if (isReserved(outputFileName)) fail(`the artifact "${outputFileName}" for ${fileName} (${algorithm.algorithm}) would overwrite a file this build already owns`);
331
342
  claimed.set(outputFileName, `${fileName} (${algorithm.algorithm})`);
332
343
  pending.push({
333
- task: {
334
- fileName,
335
- algorithm: algorithm.algorithm,
336
- level: algorithm.level,
337
- windowBits: algorithm.windowBits,
338
- sectionSize: algorithm.sectionSize
339
- },
340
- buffer,
341
344
  sourceFileName: fileName,
342
345
  outputFileName
343
346
  });
344
347
  }
348
+ pendingFiles.push({
349
+ fileName,
350
+ data: buffer
351
+ });
345
352
  processedSources.add(fileName);
346
353
  pendingSourceBytes += buffer.byteLength;
347
354
  if (chunkSize > 0 && pendingSourceBytes >= chunkSize) await flush();
package/index.d.ts CHANGED
@@ -11,15 +11,47 @@ export interface BatchOptions {
11
11
  skipIfLargerOrEqual?: boolean
12
12
  }
13
13
 
14
+ /** Algorithm settings applied to every file in a batch. */
15
+ export interface CompressAlgorithm {
16
+ /** Canonical algorithm name: "gzip" | "brotli" | "zstd". */
17
+ algorithm: string
18
+ /**
19
+ * Compression level; algorithm default when omitted
20
+ * (gzip 6, brotli 11, zstd 19).
21
+ */
22
+ level?: number
23
+ /** Brotli only: log2 window size (10-24, default 22). */
24
+ windowBits?: number
25
+ /**
26
+ * Brotli only: target section size in bytes when a large input is
27
+ * split across the brotli worker pool; inputs larger than one section
28
+ * are split. Defaults to two windows (`2^(windowBits + 1)` bytes),
29
+ * i.e. 8 MiB at the default window.
30
+ *
31
+ * Smaller sections finish large files faster and cost compression
32
+ * ratio. The encoder segments between 64 KiB and 16 MiB, and values
33
+ * outside that range are clamped to it.
34
+ */
35
+ sectionSize?: number
36
+ }
37
+
14
38
  /**
15
39
  * Compress a batch of buffers off the JS main thread.
16
40
  *
17
- * `tasks[i]` describes how to compress `buffers[i]`. Algorithm names and
41
+ * Each file carries one buffer; algorithm settings are shared by all files.
42
+ * Results follow file order, then algorithm order within each file. Empty
43
+ * files or algorithms arrays produce no results. Algorithm names and
18
44
  * levels are validated synchronously so misconfiguration fails fast;
19
45
  * I/O-shaped failures during compression are reported per task via
20
46
  * [`CompressResult::error`].
21
47
  */
22
- export declare function compressBuffers(tasks: Array<CompressTask>, buffers: Array<Buffer>, options?: BatchOptions | undefined | null): Promise<Array<CompressResult>>
48
+ export declare function compressBuffers(files: Array<CompressFile>, algorithms: Array<CompressAlgorithm>, options?: BatchOptions | undefined | null): Promise<Array<CompressResult>>
49
+
50
+ /** One source file, passed once regardless of the number of algorithms. */
51
+ export interface CompressFile {
52
+ fileName: string
53
+ data: Buffer
54
+ }
23
55
 
24
56
  /** Outcome of a single task within a batch. */
25
57
  export interface CompressResult {
@@ -37,28 +69,3 @@ export interface CompressResult {
37
69
  /** Per-task failure. A failed task never aborts the rest of the batch. */
38
70
  error?: string
39
71
  }
40
-
41
- /**
42
- * One compression task: pairs with the buffer at the same index in the
43
- * `buffers` argument of [`compress_buffers`].
44
- */
45
- export interface CompressTask {
46
- fileName: string
47
- /** Canonical algorithm name: "gzip" | "brotli" | "zstd". */
48
- algorithm: string
49
- /**
50
- * Compression level; algorithm default when omitted
51
- * (gzip 6, brotli 11, zstd 19).
52
- */
53
- level?: number
54
- /** Brotli only: log2 window size (10-24, default 22). */
55
- windowBits?: number
56
- /**
57
- * Brotli only: target section size in bytes per worker thread when
58
- * large inputs are split across the brotli worker pool; inputs at
59
- * least twice this size take the multithreaded path. Defaults
60
- * to two windows (`2^(windowBits + 1)` bytes), i.e. 8 MiB and
61
- * multithreading from 16 MiB at the default window.
62
- */
63
- sectionSize?: number
64
- }
package/index.js CHANGED
@@ -1,4 +1,3 @@
1
- // prettier-ignore
2
1
  /* eslint-disable */
3
2
  // @ts-nocheck
4
3
  /* auto-generated by NAPI-RS */
@@ -63,7 +62,7 @@ const isMuslFromChildProcess = () => {
63
62
  function requireNative() {
64
63
  if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
65
64
  try {
66
- return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
65
+ return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH)
67
66
  } catch (err) {
68
67
  loadErrors.push(err)
69
68
  }
@@ -77,8 +76,8 @@ function requireNative() {
77
76
  try {
78
77
  const binding = require('@medicomind/rolldown-compression-android-arm64')
79
78
  const bindingPackageVersion = require('@medicomind/rolldown-compression-android-arm64/package.json').version
80
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
81
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
79
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
80
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
82
81
  }
83
82
  return binding
84
83
  } catch (e) {
@@ -93,8 +92,8 @@ function requireNative() {
93
92
  try {
94
93
  const binding = require('@medicomind/rolldown-compression-android-arm-eabi')
95
94
  const bindingPackageVersion = require('@medicomind/rolldown-compression-android-arm-eabi/package.json').version
96
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
97
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
95
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
96
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
98
97
  }
99
98
  return binding
100
99
  } catch (e) {
@@ -107,36 +106,36 @@ function requireNative() {
107
106
  if (process.arch === 'x64') {
108
107
  if ((process.config && process.config.variables && process.config.variables.shlib_suffix === 'dll.a') || (process.config && process.config.variables && process.config.variables.node_target_type === 'shared_library')) {
109
108
  try {
110
- return require('./rolldown-compression.win32-x64-gnu.node')
111
- } catch (e) {
112
- loadErrors.push(e)
113
- }
114
- try {
115
- const binding = require('@medicomind/rolldown-compression-win32-x64-gnu')
116
- const bindingPackageVersion = require('@medicomind/rolldown-compression-win32-x64-gnu/package.json').version
117
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
109
+ return require('./rolldown-compression.win32-x64-gnu.node')
110
+ } catch (e) {
111
+ loadErrors.push(e)
112
+ }
113
+ try {
114
+ const binding = require('@medicomind/rolldown-compression-win32-x64-gnu')
115
+ const bindingPackageVersion = require('@medicomind/rolldown-compression-win32-x64-gnu/package.json').version
116
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
117
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
118
+ }
119
+ return binding
120
+ } catch (e) {
121
+ loadErrors.push(e)
119
122
  }
120
- return binding
121
- } catch (e) {
122
- loadErrors.push(e)
123
- }
124
123
  } else {
125
124
  try {
126
- return require('./rolldown-compression.win32-x64-msvc.node')
127
- } catch (e) {
128
- loadErrors.push(e)
129
- }
130
- try {
131
- const binding = require('@medicomind/rolldown-compression-win32-x64-msvc')
132
- const bindingPackageVersion = require('@medicomind/rolldown-compression-win32-x64-msvc/package.json').version
133
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
125
+ return require('./rolldown-compression.win32-x64-msvc.node')
126
+ } catch (e) {
127
+ loadErrors.push(e)
128
+ }
129
+ try {
130
+ const binding = require('@medicomind/rolldown-compression-win32-x64-msvc')
131
+ const bindingPackageVersion = require('@medicomind/rolldown-compression-win32-x64-msvc/package.json').version
132
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
133
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
134
+ }
135
+ return binding
136
+ } catch (e) {
137
+ loadErrors.push(e)
135
138
  }
136
- return binding
137
- } catch (e) {
138
- loadErrors.push(e)
139
- }
140
139
  }
141
140
  } else if (process.arch === 'ia32') {
142
141
  try {
@@ -147,8 +146,8 @@ function requireNative() {
147
146
  try {
148
147
  const binding = require('@medicomind/rolldown-compression-win32-ia32-msvc')
149
148
  const bindingPackageVersion = require('@medicomind/rolldown-compression-win32-ia32-msvc/package.json').version
150
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
151
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
149
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
150
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
152
151
  }
153
152
  return binding
154
153
  } catch (e) {
@@ -163,8 +162,8 @@ function requireNative() {
163
162
  try {
164
163
  const binding = require('@medicomind/rolldown-compression-win32-arm64-msvc')
165
164
  const bindingPackageVersion = require('@medicomind/rolldown-compression-win32-arm64-msvc/package.json').version
166
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
167
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
165
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
166
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
168
167
  }
169
168
  return binding
170
169
  } catch (e) {
@@ -182,8 +181,8 @@ function requireNative() {
182
181
  try {
183
182
  const binding = require('@medicomind/rolldown-compression-darwin-universal')
184
183
  const bindingPackageVersion = require('@medicomind/rolldown-compression-darwin-universal/package.json').version
185
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
186
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
184
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
185
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
187
186
  }
188
187
  return binding
189
188
  } catch (e) {
@@ -198,8 +197,8 @@ function requireNative() {
198
197
  try {
199
198
  const binding = require('@medicomind/rolldown-compression-darwin-x64')
200
199
  const bindingPackageVersion = require('@medicomind/rolldown-compression-darwin-x64/package.json').version
201
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
202
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
200
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
201
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
203
202
  }
204
203
  return binding
205
204
  } catch (e) {
@@ -214,8 +213,8 @@ function requireNative() {
214
213
  try {
215
214
  const binding = require('@medicomind/rolldown-compression-darwin-arm64')
216
215
  const bindingPackageVersion = require('@medicomind/rolldown-compression-darwin-arm64/package.json').version
217
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
218
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
216
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
217
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
219
218
  }
220
219
  return binding
221
220
  } catch (e) {
@@ -234,8 +233,8 @@ function requireNative() {
234
233
  try {
235
234
  const binding = require('@medicomind/rolldown-compression-freebsd-x64')
236
235
  const bindingPackageVersion = require('@medicomind/rolldown-compression-freebsd-x64/package.json').version
237
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
236
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
237
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
239
238
  }
240
239
  return binding
241
240
  } catch (e) {
@@ -250,8 +249,8 @@ function requireNative() {
250
249
  try {
251
250
  const binding = require('@medicomind/rolldown-compression-freebsd-arm64')
252
251
  const bindingPackageVersion = require('@medicomind/rolldown-compression-freebsd-arm64/package.json').version
253
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
254
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
252
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
253
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
255
254
  }
256
255
  return binding
257
256
  } catch (e) {
@@ -271,8 +270,8 @@ function requireNative() {
271
270
  try {
272
271
  const binding = require('@medicomind/rolldown-compression-linux-x64-musl')
273
272
  const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-x64-musl/package.json').version
274
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
275
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
273
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
274
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
276
275
  }
277
276
  return binding
278
277
  } catch (e) {
@@ -287,8 +286,8 @@ function requireNative() {
287
286
  try {
288
287
  const binding = require('@medicomind/rolldown-compression-linux-x64-gnu')
289
288
  const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-x64-gnu/package.json').version
290
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
291
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
289
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
290
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
292
291
  }
293
292
  return binding
294
293
  } catch (e) {
@@ -305,8 +304,8 @@ function requireNative() {
305
304
  try {
306
305
  const binding = require('@medicomind/rolldown-compression-linux-arm64-musl')
307
306
  const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-arm64-musl/package.json').version
308
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
309
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
307
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
308
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
310
309
  }
311
310
  return binding
312
311
  } catch (e) {
@@ -321,8 +320,8 @@ function requireNative() {
321
320
  try {
322
321
  const binding = require('@medicomind/rolldown-compression-linux-arm64-gnu')
323
322
  const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-arm64-gnu/package.json').version
324
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
325
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
323
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
324
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
326
325
  }
327
326
  return binding
328
327
  } catch (e) {
@@ -339,8 +338,8 @@ function requireNative() {
339
338
  try {
340
339
  const binding = require('@medicomind/rolldown-compression-linux-arm-musleabihf')
341
340
  const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-arm-musleabihf/package.json').version
342
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
343
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
341
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
342
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
344
343
  }
345
344
  return binding
346
345
  } catch (e) {
@@ -355,8 +354,8 @@ function requireNative() {
355
354
  try {
356
355
  const binding = require('@medicomind/rolldown-compression-linux-arm-gnueabihf')
357
356
  const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-arm-gnueabihf/package.json').version
358
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
357
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
358
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
360
359
  }
361
360
  return binding
362
361
  } catch (e) {
@@ -373,8 +372,8 @@ function requireNative() {
373
372
  try {
374
373
  const binding = require('@medicomind/rolldown-compression-linux-loong64-musl')
375
374
  const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-loong64-musl/package.json').version
376
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
377
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
375
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
376
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
378
377
  }
379
378
  return binding
380
379
  } catch (e) {
@@ -389,8 +388,8 @@ function requireNative() {
389
388
  try {
390
389
  const binding = require('@medicomind/rolldown-compression-linux-loong64-gnu')
391
390
  const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-loong64-gnu/package.json').version
392
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
391
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
392
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
394
393
  }
395
394
  return binding
396
395
  } catch (e) {
@@ -407,8 +406,8 @@ function requireNative() {
407
406
  try {
408
407
  const binding = require('@medicomind/rolldown-compression-linux-riscv64-musl')
409
408
  const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-riscv64-musl/package.json').version
410
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
409
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
410
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
412
411
  }
413
412
  return binding
414
413
  } catch (e) {
@@ -423,8 +422,8 @@ function requireNative() {
423
422
  try {
424
423
  const binding = require('@medicomind/rolldown-compression-linux-riscv64-gnu')
425
424
  const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-riscv64-gnu/package.json').version
426
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
425
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
426
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
428
427
  }
429
428
  return binding
430
429
  } catch (e) {
@@ -440,8 +439,8 @@ function requireNative() {
440
439
  try {
441
440
  const binding = require('@medicomind/rolldown-compression-linux-ppc64-gnu')
442
441
  const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-ppc64-gnu/package.json').version
443
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
444
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
442
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
443
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
445
444
  }
446
445
  return binding
447
446
  } catch (e) {
@@ -456,8 +455,8 @@ function requireNative() {
456
455
  try {
457
456
  const binding = require('@medicomind/rolldown-compression-linux-s390x-gnu')
458
457
  const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-s390x-gnu/package.json').version
459
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
460
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
458
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
459
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
461
460
  }
462
461
  return binding
463
462
  } catch (e) {
@@ -476,8 +475,8 @@ function requireNative() {
476
475
  try {
477
476
  const binding = require('@medicomind/rolldown-compression-openharmony-arm64')
478
477
  const bindingPackageVersion = require('@medicomind/rolldown-compression-openharmony-arm64/package.json').version
479
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
478
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
479
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
481
480
  }
482
481
  return binding
483
482
  } catch (e) {
@@ -492,8 +491,8 @@ function requireNative() {
492
491
  try {
493
492
  const binding = require('@medicomind/rolldown-compression-openharmony-x64')
494
493
  const bindingPackageVersion = require('@medicomind/rolldown-compression-openharmony-x64/package.json').version
495
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
494
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
495
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
497
496
  }
498
497
  return binding
499
498
  } catch (e) {
@@ -508,8 +507,8 @@ function requireNative() {
508
507
  try {
509
508
  const binding = require('@medicomind/rolldown-compression-openharmony-arm')
510
509
  const bindingPackageVersion = require('@medicomind/rolldown-compression-openharmony-arm/package.json').version
511
- if (bindingPackageVersion !== '2.4.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
512
- throw new Error(`Native binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
510
+ if (bindingPackageVersion !== '2.5.2' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
511
+ throw new Error(`Native binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
513
512
  }
514
513
  return binding
515
514
  } catch (e) {
@@ -550,7 +549,7 @@ function createLoadErrorChain(errors) {
550
549
  //
551
550
  // NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
552
551
  // WASI loading. It never crosses into another flavor or falls back to native.
553
- const __napiWasiFlavors = ["wasm32-wasi"]
552
+ const __napiWasiFlavors = ['wasm32-wasi']
554
553
  const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR
555
554
  const __napiWasiFlavorRequested =
556
555
  typeof __napiWasiFlavor === 'string' && __napiWasiFlavor.length > 0
@@ -619,11 +618,11 @@ if (!nativeBinding || forceWasi) {
619
618
  }
620
619
  return null
621
620
  }
622
- if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === "wasm32-wasi")) {
621
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
623
622
  let candidateError = null
624
623
  let candidateFailed = false
625
624
  try {
626
- candidateError = __napiWasiResolveCandidate('./rolldown-compression.wasi.cjs', false, ["./rolldown-compression.wasm32-wasi.debug.wasm","./rolldown-compression.wasm32-wasi.wasm"])
625
+ candidateError = __napiWasiResolveCandidate('./rolldown-compression.wasi.cjs', false, ['./rolldown-compression.wasm32-wasi.debug.wasm', './rolldown-compression.wasm32-wasi.wasm'])
627
626
  candidateFailed = candidateError !== null
628
627
  if (!candidateFailed) {
629
628
  wasiBinding = require('./rolldown-compression.wasi.cjs')
@@ -639,7 +638,7 @@ if (!nativeBinding || forceWasi) {
639
638
  loadErrors.push(candidateError)
640
639
  }
641
640
  }
642
- if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === "wasm32-wasi")) {
641
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
643
642
  let candidateError = null
644
643
  let candidateFailed = false
645
644
  try {
@@ -648,8 +647,8 @@ if (!nativeBinding || forceWasi) {
648
647
  if (!candidateFailed) {
649
648
  if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
650
649
  const bindingPackageVersion = require('@medicomind/rolldown-compression-wasm32-wasi/package.json').version
651
- if (bindingPackageVersion !== '2.4.2') {
652
- throw new Error(`WASI binding package version mismatch, expected 2.4.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
650
+ if (bindingPackageVersion !== '2.5.2') {
651
+ throw new Error(`WASI binding package version mismatch, expected 2.5.2 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
653
652
  }
654
653
  }
655
654
  wasiBinding = require('@medicomind/rolldown-compression-wasm32-wasi')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medicomind/rolldown-compression",
3
- "version": "2.4.2",
3
+ "version": "2.5.2",
4
4
  "description": "Fast native (Rust) gzip / brotli / zstd compression plugin for Rolldown, powered by napi-rs",
5
5
  "keywords": [
6
6
  "rolldown",
@@ -88,28 +88,28 @@
88
88
  "rolldown": "^1.0.0"
89
89
  },
90
90
  "optionalDependencies": {
91
- "@medicomind/rolldown-compression-darwin-arm64": "2.4.2",
92
- "@medicomind/rolldown-compression-darwin-x64": "2.4.2",
93
- "@medicomind/rolldown-compression-linux-arm64-gnu": "2.4.2",
94
- "@medicomind/rolldown-compression-linux-x64-gnu": "2.4.2",
95
- "@medicomind/rolldown-compression-linux-x64-musl": "2.4.2",
96
- "@medicomind/rolldown-compression-wasm32-wasi": "2.4.2",
97
- "@medicomind/rolldown-compression-win32-x64-msvc": "2.4.2"
91
+ "@medicomind/rolldown-compression-darwin-arm64": "2.5.2",
92
+ "@medicomind/rolldown-compression-darwin-x64": "2.5.2",
93
+ "@medicomind/rolldown-compression-linux-arm64-gnu": "2.5.2",
94
+ "@medicomind/rolldown-compression-linux-x64-gnu": "2.5.2",
95
+ "@medicomind/rolldown-compression-linux-x64-musl": "2.5.2",
96
+ "@medicomind/rolldown-compression-wasm32-wasi": "2.5.2",
97
+ "@medicomind/rolldown-compression-win32-x64-msvc": "2.5.2"
98
98
  },
99
99
  "devDependencies": {
100
- "@biomejs/biome": "^2.5.3",
101
- "@changesets/changelog-github": "^1.0.0",
102
- "@changesets/cli": "^3.0.0",
103
- "@emnapi/core": "2.0.0-alpha.4",
104
- "@emnapi/runtime": "2.0.0-alpha.4",
105
- "@napi-rs/cli": "^3.7.2",
106
- "@napi-rs/wasm-runtime": "^1.1.6",
107
- "@types/node": "^26.1.1",
108
- "@vitest/coverage-v8": "^4.1.10",
109
- "emnapi": "^2.0.0-alpha.4",
110
- "rolldown": "^1.1.5",
111
- "tsdown": "^0.22.4",
112
- "typescript": "^7.0.0",
113
- "vitest": "^4.1.10"
100
+ "@biomejs/biome": "^2.5.13",
101
+ "@changesets/changelog-github": "^1.0.1",
102
+ "@changesets/cli": "^3.0.2",
103
+ "@emnapi/core": "2.0.0-alpha.5",
104
+ "@emnapi/runtime": "2.0.0-alpha.5",
105
+ "@napi-rs/cli": "^3.9.1",
106
+ "@napi-rs/wasm-runtime": "^1.2.4",
107
+ "@types/node": "^26.5.1",
108
+ "@vitest/coverage-v8": "^5.0.0",
109
+ "emnapi": "^2.0.0-alpha.5",
110
+ "rolldown": "^1.2.8",
111
+ "tsdown": "^0.23.0",
112
+ "typescript": "^7.0.2",
113
+ "vitest": "^5.0.0"
114
114
  }
115
115
  }