@medicomind/rolldown-compression-wasm32-wasi 2.5.1 → 2.5.3
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medicomind/rolldown-compression-wasm32-wasi",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.3",
|
|
4
4
|
"main": "rolldown-compression.wasi.cjs",
|
|
5
5
|
"files": [
|
|
6
6
|
"rolldown-compression.wasm32-wasi.wasm",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"browser": "rolldown-compression.wasi-browser.js",
|
|
44
44
|
"type": "module",
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@napi-rs/wasm-runtime": "~1.2.
|
|
46
|
+
"@napi-rs/wasm-runtime": "~1.2.4",
|
|
47
47
|
"@emnapi/core": "2.0.0-alpha.5",
|
|
48
48
|
"@emnapi/runtime": "2.0.0-alpha.5"
|
|
49
49
|
}
|
|
50
|
-
}
|
|
50
|
+
}
|
|
@@ -51,11 +51,11 @@ let __emnapiWasmEnvCleanupDrained = false
|
|
|
51
51
|
let __emnapiWasmEnvCleanupDrainPromise
|
|
52
52
|
let __wasiDisposed = false
|
|
53
53
|
let __wasiDisposePromise
|
|
54
|
-
let __completeWasiDisposal = function() {}
|
|
54
|
+
let __completeWasiDisposal = function () {}
|
|
55
55
|
// Overridden by loader flavors that have a last-resort reclaim for a rollback
|
|
56
56
|
// that stopped short of destroying the context. See
|
|
57
57
|
// `__rollbackWasiInitialization`.
|
|
58
|
-
let __retainWasiRollbackForRetry = function() {}
|
|
58
|
+
let __retainWasiRollbackForRetry = function () {}
|
|
59
59
|
|
|
60
60
|
function __isThenable(value) {
|
|
61
61
|
return (
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// napi-rs-artifact-metadata:{"version":2,"rootEntry":"index.js","exports":["compressBuffers"],"managedRootEntries":["browser.js","index.js","rolldown-compression.wasm","rolldown-compression.debug.wasm"]}
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
/* prettier-ignore */
|
|
4
|
-
|
|
5
3
|
/* auto-generated by NAPI-RS */
|
|
6
4
|
|
|
7
5
|
const __nodeFs = require('node:fs')
|
|
@@ -91,6 +89,7 @@ function __createWasiWorker(filename) {
|
|
|
91
89
|
return new Worker(filename, {
|
|
92
90
|
env: process.env,
|
|
93
91
|
execArgv: __workerExecArgv,
|
|
92
|
+
workerData: { hostRoot: __hostRoot, rootDir: __rootDir },
|
|
94
93
|
})
|
|
95
94
|
} catch (error) {
|
|
96
95
|
if (!error || error.code !== 'ERR_WORKER_INVALID_EXEC_ARGV') {
|
|
@@ -106,14 +105,18 @@ function __createWasiWorker(filename) {
|
|
|
106
105
|
}
|
|
107
106
|
}
|
|
108
107
|
|
|
109
|
-
const
|
|
108
|
+
const __cwd = process.cwd()
|
|
109
|
+
const __rootDir = __nodePath.parse(__cwd).root
|
|
110
|
+
const __hostRoot =
|
|
111
|
+
process.platform === 'android' ? __cwd : __rootDir
|
|
110
112
|
|
|
111
113
|
const __wasi = new __nodeWASI({
|
|
112
114
|
version: 'preview1',
|
|
113
115
|
env: process.env,
|
|
114
116
|
preopens: {
|
|
115
|
-
[__rootDir]:
|
|
116
|
-
|
|
117
|
+
[__rootDir]: __hostRoot,
|
|
118
|
+
[__hostRoot]: __hostRoot,
|
|
119
|
+
},
|
|
117
120
|
})
|
|
118
121
|
|
|
119
122
|
const __sharedMemory = new WebAssembly.Memory({
|
|
@@ -155,11 +158,11 @@ let __emnapiWasmEnvCleanupDrained = false
|
|
|
155
158
|
let __emnapiWasmEnvCleanupDrainPromise
|
|
156
159
|
let __wasiDisposed = false
|
|
157
160
|
let __wasiDisposePromise
|
|
158
|
-
let __completeWasiDisposal = function() {}
|
|
161
|
+
let __completeWasiDisposal = function () {}
|
|
159
162
|
// Overridden by loader flavors that have a last-resort reclaim for a rollback
|
|
160
163
|
// that stopped short of destroying the context. See
|
|
161
164
|
// `__rollbackWasiInitialization`.
|
|
162
|
-
let __retainWasiRollbackForRetry = function() {}
|
|
165
|
+
let __retainWasiRollbackForRetry = function () {}
|
|
163
166
|
|
|
164
167
|
function __isThenable(value) {
|
|
165
168
|
return (
|
|
@@ -846,7 +849,7 @@ try {
|
|
|
846
849
|
napiModule: __napiModule,
|
|
847
850
|
} = __emnapiInstantiateNapiModuleSync(__wasmFile, {
|
|
848
851
|
context: __emnapiContext,
|
|
849
|
-
asyncWorkPoolSize: (function() {
|
|
852
|
+
asyncWorkPoolSize: (function () {
|
|
850
853
|
const threadsSizeFromEnv = Number(process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE)
|
|
851
854
|
// NaN > 0 is false
|
|
852
855
|
if (threadsSizeFromEnv > 0) {
|
|
@@ -871,21 +874,21 @@ try {
|
|
|
871
874
|
// According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415,
|
|
872
875
|
// a worker is consist of two handles: kPublicPort and kHandle.
|
|
873
876
|
{
|
|
874
|
-
const kPublicPort = Object.getOwnPropertySymbols(worker).find(s =>
|
|
875
|
-
s.toString().includes(
|
|
876
|
-
)
|
|
877
|
+
const kPublicPort = Object.getOwnPropertySymbols(worker).find((s) =>
|
|
878
|
+
s.toString().includes('kPublicPort'),
|
|
879
|
+
)
|
|
877
880
|
if (kPublicPort) {
|
|
878
|
-
worker[kPublicPort].ref = () => {}
|
|
881
|
+
worker[kPublicPort].ref = () => {}
|
|
879
882
|
}
|
|
880
883
|
|
|
881
|
-
const kHandle = Object.getOwnPropertySymbols(worker).find(s =>
|
|
882
|
-
s.toString().includes(
|
|
883
|
-
)
|
|
884
|
+
const kHandle = Object.getOwnPropertySymbols(worker).find((s) =>
|
|
885
|
+
s.toString().includes('kHandle'),
|
|
886
|
+
)
|
|
884
887
|
if (kHandle) {
|
|
885
|
-
worker[kHandle].ref = () => {}
|
|
888
|
+
worker[kHandle].ref = () => {}
|
|
886
889
|
}
|
|
887
890
|
|
|
888
|
-
worker.unref()
|
|
891
|
+
worker.unref()
|
|
889
892
|
}
|
|
890
893
|
return worker
|
|
891
894
|
},
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* auto-generated by NAPI-RS */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
+
|
|
3
4
|
/** Batch-wide options for [`compress_buffers`]. */
|
|
4
5
|
export interface BatchOptions {
|
|
5
6
|
/** Worker threads; 0 or omitted = number of logical CPUs. */
|
|
@@ -11,15 +12,47 @@ export interface BatchOptions {
|
|
|
11
12
|
skipIfLargerOrEqual?: boolean
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
/** Algorithm settings applied to every file in a batch. */
|
|
16
|
+
export interface CompressAlgorithm {
|
|
17
|
+
/** Canonical algorithm name: "gzip" | "brotli" | "zstd". */
|
|
18
|
+
algorithm: string
|
|
19
|
+
/**
|
|
20
|
+
* Compression level; algorithm default when omitted
|
|
21
|
+
* (gzip 6, brotli 11, zstd 19).
|
|
22
|
+
*/
|
|
23
|
+
level?: number
|
|
24
|
+
/** Brotli only: log2 window size (10-24, default 22). */
|
|
25
|
+
windowBits?: number
|
|
26
|
+
/**
|
|
27
|
+
* Brotli only: target section size in bytes when a large input is
|
|
28
|
+
* split across the brotli worker pool; inputs larger than one section
|
|
29
|
+
* are split. Defaults to two windows (`2^(windowBits + 1)` bytes),
|
|
30
|
+
* i.e. 8 MiB at the default window.
|
|
31
|
+
*
|
|
32
|
+
* Smaller sections finish large files faster and cost compression
|
|
33
|
+
* ratio. The encoder segments between 64 KiB and 16 MiB, and values
|
|
34
|
+
* outside that range are clamped to it.
|
|
35
|
+
*/
|
|
36
|
+
sectionSize?: number
|
|
37
|
+
}
|
|
38
|
+
|
|
14
39
|
/**
|
|
15
40
|
* Compress a batch of buffers off the JS main thread.
|
|
16
41
|
*
|
|
17
|
-
*
|
|
42
|
+
* Each file carries one buffer; algorithm settings are shared by all files.
|
|
43
|
+
* Results follow file order, then algorithm order within each file. Empty
|
|
44
|
+
* files or algorithms arrays produce no results. Algorithm names and
|
|
18
45
|
* levels are validated synchronously so misconfiguration fails fast;
|
|
19
46
|
* I/O-shaped failures during compression are reported per task via
|
|
20
47
|
* [`CompressResult::error`].
|
|
21
48
|
*/
|
|
22
|
-
export declare function compressBuffers(
|
|
49
|
+
export declare function compressBuffers(files: Array<CompressFile>, algorithms: Array<CompressAlgorithm>, options?: BatchOptions | undefined | null): Promise<Array<CompressResult>>
|
|
50
|
+
|
|
51
|
+
/** One source file, passed once regardless of the number of algorithms. */
|
|
52
|
+
export interface CompressFile {
|
|
53
|
+
fileName: string
|
|
54
|
+
data: Buffer
|
|
55
|
+
}
|
|
23
56
|
|
|
24
57
|
/** Outcome of a single task within a batch. */
|
|
25
58
|
export interface CompressResult {
|
|
@@ -37,32 +70,3 @@ export interface CompressResult {
|
|
|
37
70
|
/** Per-task failure. A failed task never aborts the rest of the batch. */
|
|
38
71
|
error?: string
|
|
39
72
|
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* One compression task: pairs with the buffer at the same index in the
|
|
43
|
-
* `buffers` argument of [`compress_buffers`].
|
|
44
|
-
*/
|
|
45
|
-
export interface CompressTask {
|
|
46
|
-
fileName: string
|
|
47
|
-
/** Canonical algorithm name: "gzip" | "brotli" | "zstd". */
|
|
48
|
-
algorithm: string
|
|
49
|
-
/**
|
|
50
|
-
* Compression level; algorithm default when omitted
|
|
51
|
-
* (gzip 6, brotli 11, zstd 19).
|
|
52
|
-
*/
|
|
53
|
-
level?: number
|
|
54
|
-
/** Brotli only: log2 window size (10-24, default 22). */
|
|
55
|
-
windowBits?: number
|
|
56
|
-
/**
|
|
57
|
-
* Brotli only: target section size in bytes when a large input is
|
|
58
|
-
* split across the brotli worker pool; inputs at least twice this
|
|
59
|
-
* size take the multithreaded path. Defaults to two windows
|
|
60
|
-
* (`2^(windowBits + 1)` bytes), i.e. 8 MiB and multithreading from
|
|
61
|
-
* 16 MiB at the default window.
|
|
62
|
-
*
|
|
63
|
-
* Smaller sections finish large files faster and cost compression
|
|
64
|
-
* ratio. The encoder segments between 64 KiB and 16 MiB, and values
|
|
65
|
-
* outside that range are clamped to it.
|
|
66
|
-
*/
|
|
67
|
-
sectionSize?: number
|
|
68
|
-
}
|
|
Binary file
|
package/wasi-worker-browser.mjs
CHANGED
|
@@ -13,10 +13,9 @@ const handler = new MessageHandler({
|
|
|
13
13
|
// eslint-disable-next-line no-console
|
|
14
14
|
console.log.apply(console, arguments)
|
|
15
15
|
},
|
|
16
|
-
printErr: function() {
|
|
16
|
+
printErr: function () {
|
|
17
17
|
// eslint-disable-next-line no-console
|
|
18
18
|
console.error.apply(console, arguments)
|
|
19
|
-
|
|
20
19
|
},
|
|
21
20
|
})
|
|
22
21
|
return instantiateNapiModuleSync(wasmModule, {
|
|
@@ -37,7 +36,6 @@ const handler = new MessageHandler({
|
|
|
37
36
|
},
|
|
38
37
|
})
|
|
39
38
|
},
|
|
40
|
-
|
|
41
39
|
})
|
|
42
40
|
|
|
43
41
|
globalThis.onmessage = function (e) {
|
package/wasi-worker.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import { createRequire } from
|
|
3
|
-
import { parse } from
|
|
4
|
-
import { WASI } from
|
|
5
|
-
import { parentPort, Worker } from
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
import { parse } from 'node:path'
|
|
4
|
+
import { WASI } from 'node:wasi'
|
|
5
|
+
import { parentPort, Worker, workerData } from 'node:worker_threads'
|
|
6
6
|
|
|
7
|
-
const require = createRequire(import.meta.url)
|
|
7
|
+
const require = createRequire(import.meta.url)
|
|
8
8
|
|
|
9
9
|
const {
|
|
10
10
|
instantiateNapiModuleSync,
|
|
@@ -12,12 +12,12 @@ const {
|
|
|
12
12
|
getDefaultContext,
|
|
13
13
|
emnapiAsyncWorkPlugin,
|
|
14
14
|
emnapiTSFNPlugin,
|
|
15
|
-
} = require(
|
|
15
|
+
} = require('@napi-rs/wasm-runtime')
|
|
16
16
|
|
|
17
17
|
if (parentPort) {
|
|
18
|
-
parentPort.on(
|
|
19
|
-
globalThis.onmessage({ data })
|
|
20
|
-
})
|
|
18
|
+
parentPort.on('message', (data) => {
|
|
19
|
+
globalThis.onmessage({ data })
|
|
20
|
+
})
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
Object.assign(globalThis, {
|
|
@@ -25,18 +25,25 @@ Object.assign(globalThis, {
|
|
|
25
25
|
require,
|
|
26
26
|
Worker,
|
|
27
27
|
importScripts: function (f) {
|
|
28
|
-
|
|
28
|
+
// oxlint-disable-next-line no-eval -- WASI importScripts polyfill
|
|
29
|
+
;(0, eval)(fs.readFileSync(f, 'utf8') + '//# sourceURL=' + f)
|
|
29
30
|
},
|
|
30
31
|
postMessage: function (msg) {
|
|
31
32
|
if (parentPort) {
|
|
32
|
-
parentPort.postMessage(msg)
|
|
33
|
+
parentPort.postMessage(msg)
|
|
33
34
|
}
|
|
34
35
|
},
|
|
35
|
-
})
|
|
36
|
+
})
|
|
36
37
|
|
|
37
|
-
const emnapiContext = getDefaultContext()
|
|
38
|
+
const emnapiContext = getDefaultContext()
|
|
38
39
|
|
|
39
|
-
const
|
|
40
|
+
const __cwd = process.cwd()
|
|
41
|
+
const __rootDir =
|
|
42
|
+
(workerData && typeof workerData.rootDir === 'string' && workerData.rootDir) ||
|
|
43
|
+
parse(__cwd).root
|
|
44
|
+
const __hostRoot =
|
|
45
|
+
(workerData && typeof workerData.hostRoot === 'string' && workerData.hostRoot) ||
|
|
46
|
+
(process.platform === 'android' ? __cwd : __rootDir)
|
|
40
47
|
|
|
41
48
|
const handler = new MessageHandler({
|
|
42
49
|
onLoad({ wasmModule, wasmMemory }) {
|
|
@@ -44,9 +51,10 @@ const handler = new MessageHandler({
|
|
|
44
51
|
version: 'preview1',
|
|
45
52
|
env: process.env,
|
|
46
53
|
preopens: {
|
|
47
|
-
[__rootDir]:
|
|
54
|
+
[__rootDir]: __hostRoot,
|
|
55
|
+
[__hostRoot]: __hostRoot,
|
|
48
56
|
},
|
|
49
|
-
})
|
|
57
|
+
})
|
|
50
58
|
|
|
51
59
|
return instantiateNapiModuleSync(wasmModule, {
|
|
52
60
|
childThread: true,
|
|
@@ -62,13 +70,13 @@ const handler = new MessageHandler({
|
|
|
62
70
|
...importObject.env,
|
|
63
71
|
...importObject.napi,
|
|
64
72
|
...importObject.emnapi,
|
|
65
|
-
memory: wasmMemory
|
|
66
|
-
}
|
|
73
|
+
memory: wasmMemory,
|
|
74
|
+
}
|
|
67
75
|
},
|
|
68
|
-
})
|
|
76
|
+
})
|
|
69
77
|
},
|
|
70
|
-
})
|
|
78
|
+
})
|
|
71
79
|
|
|
72
80
|
globalThis.onmessage = function (e) {
|
|
73
|
-
handler.handle(e)
|
|
74
|
-
}
|
|
81
|
+
handler.handle(e)
|
|
82
|
+
}
|