@tailwindcss/oxide-wasm32-wasi 0.0.0-insiders.bd9cf92 → 0.0.0-insiders.bdcd708

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 (69) hide show
  1. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.js +1469 -511
  2. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.d.ts +61 -5
  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 +61 -5
  5. package/node_modules/@emnapi/core/dist/emnapi-core.d.ts +61 -5
  6. package/node_modules/@emnapi/core/dist/emnapi-core.esm-bundler.js +1628 -523
  7. package/node_modules/@emnapi/core/dist/emnapi-core.js +1705 -585
  8. package/node_modules/@emnapi/core/dist/emnapi-core.min.d.mts +61 -5
  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 +1469 -511
  12. package/node_modules/@emnapi/core/package.json +2 -2
  13. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.js +44 -14
  14. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.d.ts +15 -7
  15. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.js +1 -1
  16. package/node_modules/@emnapi/runtime/dist/emnapi.d.mts +15 -7
  17. package/node_modules/@emnapi/runtime/dist/emnapi.d.ts +15 -7
  18. package/node_modules/@emnapi/runtime/dist/emnapi.esm-bundler.js +45 -14
  19. package/node_modules/@emnapi/runtime/dist/emnapi.iife.d.ts +12 -6
  20. package/node_modules/@emnapi/runtime/dist/emnapi.iife.js +45 -14
  21. package/node_modules/@emnapi/runtime/dist/emnapi.js +45 -14
  22. package/node_modules/@emnapi/runtime/dist/emnapi.min.d.mts +15 -7
  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 +44 -14
  26. package/node_modules/@emnapi/runtime/package.json +1 -1
  27. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.js +67 -63
  28. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.d.ts +59 -2
  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 +59 -2
  31. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +59 -2
  32. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.esm-bundler.js +67 -63
  33. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +67 -63
  34. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.d.mts +59 -2
  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 +67 -63
  38. package/node_modules/@emnapi/wasi-threads/package.json +1 -1
  39. package/node_modules/@napi-rs/wasm-runtime/dist/fs-proxy.cjs +299 -0
  40. package/node_modules/@napi-rs/wasm-runtime/dist/fs.js +22125 -20726
  41. package/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +294 -0
  42. package/node_modules/@napi-rs/wasm-runtime/package.json +25 -16
  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 +215 -33
  47. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +215 -33
  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 +215 -33
  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/path.js +142 -0
  53. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +61 -19
  54. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/index.mjs +12 -14
  55. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/path.mjs +142 -0
  56. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +61 -19
  57. package/node_modules/@tybys/wasm-util/package.json +1 -1
  58. package/node_modules/tslib/package.json +1 -1
  59. package/node_modules/tslib/tslib.es6.js +10 -1
  60. package/node_modules/tslib/tslib.es6.mjs +10 -1
  61. package/node_modules/tslib/tslib.js +42 -33
  62. package/package.json +7 -7
  63. package/tailwindcss-oxide.wasi-browser.js +7 -3
  64. package/tailwindcss-oxide.wasi.cjs +27 -4
  65. package/tailwindcss-oxide.wasm32-wasi.wasm +0 -0
  66. package/wasi-worker-browser.mjs +2 -0
  67. package/node_modules/@napi-rs/wasm-runtime/LICENSE +0 -43
  68. package/node_modules/@napi-rs/wasm-runtime/dist/runtime.js +0 -12285
  69. package/node_modules/@napi-rs/wasm-runtime/fs-proxy.cjs +0 -209
@@ -306,6 +306,141 @@ function asyncifyLoadSync(asyncify, buffer, imports) {
306
306
 
307
307
  const CHAR_DOT = 46; /* . */
308
308
  const CHAR_FORWARD_SLASH = 47; /* / */
309
+ const CHAR_BACKWARD_SLASH = 92; /* \ */
310
+ const CHAR_COLON = 58; /* : */
311
+ const CHAR_UPPERCASE_A = 65; /* A */
312
+ const CHAR_UPPERCASE_Z = 90; /* Z */
313
+ const CHAR_LOWERCASE_A = 97; /* a */
314
+ const CHAR_LOWERCASE_Z = 122; /* z */
315
+ function isPathSeparatorWin(code) {
316
+ return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
317
+ }
318
+ function isWindowsDeviceRoot(code) {
319
+ return (code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
320
+ (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z);
321
+ }
322
+ const _isWin32 = typeof process !== 'undefined' && process.platform === 'win32';
323
+ /**
324
+ * Windows variant of `resolve()`. Mirrors Node's `path.win32.resolve`
325
+ * semantics enough for the WASI shim's needs (drive-letter absolutes
326
+ * + UNC paths + per-drive cwd lookups via `process.env`/`process.cwd`).
327
+ *
328
+ * Why this is needed: on Windows, `FileDescriptor.realPath` is the
329
+ * host realpath returned by `fs.realpathSync(realPath, 'utf8')` — the
330
+ * backslash form `D:\…`. The POSIX-only `resolveImpl` below only
331
+ * treats `/` as a separator, reads `D` as non-`/`, decides realPath
332
+ * is "relative", and produces a garbage joined path. Downstream
333
+ * `fs.openSync(garbage)` then returns `EINVAL` and the WASI caller
334
+ * sees a permanent failure. This function gives us the correct
335
+ * Windows-style resolution without taking a Node-only `path` import
336
+ * (which would break browser bundles of this package).
337
+ *
338
+ * Cribbed from Node's `lib/path.js` `win32.resolve()` (MIT-licensed),
339
+ * trimmed to what WASI realpath resolution actually exercises.
340
+ */
341
+ function resolveWin32(args) {
342
+ let resolvedDevice = '';
343
+ let resolvedTail = '';
344
+ let resolvedAbsolute = false;
345
+ for (let i = args.length - 1; i >= -1; i--) {
346
+ let path;
347
+ if (i >= 0) {
348
+ path = args[i];
349
+ validateString(path, 'path');
350
+ if (path.length === 0)
351
+ continue;
352
+ }
353
+ else if (resolvedDevice.length === 0) {
354
+ path = (typeof process !== 'undefined' && typeof process.cwd === 'function')
355
+ ? process.cwd()
356
+ : '';
357
+ }
358
+ else {
359
+ // Look up per-drive cwd via the `=X:` env var convention; fall back
360
+ // to the global cwd if absent.
361
+ const envKey = `=${resolvedDevice}`;
362
+ const env = (typeof process !== 'undefined') ? process.env : undefined;
363
+ path = (env && typeof env[envKey] === 'string')
364
+ ? env[envKey]
365
+ : (typeof process !== 'undefined' && typeof process.cwd === 'function')
366
+ ? process.cwd()
367
+ : '';
368
+ if (path === undefined ||
369
+ (path.slice(0, 2).toLowerCase() !== resolvedDevice.toLowerCase() &&
370
+ path.charCodeAt(2) === CHAR_BACKWARD_SLASH)) {
371
+ path = `${resolvedDevice}\\`;
372
+ }
373
+ }
374
+ const len = path.length;
375
+ let rootEnd = 0;
376
+ let device = '';
377
+ let isAbsolute = false;
378
+ const code = path.charCodeAt(0);
379
+ if (len === 1) {
380
+ if (isPathSeparatorWin(code)) {
381
+ rootEnd = 1;
382
+ isAbsolute = true;
383
+ }
384
+ }
385
+ else if (isPathSeparatorWin(code)) {
386
+ isAbsolute = true;
387
+ if (isPathSeparatorWin(path.charCodeAt(1))) {
388
+ // UNC path: `\\server\share\…`
389
+ let j = 2;
390
+ let last = j;
391
+ while (j < len && !isPathSeparatorWin(path.charCodeAt(j)))
392
+ j++;
393
+ if (j < len && j !== last) {
394
+ const firstPart = path.slice(last, j);
395
+ last = j;
396
+ while (j < len && isPathSeparatorWin(path.charCodeAt(j)))
397
+ j++;
398
+ if (j < len && j !== last) {
399
+ last = j;
400
+ while (j < len && !isPathSeparatorWin(path.charCodeAt(j)))
401
+ j++;
402
+ if (j === len || j !== last) {
403
+ device = `\\\\${firstPart}\\${path.slice(last, j)}`;
404
+ rootEnd = j;
405
+ }
406
+ }
407
+ }
408
+ }
409
+ else {
410
+ rootEnd = 1;
411
+ }
412
+ }
413
+ else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
414
+ device = path.slice(0, 2);
415
+ rootEnd = 2;
416
+ if (len > 2 && isPathSeparatorWin(path.charCodeAt(2))) {
417
+ isAbsolute = true;
418
+ rootEnd = 3;
419
+ }
420
+ }
421
+ if (device.length > 0) {
422
+ if (resolvedDevice.length > 0) {
423
+ if (device.toLowerCase() !== resolvedDevice.toLowerCase())
424
+ continue;
425
+ }
426
+ else {
427
+ resolvedDevice = device;
428
+ }
429
+ }
430
+ if (resolvedAbsolute) {
431
+ if (resolvedDevice.length > 0)
432
+ break;
433
+ }
434
+ else {
435
+ resolvedTail = `${path.slice(rootEnd)}\\${resolvedTail}`;
436
+ resolvedAbsolute = isAbsolute;
437
+ if (isAbsolute && resolvedDevice.length > 0)
438
+ break;
439
+ }
440
+ }
441
+ resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, '\\', isPathSeparatorWin);
442
+ return resolvedDevice + (resolvedAbsolute ? '\\' : '') + resolvedTail || '.';
443
+ }
309
444
  function isPosixPathSeparator(code) {
310
445
  return code === CHAR_FORWARD_SLASH;
311
446
  }
@@ -381,6 +516,13 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
381
516
  return res;
382
517
  }
383
518
  function resolve(...args) {
519
+ // On Windows, host paths are `D:\…` style. The POSIX-only resolver
520
+ // below treats `D` as a non-`/` character and produces garbage; route
521
+ // to the Windows-aware variant. POSIX hosts (Linux/macOS/browser)
522
+ // run the original code path unchanged — `_isWin32` is constant-folded
523
+ // away on those targets.
524
+ if (_isWin32)
525
+ return resolveWin32(args);
384
526
  let resolvedPath = '';
385
527
  let resolvedAbsolute = false;
386
528
  for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
@@ -1017,6 +1159,26 @@ function wrapExports(exports, needWrap) {
1017
1159
  });
1018
1160
  }
1019
1161
 
1162
+ // Linux fcntl flag bits ↔ Windows libuv flag bits. `pathOpen()` builds
1163
+ // `flagsRes` using Linux constants (O_CREAT=0x40, O_EXCL=0x80,
1164
+ // O_APPEND=0x400). Windows libuv expects different bits (O_CREAT=0x100,
1165
+ // O_EXCL=0x400, O_APPEND=0x8). Without translation,
1166
+ // `fs.openSync(path, 0x241 /* L:WRONLY|CREAT|TRUNC */)` is rejected
1167
+ // with EINVAL because Linux's 0x40 happens to mean O_TEMPORARY on
1168
+ // Windows — and O_TEMPORARY without O_CREAT is invalid.
1169
+ const _isWin32Flags = typeof process !== 'undefined' && process.platform === 'win32';
1170
+ function _toWinOpenFlags(f) {
1171
+ let r = f & 3; // RDONLY/WRONLY/RDWR — same on both
1172
+ if ((f & 0x40) !== 0)
1173
+ r |= 0x100; // O_CREAT: Linux 0x40 -> Windows 0x100
1174
+ if ((f & 0x80) !== 0)
1175
+ r |= 0x400; // O_EXCL: Linux 0x80 -> Windows 0x400
1176
+ if ((f & 0x200) !== 0)
1177
+ r |= 0x200; // O_TRUNC: same value on both
1178
+ if ((f & 0x400) !== 0)
1179
+ r |= 0x8; // O_APPEND: Linux 0x400 -> Windows 0x8
1180
+ return r;
1181
+ }
1020
1182
  function copyMemory(targets, src) {
1021
1183
  if (targets.length === 0 || src.length === 0)
1022
1184
  return 0;
@@ -1075,26 +1237,43 @@ function defineName(name, f) {
1075
1237
  Object.defineProperty(f, 'name', { value: name });
1076
1238
  return f;
1077
1239
  }
1240
+ function tryCall(f, wasi, args) {
1241
+ let r;
1242
+ try {
1243
+ r = f.apply(wasi, args);
1244
+ }
1245
+ catch (err) {
1246
+ return handleError(err);
1247
+ }
1248
+ if (isPromiseLike(r)) {
1249
+ return r.then(_ => _, handleError);
1250
+ }
1251
+ return r;
1252
+ }
1078
1253
  function syscallWrap(self, name, f) {
1079
- return defineName(name, function () {
1080
- if (process.env.NODE_DEBUG_NATIVE === 'wasi') {
1254
+ let debug = false;
1255
+ const NODE_DEBUG_NATIVE = (() => {
1256
+ try {
1257
+ return process.env.NODE_DEBUG_NATIVE;
1258
+ }
1259
+ catch (_) {
1260
+ return undefined;
1261
+ }
1262
+ })();
1263
+ if (typeof NODE_DEBUG_NATIVE === 'string' && NODE_DEBUG_NATIVE.split(',').includes('wasi')) {
1264
+ debug = true;
1265
+ }
1266
+ return debug
1267
+ ? defineName(name, function () {
1081
1268
  const args = Array.prototype.slice.call(arguments);
1082
1269
  let debugArgs = [`${name}(${Array.from({ length: arguments.length }).map(() => '%d').join(', ')})`];
1083
1270
  debugArgs = debugArgs.concat(args);
1084
1271
  console.debug.apply(console, debugArgs);
1085
- }
1086
- let r;
1087
- try {
1088
- r = f.apply(self, arguments);
1089
- }
1090
- catch (err) {
1091
- return handleError(err);
1092
- }
1093
- if (isPromiseLike(r)) {
1094
- return r.then(_ => _, handleError);
1095
- }
1096
- return r;
1097
- });
1272
+ return tryCall(f, self, args);
1273
+ })
1274
+ : defineName(name, function () {
1275
+ return tryCall(f, self, arguments);
1276
+ });
1098
1277
  }
1099
1278
  function resolvePathSync(fs, fileDescriptor, path, flags) {
1100
1279
  let resolvedPath = resolve(fileDescriptor.realPath, path);
@@ -1240,7 +1419,7 @@ class WASI$1 {
1240
1419
  case 1 /* WasiClockid.MONOTONIC */:
1241
1420
  case 2 /* WasiClockid.PROCESS_CPUTIME_ID */:
1242
1421
  case 3 /* WasiClockid.THREAD_CPUTIME_ID */: {
1243
- const t = performance.now();
1422
+ const t = performance.now() / 1000;
1244
1423
  const s = Math.trunc(t);
1245
1424
  const ms = Math.floor((t - s) * 1000);
1246
1425
  const result = BigInt(s) * BigInt(1000000000) + BigInt(ms) * BigInt(1000000);
@@ -2256,9 +2435,11 @@ class WASI$1 {
2256
2435
  const pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
2257
2436
  const fs = getFs(this);
2258
2437
  const resolved_path = resolvePathSync(fs, fileDescriptor, pathString, dirflags);
2259
- const r = fs.openSync(resolved_path, flagsRes, 0o666);
2438
+ const r = fs.openSync(resolved_path, _isWin32Flags ? _toWinOpenFlags(flagsRes) : flagsRes, 0o666);
2260
2439
  const filetype = wasi.fds.getFileTypeByFd(r);
2261
- if ((o_flags & 2 /* WasiFileControlFlag.O_DIRECTORY */) !== 0 && filetype !== 3 /* WasiFileType.DIRECTORY */) {
2440
+ if ((filetype !== 3 /* WasiFileType.DIRECTORY */) &&
2441
+ ((o_flags & 2 /* WasiFileControlFlag.O_DIRECTORY */) !== 0 ||
2442
+ (resolved_path.endsWith('/')))) {
2262
2443
  return 54 /* WasiErrno.ENOTDIR */;
2263
2444
  }
2264
2445
  const { base: max_base, inheriting: max_inheriting } = getRights(wasi.fds.stdio, r, flagsRes, filetype);
@@ -2290,7 +2471,7 @@ class WASI$1 {
2290
2471
  const pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
2291
2472
  const fs = getFs(this);
2292
2473
  const resolved_path = await resolvePathAsync(fs, fileDescriptor, pathString, dirflags);
2293
- const r = await fs.promises.open(resolved_path, flagsRes, 0o666);
2474
+ const r = await fs.promises.open(resolved_path, _isWin32Flags ? _toWinOpenFlags(flagsRes) : flagsRes, 0o666);
2294
2475
  const filetype = await wasi.fds.getFileTypeByFd(r);
2295
2476
  if ((o_flags & 2 /* WasiFileControlFlag.O_DIRECTORY */) !== 0 && filetype !== 3 /* WasiFileType.DIRECTORY */) {
2296
2477
  return 54 /* WasiErrno.ENOTDIR */;
@@ -2447,6 +2628,9 @@ class WASI$1 {
2447
2628
  const wasi = _wasi.get(this);
2448
2629
  const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_SYMLINK, BigInt(0));
2449
2630
  const oldPath = decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len));
2631
+ if (oldPath.length > 0 && oldPath[0] === '/') {
2632
+ return 63 /* WasiErrno.EPERM */;
2633
+ }
2450
2634
  let newPath = decoder.decode(unsharedSlice(HEAPU8, new_path, new_path + new_path_len));
2451
2635
  newPath = resolve(fileDescriptor.realPath, newPath);
2452
2636
  const fs = getFs(this);
@@ -2555,12 +2739,6 @@ const kSetMemory = Symbol('kSetMemory');
2555
2739
  const kStarted = Symbol('kStarted');
2556
2740
  const kInstance = Symbol('kInstance');
2557
2741
  const kBindingName = Symbol('kBindingName');
2558
- function setupInstance(self, instance) {
2559
- validateObject(instance, 'instance');
2560
- validateObject(instance.exports, 'instance.exports');
2561
- self[kInstance] = instance;
2562
- self[kSetMemory](instance.exports.memory);
2563
- }
2564
2742
  function validateOptions(options) {
2565
2743
  var _a;
2566
2744
  validateObject(options, 'options');
@@ -2665,13 +2843,21 @@ class WASI {
2665
2843
  wrap.proc_exit = wasiReturnOnProcExit.bind(this);
2666
2844
  }
2667
2845
  }
2668
- // Must not export _initialize, must export _start
2669
- start(instance) {
2846
+ finalizeBindings(instance, _a) {
2847
+ var _b;
2848
+ var { memory = (_b = instance === null || instance === void 0 ? void 0 : instance.exports) === null || _b === void 0 ? void 0 : _b.memory } = _a === void 0 ? {} : _a;
2670
2849
  if (this[kStarted]) {
2671
2850
  throw new Error('WASI instance has already started');
2672
2851
  }
2852
+ validateObject(instance, 'instance');
2853
+ validateObject(instance.exports, 'instance.exports');
2854
+ this[kSetMemory](memory);
2855
+ this[kInstance] = instance;
2673
2856
  this[kStarted] = true;
2674
- setupInstance(this, instance);
2857
+ }
2858
+ // Must not export _initialize, must export _start
2859
+ start(instance) {
2860
+ this.finalizeBindings(instance);
2675
2861
  const { _start, _initialize } = this[kInstance].exports;
2676
2862
  validateFunction(_start, 'instance.exports._start');
2677
2863
  validateUndefined(_initialize, 'instance.exports._initialize');
@@ -2696,11 +2882,7 @@ class WASI {
2696
2882
  }
2697
2883
  // Must not export _start, may optionally export _initialize
2698
2884
  initialize(instance) {
2699
- if (this[kStarted]) {
2700
- throw new Error('WASI instance has already started');
2701
- }
2702
- this[kStarted] = true;
2703
- setupInstance(this, instance);
2885
+ this.finalizeBindings(instance);
2704
2886
  const { _start, _initialize } = this[kInstance].exports;
2705
2887
  validateUndefined(_start, 'instance.exports._start');
2706
2888
  if (_initialize !== undefined) {
@@ -306,6 +306,141 @@ function asyncifyLoadSync(asyncify, buffer, imports) {
306
306
 
307
307
  const CHAR_DOT = 46; /* . */
308
308
  const CHAR_FORWARD_SLASH = 47; /* / */
309
+ const CHAR_BACKWARD_SLASH = 92; /* \ */
310
+ const CHAR_COLON = 58; /* : */
311
+ const CHAR_UPPERCASE_A = 65; /* A */
312
+ const CHAR_UPPERCASE_Z = 90; /* Z */
313
+ const CHAR_LOWERCASE_A = 97; /* a */
314
+ const CHAR_LOWERCASE_Z = 122; /* z */
315
+ function isPathSeparatorWin(code) {
316
+ return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
317
+ }
318
+ function isWindowsDeviceRoot(code) {
319
+ return (code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
320
+ (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z);
321
+ }
322
+ const _isWin32 = typeof process !== 'undefined' && process.platform === 'win32';
323
+ /**
324
+ * Windows variant of `resolve()`. Mirrors Node's `path.win32.resolve`
325
+ * semantics enough for the WASI shim's needs (drive-letter absolutes
326
+ * + UNC paths + per-drive cwd lookups via `process.env`/`process.cwd`).
327
+ *
328
+ * Why this is needed: on Windows, `FileDescriptor.realPath` is the
329
+ * host realpath returned by `fs.realpathSync(realPath, 'utf8')` — the
330
+ * backslash form `D:\…`. The POSIX-only `resolveImpl` below only
331
+ * treats `/` as a separator, reads `D` as non-`/`, decides realPath
332
+ * is "relative", and produces a garbage joined path. Downstream
333
+ * `fs.openSync(garbage)` then returns `EINVAL` and the WASI caller
334
+ * sees a permanent failure. This function gives us the correct
335
+ * Windows-style resolution without taking a Node-only `path` import
336
+ * (which would break browser bundles of this package).
337
+ *
338
+ * Cribbed from Node's `lib/path.js` `win32.resolve()` (MIT-licensed),
339
+ * trimmed to what WASI realpath resolution actually exercises.
340
+ */
341
+ function resolveWin32(args) {
342
+ let resolvedDevice = '';
343
+ let resolvedTail = '';
344
+ let resolvedAbsolute = false;
345
+ for (let i = args.length - 1; i >= -1; i--) {
346
+ let path;
347
+ if (i >= 0) {
348
+ path = args[i];
349
+ validateString(path, 'path');
350
+ if (path.length === 0)
351
+ continue;
352
+ }
353
+ else if (resolvedDevice.length === 0) {
354
+ path = (typeof process !== 'undefined' && typeof process.cwd === 'function')
355
+ ? process.cwd()
356
+ : '';
357
+ }
358
+ else {
359
+ // Look up per-drive cwd via the `=X:` env var convention; fall back
360
+ // to the global cwd if absent.
361
+ const envKey = `=${resolvedDevice}`;
362
+ const env = (typeof process !== 'undefined') ? process.env : undefined;
363
+ path = (env && typeof env[envKey] === 'string')
364
+ ? env[envKey]
365
+ : (typeof process !== 'undefined' && typeof process.cwd === 'function')
366
+ ? process.cwd()
367
+ : '';
368
+ if (path === undefined ||
369
+ (path.slice(0, 2).toLowerCase() !== resolvedDevice.toLowerCase() &&
370
+ path.charCodeAt(2) === CHAR_BACKWARD_SLASH)) {
371
+ path = `${resolvedDevice}\\`;
372
+ }
373
+ }
374
+ const len = path.length;
375
+ let rootEnd = 0;
376
+ let device = '';
377
+ let isAbsolute = false;
378
+ const code = path.charCodeAt(0);
379
+ if (len === 1) {
380
+ if (isPathSeparatorWin(code)) {
381
+ rootEnd = 1;
382
+ isAbsolute = true;
383
+ }
384
+ }
385
+ else if (isPathSeparatorWin(code)) {
386
+ isAbsolute = true;
387
+ if (isPathSeparatorWin(path.charCodeAt(1))) {
388
+ // UNC path: `\\server\share\…`
389
+ let j = 2;
390
+ let last = j;
391
+ while (j < len && !isPathSeparatorWin(path.charCodeAt(j)))
392
+ j++;
393
+ if (j < len && j !== last) {
394
+ const firstPart = path.slice(last, j);
395
+ last = j;
396
+ while (j < len && isPathSeparatorWin(path.charCodeAt(j)))
397
+ j++;
398
+ if (j < len && j !== last) {
399
+ last = j;
400
+ while (j < len && !isPathSeparatorWin(path.charCodeAt(j)))
401
+ j++;
402
+ if (j === len || j !== last) {
403
+ device = `\\\\${firstPart}\\${path.slice(last, j)}`;
404
+ rootEnd = j;
405
+ }
406
+ }
407
+ }
408
+ }
409
+ else {
410
+ rootEnd = 1;
411
+ }
412
+ }
413
+ else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
414
+ device = path.slice(0, 2);
415
+ rootEnd = 2;
416
+ if (len > 2 && isPathSeparatorWin(path.charCodeAt(2))) {
417
+ isAbsolute = true;
418
+ rootEnd = 3;
419
+ }
420
+ }
421
+ if (device.length > 0) {
422
+ if (resolvedDevice.length > 0) {
423
+ if (device.toLowerCase() !== resolvedDevice.toLowerCase())
424
+ continue;
425
+ }
426
+ else {
427
+ resolvedDevice = device;
428
+ }
429
+ }
430
+ if (resolvedAbsolute) {
431
+ if (resolvedDevice.length > 0)
432
+ break;
433
+ }
434
+ else {
435
+ resolvedTail = `${path.slice(rootEnd)}\\${resolvedTail}`;
436
+ resolvedAbsolute = isAbsolute;
437
+ if (isAbsolute && resolvedDevice.length > 0)
438
+ break;
439
+ }
440
+ }
441
+ resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, '\\', isPathSeparatorWin);
442
+ return resolvedDevice + (resolvedAbsolute ? '\\' : '') + resolvedTail || '.';
443
+ }
309
444
  function isPosixPathSeparator(code) {
310
445
  return code === CHAR_FORWARD_SLASH;
311
446
  }
@@ -381,6 +516,13 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
381
516
  return res;
382
517
  }
383
518
  function resolve(...args) {
519
+ // On Windows, host paths are `D:\…` style. The POSIX-only resolver
520
+ // below treats `D` as a non-`/` character and produces garbage; route
521
+ // to the Windows-aware variant. POSIX hosts (Linux/macOS/browser)
522
+ // run the original code path unchanged — `_isWin32` is constant-folded
523
+ // away on those targets.
524
+ if (_isWin32)
525
+ return resolveWin32(args);
384
526
  let resolvedPath = '';
385
527
  let resolvedAbsolute = false;
386
528
  for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
@@ -1017,6 +1159,26 @@ function wrapExports(exports, needWrap) {
1017
1159
  });
1018
1160
  }
1019
1161
 
1162
+ // Linux fcntl flag bits ↔ Windows libuv flag bits. `pathOpen()` builds
1163
+ // `flagsRes` using Linux constants (O_CREAT=0x40, O_EXCL=0x80,
1164
+ // O_APPEND=0x400). Windows libuv expects different bits (O_CREAT=0x100,
1165
+ // O_EXCL=0x400, O_APPEND=0x8). Without translation,
1166
+ // `fs.openSync(path, 0x241 /* L:WRONLY|CREAT|TRUNC */)` is rejected
1167
+ // with EINVAL because Linux's 0x40 happens to mean O_TEMPORARY on
1168
+ // Windows — and O_TEMPORARY without O_CREAT is invalid.
1169
+ const _isWin32Flags = typeof process !== 'undefined' && process.platform === 'win32';
1170
+ function _toWinOpenFlags(f) {
1171
+ let r = f & 3; // RDONLY/WRONLY/RDWR — same on both
1172
+ if ((f & 0x40) !== 0)
1173
+ r |= 0x100; // O_CREAT: Linux 0x40 -> Windows 0x100
1174
+ if ((f & 0x80) !== 0)
1175
+ r |= 0x400; // O_EXCL: Linux 0x80 -> Windows 0x400
1176
+ if ((f & 0x200) !== 0)
1177
+ r |= 0x200; // O_TRUNC: same value on both
1178
+ if ((f & 0x400) !== 0)
1179
+ r |= 0x8; // O_APPEND: Linux 0x400 -> Windows 0x8
1180
+ return r;
1181
+ }
1020
1182
  function copyMemory(targets, src) {
1021
1183
  if (targets.length === 0 || src.length === 0)
1022
1184
  return 0;
@@ -1075,26 +1237,43 @@ function defineName(name, f) {
1075
1237
  Object.defineProperty(f, 'name', { value: name });
1076
1238
  return f;
1077
1239
  }
1240
+ function tryCall(f, wasi, args) {
1241
+ let r;
1242
+ try {
1243
+ r = f.apply(wasi, args);
1244
+ }
1245
+ catch (err) {
1246
+ return handleError(err);
1247
+ }
1248
+ if (isPromiseLike(r)) {
1249
+ return r.then(_ => _, handleError);
1250
+ }
1251
+ return r;
1252
+ }
1078
1253
  function syscallWrap(self, name, f) {
1079
- return defineName(name, function () {
1080
- {
1254
+ let debug = false;
1255
+ const NODE_DEBUG_NATIVE = (() => {
1256
+ try {
1257
+ return "wasi";
1258
+ }
1259
+ catch (_) {
1260
+ return undefined;
1261
+ }
1262
+ })();
1263
+ if (typeof NODE_DEBUG_NATIVE === 'string' && NODE_DEBUG_NATIVE.split(',').includes('wasi')) {
1264
+ debug = true;
1265
+ }
1266
+ return debug
1267
+ ? defineName(name, function () {
1081
1268
  const args = Array.prototype.slice.call(arguments);
1082
1269
  let debugArgs = [`${name}(${Array.from({ length: arguments.length }).map(() => '%d').join(', ')})`];
1083
1270
  debugArgs = debugArgs.concat(args);
1084
1271
  console.debug.apply(console, debugArgs);
1085
- }
1086
- let r;
1087
- try {
1088
- r = f.apply(self, arguments);
1089
- }
1090
- catch (err) {
1091
- return handleError(err);
1092
- }
1093
- if (isPromiseLike(r)) {
1094
- return r.then(_ => _, handleError);
1095
- }
1096
- return r;
1097
- });
1272
+ return tryCall(f, self, args);
1273
+ })
1274
+ : defineName(name, function () {
1275
+ return tryCall(f, self, arguments);
1276
+ });
1098
1277
  }
1099
1278
  function resolvePathSync(fs, fileDescriptor, path, flags) {
1100
1279
  let resolvedPath = resolve(fileDescriptor.realPath, path);
@@ -1240,7 +1419,7 @@ class WASI$1 {
1240
1419
  case 1 /* WasiClockid.MONOTONIC */:
1241
1420
  case 2 /* WasiClockid.PROCESS_CPUTIME_ID */:
1242
1421
  case 3 /* WasiClockid.THREAD_CPUTIME_ID */: {
1243
- const t = performance.now();
1422
+ const t = performance.now() / 1000;
1244
1423
  const s = Math.trunc(t);
1245
1424
  const ms = Math.floor((t - s) * 1000);
1246
1425
  const result = BigInt(s) * BigInt(1000000000) + BigInt(ms) * BigInt(1000000);
@@ -2256,9 +2435,11 @@ class WASI$1 {
2256
2435
  const pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
2257
2436
  const fs = getFs(this);
2258
2437
  const resolved_path = resolvePathSync(fs, fileDescriptor, pathString, dirflags);
2259
- const r = fs.openSync(resolved_path, flagsRes, 0o666);
2438
+ const r = fs.openSync(resolved_path, _isWin32Flags ? _toWinOpenFlags(flagsRes) : flagsRes, 0o666);
2260
2439
  const filetype = wasi.fds.getFileTypeByFd(r);
2261
- if ((o_flags & 2 /* WasiFileControlFlag.O_DIRECTORY */) !== 0 && filetype !== 3 /* WasiFileType.DIRECTORY */) {
2440
+ if ((filetype !== 3 /* WasiFileType.DIRECTORY */) &&
2441
+ ((o_flags & 2 /* WasiFileControlFlag.O_DIRECTORY */) !== 0 ||
2442
+ (resolved_path.endsWith('/')))) {
2262
2443
  return 54 /* WasiErrno.ENOTDIR */;
2263
2444
  }
2264
2445
  const { base: max_base, inheriting: max_inheriting } = getRights(wasi.fds.stdio, r, flagsRes, filetype);
@@ -2290,7 +2471,7 @@ class WASI$1 {
2290
2471
  const pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
2291
2472
  const fs = getFs(this);
2292
2473
  const resolved_path = await resolvePathAsync(fs, fileDescriptor, pathString, dirflags);
2293
- const r = await fs.promises.open(resolved_path, flagsRes, 0o666);
2474
+ const r = await fs.promises.open(resolved_path, _isWin32Flags ? _toWinOpenFlags(flagsRes) : flagsRes, 0o666);
2294
2475
  const filetype = await wasi.fds.getFileTypeByFd(r);
2295
2476
  if ((o_flags & 2 /* WasiFileControlFlag.O_DIRECTORY */) !== 0 && filetype !== 3 /* WasiFileType.DIRECTORY */) {
2296
2477
  return 54 /* WasiErrno.ENOTDIR */;
@@ -2447,6 +2628,9 @@ class WASI$1 {
2447
2628
  const wasi = _wasi.get(this);
2448
2629
  const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_SYMLINK, BigInt(0));
2449
2630
  const oldPath = decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len));
2631
+ if (oldPath.length > 0 && oldPath[0] === '/') {
2632
+ return 63 /* WasiErrno.EPERM */;
2633
+ }
2450
2634
  let newPath = decoder.decode(unsharedSlice(HEAPU8, new_path, new_path + new_path_len));
2451
2635
  newPath = resolve(fileDescriptor.realPath, newPath);
2452
2636
  const fs = getFs(this);
@@ -2555,12 +2739,6 @@ const kSetMemory = Symbol('kSetMemory');
2555
2739
  const kStarted = Symbol('kStarted');
2556
2740
  const kInstance = Symbol('kInstance');
2557
2741
  const kBindingName = Symbol('kBindingName');
2558
- function setupInstance(self, instance) {
2559
- validateObject(instance, 'instance');
2560
- validateObject(instance.exports, 'instance.exports');
2561
- self[kInstance] = instance;
2562
- self[kSetMemory](instance.exports.memory);
2563
- }
2564
2742
  function validateOptions(options) {
2565
2743
  var _a;
2566
2744
  validateObject(options, 'options');
@@ -2665,13 +2843,21 @@ class WASI {
2665
2843
  wrap.proc_exit = wasiReturnOnProcExit.bind(this);
2666
2844
  }
2667
2845
  }
2668
- // Must not export _initialize, must export _start
2669
- start(instance) {
2846
+ finalizeBindings(instance, _a) {
2847
+ var _b;
2848
+ var { memory = (_b = instance === null || instance === void 0 ? void 0 : instance.exports) === null || _b === void 0 ? void 0 : _b.memory } = _a === void 0 ? {} : _a;
2670
2849
  if (this[kStarted]) {
2671
2850
  throw new Error('WASI instance has already started');
2672
2851
  }
2852
+ validateObject(instance, 'instance');
2853
+ validateObject(instance.exports, 'instance.exports');
2854
+ this[kSetMemory](memory);
2855
+ this[kInstance] = instance;
2673
2856
  this[kStarted] = true;
2674
- setupInstance(this, instance);
2857
+ }
2858
+ // Must not export _initialize, must export _start
2859
+ start(instance) {
2860
+ this.finalizeBindings(instance);
2675
2861
  const { _start, _initialize } = this[kInstance].exports;
2676
2862
  validateFunction(_start, 'instance.exports._start');
2677
2863
  validateUndefined(_initialize, 'instance.exports._initialize');
@@ -2696,11 +2882,7 @@ class WASI {
2696
2882
  }
2697
2883
  // Must not export _start, may optionally export _initialize
2698
2884
  initialize(instance) {
2699
- if (this[kStarted]) {
2700
- throw new Error('WASI instance has already started');
2701
- }
2702
- this[kStarted] = true;
2703
- setupInstance(this, instance);
2885
+ this.finalizeBindings(instance);
2704
2886
  const { _start, _initialize } = this[kInstance].exports;
2705
2887
  validateUndefined(_start, 'instance.exports._start');
2706
2888
  if (_initialize !== undefined) {