@medicomind/rolldown-compression 1.0.1 → 1.2.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 +16 -0
- package/README.md +24 -3
- package/dist/index.cjs +178 -74
- package/dist/index.d.cts +18 -1
- package/dist/index.d.mts +18 -1
- package/dist/index.mjs +178 -74
- package/index.d.ts +6 -0
- package/index.js +52 -52
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @medicomind/rolldown-compression
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`31fcbe3`](https://github.com/Medico-Mind/rolldown-compression/commit/31fcbe3c3155e9d0e08b5474e184c0d34fe3ddfe) Thanks [@Mnwa](https://github.com/Mnwa)! - Move section size brotli to plugin config
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [`8788204`](https://github.com/Medico-Mind/rolldown-compression/commit/8788204ada0ba014d536b122aed787b7317cdda4) Thanks [@Mnwa](https://github.com/Mnwa)! - Reuse brotli thread pool for big files
|
|
12
|
+
|
|
13
|
+
## 1.1.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- [`1d98d99`](https://github.com/Medico-Mind/rolldown-compression/commit/1d98d995567280c60194451818c7caffb7808bc6) Thanks [@Mnwa](https://github.com/Mnwa)! - Add `stream` option: compress from disk in `writeBundle` (order `post`) instead of in memory in `generateBundle`. Files are read on demand in bounded batches (`chunkSize` source bytes per batch, or 4 MB when `chunkSize` is 0), so the whole build is never buffered by the plugin and assets written to disk by other plugins' `writeBundle` hooks are compressed as well — removing the previous `generateBundle`-only limitation.
|
|
18
|
+
|
|
3
19
|
## 1.0.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -57,6 +57,7 @@ compression({
|
|
|
57
57
|
skipIfLargerOrEqual: true,
|
|
58
58
|
concurrency: 0, // 0 = number of logical CPUs
|
|
59
59
|
chunkSize: 0, // 0 = compress everything in one batch
|
|
60
|
+
stream: false, // true = on-demand disk-based compression in writeBundle
|
|
60
61
|
logLevel: 'info',
|
|
61
62
|
})
|
|
62
63
|
```
|
|
@@ -91,7 +92,8 @@ export default defineConfig({
|
|
|
91
92
|
| `deleteOriginalAssets` | `boolean` | `false` | Remove the original from the bundle after all algorithms processed it. Errors if `filename` resolves to the source name. |
|
|
92
93
|
| `skipIfLargerOrEqual` | `boolean` | `true` | Don't emit artifacts whose compressed size is `>=` the original. |
|
|
93
94
|
| `concurrency` | `number` | `0` | Native worker threads. `0` = number of logical CPUs. |
|
|
94
|
-
| `chunkSize` | `number` | `0` | Max source bytes buffered per native compression batch. `0` = one batch for the whole build. A positive value (e.g. `64 * 1024 * 1024`) caps the plugin's peak memory overhead at roughly one batch of source copies plus its compressed outputs; a single file larger than `chunkSize` still forms its own batch. The bundler keeps the original bundle in memory regardless. |
|
|
95
|
+
| `chunkSize` | `number` | `0` | Max source bytes buffered per native compression batch. `0` = one batch for the whole build. A positive value (e.g. `64 * 1024 * 1024`) caps the plugin's peak memory overhead at roughly one batch of source copies plus its compressed outputs; a single file larger than `chunkSize` still forms its own batch. The bundler keeps the original bundle in memory regardless. In [stream mode](#stream-mode) `0` falls back to a 4 MB batch instead of one big batch. |
|
|
96
|
+
| `stream` | `boolean` | `false` | Compress from disk in `writeBundle` (order `post`) instead of in memory in `generateBundle`: files are read on demand in bounded batches (`chunkSize` bytes, default 4 MB), and assets written to disk by other plugins' `writeBundle` hooks are compressed too (see [stream mode](#stream-mode)). |
|
|
95
97
|
| `logLevel` | `'silent' \| 'error' \| 'warn' \| 'info'` | `'info'` | Plugin log verbosity; `info` prints a per-algorithm summary at build end. |
|
|
96
98
|
| `enableInWatchMode` | `boolean` | `false` | The plugin is a no-op in watch/dev mode unless enabled (see [watch mode](#watch--dev-mode)). |
|
|
97
99
|
|
|
@@ -104,6 +106,7 @@ All options are validated when `compression()` is called — invalid levels (e.g
|
|
|
104
106
|
| `gzip` | `level` | 0–9 | 6 |
|
|
105
107
|
| `brotli` | `quality` | 0–11 | 11 |
|
|
106
108
|
| `brotli` | `windowBits` | 10–24 | 22 |
|
|
109
|
+
| `brotli` | `sectionSize` | ≥ 1 (bytes) | 1 MiB |
|
|
107
110
|
| `zstd` | `level` | 1–22 | 19 |
|
|
108
111
|
|
|
109
112
|
```ts
|
|
@@ -112,6 +115,8 @@ defineAlgorithm('brotli', { quality: 7, windowBits: 22 })
|
|
|
112
115
|
defineAlgorithm('zstd', { level: 12 })
|
|
113
116
|
```
|
|
114
117
|
|
|
118
|
+
`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. Smaller sections finish large files faster at a slight cost in compression ratio — sections much smaller than the window (`2^windowBits` bytes) lose too many cross-section matches.
|
|
119
|
+
|
|
115
120
|
## How it works
|
|
116
121
|
|
|
117
122
|
- 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`.
|
|
@@ -120,7 +125,23 @@ defineAlgorithm('zstd', { level: 12 })
|
|
|
120
125
|
- A failing task never aborts the batch: per-task errors are aggregated and fail the build with one message.
|
|
121
126
|
- 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`.
|
|
122
127
|
|
|
123
|
-
Limitation: assets written to disk by other plugins in `writeBundle`/`closeBundle` (i.e. after `generateBundle`) are not seen
|
|
128
|
+
Limitation of the default mode: assets written to disk by other plugins in `writeBundle`/`closeBundle` (i.e. after `generateBundle`) are not seen. This matches how `vite-plugin-compression2` handles the in-bundle pass. Set `stream: true` to remove it.
|
|
129
|
+
|
|
130
|
+
### Stream mode
|
|
131
|
+
|
|
132
|
+
With `stream: true` the plugin skips the in-memory `generateBundle` pass entirely and instead runs at the end of `writeBundle` (hook order `post`), after the bundle — and any extra assets other plugins wrote in their own `writeBundle` hooks — is on disk:
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
compression({
|
|
136
|
+
stream: true,
|
|
137
|
+
chunkSize: 64 * 1024 * 1024, // optional: batch by source bytes instead of by file count
|
|
138
|
+
})
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
- The output directory is scanned recursively and matching files are read **on demand**, never all at once: a batch is flushed to the native module whenever it reaches `chunkSize` source bytes, defaulting to **4 MB** when `chunkSize` is `0`. Peak memory overhead is one batch of sources plus its compressed outputs, regardless of build size.
|
|
142
|
+
- Compressed artifacts are written straight to the output directory (`emitFile` is not available after write); `deleteOriginalAssets` unlinks the originals from disk.
|
|
143
|
+
- The same filter, threshold and re-compression guards apply, and everything already in the output directory that matches them is compressed — including files produced by other plugins after `generateBundle`, the default mode's limitation. Assets written in `closeBundle` (after all `writeBundle` hooks) are still not seen.
|
|
144
|
+
- Trade-off: files the bundler already had in memory are re-read from disk, and per-batch FFI calls replace the single big batch — for small builds the default in-memory mode is faster.
|
|
124
145
|
|
|
125
146
|
### Watch / dev mode
|
|
126
147
|
|
|
@@ -254,7 +275,7 @@ the host, so on an unsupported platform the wasm package must be opted into:
|
|
|
254
275
|
- **No tarball plugin**: out of scope.
|
|
255
276
|
- **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.
|
|
256
277
|
- **zstd everywhere**: zstd is compiled in, with no dependency on the Node runtime's zstd support (node >= 22.15).
|
|
257
|
-
- Extra options: `concurrency` (native thread cap), `chunkSize` (memory cap per compression batch) and `enableInWatchMode`.
|
|
278
|
+
- Extra options: `concurrency` (native thread cap), `chunkSize` (memory cap per compression batch), `stream` (on-demand disk-based compression in `writeBundle`) and `enableInWatchMode`.
|
|
258
279
|
|
|
259
280
|
## Implementation decisions
|
|
260
281
|
|
package/dist/index.cjs
CHANGED
|
@@ -25,6 +25,7 @@ let node_crypto = require("node:crypto");
|
|
|
25
25
|
let node_path = require("node:path");
|
|
26
26
|
node_path = __toESM(node_path);
|
|
27
27
|
let _rollup_pluginutils = require("@rollup/pluginutils");
|
|
28
|
+
let node_fs_promises = require("node:fs/promises");
|
|
28
29
|
let node_module = require("node:module");
|
|
29
30
|
//#region ts/options.ts
|
|
30
31
|
/**
|
|
@@ -91,9 +92,10 @@ function defineAlgorithm(name, options = {}) {
|
|
|
91
92
|
}
|
|
92
93
|
function validateAlgorithmOptions(algorithm, options) {
|
|
93
94
|
if (algorithm === "brotli") {
|
|
94
|
-
const { quality, windowBits } = options;
|
|
95
|
+
const { quality, windowBits, sectionSize } = options;
|
|
95
96
|
if (quality !== void 0) assertIntegerInRange(quality, LEVEL_RANGES.brotli, "brotli quality");
|
|
96
97
|
if (windowBits !== void 0) assertIntegerInRange(windowBits, [10, 24], "brotli windowBits");
|
|
98
|
+
if (sectionSize !== void 0) assertIntegerInRange(sectionSize, [1, 4294967295], "brotli sectionSize");
|
|
97
99
|
return;
|
|
98
100
|
}
|
|
99
101
|
const { level } = options;
|
|
@@ -110,8 +112,9 @@ function resolveAlgorithm(entry) {
|
|
|
110
112
|
extension: EXTENSIONS[algorithm]
|
|
111
113
|
};
|
|
112
114
|
if (algorithm === "brotli") {
|
|
113
|
-
const { windowBits } = options;
|
|
115
|
+
const { windowBits, sectionSize } = options;
|
|
114
116
|
if (windowBits !== void 0) resolved.windowBits = windowBits;
|
|
117
|
+
if (sectionSize !== void 0) resolved.sectionSize = sectionSize;
|
|
115
118
|
}
|
|
116
119
|
return resolved;
|
|
117
120
|
}
|
|
@@ -127,7 +130,7 @@ function validateDefined(entry) {
|
|
|
127
130
|
/** Validate and normalize user options. Throws at `compression()` call time. */
|
|
128
131
|
function resolveOptions(options = {}) {
|
|
129
132
|
if (options === null || typeof options !== "object") throw new OptionValidationError("options must be an object");
|
|
130
|
-
const { include = DEFAULT_INCLUDE, exclude, threshold = 0, algorithms = ["gzip", "brotli"], filename, deleteOriginalAssets = false, skipIfLargerOrEqual = true, concurrency = 0, chunkSize = 0, logLevel = "info", enableInWatchMode = false } = options;
|
|
133
|
+
const { include = DEFAULT_INCLUDE, exclude, threshold = 0, algorithms = ["gzip", "brotli"], filename, deleteOriginalAssets = false, skipIfLargerOrEqual = true, concurrency = 0, chunkSize = 0, stream = false, logLevel = "info", enableInWatchMode = false } = options;
|
|
131
134
|
if (typeof threshold !== "number" || Number.isNaN(threshold) || threshold < 0) throw new OptionValidationError(`invalid threshold: expected a non-negative number, got ${JSON.stringify(threshold)}`);
|
|
132
135
|
if (!Number.isInteger(concurrency) || concurrency < 0) throw new OptionValidationError(`invalid concurrency: expected a non-negative integer, got ${JSON.stringify(concurrency)}`);
|
|
133
136
|
if (!Number.isInteger(chunkSize) || chunkSize < 0) throw new OptionValidationError(`invalid chunkSize: expected a non-negative integer number of bytes, got ${JSON.stringify(chunkSize)}`);
|
|
@@ -143,6 +146,7 @@ function resolveOptions(options = {}) {
|
|
|
143
146
|
skipIfLargerOrEqual: Boolean(skipIfLargerOrEqual),
|
|
144
147
|
concurrency,
|
|
145
148
|
chunkSize,
|
|
149
|
+
stream: Boolean(stream),
|
|
146
150
|
logLevel,
|
|
147
151
|
enableInWatchMode: Boolean(enableInWatchMode)
|
|
148
152
|
};
|
|
@@ -167,7 +171,28 @@ function resolveOutputFileName(filename, fileName, algorithm, source) {
|
|
|
167
171
|
const compressBuffers = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("../index.js").compressBuffers;
|
|
168
172
|
//#endregion
|
|
169
173
|
//#region ts/plugin.ts
|
|
174
|
+
/**
|
|
175
|
+
* Rolldown plugin implementation.
|
|
176
|
+
*
|
|
177
|
+
* Default mode: all eligible assets of a build are collected in
|
|
178
|
+
* `generateBundle` (while they are still in memory) and compressed in
|
|
179
|
+
* batched FFI calls; the native module fans the work out across a rayon
|
|
180
|
+
* thread pool without ever blocking the JS event loop. By default
|
|
181
|
+
* everything goes out in a single batch; a positive `chunkSize` flushes a
|
|
182
|
+
* batch whenever its source bytes reach that limit, so only one batch of
|
|
183
|
+
* buffer copies is alive at a time.
|
|
184
|
+
*
|
|
185
|
+
* Stream mode (`stream: true`): compression instead runs at the end of
|
|
186
|
+
* `writeBundle` (order `'post'`), scanning the output directory on disk.
|
|
187
|
+
* Files are read on demand and processed in bounded batches — `chunkSize`
|
|
188
|
+
* source bytes per batch, falling back to
|
|
189
|
+
* {@link STREAM_DEFAULT_CHUNK_SIZE} when `chunkSize` is 0 — so the whole
|
|
190
|
+
* build is never held in memory and assets written to disk by other
|
|
191
|
+
* plugins' `writeBundle` hooks are compressed as well.
|
|
192
|
+
*/
|
|
170
193
|
const PLUGIN_NAME = "rolldown-compression";
|
|
194
|
+
/** Source bytes per batch in stream mode when `chunkSize` is 0. */
|
|
195
|
+
const STREAM_DEFAULT_CHUNK_SIZE = 4 * 1024 * 1024;
|
|
171
196
|
const LOG_PRIORITY = {
|
|
172
197
|
silent: 0,
|
|
173
198
|
error: 1,
|
|
@@ -197,97 +222,176 @@ function formatBytes(bytes) {
|
|
|
197
222
|
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} kB`;
|
|
198
223
|
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
199
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Shared batching core: queues per-algorithm tasks, flushes them to the
|
|
227
|
+
* native module and hands successful results to `emit`. Only one batch of
|
|
228
|
+
* source buffers is referenced at a time once a flush trigger is set.
|
|
229
|
+
*/
|
|
230
|
+
function createBatchRunner(options, logger, emittedNames, emit, fail) {
|
|
231
|
+
const processedSources = /* @__PURE__ */ new Set();
|
|
232
|
+
const emittedBySource = /* @__PURE__ */ new Map();
|
|
233
|
+
const failures = [];
|
|
234
|
+
const stats = /* @__PURE__ */ new Map();
|
|
235
|
+
const chunkSize = options.chunkSize > 0 ? options.chunkSize : options.stream ? STREAM_DEFAULT_CHUNK_SIZE : 0;
|
|
236
|
+
let pending = [];
|
|
237
|
+
let pendingSourceBytes = 0;
|
|
238
|
+
const flush = async () => {
|
|
239
|
+
if (pending.length === 0) return;
|
|
240
|
+
const batch = pending;
|
|
241
|
+
pending = [];
|
|
242
|
+
pendingSourceBytes = 0;
|
|
243
|
+
const results = await compressBuffers(batch.map((artifact) => artifact.task), batch.map((artifact) => artifact.buffer), {
|
|
244
|
+
concurrency: options.concurrency,
|
|
245
|
+
skipIfLargerOrEqual: options.skipIfLargerOrEqual
|
|
246
|
+
});
|
|
247
|
+
for (const [index, result] of results.entries()) {
|
|
248
|
+
const artifact = batch[index];
|
|
249
|
+
if (artifact === void 0) continue;
|
|
250
|
+
if (result.error !== void 0 && result.error !== null) {
|
|
251
|
+
failures.push(`${result.fileName} (${result.algorithm}): ${result.error}`);
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
if (result.skipped) {
|
|
255
|
+
logger.info(`skipped ${artifact.outputFileName}: ${result.algorithm} output would not be smaller than the original`);
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
await emit(artifact, result.data);
|
|
259
|
+
emittedNames.add(artifact.outputFileName);
|
|
260
|
+
emittedBySource.set(artifact.sourceFileName, (emittedBySource.get(artifact.sourceFileName) ?? 0) + 1);
|
|
261
|
+
const stat = stats.get(result.algorithm) ?? {
|
|
262
|
+
count: 0,
|
|
263
|
+
originalBytes: 0,
|
|
264
|
+
outputBytes: 0
|
|
265
|
+
};
|
|
266
|
+
stat.count += 1;
|
|
267
|
+
stat.originalBytes += result.originalSize;
|
|
268
|
+
stat.outputBytes += result.compressedSize;
|
|
269
|
+
stats.set(result.algorithm, stat);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
const addFile = async (fileName, buffer) => {
|
|
273
|
+
for (const algorithm of options.algorithms) {
|
|
274
|
+
const outputFileName = resolveOutputFileName(options.filename, fileName, algorithm, buffer);
|
|
275
|
+
if (outputFileName === fileName) fail(`the filename option resolved "${fileName}" (${algorithm.algorithm}) to the same name as the source asset; refusing to overwrite it`);
|
|
276
|
+
pending.push({
|
|
277
|
+
task: {
|
|
278
|
+
fileName,
|
|
279
|
+
algorithm: algorithm.algorithm,
|
|
280
|
+
level: algorithm.level,
|
|
281
|
+
windowBits: algorithm.windowBits,
|
|
282
|
+
sectionSize: algorithm.sectionSize
|
|
283
|
+
},
|
|
284
|
+
buffer,
|
|
285
|
+
sourceFileName: fileName,
|
|
286
|
+
outputFileName
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
processedSources.add(fileName);
|
|
290
|
+
pendingSourceBytes += buffer.byteLength;
|
|
291
|
+
if (chunkSize > 0 && pendingSourceBytes >= chunkSize) await flush();
|
|
292
|
+
};
|
|
293
|
+
return {
|
|
294
|
+
addFile,
|
|
295
|
+
flush,
|
|
296
|
+
processedSources,
|
|
297
|
+
emittedBySource,
|
|
298
|
+
failures,
|
|
299
|
+
stats
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
function logSummary(logger, stats, startedAt) {
|
|
303
|
+
const summary = [...stats.entries()].map(([algorithm, stat]) => `${algorithm}: ${stat.count} file(s), ${formatBytes(stat.originalBytes)} -> ${formatBytes(stat.outputBytes)}`).join("; ");
|
|
304
|
+
if (summary.length === 0) return;
|
|
305
|
+
const totalSaved = [...stats.values()].reduce((sum, stat) => sum + (stat.originalBytes - stat.outputBytes), 0);
|
|
306
|
+
const elapsedMs = performance.now() - startedAt;
|
|
307
|
+
logger.info(`${summary}; saved ${formatBytes(totalSaved)} in ${(elapsedMs / 1e3).toFixed(2)}s`);
|
|
308
|
+
}
|
|
309
|
+
/** Recursively list every file under `root`, in a deterministic order. */
|
|
310
|
+
async function walkFiles(root) {
|
|
311
|
+
const files = [];
|
|
312
|
+
const visit = async (dir) => {
|
|
313
|
+
const entries = await (0, node_fs_promises.readdir)(dir, { withFileTypes: true });
|
|
314
|
+
entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
315
|
+
for (const entry of entries) {
|
|
316
|
+
const absolute = node_path.default.join(dir, entry.name);
|
|
317
|
+
if (entry.isDirectory()) await visit(absolute);
|
|
318
|
+
else if (entry.isFile()) files.push(absolute);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
await visit(root);
|
|
322
|
+
return files;
|
|
323
|
+
}
|
|
200
324
|
function createCompressionPlugin(options) {
|
|
201
325
|
const logger = createLogger(options.logLevel);
|
|
202
326
|
const emittedNames = /* @__PURE__ */ new Set();
|
|
203
327
|
return Object.assign({
|
|
204
328
|
name: PLUGIN_NAME,
|
|
205
329
|
async generateBundle(_outputOptions, bundle) {
|
|
330
|
+
if (options.stream) return;
|
|
206
331
|
if (this.meta?.watchMode && !options.enableInWatchMode) {
|
|
207
332
|
logger.info("watch mode detected, skipping compression (set enableInWatchMode to opt in)");
|
|
208
333
|
return;
|
|
209
334
|
}
|
|
210
335
|
const startedAt = performance.now();
|
|
211
|
-
const
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const flush = async () => {
|
|
218
|
-
if (pending.length === 0) return;
|
|
219
|
-
const batch = pending;
|
|
220
|
-
pending = [];
|
|
221
|
-
pendingSourceBytes = 0;
|
|
222
|
-
const results = await compressBuffers(batch.map((artifact) => artifact.task), batch.map((artifact) => artifact.buffer), {
|
|
223
|
-
concurrency: options.concurrency,
|
|
224
|
-
skipIfLargerOrEqual: options.skipIfLargerOrEqual
|
|
336
|
+
const fail = (message) => this.error(/* @__PURE__ */ new Error(`[${PLUGIN_NAME}] ${message}`));
|
|
337
|
+
const runner = createBatchRunner(options, logger, emittedNames, (artifact, data) => {
|
|
338
|
+
this.emitFile({
|
|
339
|
+
type: "asset",
|
|
340
|
+
fileName: artifact.outputFileName,
|
|
341
|
+
source: data
|
|
225
342
|
});
|
|
226
|
-
|
|
227
|
-
const artifact = batch[index];
|
|
228
|
-
if (artifact === void 0) continue;
|
|
229
|
-
if (result.error !== void 0 && result.error !== null) {
|
|
230
|
-
failures.push(`${result.fileName} (${result.algorithm}): ${result.error}`);
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
if (result.skipped) {
|
|
234
|
-
logger.info(`skipped ${artifact.outputFileName}: ${result.algorithm} output would not be smaller than the original`);
|
|
235
|
-
continue;
|
|
236
|
-
}
|
|
237
|
-
this.emitFile({
|
|
238
|
-
type: "asset",
|
|
239
|
-
fileName: artifact.outputFileName,
|
|
240
|
-
source: result.data
|
|
241
|
-
});
|
|
242
|
-
emittedNames.add(artifact.outputFileName);
|
|
243
|
-
emittedBySource.set(artifact.sourceFileName, (emittedBySource.get(artifact.sourceFileName) ?? 0) + 1);
|
|
244
|
-
const stat = stats.get(result.algorithm) ?? {
|
|
245
|
-
count: 0,
|
|
246
|
-
originalBytes: 0,
|
|
247
|
-
outputBytes: 0
|
|
248
|
-
};
|
|
249
|
-
stat.count += 1;
|
|
250
|
-
stat.originalBytes += result.originalSize;
|
|
251
|
-
stat.outputBytes += result.compressedSize;
|
|
252
|
-
stats.set(result.algorithm, stat);
|
|
253
|
-
}
|
|
254
|
-
};
|
|
343
|
+
}, fail);
|
|
255
344
|
for (const [fileName, output] of Object.entries(bundle)) {
|
|
256
345
|
if (!options.filter(fileName)) continue;
|
|
257
346
|
if (COMPRESSED_EXTENSION_RE.test(fileName) || emittedNames.has(fileName)) continue;
|
|
258
347
|
const buffer = toBuffer(output.type === "chunk" ? output.code : output.source);
|
|
259
348
|
if (buffer.byteLength < options.threshold) continue;
|
|
260
|
-
|
|
261
|
-
const outputFileName = resolveOutputFileName(options.filename, fileName, algorithm, buffer);
|
|
262
|
-
if (outputFileName === fileName) this.error(/* @__PURE__ */ new Error(`[${PLUGIN_NAME}] the filename option resolved "${fileName}" (${algorithm.algorithm}) to the same name as the source asset; refusing to overwrite it`));
|
|
263
|
-
pending.push({
|
|
264
|
-
task: {
|
|
265
|
-
fileName,
|
|
266
|
-
algorithm: algorithm.algorithm,
|
|
267
|
-
level: algorithm.level,
|
|
268
|
-
windowBits: algorithm.windowBits
|
|
269
|
-
},
|
|
270
|
-
buffer,
|
|
271
|
-
sourceFileName: fileName,
|
|
272
|
-
outputFileName
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
processedSources.add(fileName);
|
|
276
|
-
pendingSourceBytes += buffer.byteLength;
|
|
277
|
-
if (options.chunkSize > 0 && pendingSourceBytes >= options.chunkSize) await flush();
|
|
349
|
+
await runner.addFile(fileName, buffer);
|
|
278
350
|
}
|
|
279
|
-
await flush();
|
|
280
|
-
if (processedSources.size === 0) return;
|
|
281
|
-
if (failures.length > 0)
|
|
282
|
-
if (options.deleteOriginalAssets) for (const fileName of processedSources) {
|
|
283
|
-
if ((emittedBySource.get(fileName) ?? 0) === 0) logger.warn(`deleteOriginalAssets removed "${fileName}" even though no compressed variant was emitted for it`);
|
|
351
|
+
await runner.flush();
|
|
352
|
+
if (runner.processedSources.size === 0) return;
|
|
353
|
+
if (runner.failures.length > 0) fail(`${runner.failures.length} compression task(s) failed:\n${runner.failures.join("\n")}`);
|
|
354
|
+
if (options.deleteOriginalAssets) for (const fileName of runner.processedSources) {
|
|
355
|
+
if ((runner.emittedBySource.get(fileName) ?? 0) === 0) logger.warn(`deleteOriginalAssets removed "${fileName}" even though no compressed variant was emitted for it`);
|
|
284
356
|
delete bundle[fileName];
|
|
285
357
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
358
|
+
logSummary(logger, runner.stats, startedAt);
|
|
359
|
+
},
|
|
360
|
+
writeBundle: {
|
|
361
|
+
order: "post",
|
|
362
|
+
async handler(outputOptions) {
|
|
363
|
+
if (!options.stream) return;
|
|
364
|
+
if (this.meta?.watchMode && !options.enableInWatchMode) {
|
|
365
|
+
logger.info("watch mode detected, skipping compression (set enableInWatchMode to opt in)");
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const outDir = outputOptions.dir !== void 0 ? node_path.default.resolve(outputOptions.dir) : outputOptions.file !== void 0 ? node_path.default.resolve(node_path.default.dirname(outputOptions.file)) : void 0;
|
|
369
|
+
if (outDir === void 0) {
|
|
370
|
+
logger.warn("stream mode could not determine the output directory, skipping compression");
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
const startedAt = performance.now();
|
|
374
|
+
const fail = (message) => this.error(/* @__PURE__ */ new Error(`[${PLUGIN_NAME}] ${message}`));
|
|
375
|
+
const runner = createBatchRunner(options, logger, emittedNames, async (artifact, data) => {
|
|
376
|
+
const target = node_path.default.join(outDir, artifact.outputFileName);
|
|
377
|
+
await (0, node_fs_promises.mkdir)(node_path.default.dirname(target), { recursive: true });
|
|
378
|
+
await (0, node_fs_promises.writeFile)(target, data);
|
|
379
|
+
}, fail);
|
|
380
|
+
for (const absolute of await walkFiles(outDir)) {
|
|
381
|
+
const fileName = node_path.default.relative(outDir, absolute).split(node_path.default.sep).join("/");
|
|
382
|
+
if (!options.filter(fileName)) continue;
|
|
383
|
+
if (COMPRESSED_EXTENSION_RE.test(fileName) || emittedNames.has(fileName)) continue;
|
|
384
|
+
if ((await (0, node_fs_promises.stat)(absolute)).size < options.threshold) continue;
|
|
385
|
+
await runner.addFile(fileName, await (0, node_fs_promises.readFile)(absolute));
|
|
386
|
+
}
|
|
387
|
+
await runner.flush();
|
|
388
|
+
if (runner.processedSources.size === 0) return;
|
|
389
|
+
if (runner.failures.length > 0) fail(`${runner.failures.length} compression task(s) failed:\n${runner.failures.join("\n")}`);
|
|
390
|
+
if (options.deleteOriginalAssets) for (const fileName of runner.processedSources) {
|
|
391
|
+
if ((runner.emittedBySource.get(fileName) ?? 0) === 0) logger.warn(`deleteOriginalAssets removed "${fileName}" even though no compressed variant was emitted for it`);
|
|
392
|
+
await (0, node_fs_promises.unlink)(node_path.default.join(outDir, fileName));
|
|
393
|
+
}
|
|
394
|
+
logSummary(logger, runner.stats, startedAt);
|
|
291
395
|
}
|
|
292
396
|
}
|
|
293
397
|
}, { apply: "build" });
|
package/dist/index.d.cts
CHANGED
|
@@ -8,10 +8,17 @@ type CanonicalAlgorithm = 'gzip' | 'brotli' | 'zstd';
|
|
|
8
8
|
interface GzipOptions {
|
|
9
9
|
level?: number;
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
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 take
|
|
15
|
+
* the multithreaded path. Default 1 MiB. Smaller sections finish large files
|
|
16
|
+
* faster at a slight cost in compression ratio.
|
|
17
|
+
*/
|
|
12
18
|
interface BrotliOptions {
|
|
13
19
|
quality?: number;
|
|
14
20
|
windowBits?: number;
|
|
21
|
+
sectionSize?: number;
|
|
15
22
|
}
|
|
16
23
|
/** Zstandard options. `level`: 1-22, default 19. */
|
|
17
24
|
interface ZstdOptions {
|
|
@@ -79,6 +86,16 @@ interface CompressionOptions {
|
|
|
79
86
|
* @default 0
|
|
80
87
|
*/
|
|
81
88
|
chunkSize?: number;
|
|
89
|
+
/**
|
|
90
|
+
* Compress from disk at the end of `writeBundle` instead of in memory in
|
|
91
|
+
* `generateBundle`. The output directory is scanned and files are read on
|
|
92
|
+
* demand in bounded batches (`chunkSize` source bytes per batch, or 4 MB
|
|
93
|
+
* per batch when `chunkSize` is 0), so the whole build is never held in
|
|
94
|
+
* memory and assets written to disk by other plugins' `writeBundle`
|
|
95
|
+
* hooks are picked up as well.
|
|
96
|
+
* @default false
|
|
97
|
+
*/
|
|
98
|
+
stream?: boolean;
|
|
82
99
|
/** @default 'info' */
|
|
83
100
|
logLevel?: LogLevel;
|
|
84
101
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -8,10 +8,17 @@ type CanonicalAlgorithm = 'gzip' | 'brotli' | 'zstd';
|
|
|
8
8
|
interface GzipOptions {
|
|
9
9
|
level?: number;
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
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 take
|
|
15
|
+
* the multithreaded path. Default 1 MiB. Smaller sections finish large files
|
|
16
|
+
* faster at a slight cost in compression ratio.
|
|
17
|
+
*/
|
|
12
18
|
interface BrotliOptions {
|
|
13
19
|
quality?: number;
|
|
14
20
|
windowBits?: number;
|
|
21
|
+
sectionSize?: number;
|
|
15
22
|
}
|
|
16
23
|
/** Zstandard options. `level`: 1-22, default 19. */
|
|
17
24
|
interface ZstdOptions {
|
|
@@ -79,6 +86,16 @@ interface CompressionOptions {
|
|
|
79
86
|
* @default 0
|
|
80
87
|
*/
|
|
81
88
|
chunkSize?: number;
|
|
89
|
+
/**
|
|
90
|
+
* Compress from disk at the end of `writeBundle` instead of in memory in
|
|
91
|
+
* `generateBundle`. The output directory is scanned and files are read on
|
|
92
|
+
* demand in bounded batches (`chunkSize` source bytes per batch, or 4 MB
|
|
93
|
+
* per batch when `chunkSize` is 0), so the whole build is never held in
|
|
94
|
+
* memory and assets written to disk by other plugins' `writeBundle`
|
|
95
|
+
* hooks are picked up as well.
|
|
96
|
+
* @default false
|
|
97
|
+
*/
|
|
98
|
+
stream?: boolean;
|
|
82
99
|
/** @default 'info' */
|
|
83
100
|
logLevel?: LogLevel;
|
|
84
101
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { createFilter } from "@rollup/pluginutils";
|
|
5
|
+
import { mkdir, readFile, readdir, stat, unlink, writeFile } from "node:fs/promises";
|
|
5
6
|
//#region ts/options.ts
|
|
6
7
|
/**
|
|
7
8
|
* Option types, normalization and validation for the public API.
|
|
@@ -67,9 +68,10 @@ function defineAlgorithm(name, options = {}) {
|
|
|
67
68
|
}
|
|
68
69
|
function validateAlgorithmOptions(algorithm, options) {
|
|
69
70
|
if (algorithm === "brotli") {
|
|
70
|
-
const { quality, windowBits } = options;
|
|
71
|
+
const { quality, windowBits, sectionSize } = options;
|
|
71
72
|
if (quality !== void 0) assertIntegerInRange(quality, LEVEL_RANGES.brotli, "brotli quality");
|
|
72
73
|
if (windowBits !== void 0) assertIntegerInRange(windowBits, [10, 24], "brotli windowBits");
|
|
74
|
+
if (sectionSize !== void 0) assertIntegerInRange(sectionSize, [1, 4294967295], "brotli sectionSize");
|
|
73
75
|
return;
|
|
74
76
|
}
|
|
75
77
|
const { level } = options;
|
|
@@ -86,8 +88,9 @@ function resolveAlgorithm(entry) {
|
|
|
86
88
|
extension: EXTENSIONS[algorithm]
|
|
87
89
|
};
|
|
88
90
|
if (algorithm === "brotli") {
|
|
89
|
-
const { windowBits } = options;
|
|
91
|
+
const { windowBits, sectionSize } = options;
|
|
90
92
|
if (windowBits !== void 0) resolved.windowBits = windowBits;
|
|
93
|
+
if (sectionSize !== void 0) resolved.sectionSize = sectionSize;
|
|
91
94
|
}
|
|
92
95
|
return resolved;
|
|
93
96
|
}
|
|
@@ -103,7 +106,7 @@ function validateDefined(entry) {
|
|
|
103
106
|
/** Validate and normalize user options. Throws at `compression()` call time. */
|
|
104
107
|
function resolveOptions(options = {}) {
|
|
105
108
|
if (options === null || typeof options !== "object") throw new OptionValidationError("options must be an object");
|
|
106
|
-
const { include = DEFAULT_INCLUDE, exclude, threshold = 0, algorithms = ["gzip", "brotli"], filename, deleteOriginalAssets = false, skipIfLargerOrEqual = true, concurrency = 0, chunkSize = 0, logLevel = "info", enableInWatchMode = false } = options;
|
|
109
|
+
const { include = DEFAULT_INCLUDE, exclude, threshold = 0, algorithms = ["gzip", "brotli"], filename, deleteOriginalAssets = false, skipIfLargerOrEqual = true, concurrency = 0, chunkSize = 0, stream = false, logLevel = "info", enableInWatchMode = false } = options;
|
|
107
110
|
if (typeof threshold !== "number" || Number.isNaN(threshold) || threshold < 0) throw new OptionValidationError(`invalid threshold: expected a non-negative number, got ${JSON.stringify(threshold)}`);
|
|
108
111
|
if (!Number.isInteger(concurrency) || concurrency < 0) throw new OptionValidationError(`invalid concurrency: expected a non-negative integer, got ${JSON.stringify(concurrency)}`);
|
|
109
112
|
if (!Number.isInteger(chunkSize) || chunkSize < 0) throw new OptionValidationError(`invalid chunkSize: expected a non-negative integer number of bytes, got ${JSON.stringify(chunkSize)}`);
|
|
@@ -119,6 +122,7 @@ function resolveOptions(options = {}) {
|
|
|
119
122
|
skipIfLargerOrEqual: Boolean(skipIfLargerOrEqual),
|
|
120
123
|
concurrency,
|
|
121
124
|
chunkSize,
|
|
125
|
+
stream: Boolean(stream),
|
|
122
126
|
logLevel,
|
|
123
127
|
enableInWatchMode: Boolean(enableInWatchMode)
|
|
124
128
|
};
|
|
@@ -143,7 +147,28 @@ function resolveOutputFileName(filename, fileName, algorithm, source) {
|
|
|
143
147
|
const compressBuffers = createRequire(import.meta.url)("../index.js").compressBuffers;
|
|
144
148
|
//#endregion
|
|
145
149
|
//#region ts/plugin.ts
|
|
150
|
+
/**
|
|
151
|
+
* Rolldown plugin implementation.
|
|
152
|
+
*
|
|
153
|
+
* Default mode: all eligible assets of a build are collected in
|
|
154
|
+
* `generateBundle` (while they are still in memory) and compressed in
|
|
155
|
+
* batched FFI calls; the native module fans the work out across a rayon
|
|
156
|
+
* thread pool without ever blocking the JS event loop. By default
|
|
157
|
+
* everything goes out in a single batch; a positive `chunkSize` flushes a
|
|
158
|
+
* batch whenever its source bytes reach that limit, so only one batch of
|
|
159
|
+
* buffer copies is alive at a time.
|
|
160
|
+
*
|
|
161
|
+
* Stream mode (`stream: true`): compression instead runs at the end of
|
|
162
|
+
* `writeBundle` (order `'post'`), scanning the output directory on disk.
|
|
163
|
+
* Files are read on demand and processed in bounded batches — `chunkSize`
|
|
164
|
+
* source bytes per batch, falling back to
|
|
165
|
+
* {@link STREAM_DEFAULT_CHUNK_SIZE} when `chunkSize` is 0 — so the whole
|
|
166
|
+
* build is never held in memory and assets written to disk by other
|
|
167
|
+
* plugins' `writeBundle` hooks are compressed as well.
|
|
168
|
+
*/
|
|
146
169
|
const PLUGIN_NAME = "rolldown-compression";
|
|
170
|
+
/** Source bytes per batch in stream mode when `chunkSize` is 0. */
|
|
171
|
+
const STREAM_DEFAULT_CHUNK_SIZE = 4 * 1024 * 1024;
|
|
147
172
|
const LOG_PRIORITY = {
|
|
148
173
|
silent: 0,
|
|
149
174
|
error: 1,
|
|
@@ -173,97 +198,176 @@ function formatBytes(bytes) {
|
|
|
173
198
|
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} kB`;
|
|
174
199
|
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
175
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Shared batching core: queues per-algorithm tasks, flushes them to the
|
|
203
|
+
* native module and hands successful results to `emit`. Only one batch of
|
|
204
|
+
* source buffers is referenced at a time once a flush trigger is set.
|
|
205
|
+
*/
|
|
206
|
+
function createBatchRunner(options, logger, emittedNames, emit, fail) {
|
|
207
|
+
const processedSources = /* @__PURE__ */ new Set();
|
|
208
|
+
const emittedBySource = /* @__PURE__ */ new Map();
|
|
209
|
+
const failures = [];
|
|
210
|
+
const stats = /* @__PURE__ */ new Map();
|
|
211
|
+
const chunkSize = options.chunkSize > 0 ? options.chunkSize : options.stream ? STREAM_DEFAULT_CHUNK_SIZE : 0;
|
|
212
|
+
let pending = [];
|
|
213
|
+
let pendingSourceBytes = 0;
|
|
214
|
+
const flush = async () => {
|
|
215
|
+
if (pending.length === 0) return;
|
|
216
|
+
const batch = pending;
|
|
217
|
+
pending = [];
|
|
218
|
+
pendingSourceBytes = 0;
|
|
219
|
+
const results = await compressBuffers(batch.map((artifact) => artifact.task), batch.map((artifact) => artifact.buffer), {
|
|
220
|
+
concurrency: options.concurrency,
|
|
221
|
+
skipIfLargerOrEqual: options.skipIfLargerOrEqual
|
|
222
|
+
});
|
|
223
|
+
for (const [index, result] of results.entries()) {
|
|
224
|
+
const artifact = batch[index];
|
|
225
|
+
if (artifact === void 0) continue;
|
|
226
|
+
if (result.error !== void 0 && result.error !== null) {
|
|
227
|
+
failures.push(`${result.fileName} (${result.algorithm}): ${result.error}`);
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (result.skipped) {
|
|
231
|
+
logger.info(`skipped ${artifact.outputFileName}: ${result.algorithm} output would not be smaller than the original`);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
await emit(artifact, result.data);
|
|
235
|
+
emittedNames.add(artifact.outputFileName);
|
|
236
|
+
emittedBySource.set(artifact.sourceFileName, (emittedBySource.get(artifact.sourceFileName) ?? 0) + 1);
|
|
237
|
+
const stat = stats.get(result.algorithm) ?? {
|
|
238
|
+
count: 0,
|
|
239
|
+
originalBytes: 0,
|
|
240
|
+
outputBytes: 0
|
|
241
|
+
};
|
|
242
|
+
stat.count += 1;
|
|
243
|
+
stat.originalBytes += result.originalSize;
|
|
244
|
+
stat.outputBytes += result.compressedSize;
|
|
245
|
+
stats.set(result.algorithm, stat);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
const addFile = async (fileName, buffer) => {
|
|
249
|
+
for (const algorithm of options.algorithms) {
|
|
250
|
+
const outputFileName = resolveOutputFileName(options.filename, fileName, algorithm, buffer);
|
|
251
|
+
if (outputFileName === fileName) fail(`the filename option resolved "${fileName}" (${algorithm.algorithm}) to the same name as the source asset; refusing to overwrite it`);
|
|
252
|
+
pending.push({
|
|
253
|
+
task: {
|
|
254
|
+
fileName,
|
|
255
|
+
algorithm: algorithm.algorithm,
|
|
256
|
+
level: algorithm.level,
|
|
257
|
+
windowBits: algorithm.windowBits,
|
|
258
|
+
sectionSize: algorithm.sectionSize
|
|
259
|
+
},
|
|
260
|
+
buffer,
|
|
261
|
+
sourceFileName: fileName,
|
|
262
|
+
outputFileName
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
processedSources.add(fileName);
|
|
266
|
+
pendingSourceBytes += buffer.byteLength;
|
|
267
|
+
if (chunkSize > 0 && pendingSourceBytes >= chunkSize) await flush();
|
|
268
|
+
};
|
|
269
|
+
return {
|
|
270
|
+
addFile,
|
|
271
|
+
flush,
|
|
272
|
+
processedSources,
|
|
273
|
+
emittedBySource,
|
|
274
|
+
failures,
|
|
275
|
+
stats
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function logSummary(logger, stats, startedAt) {
|
|
279
|
+
const summary = [...stats.entries()].map(([algorithm, stat]) => `${algorithm}: ${stat.count} file(s), ${formatBytes(stat.originalBytes)} -> ${formatBytes(stat.outputBytes)}`).join("; ");
|
|
280
|
+
if (summary.length === 0) return;
|
|
281
|
+
const totalSaved = [...stats.values()].reduce((sum, stat) => sum + (stat.originalBytes - stat.outputBytes), 0);
|
|
282
|
+
const elapsedMs = performance.now() - startedAt;
|
|
283
|
+
logger.info(`${summary}; saved ${formatBytes(totalSaved)} in ${(elapsedMs / 1e3).toFixed(2)}s`);
|
|
284
|
+
}
|
|
285
|
+
/** Recursively list every file under `root`, in a deterministic order. */
|
|
286
|
+
async function walkFiles(root) {
|
|
287
|
+
const files = [];
|
|
288
|
+
const visit = async (dir) => {
|
|
289
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
290
|
+
entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
291
|
+
for (const entry of entries) {
|
|
292
|
+
const absolute = path.join(dir, entry.name);
|
|
293
|
+
if (entry.isDirectory()) await visit(absolute);
|
|
294
|
+
else if (entry.isFile()) files.push(absolute);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
await visit(root);
|
|
298
|
+
return files;
|
|
299
|
+
}
|
|
176
300
|
function createCompressionPlugin(options) {
|
|
177
301
|
const logger = createLogger(options.logLevel);
|
|
178
302
|
const emittedNames = /* @__PURE__ */ new Set();
|
|
179
303
|
return Object.assign({
|
|
180
304
|
name: PLUGIN_NAME,
|
|
181
305
|
async generateBundle(_outputOptions, bundle) {
|
|
306
|
+
if (options.stream) return;
|
|
182
307
|
if (this.meta?.watchMode && !options.enableInWatchMode) {
|
|
183
308
|
logger.info("watch mode detected, skipping compression (set enableInWatchMode to opt in)");
|
|
184
309
|
return;
|
|
185
310
|
}
|
|
186
311
|
const startedAt = performance.now();
|
|
187
|
-
const
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const flush = async () => {
|
|
194
|
-
if (pending.length === 0) return;
|
|
195
|
-
const batch = pending;
|
|
196
|
-
pending = [];
|
|
197
|
-
pendingSourceBytes = 0;
|
|
198
|
-
const results = await compressBuffers(batch.map((artifact) => artifact.task), batch.map((artifact) => artifact.buffer), {
|
|
199
|
-
concurrency: options.concurrency,
|
|
200
|
-
skipIfLargerOrEqual: options.skipIfLargerOrEqual
|
|
312
|
+
const fail = (message) => this.error(/* @__PURE__ */ new Error(`[${PLUGIN_NAME}] ${message}`));
|
|
313
|
+
const runner = createBatchRunner(options, logger, emittedNames, (artifact, data) => {
|
|
314
|
+
this.emitFile({
|
|
315
|
+
type: "asset",
|
|
316
|
+
fileName: artifact.outputFileName,
|
|
317
|
+
source: data
|
|
201
318
|
});
|
|
202
|
-
|
|
203
|
-
const artifact = batch[index];
|
|
204
|
-
if (artifact === void 0) continue;
|
|
205
|
-
if (result.error !== void 0 && result.error !== null) {
|
|
206
|
-
failures.push(`${result.fileName} (${result.algorithm}): ${result.error}`);
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
if (result.skipped) {
|
|
210
|
-
logger.info(`skipped ${artifact.outputFileName}: ${result.algorithm} output would not be smaller than the original`);
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
this.emitFile({
|
|
214
|
-
type: "asset",
|
|
215
|
-
fileName: artifact.outputFileName,
|
|
216
|
-
source: result.data
|
|
217
|
-
});
|
|
218
|
-
emittedNames.add(artifact.outputFileName);
|
|
219
|
-
emittedBySource.set(artifact.sourceFileName, (emittedBySource.get(artifact.sourceFileName) ?? 0) + 1);
|
|
220
|
-
const stat = stats.get(result.algorithm) ?? {
|
|
221
|
-
count: 0,
|
|
222
|
-
originalBytes: 0,
|
|
223
|
-
outputBytes: 0
|
|
224
|
-
};
|
|
225
|
-
stat.count += 1;
|
|
226
|
-
stat.originalBytes += result.originalSize;
|
|
227
|
-
stat.outputBytes += result.compressedSize;
|
|
228
|
-
stats.set(result.algorithm, stat);
|
|
229
|
-
}
|
|
230
|
-
};
|
|
319
|
+
}, fail);
|
|
231
320
|
for (const [fileName, output] of Object.entries(bundle)) {
|
|
232
321
|
if (!options.filter(fileName)) continue;
|
|
233
322
|
if (COMPRESSED_EXTENSION_RE.test(fileName) || emittedNames.has(fileName)) continue;
|
|
234
323
|
const buffer = toBuffer(output.type === "chunk" ? output.code : output.source);
|
|
235
324
|
if (buffer.byteLength < options.threshold) continue;
|
|
236
|
-
|
|
237
|
-
const outputFileName = resolveOutputFileName(options.filename, fileName, algorithm, buffer);
|
|
238
|
-
if (outputFileName === fileName) this.error(/* @__PURE__ */ new Error(`[${PLUGIN_NAME}] the filename option resolved "${fileName}" (${algorithm.algorithm}) to the same name as the source asset; refusing to overwrite it`));
|
|
239
|
-
pending.push({
|
|
240
|
-
task: {
|
|
241
|
-
fileName,
|
|
242
|
-
algorithm: algorithm.algorithm,
|
|
243
|
-
level: algorithm.level,
|
|
244
|
-
windowBits: algorithm.windowBits
|
|
245
|
-
},
|
|
246
|
-
buffer,
|
|
247
|
-
sourceFileName: fileName,
|
|
248
|
-
outputFileName
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
processedSources.add(fileName);
|
|
252
|
-
pendingSourceBytes += buffer.byteLength;
|
|
253
|
-
if (options.chunkSize > 0 && pendingSourceBytes >= options.chunkSize) await flush();
|
|
325
|
+
await runner.addFile(fileName, buffer);
|
|
254
326
|
}
|
|
255
|
-
await flush();
|
|
256
|
-
if (processedSources.size === 0) return;
|
|
257
|
-
if (failures.length > 0)
|
|
258
|
-
if (options.deleteOriginalAssets) for (const fileName of processedSources) {
|
|
259
|
-
if ((emittedBySource.get(fileName) ?? 0) === 0) logger.warn(`deleteOriginalAssets removed "${fileName}" even though no compressed variant was emitted for it`);
|
|
327
|
+
await runner.flush();
|
|
328
|
+
if (runner.processedSources.size === 0) return;
|
|
329
|
+
if (runner.failures.length > 0) fail(`${runner.failures.length} compression task(s) failed:\n${runner.failures.join("\n")}`);
|
|
330
|
+
if (options.deleteOriginalAssets) for (const fileName of runner.processedSources) {
|
|
331
|
+
if ((runner.emittedBySource.get(fileName) ?? 0) === 0) logger.warn(`deleteOriginalAssets removed "${fileName}" even though no compressed variant was emitted for it`);
|
|
260
332
|
delete bundle[fileName];
|
|
261
333
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
334
|
+
logSummary(logger, runner.stats, startedAt);
|
|
335
|
+
},
|
|
336
|
+
writeBundle: {
|
|
337
|
+
order: "post",
|
|
338
|
+
async handler(outputOptions) {
|
|
339
|
+
if (!options.stream) return;
|
|
340
|
+
if (this.meta?.watchMode && !options.enableInWatchMode) {
|
|
341
|
+
logger.info("watch mode detected, skipping compression (set enableInWatchMode to opt in)");
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const outDir = outputOptions.dir !== void 0 ? path.resolve(outputOptions.dir) : outputOptions.file !== void 0 ? path.resolve(path.dirname(outputOptions.file)) : void 0;
|
|
345
|
+
if (outDir === void 0) {
|
|
346
|
+
logger.warn("stream mode could not determine the output directory, skipping compression");
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
const startedAt = performance.now();
|
|
350
|
+
const fail = (message) => this.error(/* @__PURE__ */ new Error(`[${PLUGIN_NAME}] ${message}`));
|
|
351
|
+
const runner = createBatchRunner(options, logger, emittedNames, async (artifact, data) => {
|
|
352
|
+
const target = path.join(outDir, artifact.outputFileName);
|
|
353
|
+
await mkdir(path.dirname(target), { recursive: true });
|
|
354
|
+
await writeFile(target, data);
|
|
355
|
+
}, fail);
|
|
356
|
+
for (const absolute of await walkFiles(outDir)) {
|
|
357
|
+
const fileName = path.relative(outDir, absolute).split(path.sep).join("/");
|
|
358
|
+
if (!options.filter(fileName)) continue;
|
|
359
|
+
if (COMPRESSED_EXTENSION_RE.test(fileName) || emittedNames.has(fileName)) continue;
|
|
360
|
+
if ((await stat(absolute)).size < options.threshold) continue;
|
|
361
|
+
await runner.addFile(fileName, await readFile(absolute));
|
|
362
|
+
}
|
|
363
|
+
await runner.flush();
|
|
364
|
+
if (runner.processedSources.size === 0) return;
|
|
365
|
+
if (runner.failures.length > 0) fail(`${runner.failures.length} compression task(s) failed:\n${runner.failures.join("\n")}`);
|
|
366
|
+
if (options.deleteOriginalAssets) for (const fileName of runner.processedSources) {
|
|
367
|
+
if ((runner.emittedBySource.get(fileName) ?? 0) === 0) logger.warn(`deleteOriginalAssets removed "${fileName}" even though no compressed variant was emitted for it`);
|
|
368
|
+
await unlink(path.join(outDir, fileName));
|
|
369
|
+
}
|
|
370
|
+
logSummary(logger, runner.stats, startedAt);
|
|
267
371
|
}
|
|
268
372
|
}
|
|
269
373
|
}, { apply: "build" });
|
package/index.d.ts
CHANGED
|
@@ -53,4 +53,10 @@ export interface CompressTask {
|
|
|
53
53
|
level?: number
|
|
54
54
|
/** Brotli only: log2 window size (10-24, default 22). */
|
|
55
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 (default 1 MiB).
|
|
60
|
+
*/
|
|
61
|
+
sectionSize?: number
|
|
56
62
|
}
|
package/index.js
CHANGED
|
@@ -77,8 +77,8 @@ function requireNative() {
|
|
|
77
77
|
try {
|
|
78
78
|
const binding = require('@medicomind/rolldown-compression-android-arm64')
|
|
79
79
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-android-arm64/package.json').version
|
|
80
|
-
if (bindingPackageVersion !== '
|
|
81
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
80
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
82
82
|
}
|
|
83
83
|
return binding
|
|
84
84
|
} catch (e) {
|
|
@@ -93,8 +93,8 @@ function requireNative() {
|
|
|
93
93
|
try {
|
|
94
94
|
const binding = require('@medicomind/rolldown-compression-android-arm-eabi')
|
|
95
95
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-android-arm-eabi/package.json').version
|
|
96
|
-
if (bindingPackageVersion !== '
|
|
97
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
96
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
98
98
|
}
|
|
99
99
|
return binding
|
|
100
100
|
} catch (e) {
|
|
@@ -114,8 +114,8 @@ function requireNative() {
|
|
|
114
114
|
try {
|
|
115
115
|
const binding = require('@medicomind/rolldown-compression-win32-x64-gnu')
|
|
116
116
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-win32-x64-gnu/package.json').version
|
|
117
|
-
if (bindingPackageVersion !== '
|
|
118
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
117
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
119
119
|
}
|
|
120
120
|
return binding
|
|
121
121
|
} catch (e) {
|
|
@@ -130,8 +130,8 @@ function requireNative() {
|
|
|
130
130
|
try {
|
|
131
131
|
const binding = require('@medicomind/rolldown-compression-win32-x64-msvc')
|
|
132
132
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-win32-x64-msvc/package.json').version
|
|
133
|
-
if (bindingPackageVersion !== '
|
|
134
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
133
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
135
135
|
}
|
|
136
136
|
return binding
|
|
137
137
|
} catch (e) {
|
|
@@ -147,8 +147,8 @@ function requireNative() {
|
|
|
147
147
|
try {
|
|
148
148
|
const binding = require('@medicomind/rolldown-compression-win32-ia32-msvc')
|
|
149
149
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-win32-ia32-msvc/package.json').version
|
|
150
|
-
if (bindingPackageVersion !== '
|
|
151
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
150
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
152
152
|
}
|
|
153
153
|
return binding
|
|
154
154
|
} catch (e) {
|
|
@@ -163,8 +163,8 @@ function requireNative() {
|
|
|
163
163
|
try {
|
|
164
164
|
const binding = require('@medicomind/rolldown-compression-win32-arm64-msvc')
|
|
165
165
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-win32-arm64-msvc/package.json').version
|
|
166
|
-
if (bindingPackageVersion !== '
|
|
167
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
166
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
168
168
|
}
|
|
169
169
|
return binding
|
|
170
170
|
} catch (e) {
|
|
@@ -182,8 +182,8 @@ function requireNative() {
|
|
|
182
182
|
try {
|
|
183
183
|
const binding = require('@medicomind/rolldown-compression-darwin-universal')
|
|
184
184
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-darwin-universal/package.json').version
|
|
185
|
-
if (bindingPackageVersion !== '
|
|
186
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
185
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
187
187
|
}
|
|
188
188
|
return binding
|
|
189
189
|
} catch (e) {
|
|
@@ -198,8 +198,8 @@ function requireNative() {
|
|
|
198
198
|
try {
|
|
199
199
|
const binding = require('@medicomind/rolldown-compression-darwin-x64')
|
|
200
200
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-darwin-x64/package.json').version
|
|
201
|
-
if (bindingPackageVersion !== '
|
|
202
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
201
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
203
203
|
}
|
|
204
204
|
return binding
|
|
205
205
|
} catch (e) {
|
|
@@ -214,8 +214,8 @@ function requireNative() {
|
|
|
214
214
|
try {
|
|
215
215
|
const binding = require('@medicomind/rolldown-compression-darwin-arm64')
|
|
216
216
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-darwin-arm64/package.json').version
|
|
217
|
-
if (bindingPackageVersion !== '
|
|
218
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
217
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
219
219
|
}
|
|
220
220
|
return binding
|
|
221
221
|
} catch (e) {
|
|
@@ -234,8 +234,8 @@ function requireNative() {
|
|
|
234
234
|
try {
|
|
235
235
|
const binding = require('@medicomind/rolldown-compression-freebsd-x64')
|
|
236
236
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-freebsd-x64/package.json').version
|
|
237
|
-
if (bindingPackageVersion !== '
|
|
238
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
237
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
239
239
|
}
|
|
240
240
|
return binding
|
|
241
241
|
} catch (e) {
|
|
@@ -250,8 +250,8 @@ function requireNative() {
|
|
|
250
250
|
try {
|
|
251
251
|
const binding = require('@medicomind/rolldown-compression-freebsd-arm64')
|
|
252
252
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-freebsd-arm64/package.json').version
|
|
253
|
-
if (bindingPackageVersion !== '
|
|
254
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
253
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
255
255
|
}
|
|
256
256
|
return binding
|
|
257
257
|
} catch (e) {
|
|
@@ -271,8 +271,8 @@ function requireNative() {
|
|
|
271
271
|
try {
|
|
272
272
|
const binding = require('@medicomind/rolldown-compression-linux-x64-musl')
|
|
273
273
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-x64-musl/package.json').version
|
|
274
|
-
if (bindingPackageVersion !== '
|
|
275
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
274
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
276
276
|
}
|
|
277
277
|
return binding
|
|
278
278
|
} catch (e) {
|
|
@@ -287,8 +287,8 @@ function requireNative() {
|
|
|
287
287
|
try {
|
|
288
288
|
const binding = require('@medicomind/rolldown-compression-linux-x64-gnu')
|
|
289
289
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-x64-gnu/package.json').version
|
|
290
|
-
if (bindingPackageVersion !== '
|
|
291
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
290
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
292
292
|
}
|
|
293
293
|
return binding
|
|
294
294
|
} catch (e) {
|
|
@@ -305,8 +305,8 @@ function requireNative() {
|
|
|
305
305
|
try {
|
|
306
306
|
const binding = require('@medicomind/rolldown-compression-linux-arm64-musl')
|
|
307
307
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-arm64-musl/package.json').version
|
|
308
|
-
if (bindingPackageVersion !== '
|
|
309
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
308
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
310
310
|
}
|
|
311
311
|
return binding
|
|
312
312
|
} catch (e) {
|
|
@@ -321,8 +321,8 @@ function requireNative() {
|
|
|
321
321
|
try {
|
|
322
322
|
const binding = require('@medicomind/rolldown-compression-linux-arm64-gnu')
|
|
323
323
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-arm64-gnu/package.json').version
|
|
324
|
-
if (bindingPackageVersion !== '
|
|
325
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
324
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
326
326
|
}
|
|
327
327
|
return binding
|
|
328
328
|
} catch (e) {
|
|
@@ -339,8 +339,8 @@ function requireNative() {
|
|
|
339
339
|
try {
|
|
340
340
|
const binding = require('@medicomind/rolldown-compression-linux-arm-musleabihf')
|
|
341
341
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-arm-musleabihf/package.json').version
|
|
342
|
-
if (bindingPackageVersion !== '
|
|
343
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
342
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
344
344
|
}
|
|
345
345
|
return binding
|
|
346
346
|
} catch (e) {
|
|
@@ -355,8 +355,8 @@ function requireNative() {
|
|
|
355
355
|
try {
|
|
356
356
|
const binding = require('@medicomind/rolldown-compression-linux-arm-gnueabihf')
|
|
357
357
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-arm-gnueabihf/package.json').version
|
|
358
|
-
if (bindingPackageVersion !== '
|
|
359
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
358
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
360
360
|
}
|
|
361
361
|
return binding
|
|
362
362
|
} catch (e) {
|
|
@@ -373,8 +373,8 @@ function requireNative() {
|
|
|
373
373
|
try {
|
|
374
374
|
const binding = require('@medicomind/rolldown-compression-linux-loong64-musl')
|
|
375
375
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-loong64-musl/package.json').version
|
|
376
|
-
if (bindingPackageVersion !== '
|
|
377
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
376
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
378
378
|
}
|
|
379
379
|
return binding
|
|
380
380
|
} catch (e) {
|
|
@@ -389,8 +389,8 @@ function requireNative() {
|
|
|
389
389
|
try {
|
|
390
390
|
const binding = require('@medicomind/rolldown-compression-linux-loong64-gnu')
|
|
391
391
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-loong64-gnu/package.json').version
|
|
392
|
-
if (bindingPackageVersion !== '
|
|
393
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
392
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
394
394
|
}
|
|
395
395
|
return binding
|
|
396
396
|
} catch (e) {
|
|
@@ -407,8 +407,8 @@ function requireNative() {
|
|
|
407
407
|
try {
|
|
408
408
|
const binding = require('@medicomind/rolldown-compression-linux-riscv64-musl')
|
|
409
409
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-riscv64-musl/package.json').version
|
|
410
|
-
if (bindingPackageVersion !== '
|
|
411
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
410
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
412
412
|
}
|
|
413
413
|
return binding
|
|
414
414
|
} catch (e) {
|
|
@@ -423,8 +423,8 @@ function requireNative() {
|
|
|
423
423
|
try {
|
|
424
424
|
const binding = require('@medicomind/rolldown-compression-linux-riscv64-gnu')
|
|
425
425
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-riscv64-gnu/package.json').version
|
|
426
|
-
if (bindingPackageVersion !== '
|
|
427
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
426
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
428
428
|
}
|
|
429
429
|
return binding
|
|
430
430
|
} catch (e) {
|
|
@@ -440,8 +440,8 @@ function requireNative() {
|
|
|
440
440
|
try {
|
|
441
441
|
const binding = require('@medicomind/rolldown-compression-linux-ppc64-gnu')
|
|
442
442
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-ppc64-gnu/package.json').version
|
|
443
|
-
if (bindingPackageVersion !== '
|
|
444
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
443
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
445
445
|
}
|
|
446
446
|
return binding
|
|
447
447
|
} catch (e) {
|
|
@@ -456,8 +456,8 @@ function requireNative() {
|
|
|
456
456
|
try {
|
|
457
457
|
const binding = require('@medicomind/rolldown-compression-linux-s390x-gnu')
|
|
458
458
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-linux-s390x-gnu/package.json').version
|
|
459
|
-
if (bindingPackageVersion !== '
|
|
460
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
459
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
461
461
|
}
|
|
462
462
|
return binding
|
|
463
463
|
} catch (e) {
|
|
@@ -476,8 +476,8 @@ function requireNative() {
|
|
|
476
476
|
try {
|
|
477
477
|
const binding = require('@medicomind/rolldown-compression-openharmony-arm64')
|
|
478
478
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-openharmony-arm64/package.json').version
|
|
479
|
-
if (bindingPackageVersion !== '
|
|
480
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
479
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
481
481
|
}
|
|
482
482
|
return binding
|
|
483
483
|
} catch (e) {
|
|
@@ -492,8 +492,8 @@ function requireNative() {
|
|
|
492
492
|
try {
|
|
493
493
|
const binding = require('@medicomind/rolldown-compression-openharmony-x64')
|
|
494
494
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-openharmony-x64/package.json').version
|
|
495
|
-
if (bindingPackageVersion !== '
|
|
496
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
495
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
497
497
|
}
|
|
498
498
|
return binding
|
|
499
499
|
} catch (e) {
|
|
@@ -508,8 +508,8 @@ function requireNative() {
|
|
|
508
508
|
try {
|
|
509
509
|
const binding = require('@medicomind/rolldown-compression-openharmony-arm')
|
|
510
510
|
const bindingPackageVersion = require('@medicomind/rolldown-compression-openharmony-arm/package.json').version
|
|
511
|
-
if (bindingPackageVersion !== '
|
|
512
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
511
|
+
if (bindingPackageVersion !== '1.1.0' && 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 1.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
513
513
|
}
|
|
514
514
|
return binding
|
|
515
515
|
} catch (e) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medicomind/rolldown-compression",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Fast native (Rust) gzip / brotli / zstd compression plugin for Rolldown, powered by napi-rs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rolldown",
|
|
@@ -91,13 +91,13 @@
|
|
|
91
91
|
"rolldown": "^1.0.0"
|
|
92
92
|
},
|
|
93
93
|
"optionalDependencies": {
|
|
94
|
-
"@medicomind/rolldown-compression-darwin-arm64": "1.0
|
|
95
|
-
"@medicomind/rolldown-compression-darwin-x64": "1.0
|
|
96
|
-
"@medicomind/rolldown-compression-linux-arm64-gnu": "1.0
|
|
97
|
-
"@medicomind/rolldown-compression-linux-x64-gnu": "1.0
|
|
98
|
-
"@medicomind/rolldown-compression-linux-x64-musl": "1.0
|
|
99
|
-
"@medicomind/rolldown-compression-wasm32-wasi": "1.0
|
|
100
|
-
"@medicomind/rolldown-compression-win32-x64-msvc": "1.0
|
|
94
|
+
"@medicomind/rolldown-compression-darwin-arm64": "1.2.0",
|
|
95
|
+
"@medicomind/rolldown-compression-darwin-x64": "1.2.0",
|
|
96
|
+
"@medicomind/rolldown-compression-linux-arm64-gnu": "1.2.0",
|
|
97
|
+
"@medicomind/rolldown-compression-linux-x64-gnu": "1.2.0",
|
|
98
|
+
"@medicomind/rolldown-compression-linux-x64-musl": "1.2.0",
|
|
99
|
+
"@medicomind/rolldown-compression-wasm32-wasi": "1.2.0",
|
|
100
|
+
"@medicomind/rolldown-compression-win32-x64-msvc": "1.2.0"
|
|
101
101
|
},
|
|
102
102
|
"devDependencies": {
|
|
103
103
|
"@biomejs/biome": "^2.5.3",
|