@tailwindcss/oxide-wasm32-wasi 0.0.0-insiders.f4a7eea → 0.0.0-insiders.f945c3d

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 (66) 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 +266 -160
  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 +46 -30
  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 +46 -30
  33. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +46 -30
  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 +46 -30
  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 +14895 -13935
  41. package/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +259 -0
  42. package/node_modules/@napi-rs/wasm-runtime/package.json +13 -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.d.ts +6 -0
  46. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js +51 -31
  47. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +51 -31
  48. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm.min.js +1 -1
  49. package/node_modules/@tybys/wasm-util/dist/wasm-util.js +51 -31
  50. package/node_modules/@tybys/wasm-util/dist/wasm-util.min.js +1 -1
  51. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/index.js +12 -14
  52. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +39 -17
  53. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/index.mjs +12 -14
  54. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +39 -17
  55. package/node_modules/@tybys/wasm-util/package.json +1 -1
  56. package/node_modules/tslib/package.json +1 -1
  57. package/node_modules/tslib/tslib.es6.js +10 -1
  58. package/node_modules/tslib/tslib.es6.mjs +10 -1
  59. package/node_modules/tslib/tslib.js +42 -33
  60. package/package.json +7 -7
  61. package/tailwindcss-oxide.wasi-browser.js +6 -3
  62. package/tailwindcss-oxide.wasi.cjs +26 -3
  63. package/tailwindcss-oxide.wasm32-wasi.wasm +0 -0
  64. package/node_modules/@napi-rs/wasm-runtime/LICENSE +0 -43
  65. package/node_modules/@napi-rs/wasm-runtime/dist/runtime.js +0 -12285
  66. package/node_modules/@napi-rs/wasm-runtime/fs-proxy.cjs +0 -209
@@ -238,12 +238,17 @@ class ThreadManager {
238
238
  if (worker.__emnapi_tid !== undefined) {
239
239
  message = 'worker (tid = ' + worker.__emnapi_tid + ') sent an error!';
240
240
  }
241
- err(message + ' ' + e.message);
242
- if (e.message.indexOf('RuntimeError') !== -1 || e.message.indexOf('unreachable') !== -1) {
243
- try {
244
- _this.terminateAllThreads();
241
+ if ('message' in e) {
242
+ err(message + ' ' + e.message);
243
+ if (e.message.indexOf('RuntimeError') !== -1 || e.message.indexOf('unreachable') !== -1) {
244
+ try {
245
+ _this.terminateAllThreads();
246
+ }
247
+ catch (_) { }
245
248
  }
246
- catch (_) { }
249
+ }
250
+ else {
251
+ err(message);
247
252
  }
248
253
  reject(e);
249
254
  throw e;
@@ -536,7 +541,7 @@ class WASIThreads {
536
541
  return 1;
537
542
  }
538
543
  else {
539
- return -6;
544
+ return -EAGAIN;
540
545
  }
541
546
  }
542
547
  if (!isNewABI) {
@@ -622,7 +627,7 @@ class WASIThreads {
622
627
  return 1;
623
628
  }
624
629
  free(errorOrTid);
625
- return -6;
630
+ return -EAGAIN;
626
631
  }
627
632
  Atomics.store(struct, 0, 0);
628
633
  Atomics.store(struct, 1, tid);
@@ -724,19 +729,21 @@ function patchWasiInstance(wasiThreads, wasi) {
724
729
  return proc_exit.call(this, code);
725
730
  };
726
731
  }
727
- const start = wasi.start;
728
- if (typeof start === 'function') {
729
- wasi.start = function (instance) {
730
- try {
731
- return start.call(this, instance);
732
- }
733
- catch (err) {
734
- if (isTrapError(err)) {
735
- _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);
736
738
  }
737
- throw err;
738
- }
739
- };
739
+ catch (err) {
740
+ if (isTrapError(err)) {
741
+ _this.terminateAllThreads();
742
+ }
743
+ throw err;
744
+ }
745
+ };
746
+ }
740
747
  }
741
748
  patched.add(wasi);
742
749
  }
@@ -767,6 +774,7 @@ class ThreadMessageHandler {
767
774
  }
768
775
  this.postMessage = postMsg;
769
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; };
770
778
  this.instance = undefined;
771
779
  this.messagesBeforeLoad = [];
772
780
  }
@@ -781,13 +789,18 @@ class ThreadMessageHandler {
781
789
  if ((_a = e === null || e === void 0 ? void 0 : e.data) === null || _a === void 0 ? void 0 : _a.__emnapi__) {
782
790
  const type = e.data.__emnapi__.type;
783
791
  const payload = e.data.__emnapi__.payload;
784
- if (type === 'load') {
785
- 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
+ }
786
801
  }
787
- else if (type === 'start') {
788
- this.handleAfterLoad(e, () => {
789
- this._start(payload);
790
- });
802
+ catch (err) {
803
+ this.onError(err, type);
791
804
  }
792
805
  }
793
806
  }
@@ -811,7 +824,8 @@ class ThreadMessageHandler {
811
824
  }
812
825
  }
813
826
  _start(payload) {
814
- 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') {
815
829
  const err = new TypeError('wasi_thread_start is not exported');
816
830
  notifyPthreadCreateResult(payload.sab, 2, err);
817
831
  throw err;
@@ -821,13 +835,15 @@ class ThreadMessageHandler {
821
835
  const startArg = payload.arg;
822
836
  notifyPthreadCreateResult(payload.sab, 1);
823
837
  try {
824
- this.instance.exports.wasi_thread_start(tid, startArg);
838
+ wasi_thread_start(tid, startArg);
825
839
  }
826
840
  catch (err) {
827
- if (isTrapError(err)) {
828
- postMessage(createMessage('terminate-all-threads', {}));
841
+ if (err !== 'unwind') {
842
+ throw err;
843
+ }
844
+ else {
845
+ return;
829
846
  }
830
- throw err;
831
847
  }
832
848
  postMessage(createMessage('cleanup-thread', { tid }));
833
849
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emnapi/wasi-threads",
3
- "version": "1.0.2",
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;