@tailwindcss/oxide-wasm32-wasi 0.0.0-insiders.fa3f45f → 0.0.0-insiders.fb0f432

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.
Files changed (63) hide show
  1. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.js +175 -129
  2. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.d.ts +58 -2
  3. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.js +1 -1
  4. package/node_modules/@emnapi/core/dist/emnapi-core.d.mts +58 -2
  5. package/node_modules/@emnapi/core/dist/emnapi-core.d.ts +58 -2
  6. package/node_modules/@emnapi/core/dist/emnapi-core.esm-bundler.js +210 -131
  7. package/node_modules/@emnapi/core/dist/emnapi-core.js +254 -153
  8. package/node_modules/@emnapi/core/dist/emnapi-core.min.d.mts +58 -2
  9. package/node_modules/@emnapi/core/dist/emnapi-core.min.js +1 -1
  10. package/node_modules/@emnapi/core/dist/emnapi-core.min.mjs +1 -1
  11. package/node_modules/@emnapi/core/dist/emnapi-core.mjs +175 -129
  12. package/node_modules/@emnapi/core/package.json +2 -2
  13. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.js +13 -10
  14. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.d.ts +4 -4
  15. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.js +1 -1
  16. package/node_modules/@emnapi/runtime/dist/emnapi.d.mts +4 -4
  17. package/node_modules/@emnapi/runtime/dist/emnapi.d.ts +4 -4
  18. package/node_modules/@emnapi/runtime/dist/emnapi.esm-bundler.js +13 -10
  19. package/node_modules/@emnapi/runtime/dist/emnapi.iife.d.ts +4 -4
  20. package/node_modules/@emnapi/runtime/dist/emnapi.iife.js +13 -10
  21. package/node_modules/@emnapi/runtime/dist/emnapi.js +13 -10
  22. package/node_modules/@emnapi/runtime/dist/emnapi.min.d.mts +4 -4
  23. package/node_modules/@emnapi/runtime/dist/emnapi.min.js +1 -1
  24. package/node_modules/@emnapi/runtime/dist/emnapi.min.mjs +1 -1
  25. package/node_modules/@emnapi/runtime/dist/emnapi.mjs +13 -10
  26. package/node_modules/@emnapi/runtime/package.json +1 -1
  27. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.js +34 -23
  28. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.d.ts +57 -1
  29. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.js +1 -1
  30. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.mts +57 -1
  31. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +57 -1
  32. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.esm-bundler.js +34 -23
  33. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +34 -23
  34. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.d.mts +57 -1
  35. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.js +1 -1
  36. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.mjs +1 -1
  37. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.mjs +34 -23
  38. package/node_modules/@emnapi/wasi-threads/package.json +1 -1
  39. package/node_modules/@napi-rs/wasm-runtime/dist/fs-proxy.cjs +264 -0
  40. package/node_modules/@napi-rs/wasm-runtime/dist/fs.js +15502 -18356
  41. package/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +259 -0
  42. package/node_modules/@napi-rs/wasm-runtime/package.json +14 -12
  43. package/node_modules/@napi-rs/wasm-runtime/runtime.cjs +1 -1
  44. package/node_modules/@napi-rs/wasm-runtime/runtime.js +8 -0
  45. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js +32 -15
  46. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +32 -15
  47. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm.min.js +1 -1
  48. package/node_modules/@tybys/wasm-util/dist/wasm-util.js +32 -15
  49. package/node_modules/@tybys/wasm-util/dist/wasm-util.min.js +1 -1
  50. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +32 -15
  51. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +32 -15
  52. package/node_modules/@tybys/wasm-util/package.json +1 -1
  53. package/node_modules/tslib/package.json +1 -1
  54. package/node_modules/tslib/tslib.es6.js +10 -1
  55. package/node_modules/tslib/tslib.es6.mjs +10 -1
  56. package/node_modules/tslib/tslib.js +42 -33
  57. package/package.json +7 -7
  58. package/tailwindcss-oxide.wasi-browser.js +6 -3
  59. package/tailwindcss-oxide.wasi.cjs +26 -3
  60. package/tailwindcss-oxide.wasm32-wasi.wasm +0 -0
  61. package/node_modules/@napi-rs/wasm-runtime/LICENSE +0 -43
  62. package/node_modules/@napi-rs/wasm-runtime/dist/runtime.js +0 -12288
  63. package/node_modules/@napi-rs/wasm-runtime/fs-proxy.cjs +0 -209
@@ -729,19 +729,21 @@ function patchWasiInstance(wasiThreads, wasi) {
729
729
  return proc_exit.call(this, code);
730
730
  };
731
731
  }
732
- const start = wasi.start;
733
- if (typeof start === 'function') {
734
- wasi.start = function (instance) {
735
- try {
736
- return start.call(this, instance);
737
- }
738
- catch (err) {
739
- if (isTrapError(err)) {
740
- _this.terminateAllThreads();
732
+ if (!_this.childThread) {
733
+ const start = wasi.start;
734
+ if (typeof start === 'function') {
735
+ wasi.start = function (instance) {
736
+ try {
737
+ return start.call(this, instance);
741
738
  }
742
- throw err;
743
- }
744
- };
739
+ catch (err) {
740
+ if (isTrapError(err)) {
741
+ _this.terminateAllThreads();
742
+ }
743
+ throw err;
744
+ }
745
+ };
746
+ }
745
747
  }
746
748
  patched.add(wasi);
747
749
  }
@@ -772,6 +774,7 @@ class ThreadMessageHandler {
772
774
  }
773
775
  this.postMessage = postMsg;
774
776
  this.onLoad = options === null || options === void 0 ? void 0 : options.onLoad;
777
+ this.onError = typeof (options === null || options === void 0 ? void 0 : options.onError) === 'function' ? options.onError : (_type, err) => { throw err; };
775
778
  this.instance = undefined;
776
779
  this.messagesBeforeLoad = [];
777
780
  }
@@ -786,13 +789,18 @@ class ThreadMessageHandler {
786
789
  if ((_a = e === null || e === void 0 ? void 0 : e.data) === null || _a === void 0 ? void 0 : _a.__emnapi__) {
787
790
  const type = e.data.__emnapi__.type;
788
791
  const payload = e.data.__emnapi__.payload;
789
- if (type === 'load') {
790
- this._load(payload);
792
+ try {
793
+ if (type === 'load') {
794
+ this._load(payload);
795
+ }
796
+ else if (type === 'start') {
797
+ this.handleAfterLoad(e, () => {
798
+ this._start(payload);
799
+ });
800
+ }
791
801
  }
792
- else if (type === 'start') {
793
- this.handleAfterLoad(e, () => {
794
- this._start(payload);
795
- });
802
+ catch (err) {
803
+ this.onError(err, type);
796
804
  }
797
805
  }
798
806
  }
@@ -816,7 +824,8 @@ class ThreadMessageHandler {
816
824
  }
817
825
  }
818
826
  _start(payload) {
819
- if (typeof this.instance.exports.wasi_thread_start !== 'function') {
827
+ const wasi_thread_start = this.instance.exports.wasi_thread_start;
828
+ if (typeof wasi_thread_start !== 'function') {
820
829
  const err = new TypeError('wasi_thread_start is not exported');
821
830
  notifyPthreadCreateResult(payload.sab, 2, err);
822
831
  throw err;
@@ -826,13 +835,15 @@ class ThreadMessageHandler {
826
835
  const startArg = payload.arg;
827
836
  notifyPthreadCreateResult(payload.sab, 1);
828
837
  try {
829
- this.instance.exports.wasi_thread_start(tid, startArg);
838
+ wasi_thread_start(tid, startArg);
830
839
  }
831
840
  catch (err) {
832
- if (isTrapError(err)) {
833
- postMessage(createMessage('terminate-all-threads', {}));
841
+ if (err !== 'unwind') {
842
+ throw err;
843
+ }
844
+ else {
845
+ return;
834
846
  }
835
- throw err;
836
847
  }
837
848
  postMessage(createMessage('cleanup-thread', { tid }));
838
849
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emnapi/wasi-threads",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "WASI threads proposal implementation in JavaScript",
5
5
  "main": "index.js",
6
6
  "module": "./dist/wasi-threads.esm-bundler.js",
@@ -0,0 +1,264 @@
1
+ 'use strict';
2
+
3
+ // @ts-check
4
+
5
+ /**
6
+ * @param {unknown} value
7
+ */
8
+ const getType = (value) => {
9
+ if (value === undefined) return 0
10
+ if (value === null) return 1
11
+ const t = typeof value;
12
+ if (t === 'boolean') return 2
13
+ if (t === 'number') return 3
14
+ if (t === 'string') return 4
15
+ if (t === 'object') return 6
16
+ if (t === 'bigint') return 9
17
+ return -1
18
+ };
19
+
20
+ /**
21
+ * @param {import('memfs').IFs} memfs
22
+ * @param {any} value
23
+ * @param {ReturnType<typeof getType>} type
24
+ * @returns {Uint8Array}
25
+ */
26
+ const encodeValue = (memfs, value, type) => {
27
+ switch (type) {
28
+ case 0:
29
+ case 1:
30
+ return new Uint8Array(0)
31
+ case 2: {
32
+ const view = new Int32Array(1);
33
+ view[0] = value ? 1 : 0;
34
+ return new Uint8Array(view.buffer)
35
+ }
36
+ case 3: {
37
+ const view = new Float64Array(1);
38
+ view[0] = value;
39
+ return new Uint8Array(view.buffer)
40
+ }
41
+ case 4: {
42
+ const view = new TextEncoder().encode(value);
43
+ return view
44
+ }
45
+ case 6: {
46
+ function storeConstructor(obj, memfs, processed = new WeakSet()) {
47
+ if (!obj || typeof obj !== 'object') {
48
+ return
49
+ }
50
+
51
+ if (processed.has(obj)) {
52
+ return
53
+ }
54
+
55
+ processed.add(obj);
56
+
57
+ const [entry] =
58
+ Object.entries(memfs).filter(([_, v]) => v === obj.constructor)[0] ??
59
+ [];
60
+ if (entry) {
61
+ Object.defineProperty(obj, '__constructor__', {
62
+ configurable: true,
63
+ writable: true,
64
+ enumerable: true,
65
+ value: entry,
66
+ });
67
+ }
68
+
69
+ for (const value of Object.values(obj)) {
70
+ storeConstructor(value, memfs, processed);
71
+ }
72
+ }
73
+
74
+ storeConstructor(value, memfs);
75
+
76
+ const json = JSON.stringify(value, (_, value) => {
77
+ if (typeof value === 'bigint') {
78
+ return `BigInt(${String(value)})`
79
+ }
80
+ if (value instanceof Error) {
81
+ return {
82
+ ...value,
83
+ message: value.message,
84
+ stack: value.stack,
85
+ __error__: value.constructor.name,
86
+ }
87
+ }
88
+ return value
89
+ });
90
+ const view = new TextEncoder().encode(json);
91
+ return view
92
+ }
93
+ case 9: {
94
+ const view = new BigInt64Array(1);
95
+ view[0] = value;
96
+ return new Uint8Array(view.buffer)
97
+ }
98
+ case -1:
99
+ default:
100
+ throw new Error('unsupported data')
101
+ }
102
+ };
103
+
104
+ /**
105
+ * @param {typeof import('memfs')} memfs
106
+ * @param {Uint8Array} payload
107
+ * @param {number} type
108
+ * @returns {any}
109
+ */
110
+ const decodeValue = (memfs, payload, type) => {
111
+ if (type === 0) return undefined
112
+ if (type === 1) return null
113
+ if (type === 2)
114
+ return Boolean(new Int32Array(payload.buffer, payload.byteOffset, 1)[0])
115
+ if (type === 3)
116
+ return new Float64Array(payload.buffer, payload.byteOffset, 1)[0]
117
+ if (type === 4) return new TextDecoder().decode(payload.slice())
118
+ if (type === 6) {
119
+ const obj = JSON.parse(
120
+ new TextDecoder().decode(payload.slice()),
121
+ (_key, value) => {
122
+ if (typeof value === 'string') {
123
+ const matched = value.match(/^BigInt\((-?\d+)\)$/);
124
+ if (matched && matched[1]) {
125
+ return BigInt(matched[1])
126
+ }
127
+ }
128
+ return value
129
+ },
130
+ );
131
+
132
+ function loadConstructor(obj, memfs, processed = new WeakSet()) {
133
+ if (!obj || typeof obj !== 'object') {
134
+ return
135
+ }
136
+
137
+ if (processed.has(obj)) {
138
+ return
139
+ }
140
+
141
+ processed.add(obj);
142
+
143
+ if (obj.__constructor__) {
144
+ const ctor = obj.__constructor__;
145
+ delete obj.__constructor__;
146
+ Object.setPrototypeOf(obj, memfs[ctor].prototype);
147
+ }
148
+
149
+ for (const value of Object.values(obj)) {
150
+ loadConstructor(value, memfs, processed);
151
+ }
152
+ }
153
+
154
+ loadConstructor(obj, memfs);
155
+
156
+ if (obj.__error__) {
157
+ const name = obj.__error__;
158
+ const ErrorConstructor = globalThis[name] || Error;
159
+ delete obj.__error__;
160
+ const err = new ErrorConstructor(obj.message);
161
+ Object.defineProperty(err, 'stack', {
162
+ configurable: true,
163
+ enumerable: false,
164
+ writable: true,
165
+ value: err.stack,
166
+ });
167
+ Object.defineProperty(err, Symbol.toStringTag, {
168
+ configurable: true,
169
+ enumerable: false,
170
+ writable: true,
171
+ value: name,
172
+ });
173
+ for (const [k, v] of Object.entries(obj)) {
174
+ if (k === 'message' || k === 'stack') continue
175
+ err[k] = v;
176
+ }
177
+ return err
178
+ }
179
+ return obj
180
+ }
181
+ if (type === 9)
182
+ return new BigInt64Array(payload.buffer, payload.byteOffset, 1)[0]
183
+ throw new Error('unsupported data')
184
+ };
185
+
186
+ /**
187
+ * @param {import('memfs').IFs} fs
188
+ * @returns {(e: { data: { __fs__: { sab: Int32Array, type: keyof import('memfs').IFs, payload: any[] } } }) => void}
189
+ */
190
+ // oxlint-disable-next-line no-unused-vars -- fixed in an upcoming release
191
+ const createOnMessage = (fs) =>
192
+ function onMessage(e) {
193
+ if (e.data.__fs__) {
194
+ /**
195
+ * 0..4 status(int32_t): 21(waiting) 0(success) 1(error)
196
+ * 5..8 type(napi_valuetype): 0(undefined) 1(null) 2(boolean) 3(number) 4(string) 6(jsonstring) 9(bigint) -1(unsupported)
197
+ * 9..16 payload_size(uint32_t) <= 1024
198
+ * 16..16 + payload_size payload_content
199
+ */
200
+ const { sab, type, payload } = e.data.__fs__;
201
+ const fn = fs[type];
202
+ try {
203
+ const ret = fn.apply(fs, payload);
204
+ const t = getType(ret);
205
+ Atomics.store(sab, 1, t);
206
+ const v = encodeValue(fs, ret, t);
207
+ Atomics.store(sab, 2, v.length);
208
+ new Uint8Array(sab.buffer).set(v, 16);
209
+ Atomics.store(sab, 0, 0); // success
210
+ } catch (/** @type {any} */ err) {
211
+ const t = getType(err);
212
+ Atomics.store(sab, 1, t);
213
+ const v = encodeValue(fs, err, t);
214
+ Atomics.store(sab, 2, v.length);
215
+ new Uint8Array(sab.buffer).set(v, 16);
216
+ Atomics.store(sab, 0, 1); // error
217
+ } finally {
218
+ Atomics.notify(sab, 0);
219
+ }
220
+ }
221
+ };
222
+
223
+ /**
224
+ * @param {typeof import('memfs')} memfs
225
+ */
226
+ const createFsProxy = (memfs) =>
227
+ new Proxy(
228
+ {},
229
+ {
230
+ get(_target, p, _receiver) {
231
+ /**
232
+ * @param {any[]} args
233
+ */
234
+ return function (...args) {
235
+ const sab = new SharedArrayBuffer(16 + 10240);
236
+ const i32arr = new Int32Array(sab);
237
+ Atomics.store(i32arr, 0, 21);
238
+
239
+ postMessage({
240
+ __fs__: {
241
+ sab: i32arr,
242
+ type: p,
243
+ payload: args,
244
+ },
245
+ });
246
+
247
+ Atomics.wait(i32arr, 0, 21);
248
+
249
+ const status = Atomics.load(i32arr, 0);
250
+ const type = Atomics.load(i32arr, 1);
251
+ const size = Atomics.load(i32arr, 2);
252
+ const content = new Uint8Array(sab, 16, size);
253
+ const value = decodeValue(memfs, content, type);
254
+ if (status === 1) {
255
+ throw value
256
+ }
257
+ return value
258
+ }
259
+ },
260
+ },
261
+ );
262
+
263
+ exports.createFsProxy = createFsProxy;
264
+ exports.createOnMessage = createOnMessage;