@napi-rs/tar-wasm32-wasi 0.1.4 → 1.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napi-rs/tar-wasm32-wasi",
3
- "version": "0.1.4",
3
+ "version": "1.0.0",
4
4
  "cpu": [
5
5
  "wasm32"
6
6
  ],
@@ -25,13 +25,13 @@
25
25
  "engines": {
26
26
  "node": ">=14.0.0"
27
27
  },
28
+ "repository": "git@github.com:napi-rs/tar.git",
28
29
  "publishConfig": {
29
30
  "registry": "https://registry.npmjs.org/",
30
31
  "access": "public"
31
32
  },
32
- "repository": "git@github.com:napi-rs/tar.git",
33
33
  "browser": "tar.wasi-browser.js",
34
34
  "dependencies": {
35
- "@napi-rs/wasm-runtime": "^0.2.4"
35
+ "@napi-rs/wasm-runtime": "^1.0.1"
36
36
  }
37
37
  }
@@ -1,18 +1,20 @@
1
1
  import {
2
- instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
2
+ createOnMessage as __wasmCreateOnMessageForFsProxy,
3
3
  getDefaultContext as __emnapiGetDefaultContext,
4
+ instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
4
5
  WASI as __WASI,
5
- createOnMessage as __wasmCreateOnMessageForFsProxy,
6
6
  } from '@napi-rs/wasm-runtime'
7
7
 
8
- import __wasmUrl from './tar.wasm32-wasi.wasm?url'
8
+
9
9
 
10
10
  const __wasi = new __WASI({
11
11
  version: 'preview1',
12
12
  })
13
13
 
14
+ const __wasmUrl = new URL('./tar.wasm32-wasi.wasm', import.meta.url).href
14
15
  const __emnapiContext = __emnapiGetDefaultContext()
15
16
 
17
+
16
18
  const __sharedMemory = new WebAssembly.Memory({
17
19
  initial: 4000,
18
20
  maximum: 65536,
@@ -46,23 +48,14 @@ const {
46
48
  return importObject
47
49
  },
48
50
  beforeInit({ instance }) {
49
- __napi_rs_initialize_modules(instance)
51
+ for (const name of Object.keys(instance.exports)) {
52
+ if (name.startsWith('__napi_register__')) {
53
+ instance.exports[name]()
54
+ }
55
+ }
50
56
  },
51
57
  })
52
-
53
- function __napi_rs_initialize_modules(__napiInstance) {
54
- __napiInstance.exports['__napi_register__Entries_struct_0']?.()
55
- __napiInstance.exports['__napi_register__Entries_impl_1']?.()
56
- __napiInstance.exports['__napi_register__Entry_struct_2']?.()
57
- __napiInstance.exports['__napi_register__Entry_impl_5']?.()
58
- __napiInstance.exports['__napi_register__EntryType_6']?.()
59
- __napiInstance.exports['__napi_register__Header_struct_7']?.()
60
- __napiInstance.exports['__napi_register__Header_impl_37']?.()
61
- __napiInstance.exports['__napi_register__ReadonlyHeader_struct_38']?.()
62
- __napiInstance.exports['__napi_register__ReadonlyHeader_impl_54']?.()
63
- __napiInstance.exports['__napi_register__Archive_struct_55']?.()
64
- __napiInstance.exports['__napi_register__Archive_impl_66']?.()
65
- }
58
+ export default __napiModule.exports
66
59
  export const Archive = __napiModule.exports.Archive
67
60
  export const Entries = __napiModule.exports.Entries
68
61
  export const Entry = __napiModule.exports.Entry
package/tar.wasi.cjs CHANGED
@@ -9,9 +9,9 @@ const { WASI: __nodeWASI } = require('node:wasi')
9
9
  const { Worker } = require('node:worker_threads')
10
10
 
11
11
  const {
12
- instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
13
- getDefaultContext: __emnapiGetDefaultContext,
14
12
  createOnMessage: __wasmCreateOnMessageForFsProxy,
13
+ getDefaultContext: __emnapiGetDefaultContext,
14
+ instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
15
15
  } = require('@napi-rs/wasm-runtime')
16
16
 
17
17
  const __rootDir = __nodePath.parse(process.cwd()).root
@@ -56,15 +56,38 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
56
56
  return 4
57
57
  }
58
58
  })(),
59
+ reuseWorker: true,
59
60
  wasi: __wasi,
60
61
  onCreateWorker() {
61
62
  const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
62
63
  env: process.env,
63
- execArgv: ['--experimental-wasi-unstable-preview1'],
64
64
  })
65
65
  worker.onmessage = ({ data }) => {
66
66
  __wasmCreateOnMessageForFsProxy(__nodeFs)(data)
67
67
  }
68
+
69
+ // The main thread of Node.js waits for all the active handles before exiting.
70
+ // But Rust threads are never waited without `thread::join`.
71
+ // So here we hack the code of Node.js to prevent the workers from being referenced (active).
72
+ // According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415,
73
+ // a worker is consist of two handles: kPublicPort and kHandle.
74
+ {
75
+ const kPublicPort = Object.getOwnPropertySymbols(worker).find(s =>
76
+ s.toString().includes("kPublicPort")
77
+ );
78
+ if (kPublicPort) {
79
+ worker[kPublicPort].ref = () => {};
80
+ }
81
+
82
+ const kHandle = Object.getOwnPropertySymbols(worker).find(s =>
83
+ s.toString().includes("kHandle")
84
+ );
85
+ if (kHandle) {
86
+ worker[kHandle].ref = () => {};
87
+ }
88
+
89
+ worker.unref();
90
+ }
68
91
  return worker
69
92
  },
70
93
  overwriteImports(importObject) {
@@ -77,23 +100,14 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
77
100
  return importObject
78
101
  },
79
102
  beforeInit({ instance }) {
80
- __napi_rs_initialize_modules(instance)
81
- }
103
+ for (const name of Object.keys(instance.exports)) {
104
+ if (name.startsWith('__napi_register__')) {
105
+ instance.exports[name]()
106
+ }
107
+ }
108
+ },
82
109
  })
83
-
84
- function __napi_rs_initialize_modules(__napiInstance) {
85
- __napiInstance.exports['__napi_register__Entries_struct_0']?.()
86
- __napiInstance.exports['__napi_register__Entries_impl_1']?.()
87
- __napiInstance.exports['__napi_register__Entry_struct_2']?.()
88
- __napiInstance.exports['__napi_register__Entry_impl_5']?.()
89
- __napiInstance.exports['__napi_register__EntryType_6']?.()
90
- __napiInstance.exports['__napi_register__Header_struct_7']?.()
91
- __napiInstance.exports['__napi_register__Header_impl_37']?.()
92
- __napiInstance.exports['__napi_register__ReadonlyHeader_struct_38']?.()
93
- __napiInstance.exports['__napi_register__ReadonlyHeader_impl_54']?.()
94
- __napiInstance.exports['__napi_register__Archive_struct_55']?.()
95
- __napiInstance.exports['__napi_register__Archive_impl_66']?.()
96
- }
110
+ module.exports = __napiModule.exports
97
111
  module.exports.Archive = __napiModule.exports.Archive
98
112
  module.exports.Entries = __napiModule.exports.Entries
99
113
  module.exports.Entry = __napiModule.exports.Entry
Binary file