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