@rolldown/binding-wasm32-wasi 0.10.1-snapshot-eae188a-20240416155744

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/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present Rolldown Team & Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ end of terms and conditions
24
+
25
+ The licenses of externally maintained libraries from which parts of the Software is derived are listed [here](https://github.com/rolldown/rolldown/blob/main/THIRD-PARTY-LICENSE).
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # `@rolldown/binding-wasm32-wasi`
2
+
3
+ This is the **wasm32-wasi-preview1-threads** binary for `@rolldown/binding`
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@rolldown/binding-wasm32-wasi",
3
+ "version": "0.10.1-snapshot-eae188a-20240416155744",
4
+ "cpu": [
5
+ "wasm32"
6
+ ],
7
+ "main": "rolldown-binding.wasi.cjs",
8
+ "files": [
9
+ "rolldown-binding.wasm32-wasi.wasm",
10
+ "rolldown-binding.wasi.cjs",
11
+ "rolldown-binding.wasi-browser.js",
12
+ "wasi-worker.mjs",
13
+ "wasi-worker-browser.mjs"
14
+ ],
15
+ "description": "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.",
16
+ "keywords": [
17
+ "webpack",
18
+ "parcel",
19
+ "esbuild",
20
+ "rollup",
21
+ "bundler",
22
+ "rolldown"
23
+ ],
24
+ "homepage": "https://rolldown.rs/",
25
+ "license": "MIT",
26
+ "engines": {
27
+ "node": ">=14.0.0"
28
+ },
29
+ "publishConfig": {
30
+ "registry": "https://registry.npmjs.org/",
31
+ "access": "public"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/rolldown/rolldown.git",
36
+ "directory": "packages/rolldown"
37
+ },
38
+ "browser": "rolldown-binding.wasi-browser.js",
39
+ "dependencies": {
40
+ "@napi-rs/wasm-runtime": "^0.1.2"
41
+ }
42
+ }
@@ -0,0 +1,93 @@
1
+ import {
2
+ instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
3
+ getDefaultContext as __emnapiGetDefaultContext,
4
+ WASI as __WASI,
5
+ } from '@napi-rs/wasm-runtime'
6
+ import { Volume as __Volume, createFsFromVolume as __createFsFromVolume } from '@napi-rs/wasm-runtime/fs'
7
+
8
+ import __wasmUrl from './rolldown-binding.wasm32-wasi.wasm?url'
9
+
10
+ const __fs = __createFsFromVolume(
11
+ __Volume.fromJSON({
12
+ '/': null,
13
+ }),
14
+ )
15
+
16
+ const __wasi = new __WASI({
17
+ version: 'preview1',
18
+ fs: __fs,
19
+ })
20
+
21
+ const __emnapiContext = __emnapiGetDefaultContext()
22
+
23
+ const __sharedMemory = new WebAssembly.Memory({
24
+ initial: 16384,
25
+ maximum: 65536,
26
+ shared: true,
27
+ })
28
+
29
+ const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer())
30
+
31
+ const {
32
+ instance: __napiInstance,
33
+ module: __wasiModule,
34
+ napiModule: __napiModule,
35
+ } = __emnapiInstantiateNapiModuleSync(__wasmFile, {
36
+ context: __emnapiContext,
37
+ asyncWorkPoolSize: 4,
38
+ wasi: __wasi,
39
+ onCreateWorker() {
40
+ return new Worker(new URL('@rolldown/binding-wasm32-wasi/wasi-worker-browser.mjs', import.meta.url), {
41
+ type: 'module',
42
+ })
43
+ },
44
+ overwriteImports(importObject) {
45
+ importObject.env = {
46
+ ...importObject.env,
47
+ ...importObject.napi,
48
+ ...importObject.emnapi,
49
+ memory: __sharedMemory,
50
+ }
51
+ return importObject
52
+ },
53
+ beforeInit({ instance }) {
54
+ __napi_rs_initialize_modules(instance)
55
+ },
56
+ })
57
+
58
+ function __napi_rs_initialize_modules(__napiInstance) {
59
+ __napiInstance.exports['__napi_register__Bundler_struct_0']?.()
60
+ __napiInstance.exports['__napi_register__Bundler_impl_5']?.()
61
+ __napiInstance.exports['__napi_register__BindingInputItem_struct_6']?.()
62
+ __napiInstance.exports['__napi_register__BindingResolveOptions_struct_7']?.()
63
+ __napiInstance.exports['__napi_register__BindingInputOptions_struct_8']?.()
64
+ __napiInstance.exports['__napi_register__BindingOutputOptions_struct_9']?.()
65
+ __napiInstance.exports['__napi_register__BindingPluginContext_struct_10']?.()
66
+ __napiInstance.exports['__napi_register__BindingPluginContext_impl_12']?.()
67
+ __napiInstance.exports['__napi_register__BindingPluginOptions_struct_13']?.()
68
+ __napiInstance.exports['__napi_register__BindingPluginWithIndex_struct_14']?.()
69
+ __napiInstance.exports['__napi_register__BindingHookLoadOutput_struct_15']?.()
70
+ __napiInstance.exports['__napi_register__BindingHookRenderChunkOutput_struct_16']?.()
71
+ __napiInstance.exports['__napi_register__BindingHookResolveIdExtraOptions_struct_17']?.()
72
+ __napiInstance.exports['__napi_register__BindingHookResolveIdOutput_struct_18']?.()
73
+ __napiInstance.exports['__napi_register__BindingPluginContextResolveOptions_struct_19']?.()
74
+ __napiInstance.exports['__napi_register__ParallelJsPluginRegistry_struct_20']?.()
75
+ __napiInstance.exports['__napi_register__ParallelJsPluginRegistry_impl_22']?.()
76
+ __napiInstance.exports['__napi_register__register_plugins_23']?.()
77
+ __napiInstance.exports['__napi_register__BindingOutputAsset_struct_24']?.()
78
+ __napiInstance.exports['__napi_register__BindingOutputAsset_impl_27']?.()
79
+ __napiInstance.exports['__napi_register__BindingOutputChunk_struct_28']?.()
80
+ __napiInstance.exports['__napi_register__BindingOutputChunk_impl_39']?.()
81
+ __napiInstance.exports['__napi_register__BindingOutputs_struct_40']?.()
82
+ __napiInstance.exports['__napi_register__BindingOutputs_impl_43']?.()
83
+ __napiInstance.exports['__napi_register__RenderedChunk_struct_44']?.()
84
+ __napiInstance.exports['__napi_register__BindingRenderedModule_struct_45']?.()
85
+ __napiInstance.exports['__napi_register__AliasItem_struct_46']?.()
86
+ }
87
+ export const BindingOutputAsset = __napiModule.exports.BindingOutputAsset
88
+ export const BindingOutputChunk = __napiModule.exports.BindingOutputChunk
89
+ export const BindingOutputs = __napiModule.exports.BindingOutputs
90
+ export const BindingPluginContext = __napiModule.exports.BindingPluginContext
91
+ export const Bundler = __napiModule.exports.Bundler
92
+ export const ParallelJsPluginRegistry = __napiModule.exports.ParallelJsPluginRegistry
93
+ export const registerPlugins = __napiModule.exports.registerPlugins
@@ -0,0 +1,109 @@
1
+ /* eslint-disable */
2
+ /* prettier-ignore */
3
+
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ const __nodeFs= require('node:fs')
7
+ const __nodePath = require('node:path')
8
+ const { WASI: __nodeWASI } = require('node:wasi')
9
+ const { Worker } = require('node:worker_threads')
10
+
11
+ const {
12
+ instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
13
+ getDefaultContext: __emnapiGetDefaultContext,
14
+ } = require('@napi-rs/wasm-runtime')
15
+
16
+ const __wasi = new __nodeWASI({
17
+ version: 'preview1',
18
+ env: process.env,
19
+ preopens: {
20
+ '/': '/'
21
+ }
22
+ })
23
+
24
+ const __emnapiContext = __emnapiGetDefaultContext()
25
+
26
+ const __sharedMemory = new WebAssembly.Memory({
27
+ initial: 16384,
28
+ maximum: 65536,
29
+ shared: true,
30
+ })
31
+
32
+ let __wasmFilePath = __nodePath.join(__dirname, 'rolldown-binding.wasm32-wasi.wasm')
33
+
34
+ if (!__nodeFs.existsSync(__wasmFilePath)) {
35
+ try {
36
+ __wasmFilePath = __nodePath.resolve('@rolldown/binding-wasm32-wasi')
37
+ } catch {
38
+ throw new Error('Cannot find rolldown-binding.wasm32-wasi.wasm file, and @rolldown/binding-wasm32-wasi package is not installed.')
39
+ }
40
+ }
41
+
42
+ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
43
+ context: __emnapiContext,
44
+ asyncWorkPoolSize: (function() {
45
+ const threadsSizeFromEnv = Number(process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE)
46
+ // NaN > 0 is false
47
+ if (threadsSizeFromEnv > 0) {
48
+ return threadsSizeFromEnv
49
+ } else {
50
+ return 4
51
+ }
52
+ })(),
53
+ wasi: __wasi,
54
+ onCreateWorker() {
55
+ return new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
56
+ env: process.env,
57
+ execArgv: ['--experimental-wasi-unstable-preview1'],
58
+ })
59
+ },
60
+ overwriteImports(importObject) {
61
+ importObject.env = {
62
+ ...importObject.env,
63
+ ...importObject.napi,
64
+ ...importObject.emnapi,
65
+ memory: __sharedMemory,
66
+ }
67
+ return importObject
68
+ },
69
+ beforeInit({ instance }) {
70
+ __napi_rs_initialize_modules(instance)
71
+ }
72
+ })
73
+
74
+ function __napi_rs_initialize_modules(__napiInstance) {
75
+ __napiInstance.exports['__napi_register__Bundler_struct_0']?.()
76
+ __napiInstance.exports['__napi_register__Bundler_impl_5']?.()
77
+ __napiInstance.exports['__napi_register__BindingInputItem_struct_6']?.()
78
+ __napiInstance.exports['__napi_register__BindingResolveOptions_struct_7']?.()
79
+ __napiInstance.exports['__napi_register__BindingInputOptions_struct_8']?.()
80
+ __napiInstance.exports['__napi_register__BindingOutputOptions_struct_9']?.()
81
+ __napiInstance.exports['__napi_register__BindingPluginContext_struct_10']?.()
82
+ __napiInstance.exports['__napi_register__BindingPluginContext_impl_12']?.()
83
+ __napiInstance.exports['__napi_register__BindingPluginOptions_struct_13']?.()
84
+ __napiInstance.exports['__napi_register__BindingPluginWithIndex_struct_14']?.()
85
+ __napiInstance.exports['__napi_register__BindingHookLoadOutput_struct_15']?.()
86
+ __napiInstance.exports['__napi_register__BindingHookRenderChunkOutput_struct_16']?.()
87
+ __napiInstance.exports['__napi_register__BindingHookResolveIdExtraOptions_struct_17']?.()
88
+ __napiInstance.exports['__napi_register__BindingHookResolveIdOutput_struct_18']?.()
89
+ __napiInstance.exports['__napi_register__BindingPluginContextResolveOptions_struct_19']?.()
90
+ __napiInstance.exports['__napi_register__ParallelJsPluginRegistry_struct_20']?.()
91
+ __napiInstance.exports['__napi_register__ParallelJsPluginRegistry_impl_22']?.()
92
+ __napiInstance.exports['__napi_register__register_plugins_23']?.()
93
+ __napiInstance.exports['__napi_register__BindingOutputAsset_struct_24']?.()
94
+ __napiInstance.exports['__napi_register__BindingOutputAsset_impl_27']?.()
95
+ __napiInstance.exports['__napi_register__BindingOutputChunk_struct_28']?.()
96
+ __napiInstance.exports['__napi_register__BindingOutputChunk_impl_39']?.()
97
+ __napiInstance.exports['__napi_register__BindingOutputs_struct_40']?.()
98
+ __napiInstance.exports['__napi_register__BindingOutputs_impl_43']?.()
99
+ __napiInstance.exports['__napi_register__RenderedChunk_struct_44']?.()
100
+ __napiInstance.exports['__napi_register__BindingRenderedModule_struct_45']?.()
101
+ __napiInstance.exports['__napi_register__AliasItem_struct_46']?.()
102
+ }
103
+ module.exports.BindingOutputAsset = __napiModule.exports.BindingOutputAsset
104
+ module.exports.BindingOutputChunk = __napiModule.exports.BindingOutputChunk
105
+ module.exports.BindingOutputs = __napiModule.exports.BindingOutputs
106
+ module.exports.BindingPluginContext = __napiModule.exports.BindingPluginContext
107
+ module.exports.Bundler = __napiModule.exports.Bundler
108
+ module.exports.ParallelJsPluginRegistry = __napiModule.exports.ParallelJsPluginRegistry
109
+ module.exports.registerPlugins = __napiModule.exports.registerPlugins
@@ -0,0 +1,40 @@
1
+ import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'
2
+ import { Volume, createFsFromVolume } from '@napi-rs/wasm-runtime/fs'
3
+
4
+ const fs = createFsFromVolume(
5
+ Volume.fromJSON({
6
+ '/': null,
7
+ }),
8
+ )
9
+
10
+ const handler = new MessageHandler({
11
+ onLoad({ wasmModule, wasmMemory }) {
12
+ const wasi = new WASI({
13
+ fs,
14
+ print: function () {
15
+ // eslint-disable-next-line no-console
16
+ console.log.apply(console, arguments)
17
+ },
18
+ printErr: function() {
19
+ // eslint-disable-next-line no-console
20
+ console.error.apply(console, arguments)
21
+ },
22
+ })
23
+ return instantiateNapiModuleSync(wasmModule, {
24
+ childThread: true,
25
+ wasi,
26
+ overwriteImports(importObject) {
27
+ importObject.env = {
28
+ ...importObject.env,
29
+ ...importObject.napi,
30
+ ...importObject.emnapi,
31
+ memory: wasmMemory,
32
+ }
33
+ },
34
+ })
35
+ },
36
+ })
37
+
38
+ globalThis.onmessage = function (e) {
39
+ handler.handle(e)
40
+ }
@@ -0,0 +1,60 @@
1
+ import fs from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import { WASI } from "node:wasi";
4
+ import { parentPort, Worker } from "node:worker_threads";
5
+
6
+ const require = createRequire(import.meta.url);
7
+
8
+ const { instantiateNapiModuleSync, MessageHandler, getDefaultContext } = require("@napi-rs/wasm-runtime");
9
+
10
+ if (parentPort) {
11
+ parentPort.on("message", (data) => {
12
+ globalThis.onmessage({ data });
13
+ });
14
+ }
15
+
16
+ Object.assign(globalThis, {
17
+ self: globalThis,
18
+ require,
19
+ Worker,
20
+ importScripts: function (f) {
21
+ ;(0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
22
+ },
23
+ postMessage: function (msg) {
24
+ if (parentPort) {
25
+ parentPort.postMessage(msg);
26
+ }
27
+ },
28
+ });
29
+
30
+ const emnapiContext = getDefaultContext()
31
+
32
+ const handler = new MessageHandler({
33
+ onLoad({ wasmModule, wasmMemory }) {
34
+ const wasi = new WASI({
35
+ version: 'preview1',
36
+ env: process.env,
37
+ preopens: {
38
+ '/': '/',
39
+ },
40
+ });
41
+
42
+ return instantiateNapiModuleSync(wasmModule, {
43
+ childThread: true,
44
+ wasi,
45
+ context: emnapiContext,
46
+ overwriteImports(importObject) {
47
+ importObject.env = {
48
+ ...importObject.env,
49
+ ...importObject.napi,
50
+ ...importObject.emnapi,
51
+ memory: wasmMemory
52
+ };
53
+ },
54
+ });
55
+ },
56
+ });
57
+
58
+ globalThis.onmessage = function (e) {
59
+ handler.handle(e);
60
+ };