@vue-jsx-vapor/compiler-rs-wasm32-wasi 2.6.11 → 2.6.12

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.
@@ -0,0 +1,62 @@
1
+ import {
2
+ createOnMessage as __wasmCreateOnMessageForFsProxy,
3
+ getDefaultContext as __emnapiGetDefaultContext,
4
+ instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
5
+ WASI as __WASI,
6
+ } from '@napi-rs/wasm-runtime'
7
+
8
+ const __wasi = new __WASI({
9
+ version: 'preview1',
10
+ })
11
+
12
+ const __wasmUrl = new URL('./compiler-rs.wasm32-wasi.wasm', import.meta.url)
13
+ .href
14
+ const __emnapiContext = __emnapiGetDefaultContext()
15
+
16
+ const __sharedMemory = new WebAssembly.Memory({
17
+ initial: 4000,
18
+ maximum: 65536,
19
+ shared: true,
20
+ })
21
+
22
+ const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer())
23
+
24
+ const {
25
+ instance: __napiInstance,
26
+ module: __wasiModule,
27
+ napiModule: __napiModule,
28
+ } = __emnapiInstantiateNapiModuleSync(__wasmFile, {
29
+ context: __emnapiContext,
30
+ asyncWorkPoolSize: 4,
31
+ wasi: __wasi,
32
+ onCreateWorker() {
33
+ const worker = new Worker(
34
+ new URL('@vue-jsx-vapor/compiler-rs-wasm32-wasi/wasi-worker-browser.mjs', import.meta.url),
35
+ {
36
+ type: 'module',
37
+ },
38
+ )
39
+
40
+ return worker
41
+ },
42
+ overwriteImports(importObject) {
43
+ importObject.env = {
44
+ ...importObject.env,
45
+ ...importObject.napi,
46
+ ...importObject.emnapi,
47
+ memory: __sharedMemory,
48
+ }
49
+ return importObject
50
+ },
51
+ beforeInit({ instance }) {
52
+ for (const name of Object.keys(instance.exports)) {
53
+ if (name.startsWith('__napi_register__')) {
54
+ instance.exports[name]()
55
+ }
56
+ }
57
+ },
58
+ })
59
+ export default __napiModule.exports
60
+ export const compile = __napiModule.exports.compile
61
+ export const ErrorCodes = __napiModule.exports.ErrorCodes
62
+ export const transform = __napiModule.exports.transform
@@ -0,0 +1,127 @@
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
+ createOnMessage: __wasmCreateOnMessageForFsProxy,
13
+ getDefaultContext: __emnapiGetDefaultContext,
14
+ instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
15
+ } = require('@napi-rs/wasm-runtime')
16
+
17
+ const __rootDir = __nodePath.parse(process.cwd()).root
18
+
19
+ const __wasi = new __nodeWASI({
20
+ version: 'preview1',
21
+ env: process.env,
22
+ preopens: {
23
+ [__rootDir]: __rootDir,
24
+ },
25
+ })
26
+
27
+ const __emnapiContext = __emnapiGetDefaultContext()
28
+
29
+ const __sharedMemory = new WebAssembly.Memory({
30
+ initial: 4000,
31
+ maximum: 65536,
32
+ shared: true,
33
+ })
34
+
35
+ let __wasmFilePath = __nodePath.join(__dirname, 'compiler-rs.wasm32-wasi.wasm')
36
+ const __wasmDebugFilePath = __nodePath.join(
37
+ __dirname,
38
+ 'compiler-rs.wasm32-wasi.debug.wasm',
39
+ )
40
+
41
+ if (__nodeFs.existsSync(__wasmDebugFilePath)) {
42
+ __wasmFilePath = __wasmDebugFilePath
43
+ } else if (!__nodeFs.existsSync(__wasmFilePath)) {
44
+ try {
45
+ __wasmFilePath = __nodePath.resolve(
46
+ '@vue-jsx-vapor/compiler-rs-wasm32-wasi',
47
+ )
48
+ } catch {
49
+ throw new Error(
50
+ 'Cannot find compiler-rs.wasm32-wasi.wasm file, and @vue-jsx-vapor/compiler-rs-wasm32-wasi package is not installed.',
51
+ )
52
+ }
53
+ }
54
+
55
+ const {
56
+ instance: __napiInstance,
57
+ module: __wasiModule,
58
+ napiModule: __napiModule,
59
+ } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
60
+ context: __emnapiContext,
61
+ asyncWorkPoolSize: (function () {
62
+ const threadsSizeFromEnv = Number(
63
+ process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ??
64
+ process.env.UV_THREADPOOL_SIZE,
65
+ )
66
+ // NaN > 0 is false
67
+ if (threadsSizeFromEnv > 0) {
68
+ return threadsSizeFromEnv
69
+ } else {
70
+ return 4
71
+ }
72
+ })(),
73
+ reuseWorker: true,
74
+ wasi: __wasi,
75
+ onCreateWorker() {
76
+ const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
77
+ env: process.env,
78
+ })
79
+ worker.onmessage = ({ data }) => {
80
+ __wasmCreateOnMessageForFsProxy(__nodeFs)(data)
81
+ }
82
+
83
+ // The main thread of Node.js waits for all the active handles before exiting.
84
+ // But Rust threads are never waited without `thread::join`.
85
+ // So here we hack the code of Node.js to prevent the workers from being referenced (active).
86
+ // According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415,
87
+ // a worker is consist of two handles: kPublicPort and kHandle.
88
+ {
89
+ const kPublicPort = Object.getOwnPropertySymbols(worker).find((s) =>
90
+ s.toString().includes('kPublicPort'),
91
+ )
92
+ if (kPublicPort) {
93
+ worker[kPublicPort].ref = () => {}
94
+ }
95
+
96
+ const kHandle = Object.getOwnPropertySymbols(worker).find((s) =>
97
+ s.toString().includes('kHandle'),
98
+ )
99
+ if (kHandle) {
100
+ worker[kHandle].ref = () => {}
101
+ }
102
+
103
+ worker.unref()
104
+ }
105
+ return worker
106
+ },
107
+ overwriteImports(importObject) {
108
+ importObject.env = {
109
+ ...importObject.env,
110
+ ...importObject.napi,
111
+ ...importObject.emnapi,
112
+ memory: __sharedMemory,
113
+ }
114
+ return importObject
115
+ },
116
+ beforeInit({ instance }) {
117
+ for (const name of Object.keys(instance.exports)) {
118
+ if (name.startsWith('__napi_register__')) {
119
+ instance.exports[name]()
120
+ }
121
+ }
122
+ },
123
+ })
124
+ module.exports = __napiModule.exports
125
+ module.exports.compile = __napiModule.exports.compile
126
+ module.exports.ErrorCodes = __napiModule.exports.ErrorCodes
127
+ module.exports.transform = __napiModule.exports.transform
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue-jsx-vapor/compiler-rs-wasm32-wasi",
3
- "version": "2.6.11",
3
+ "version": "2.6.12",
4
4
  "cpu": [
5
5
  "wasm32"
6
6
  ],
@@ -26,7 +26,7 @@
26
26
  "node": ">=14.0.0"
27
27
  },
28
28
  "repository": {
29
- "url": "git+ssh://git@github.com/napi-rs/package-template-pnpm.git",
29
+ "url": "git+ssh://git@github.com/zhiyuanzmj/compiler-rs.git",
30
30
  "type": "git"
31
31
  },
32
32
  "publishConfig": {
@@ -37,4 +37,4 @@
37
37
  "dependencies": {
38
38
  "@napi-rs/wasm-runtime": "^1.0.7"
39
39
  }
40
- }
40
+ }
@@ -0,0 +1,36 @@
1
+ import {
2
+ instantiateNapiModuleSync,
3
+ MessageHandler,
4
+ WASI,
5
+ } from '@napi-rs/wasm-runtime'
6
+
7
+ const handler = new MessageHandler({
8
+ onLoad({ wasmModule, wasmMemory }) {
9
+ const wasi = new WASI({
10
+ print: function () {
11
+ // eslint-disable-next-line no-console
12
+ console.log.apply(console, arguments)
13
+ },
14
+ printErr: function () {
15
+ // eslint-disable-next-line no-console
16
+ console.error.apply(console, arguments)
17
+ },
18
+ })
19
+ return instantiateNapiModuleSync(wasmModule, {
20
+ childThread: true,
21
+ wasi,
22
+ overwriteImports(importObject) {
23
+ importObject.env = {
24
+ ...importObject.env,
25
+ ...importObject.napi,
26
+ ...importObject.emnapi,
27
+ memory: wasmMemory,
28
+ }
29
+ },
30
+ })
31
+ },
32
+ })
33
+
34
+ globalThis.onmessage = function (e) {
35
+ handler.handle(e)
36
+ }
@@ -0,0 +1,67 @@
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 } from 'node:worker_threads'
6
+
7
+ const require = createRequire(import.meta.url)
8
+
9
+ const {
10
+ instantiateNapiModuleSync,
11
+ MessageHandler,
12
+ getDefaultContext,
13
+ } = require('@napi-rs/wasm-runtime')
14
+
15
+ if (parentPort) {
16
+ parentPort.on('message', (data) => {
17
+ globalThis.onmessage({ data })
18
+ })
19
+ }
20
+
21
+ Object.assign(globalThis, {
22
+ self: globalThis,
23
+ require,
24
+ Worker,
25
+ importScripts: function (f) {
26
+ ;(0, eval)(fs.readFileSync(f, 'utf8') + '//# sourceURL=' + f)
27
+ },
28
+ postMessage: function (msg) {
29
+ if (parentPort) {
30
+ parentPort.postMessage(msg)
31
+ }
32
+ },
33
+ })
34
+
35
+ const emnapiContext = getDefaultContext()
36
+
37
+ const __rootDir = parse(process.cwd()).root
38
+
39
+ const handler = new MessageHandler({
40
+ onLoad({ wasmModule, wasmMemory }) {
41
+ const wasi = new WASI({
42
+ version: 'preview1',
43
+ env: process.env,
44
+ preopens: {
45
+ [__rootDir]: __rootDir,
46
+ },
47
+ })
48
+
49
+ return instantiateNapiModuleSync(wasmModule, {
50
+ childThread: true,
51
+ wasi,
52
+ context: emnapiContext,
53
+ overwriteImports(importObject) {
54
+ importObject.env = {
55
+ ...importObject.env,
56
+ ...importObject.napi,
57
+ ...importObject.emnapi,
58
+ memory: wasmMemory,
59
+ }
60
+ },
61
+ })
62
+ },
63
+ })
64
+
65
+ globalThis.onmessage = function (e) {
66
+ handler.handle(e)
67
+ }