@medicomind/rolldown-compression 2.5.3 → 2.6.0
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 +27 -0
- package/README.md +4 -2
- package/index.js +134 -55
- package/package.json +20 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @medicomind/rolldown-compression
|
|
2
2
|
|
|
3
|
+
## 2.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`64f47e1`](https://github.com/Medico-Mind/rolldown-compression/commit/64f47e1c466128aec224d258bf86ed7f0b30d399) Thanks [@Mnwa](https://github.com/Mnwa)! - Migrate zstd encoding to `mzstd`, a pure-Rust zstd encoder.
|
|
8
|
+
|
|
9
|
+
- **Inputs up to 4 MiB compress to the same bytes as before.** `mzstd`'s single-threaded encoder is byte-identical to zstd 1.5.7.
|
|
10
|
+
- **Larger inputs are split across the worker pool**, like brotli's sections: 4 MiB segments, each compressed by its own task into one standard Zstandard frame. The bytes differ from a single stream's, at about +0.05% size at level 19, and as with brotli they do not depend on core count or `concurrency`.
|
|
11
|
+
- **Splitting costs little below level 18 and a lot from level 18 up.** Every segment after the first first re-reads the input before it so its matches can reach back: an eighth of the window up to level 17 (256 KiB at level 3, 1 MiB at level 17), but the whole 8 MiB window for the `btultra` strategies of levels 18–22. A 20 MiB file at level 19 therefore costs about 2.4x the CPU of a single stream and finishes at best about 1.7x sooner. Measured on 18 threads with the benchmark fixtures, the three largest files alone finished 2.5x faster at level 3, 2.75x at level 9 and 1.32x at level 19. On the full 202-file set at level 19, the result ranged from 10% slower to 17% faster across runs, because there the extra work competes with the small files for cores, and peak RSS rose from about 1.9 GB to 2.2–2.8 GB.
|
|
12
|
+
- **The frame header is unchanged**, so the window stays within the 8 MiB limit browsers enforce for `Content-Encoding: zstd` at levels 1–19.
|
|
13
|
+
- **Levels 20–22 are capped at an 8 MiB window.** Their default 32–128 MiB windows made browsers reject any `.zst` file above 8 MiB (RFC 9659 limits the `zstd` content coding to 8 MiB). Files up to 8 MiB are unchanged.
|
|
14
|
+
- **No C toolchain is needed for zstd anymore**, including the wasm32 build. The C `zstd` crate is now a dev-dependency only, used as the reference decoder in round-trip tests.
|
|
15
|
+
|
|
16
|
+
## 2.5.5
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- [`062c592`](https://github.com/Medico-Mind/rolldown-compression/commit/062c59200ad5202394302fb96de766b3df7a3100) Thanks [@Mnwa](https://github.com/Mnwa)! - remove prealloc for mbrotli compression
|
|
21
|
+
|
|
22
|
+
## 2.5.4
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- [`db89429`](https://github.com/Medico-Mind/rolldown-compression/commit/db894294d6fcdc1c83eb90a562b89ab32e301bd2) Thanks [@Mnwa](https://github.com/Mnwa)! - Update the WebAssembly runtime dependencies to @emnapi/core and @emnapi/runtime 2.0.0-alpha.6.
|
|
27
|
+
|
|
28
|
+
- [`5044f68`](https://github.com/Medico-Mind/rolldown-compression/commit/5044f6880bf6d0bd22d3e14206b6fcc5071f1875) Thanks [@Mnwa](https://github.com/Mnwa)! - Bump mbrotli and add prealloc memory for output
|
|
29
|
+
|
|
3
30
|
## 2.5.3
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -113,6 +113,8 @@ defineAlgorithm('brotli', { quality: 7, windowBits: 22 })
|
|
|
113
113
|
defineAlgorithm('zstd', { level: 12 })
|
|
114
114
|
```
|
|
115
115
|
|
|
116
|
+
zstd levels 20–22 are capped at an 8 MiB window (`windowLog` 23), the most browsers accept for `Content-Encoding: zstd` (RFC 9659); their default 32–128 MiB windows would make Chrome and Firefox reject any file above 8 MiB. Files up to 8 MiB compress exactly as without the cap.
|
|
117
|
+
|
|
116
118
|
`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
119
|
|
|
118
120
|
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:
|
|
@@ -257,7 +259,7 @@ Results on an Apple M5 Pro (18 cores), Node 26, default `UV_THREADPOOL_SIZE`:
|
|
|
257
259
|
|
|
258
260
|
Reading these numbers honestly:
|
|
259
261
|
|
|
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:
|
|
262
|
+
- **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; [mzstd](https://github.com/M-Compressors/mzstd), byte-identical to libzstd 1.5.7) *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: gzip has no 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.
|
|
261
263
|
- **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
264
|
> [!WARNING]
|
|
263
265
|
> **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.
|
|
@@ -324,7 +326,7 @@ the host, so on an unsupported platform the wasm package must be opted into:
|
|
|
324
326
|
- **No custom JS algorithms**: `algorithms` accepts only the built-in `gzip` / `brotli` / `zstd` (function-form algorithms can't cross the FFI boundary). `defineAlgorithm` returns an opaque object, not a `[name, options]` tuple — treat it as such.
|
|
325
327
|
- **No tarball plugin**: out of scope.
|
|
326
328
|
- **gzip default level is 6** (zlib default), not 9 — measurably faster for a ~1% size difference. Pass `defineAlgorithm('gzip', { level: 9 })` to match the reference.
|
|
327
|
-
- **zstd everywhere**: zstd is compiled in, with no dependency on the Node runtime's zstd support (node >= 22.15).
|
|
329
|
+
- **zstd everywhere**: zstd is compiled in (pure Rust, via `mzstd`), with no dependency on the Node runtime's zstd support (node >= 22.15). Inputs above 4 MiB are split into segments across the worker pool, like brotli's sections.
|
|
328
330
|
- Extra options: `concurrency` (native thread cap), `chunkSize` (memory cap per compression batch), `stream` (on-demand disk-based compression in `writeBundle`) and `enableInWatchMode`.
|
|
329
331
|
|
|
330
332
|
## Implementation decisions
|
package/index.js
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
const { readFileSync } = require('fs')
|
|
6
6
|
let nativeBinding = null
|
|
7
|
+
// Which artifact actually loaded. The WASI fallback chain overwrites it with
|
|
8
|
+
// the flavor it resolved; the late native retry below leaves it alone because
|
|
9
|
+
// it only runs while no WASI candidate has been loaded.
|
|
10
|
+
let __napiLoadedBindingTarget = 'native'
|
|
7
11
|
const loadErrors = []
|
|
8
12
|
|
|
9
13
|
const isMusl = () => {
|
|
@@ -62,7 +66,16 @@ const isMuslFromChildProcess = () => {
|
|
|
62
66
|
function requireNative() {
|
|
63
67
|
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
64
68
|
try {
|
|
65
|
-
|
|
69
|
+
const overrideBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH)
|
|
70
|
+
// The override may be a generated WASI loader, which already reports its
|
|
71
|
+
// own flavor. Adopt it: `module.exports` aliases this object, so claiming
|
|
72
|
+
// 'native' would both misreport the artifact and overwrite the loader's
|
|
73
|
+
// marker through the alias.
|
|
74
|
+
__napiLoadedBindingTarget =
|
|
75
|
+
overrideBinding && typeof overrideBinding.__napiBindingTarget === 'string'
|
|
76
|
+
? overrideBinding.__napiBindingTarget
|
|
77
|
+
: 'native'
|
|
78
|
+
return overrideBinding
|
|
66
79
|
} catch (err) {
|
|
67
80
|
loadErrors.push(err)
|
|
68
81
|
}
|
|
@@ -76,8 +89,8 @@ function requireNative() {
|
|
|
76
89
|
try {
|
|
77
90
|
const binding = require('@medicomind/rolldown-compression-android-arm64')
|
|
78
91
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-android-arm64/package.json').version
|
|
79
|
-
if (bindingPackageVersion !== '2.
|
|
80
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
92
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
93
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
81
94
|
}
|
|
82
95
|
return binding
|
|
83
96
|
} catch (e) {
|
|
@@ -92,8 +105,8 @@ function requireNative() {
|
|
|
92
105
|
try {
|
|
93
106
|
const binding = require('@medicomind/rolldown-compression-android-arm-eabi')
|
|
94
107
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-android-arm-eabi/package.json').version
|
|
95
|
-
if (bindingPackageVersion !== '2.
|
|
96
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
108
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
109
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
97
110
|
}
|
|
98
111
|
return binding
|
|
99
112
|
} catch (e) {
|
|
@@ -113,8 +126,8 @@ function requireNative() {
|
|
|
113
126
|
try {
|
|
114
127
|
const binding = require('@medicomind/rolldown-compression-win32-x64-gnu')
|
|
115
128
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-win32-x64-gnu/package.json').version
|
|
116
|
-
if (bindingPackageVersion !== '2.
|
|
117
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
129
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
130
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
118
131
|
}
|
|
119
132
|
return binding
|
|
120
133
|
} catch (e) {
|
|
@@ -129,8 +142,8 @@ function requireNative() {
|
|
|
129
142
|
try {
|
|
130
143
|
const binding = require('@medicomind/rolldown-compression-win32-x64-msvc')
|
|
131
144
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-win32-x64-msvc/package.json').version
|
|
132
|
-
if (bindingPackageVersion !== '2.
|
|
133
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
145
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
146
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
134
147
|
}
|
|
135
148
|
return binding
|
|
136
149
|
} catch (e) {
|
|
@@ -146,8 +159,8 @@ function requireNative() {
|
|
|
146
159
|
try {
|
|
147
160
|
const binding = require('@medicomind/rolldown-compression-win32-ia32-msvc')
|
|
148
161
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-win32-ia32-msvc/package.json').version
|
|
149
|
-
if (bindingPackageVersion !== '2.
|
|
150
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
162
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
163
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
151
164
|
}
|
|
152
165
|
return binding
|
|
153
166
|
} catch (e) {
|
|
@@ -162,8 +175,8 @@ function requireNative() {
|
|
|
162
175
|
try {
|
|
163
176
|
const binding = require('@medicomind/rolldown-compression-win32-arm64-msvc')
|
|
164
177
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-win32-arm64-msvc/package.json').version
|
|
165
|
-
if (bindingPackageVersion !== '2.
|
|
166
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
178
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
179
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
167
180
|
}
|
|
168
181
|
return binding
|
|
169
182
|
} catch (e) {
|
|
@@ -181,8 +194,8 @@ function requireNative() {
|
|
|
181
194
|
try {
|
|
182
195
|
const binding = require('@medicomind/rolldown-compression-darwin-universal')
|
|
183
196
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-darwin-universal/package.json').version
|
|
184
|
-
if (bindingPackageVersion !== '2.
|
|
185
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
197
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
198
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
186
199
|
}
|
|
187
200
|
return binding
|
|
188
201
|
} catch (e) {
|
|
@@ -197,8 +210,8 @@ function requireNative() {
|
|
|
197
210
|
try {
|
|
198
211
|
const binding = require('@medicomind/rolldown-compression-darwin-x64')
|
|
199
212
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-darwin-x64/package.json').version
|
|
200
|
-
if (bindingPackageVersion !== '2.
|
|
201
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
213
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
214
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
202
215
|
}
|
|
203
216
|
return binding
|
|
204
217
|
} catch (e) {
|
|
@@ -213,8 +226,8 @@ function requireNative() {
|
|
|
213
226
|
try {
|
|
214
227
|
const binding = require('@medicomind/rolldown-compression-darwin-arm64')
|
|
215
228
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-darwin-arm64/package.json').version
|
|
216
|
-
if (bindingPackageVersion !== '2.
|
|
217
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
229
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
230
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
218
231
|
}
|
|
219
232
|
return binding
|
|
220
233
|
} catch (e) {
|
|
@@ -233,8 +246,8 @@ function requireNative() {
|
|
|
233
246
|
try {
|
|
234
247
|
const binding = require('@medicomind/rolldown-compression-freebsd-x64')
|
|
235
248
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-freebsd-x64/package.json').version
|
|
236
|
-
if (bindingPackageVersion !== '2.
|
|
237
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
249
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
250
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
238
251
|
}
|
|
239
252
|
return binding
|
|
240
253
|
} catch (e) {
|
|
@@ -249,8 +262,8 @@ function requireNative() {
|
|
|
249
262
|
try {
|
|
250
263
|
const binding = require('@medicomind/rolldown-compression-freebsd-arm64')
|
|
251
264
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-freebsd-arm64/package.json').version
|
|
252
|
-
if (bindingPackageVersion !== '2.
|
|
253
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
265
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
266
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
254
267
|
}
|
|
255
268
|
return binding
|
|
256
269
|
} catch (e) {
|
|
@@ -270,8 +283,8 @@ function requireNative() {
|
|
|
270
283
|
try {
|
|
271
284
|
const binding = require('@medicomind/rolldown-compression-linux-x64-musl')
|
|
272
285
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-x64-musl/package.json').version
|
|
273
|
-
if (bindingPackageVersion !== '2.
|
|
274
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
286
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
287
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
275
288
|
}
|
|
276
289
|
return binding
|
|
277
290
|
} catch (e) {
|
|
@@ -286,8 +299,8 @@ function requireNative() {
|
|
|
286
299
|
try {
|
|
287
300
|
const binding = require('@medicomind/rolldown-compression-linux-x64-gnu')
|
|
288
301
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-x64-gnu/package.json').version
|
|
289
|
-
if (bindingPackageVersion !== '2.
|
|
290
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
302
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
303
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
291
304
|
}
|
|
292
305
|
return binding
|
|
293
306
|
} catch (e) {
|
|
@@ -304,8 +317,8 @@ function requireNative() {
|
|
|
304
317
|
try {
|
|
305
318
|
const binding = require('@medicomind/rolldown-compression-linux-arm64-musl')
|
|
306
319
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-arm64-musl/package.json').version
|
|
307
|
-
if (bindingPackageVersion !== '2.
|
|
308
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
320
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
321
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
309
322
|
}
|
|
310
323
|
return binding
|
|
311
324
|
} catch (e) {
|
|
@@ -320,8 +333,8 @@ function requireNative() {
|
|
|
320
333
|
try {
|
|
321
334
|
const binding = require('@medicomind/rolldown-compression-linux-arm64-gnu')
|
|
322
335
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-arm64-gnu/package.json').version
|
|
323
|
-
if (bindingPackageVersion !== '2.
|
|
324
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
336
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
337
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
325
338
|
}
|
|
326
339
|
return binding
|
|
327
340
|
} catch (e) {
|
|
@@ -338,8 +351,8 @@ function requireNative() {
|
|
|
338
351
|
try {
|
|
339
352
|
const binding = require('@medicomind/rolldown-compression-linux-arm-musleabihf')
|
|
340
353
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-arm-musleabihf/package.json').version
|
|
341
|
-
if (bindingPackageVersion !== '2.
|
|
342
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
354
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
355
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
343
356
|
}
|
|
344
357
|
return binding
|
|
345
358
|
} catch (e) {
|
|
@@ -354,8 +367,8 @@ function requireNative() {
|
|
|
354
367
|
try {
|
|
355
368
|
const binding = require('@medicomind/rolldown-compression-linux-arm-gnueabihf')
|
|
356
369
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-arm-gnueabihf/package.json').version
|
|
357
|
-
if (bindingPackageVersion !== '2.
|
|
358
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
370
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
371
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
359
372
|
}
|
|
360
373
|
return binding
|
|
361
374
|
} catch (e) {
|
|
@@ -372,8 +385,8 @@ function requireNative() {
|
|
|
372
385
|
try {
|
|
373
386
|
const binding = require('@medicomind/rolldown-compression-linux-loong64-musl')
|
|
374
387
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-loong64-musl/package.json').version
|
|
375
|
-
if (bindingPackageVersion !== '2.
|
|
376
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
388
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
389
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
377
390
|
}
|
|
378
391
|
return binding
|
|
379
392
|
} catch (e) {
|
|
@@ -388,8 +401,8 @@ function requireNative() {
|
|
|
388
401
|
try {
|
|
389
402
|
const binding = require('@medicomind/rolldown-compression-linux-loong64-gnu')
|
|
390
403
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-loong64-gnu/package.json').version
|
|
391
|
-
if (bindingPackageVersion !== '2.
|
|
392
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
404
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
405
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
393
406
|
}
|
|
394
407
|
return binding
|
|
395
408
|
} catch (e) {
|
|
@@ -406,8 +419,8 @@ function requireNative() {
|
|
|
406
419
|
try {
|
|
407
420
|
const binding = require('@medicomind/rolldown-compression-linux-riscv64-musl')
|
|
408
421
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-riscv64-musl/package.json').version
|
|
409
|
-
if (bindingPackageVersion !== '2.
|
|
410
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
422
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
423
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
411
424
|
}
|
|
412
425
|
return binding
|
|
413
426
|
} catch (e) {
|
|
@@ -422,8 +435,8 @@ function requireNative() {
|
|
|
422
435
|
try {
|
|
423
436
|
const binding = require('@medicomind/rolldown-compression-linux-riscv64-gnu')
|
|
424
437
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-riscv64-gnu/package.json').version
|
|
425
|
-
if (bindingPackageVersion !== '2.
|
|
426
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
438
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
439
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
427
440
|
}
|
|
428
441
|
return binding
|
|
429
442
|
} catch (e) {
|
|
@@ -439,8 +452,8 @@ function requireNative() {
|
|
|
439
452
|
try {
|
|
440
453
|
const binding = require('@medicomind/rolldown-compression-linux-ppc64-gnu')
|
|
441
454
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-ppc64-gnu/package.json').version
|
|
442
|
-
if (bindingPackageVersion !== '2.
|
|
443
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
455
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
456
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
444
457
|
}
|
|
445
458
|
return binding
|
|
446
459
|
} catch (e) {
|
|
@@ -455,8 +468,8 @@ function requireNative() {
|
|
|
455
468
|
try {
|
|
456
469
|
const binding = require('@medicomind/rolldown-compression-linux-s390x-gnu')
|
|
457
470
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-s390x-gnu/package.json').version
|
|
458
|
-
if (bindingPackageVersion !== '2.
|
|
459
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
471
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
472
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
460
473
|
}
|
|
461
474
|
return binding
|
|
462
475
|
} catch (e) {
|
|
@@ -475,8 +488,8 @@ function requireNative() {
|
|
|
475
488
|
try {
|
|
476
489
|
const binding = require('@medicomind/rolldown-compression-openharmony-arm64')
|
|
477
490
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-openharmony-arm64/package.json').version
|
|
478
|
-
if (bindingPackageVersion !== '2.
|
|
479
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
491
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
492
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
480
493
|
}
|
|
481
494
|
return binding
|
|
482
495
|
} catch (e) {
|
|
@@ -491,8 +504,8 @@ function requireNative() {
|
|
|
491
504
|
try {
|
|
492
505
|
const binding = require('@medicomind/rolldown-compression-openharmony-x64')
|
|
493
506
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-openharmony-x64/package.json').version
|
|
494
|
-
if (bindingPackageVersion !== '2.
|
|
495
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
507
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
508
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
496
509
|
}
|
|
497
510
|
return binding
|
|
498
511
|
} catch (e) {
|
|
@@ -507,8 +520,8 @@ function requireNative() {
|
|
|
507
520
|
try {
|
|
508
521
|
const binding = require('@medicomind/rolldown-compression-openharmony-arm')
|
|
509
522
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-openharmony-arm/package.json').version
|
|
510
|
-
if (bindingPackageVersion !== '2.
|
|
511
|
-
throw new Error(`Native binding package version mismatch, expected 2.
|
|
523
|
+
if (bindingPackageVersion !== '2.6.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
524
|
+
throw new Error(`Native binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
512
525
|
}
|
|
513
526
|
return binding
|
|
514
527
|
} catch (e) {
|
|
@@ -627,6 +640,7 @@ if (!nativeBinding || forceWasi) {
|
|
|
627
640
|
if (!candidateFailed) {
|
|
628
641
|
wasiBinding = require('./rolldown-compression.wasi.cjs')
|
|
629
642
|
nativeBinding = wasiBinding
|
|
643
|
+
__napiLoadedBindingTarget = 'wasm32-wasi'
|
|
630
644
|
wasiBindingLoaded = true
|
|
631
645
|
}
|
|
632
646
|
} catch (err) {
|
|
@@ -647,12 +661,13 @@ if (!nativeBinding || forceWasi) {
|
|
|
647
661
|
if (!candidateFailed) {
|
|
648
662
|
if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
649
663
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-wasm32-wasi/package.json').version
|
|
650
|
-
if (bindingPackageVersion !== '2.
|
|
651
|
-
throw new Error(`WASI binding package version mismatch, expected 2.
|
|
664
|
+
if (bindingPackageVersion !== '2.6.0') {
|
|
665
|
+
throw new Error(`WASI binding package version mismatch, expected 2.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
652
666
|
}
|
|
653
667
|
}
|
|
654
668
|
wasiBinding = require('@medicomind/rolldown-compression-wasm32-wasi')
|
|
655
669
|
nativeBinding = wasiBinding
|
|
670
|
+
__napiLoadedBindingTarget = 'wasm32-wasi'
|
|
656
671
|
wasiBindingLoaded = true
|
|
657
672
|
}
|
|
658
673
|
} catch (err) {
|
|
@@ -698,5 +713,69 @@ if (!nativeBinding) {
|
|
|
698
713
|
throw new Error(`Failed to load native binding`)
|
|
699
714
|
}
|
|
700
715
|
|
|
716
|
+
function __napiStampBindingTarget(exportsObject, target) {
|
|
717
|
+
if (
|
|
718
|
+
Object.prototype.hasOwnProperty.call(exportsObject, '__napiBindingTarget')
|
|
719
|
+
) {
|
|
720
|
+
if (exportsObject.__napiBindingTarget === target) {
|
|
721
|
+
// Already ours: the root entry aliases the object it loaded, so a WASI
|
|
722
|
+
// fallback candidate — or a `NAPI_RS_NATIVE_LIBRARY_PATH` override that
|
|
723
|
+
// is a generated loader — arrives already stamped with this same value.
|
|
724
|
+
return target
|
|
725
|
+
}
|
|
726
|
+
const error = new Error(
|
|
727
|
+
'`__napiBindingTarget` is reserved by the generated binding loader, but the loaded binding already exports it. Rename the export, e.g. #[napi(js_name = "...")].',
|
|
728
|
+
)
|
|
729
|
+
error.code = 'ERR_NAPI_BINDING_TARGET_CONFLICT'
|
|
730
|
+
throw error
|
|
731
|
+
}
|
|
732
|
+
if (!Object.isExtensible(exportsObject)) {
|
|
733
|
+
// A `#[napi(module_exports)]` hook may seal or freeze this object
|
|
734
|
+
// (`Object::seal` / `Object::freeze`). Reporting the artifact is metadata,
|
|
735
|
+
// never a reason to fail an otherwise successful load, so the stamp is
|
|
736
|
+
// skipped. What a consumer still sees then follows the entry point: the
|
|
737
|
+
// browser and deferred loaders declare `__napiBindingTarget` at module
|
|
738
|
+
// level and go on reporting it, while the CommonJS entries hand back this
|
|
739
|
+
// very object as `module.exports`, so there the value is absent.
|
|
740
|
+
return target
|
|
741
|
+
}
|
|
742
|
+
try {
|
|
743
|
+
// [[Define]], not [[Set]]: an ordinary assignment walks the prototype
|
|
744
|
+
// chain, so an inherited accessor could swallow the value or throw and
|
|
745
|
+
// fail an otherwise successful load. The descriptor is what a successful
|
|
746
|
+
// assignment would have produced.
|
|
747
|
+
Object.defineProperty(exportsObject, '__napiBindingTarget', {
|
|
748
|
+
configurable: true,
|
|
749
|
+
enumerable: true,
|
|
750
|
+
value: target,
|
|
751
|
+
writable: true,
|
|
752
|
+
})
|
|
753
|
+
} catch {
|
|
754
|
+
// Same rule as the non-extensible skip above: reporting the artifact is
|
|
755
|
+
// metadata, never a reason to fail an otherwise successful load. An exotic
|
|
756
|
+
// object (a Proxy whose defineProperty trap refuses) is skipped, not
|
|
757
|
+
// thrown over.
|
|
758
|
+
}
|
|
759
|
+
// The CommonJS loaders assign this return value so `cjs-module-lexer` — and
|
|
760
|
+
// therefore Node's CJS -> ESM named export detection — can see
|
|
761
|
+
// `__napiBindingTarget` statically.
|
|
762
|
+
return target
|
|
763
|
+
}
|
|
764
|
+
// Stamp before the alias, not after. The guard only reads `nativeBinding`
|
|
765
|
+
// (`hasOwnProperty` plus a comparison), which is safe against any addon
|
|
766
|
+
// accessor; an assignment is not, because a `#[napi(module_exports)]` hook can
|
|
767
|
+
// expose a getter reporting this very value and a setter that throws. So the
|
|
768
|
+
// assignment lands on the loader's own `module.exports`, still the original
|
|
769
|
+
// object here, and the alias below replaces it.
|
|
770
|
+
//
|
|
771
|
+
// The assignment is what keeps the marker a statically visible CommonJS export:
|
|
772
|
+
// `cjs-module-lexer` is Node's CJS -> ESM named export detection, it cannot see
|
|
773
|
+
// a bare call, and the later `module.exports = nativeBinding` does not undo the
|
|
774
|
+
// detection. The assignment itself always succeeds — its target is this
|
|
775
|
+
// loader's own, still extensible `module.exports` — and the alias below then
|
|
776
|
+
// discards the value it wrote. What a consumer reads is whatever the guard put
|
|
777
|
+
// on `nativeBinding`, so on a frozen binding, where the guard skips, the
|
|
778
|
+
// linked import resolves to `undefined`.
|
|
779
|
+
module.exports.__napiBindingTarget = __napiStampBindingTarget(nativeBinding, __napiLoadedBindingTarget)
|
|
701
780
|
module.exports = nativeBinding
|
|
702
781
|
module.exports.compressBuffers = nativeBinding.compressBuffers
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medicomind/rolldown-compression",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
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.
|
|
92
|
-
"@medicomind/rolldown-compression-darwin-x64": "2.
|
|
93
|
-
"@medicomind/rolldown-compression-linux-arm64-gnu": "2.
|
|
94
|
-
"@medicomind/rolldown-compression-linux-x64-gnu": "2.
|
|
95
|
-
"@medicomind/rolldown-compression-linux-x64-musl": "2.
|
|
96
|
-
"@medicomind/rolldown-compression-wasm32-wasi": "2.
|
|
97
|
-
"@medicomind/rolldown-compression-win32-x64-msvc": "2.
|
|
91
|
+
"@medicomind/rolldown-compression-darwin-arm64": "2.6.0",
|
|
92
|
+
"@medicomind/rolldown-compression-darwin-x64": "2.6.0",
|
|
93
|
+
"@medicomind/rolldown-compression-linux-arm64-gnu": "2.6.0",
|
|
94
|
+
"@medicomind/rolldown-compression-linux-x64-gnu": "2.6.0",
|
|
95
|
+
"@medicomind/rolldown-compression-linux-x64-musl": "2.6.0",
|
|
96
|
+
"@medicomind/rolldown-compression-wasm32-wasi": "2.6.0",
|
|
97
|
+
"@medicomind/rolldown-compression-win32-x64-msvc": "2.6.0"
|
|
98
98
|
},
|
|
99
99
|
"devDependencies": {
|
|
100
|
-
"@biomejs/biome": "^2.5.
|
|
100
|
+
"@biomejs/biome": "^2.5.15",
|
|
101
101
|
"@changesets/changelog-github": "^1.0.1",
|
|
102
|
-
"@changesets/cli": "^3.0.
|
|
103
|
-
"@emnapi/core": "2.0.0-alpha.
|
|
104
|
-
"@emnapi/runtime": "2.0.0-alpha.
|
|
105
|
-
"@napi-rs/cli": "^3.
|
|
106
|
-
"@napi-rs/wasm-runtime": "^1.2.
|
|
107
|
-
"@types/node": "^26.5
|
|
108
|
-
"@vitest/coverage-v8": "^5.0.
|
|
109
|
-
"emnapi": "
|
|
110
|
-
"rolldown": "^1.2.
|
|
111
|
-
"tsdown": "^0.23.
|
|
102
|
+
"@changesets/cli": "^3.0.3",
|
|
103
|
+
"@emnapi/core": "2.0.0-alpha.6",
|
|
104
|
+
"@emnapi/runtime": "2.0.0-alpha.6",
|
|
105
|
+
"@napi-rs/cli": "^3.10.8",
|
|
106
|
+
"@napi-rs/wasm-runtime": "^1.2.5",
|
|
107
|
+
"@types/node": "^26.6.5",
|
|
108
|
+
"@vitest/coverage-v8": "^5.0.4",
|
|
109
|
+
"emnapi": "2.0.0-alpha.6",
|
|
110
|
+
"rolldown": "^1.2.13",
|
|
111
|
+
"tsdown": "^0.23.1",
|
|
112
112
|
"typescript": "^7.0.2",
|
|
113
|
-
"vitest": "^5.0.
|
|
113
|
+
"vitest": "^5.0.4"
|
|
114
114
|
}
|
|
115
115
|
}
|