@build-qube/takeoff-calculator-wasm32-wasi 2.0.2 → 2.0.4

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