@tailwindcss/oxide-wasm32-wasi 0.0.0-insiders.d801d8d

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 (113) hide show
  1. package/README.md +3 -0
  2. package/node_modules/@emnapi/core/LICENSE +21 -0
  3. package/node_modules/@emnapi/core/README.md +1 -0
  4. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.js +6661 -0
  5. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.d.ts +363 -0
  6. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.js +1 -0
  7. package/node_modules/@emnapi/core/dist/emnapi-core.d.mts +363 -0
  8. package/node_modules/@emnapi/core/dist/emnapi-core.d.ts +365 -0
  9. package/node_modules/@emnapi/core/dist/emnapi-core.esm-bundler.js +7411 -0
  10. package/node_modules/@emnapi/core/dist/emnapi-core.js +8390 -0
  11. package/node_modules/@emnapi/core/dist/emnapi-core.min.d.mts +363 -0
  12. package/node_modules/@emnapi/core/dist/emnapi-core.min.js +1 -0
  13. package/node_modules/@emnapi/core/dist/emnapi-core.min.mjs +1 -0
  14. package/node_modules/@emnapi/core/dist/emnapi-core.mjs +6650 -0
  15. package/node_modules/@emnapi/core/index.js +5 -0
  16. package/node_modules/@emnapi/core/package.json +49 -0
  17. package/node_modules/@emnapi/runtime/LICENSE +21 -0
  18. package/node_modules/@emnapi/runtime/README.md +1 -0
  19. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.js +1347 -0
  20. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.d.ts +663 -0
  21. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.js +1 -0
  22. package/node_modules/@emnapi/runtime/dist/emnapi.d.mts +663 -0
  23. package/node_modules/@emnapi/runtime/dist/emnapi.d.ts +665 -0
  24. package/node_modules/@emnapi/runtime/dist/emnapi.esm-bundler.js +1403 -0
  25. package/node_modules/@emnapi/runtime/dist/emnapi.iife.d.ts +420 -0
  26. package/node_modules/@emnapi/runtime/dist/emnapi.iife.js +1474 -0
  27. package/node_modules/@emnapi/runtime/dist/emnapi.js +1475 -0
  28. package/node_modules/@emnapi/runtime/dist/emnapi.min.d.mts +663 -0
  29. package/node_modules/@emnapi/runtime/dist/emnapi.min.js +1 -0
  30. package/node_modules/@emnapi/runtime/dist/emnapi.min.mjs +1 -0
  31. package/node_modules/@emnapi/runtime/dist/emnapi.mjs +1316 -0
  32. package/node_modules/@emnapi/runtime/index.js +5 -0
  33. package/node_modules/@emnapi/runtime/package.json +48 -0
  34. package/node_modules/@emnapi/wasi-threads/LICENSE +21 -0
  35. package/node_modules/@emnapi/wasi-threads/README.md +203 -0
  36. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.js +881 -0
  37. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.d.ts +214 -0
  38. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.js +1 -0
  39. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.mts +214 -0
  40. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +216 -0
  41. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.esm-bundler.js +929 -0
  42. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +941 -0
  43. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.d.mts +214 -0
  44. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.js +1 -0
  45. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.mjs +1 -0
  46. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.mjs +876 -0
  47. package/node_modules/@emnapi/wasi-threads/index.js +5 -0
  48. package/node_modules/@emnapi/wasi-threads/package.json +50 -0
  49. package/node_modules/@napi-rs/wasm-runtime/LICENSE +43 -0
  50. package/node_modules/@napi-rs/wasm-runtime/dist/fs.js +23712 -0
  51. package/node_modules/@napi-rs/wasm-runtime/dist/runtime.js +12269 -0
  52. package/node_modules/@napi-rs/wasm-runtime/fs-proxy.cjs +193 -0
  53. package/node_modules/@napi-rs/wasm-runtime/package.json +60 -0
  54. package/node_modules/@napi-rs/wasm-runtime/runtime.cjs +15 -0
  55. package/node_modules/@tybys/wasm-util/README.md +193 -0
  56. package/node_modules/@tybys/wasm-util/dist/tsdoc-metadata.json +11 -0
  57. package/node_modules/@tybys/wasm-util/dist/wasm-util.d.ts +417 -0
  58. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js +2738 -0
  59. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +2738 -0
  60. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm.min.js +1 -0
  61. package/node_modules/@tybys/wasm-util/dist/wasm-util.js +2760 -0
  62. package/node_modules/@tybys/wasm-util/dist/wasm-util.min.js +1 -0
  63. package/node_modules/@tybys/wasm-util/lib/cjs/asyncify.js +158 -0
  64. package/node_modules/@tybys/wasm-util/lib/cjs/index.js +13 -0
  65. package/node_modules/@tybys/wasm-util/lib/cjs/jspi.js +46 -0
  66. package/node_modules/@tybys/wasm-util/lib/cjs/load.js +97 -0
  67. package/node_modules/@tybys/wasm-util/lib/cjs/memory.js +35 -0
  68. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/error.js +103 -0
  69. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/fd.js +268 -0
  70. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/fs.js +3 -0
  71. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/index.js +194 -0
  72. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/path.js +174 -0
  73. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +1544 -0
  74. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/rights.js +141 -0
  75. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/types.js +220 -0
  76. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/util.js +128 -0
  77. package/node_modules/@tybys/wasm-util/lib/cjs/webassembly.js +13 -0
  78. package/node_modules/@tybys/wasm-util/lib/mjs/asyncify.mjs +153 -0
  79. package/node_modules/@tybys/wasm-util/lib/mjs/index.mjs +9 -0
  80. package/node_modules/@tybys/wasm-util/lib/mjs/jspi.mjs +39 -0
  81. package/node_modules/@tybys/wasm-util/lib/mjs/load.mjs +89 -0
  82. package/node_modules/@tybys/wasm-util/lib/mjs/memory.mjs +28 -0
  83. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/error.mjs +97 -0
  84. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/fd.mjs +256 -0
  85. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/fs.mjs +1 -0
  86. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/index.mjs +188 -0
  87. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/path.mjs +168 -0
  88. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +1539 -0
  89. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/rights.mjs +135 -0
  90. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/types.mjs +216 -0
  91. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/util.mjs +113 -0
  92. package/node_modules/@tybys/wasm-util/lib/mjs/webassembly.mjs +9 -0
  93. package/node_modules/@tybys/wasm-util/package.json +58 -0
  94. package/node_modules/tslib/CopyrightNotice.txt +15 -0
  95. package/node_modules/tslib/LICENSE.txt +12 -0
  96. package/node_modules/tslib/README.md +164 -0
  97. package/node_modules/tslib/SECURITY.md +41 -0
  98. package/node_modules/tslib/modules/index.d.ts +38 -0
  99. package/node_modules/tslib/modules/index.js +70 -0
  100. package/node_modules/tslib/modules/package.json +3 -0
  101. package/node_modules/tslib/package.json +47 -0
  102. package/node_modules/tslib/tslib.d.ts +460 -0
  103. package/node_modules/tslib/tslib.es6.html +1 -0
  104. package/node_modules/tslib/tslib.es6.js +393 -0
  105. package/node_modules/tslib/tslib.es6.mjs +392 -0
  106. package/node_modules/tslib/tslib.html +1 -0
  107. package/node_modules/tslib/tslib.js +475 -0
  108. package/package.json +45 -0
  109. package/tailwindcss-oxide.wasi-browser.js +63 -0
  110. package/tailwindcss-oxide.wasi.cjs +88 -0
  111. package/tailwindcss-oxide.wasm32-wasi.wasm +0 -0
  112. package/wasi-worker-browser.mjs +39 -0
  113. package/wasi-worker.mjs +63 -0
@@ -0,0 +1,268 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AsyncTable = exports.SyncTable = exports.FileDescriptorTable = exports.toFileStat = exports.toFileType = exports.StandardOutput = exports.FileDescriptor = exports.concatBuffer = void 0;
4
+ const types_1 = require("./types");
5
+ const rights_1 = require("./rights");
6
+ const error_1 = require("./error");
7
+ function concatBuffer(buffers, size) {
8
+ let total = 0;
9
+ if (typeof size === 'number' && size >= 0) {
10
+ total = size;
11
+ }
12
+ else {
13
+ for (let i = 0; i < buffers.length; i++) {
14
+ const buffer = buffers[i];
15
+ total += buffer.length;
16
+ }
17
+ }
18
+ let pos = 0;
19
+ const ret = new Uint8Array(total);
20
+ for (let i = 0; i < buffers.length; i++) {
21
+ const buffer = buffers[i];
22
+ ret.set(buffer, pos);
23
+ pos += buffer.length;
24
+ }
25
+ return ret;
26
+ }
27
+ exports.concatBuffer = concatBuffer;
28
+ class FileDescriptor {
29
+ constructor(id, fd, path, realPath, type, rightsBase, rightsInheriting, preopen) {
30
+ this.id = id;
31
+ this.fd = fd;
32
+ this.path = path;
33
+ this.realPath = realPath;
34
+ this.type = type;
35
+ this.rightsBase = rightsBase;
36
+ this.rightsInheriting = rightsInheriting;
37
+ this.preopen = preopen;
38
+ this.pos = BigInt(0);
39
+ this.size = BigInt(0);
40
+ }
41
+ seek(offset, whence) {
42
+ if (whence === types_1.WasiWhence.SET) {
43
+ this.pos = BigInt(offset);
44
+ }
45
+ else if (whence === types_1.WasiWhence.CUR) {
46
+ this.pos += BigInt(offset);
47
+ }
48
+ else if (whence === types_1.WasiWhence.END) {
49
+ this.pos = BigInt(this.size) - BigInt(offset);
50
+ }
51
+ else {
52
+ throw new error_1.WasiError('Unknown whence', types_1.WasiErrno.EIO);
53
+ }
54
+ return this.pos;
55
+ }
56
+ }
57
+ exports.FileDescriptor = FileDescriptor;
58
+ class StandardOutput extends FileDescriptor {
59
+ constructor(log, id, fd, path, realPath, type, rightsBase, rightsInheriting, preopen) {
60
+ super(id, fd, path, realPath, type, rightsBase, rightsInheriting, preopen);
61
+ this._log = log;
62
+ this._buf = null;
63
+ }
64
+ write(buffer) {
65
+ const originalBuffer = buffer;
66
+ if (this._buf) {
67
+ buffer = concatBuffer([this._buf, buffer]);
68
+ this._buf = null;
69
+ }
70
+ if (buffer.indexOf(10) === -1) {
71
+ this._buf = buffer;
72
+ return originalBuffer.byteLength;
73
+ }
74
+ let written = 0;
75
+ let lastBegin = 0;
76
+ let index;
77
+ while ((index = buffer.indexOf(10, written)) !== -1) {
78
+ const str = new TextDecoder().decode(buffer.subarray(lastBegin, index));
79
+ this._log(str);
80
+ written += index - lastBegin + 1;
81
+ lastBegin = index + 1;
82
+ }
83
+ if (written < buffer.length) {
84
+ this._buf = buffer.slice(written);
85
+ }
86
+ return originalBuffer.byteLength;
87
+ }
88
+ }
89
+ exports.StandardOutput = StandardOutput;
90
+ function toFileType(stat) {
91
+ if (stat.isBlockDevice())
92
+ return types_1.WasiFileType.BLOCK_DEVICE;
93
+ if (stat.isCharacterDevice())
94
+ return types_1.WasiFileType.CHARACTER_DEVICE;
95
+ if (stat.isDirectory())
96
+ return types_1.WasiFileType.DIRECTORY;
97
+ if (stat.isSocket())
98
+ return types_1.WasiFileType.SOCKET_STREAM;
99
+ if (stat.isFile())
100
+ return types_1.WasiFileType.REGULAR_FILE;
101
+ if (stat.isSymbolicLink())
102
+ return types_1.WasiFileType.SYMBOLIC_LINK;
103
+ return types_1.WasiFileType.UNKNOWN;
104
+ }
105
+ exports.toFileType = toFileType;
106
+ function toFileStat(view, buf, stat) {
107
+ view.setBigUint64(buf, stat.dev, true);
108
+ view.setBigUint64(buf + 8, stat.ino, true);
109
+ view.setBigUint64(buf + 16, BigInt(toFileType(stat)), true);
110
+ view.setBigUint64(buf + 24, stat.nlink, true);
111
+ view.setBigUint64(buf + 32, stat.size, true);
112
+ view.setBigUint64(buf + 40, stat.atimeMs * BigInt(1000000), true);
113
+ view.setBigUint64(buf + 48, stat.mtimeMs * BigInt(1000000), true);
114
+ view.setBigUint64(buf + 56, stat.ctimeMs * BigInt(1000000), true);
115
+ }
116
+ exports.toFileStat = toFileStat;
117
+ class FileDescriptorTable {
118
+ constructor(options) {
119
+ this.used = 0;
120
+ this.size = options.size;
121
+ this.fds = Array(options.size);
122
+ this.stdio = [options.in, options.out, options.err];
123
+ this.print = options.print;
124
+ this.printErr = options.printErr;
125
+ this.insertStdio(options.in, 0, '<stdin>');
126
+ this.insertStdio(options.out, 1, '<stdout>');
127
+ this.insertStdio(options.err, 2, '<stderr>');
128
+ }
129
+ insertStdio(fd, expected, name) {
130
+ const type = types_1.WasiFileType.CHARACTER_DEVICE;
131
+ const { base, inheriting } = (0, rights_1.getRights)(this.stdio, fd, types_1.FileControlFlag.O_RDWR, type);
132
+ const wrap = this.insert(fd, name, name, type, base, inheriting, 0);
133
+ if (wrap.id !== expected) {
134
+ throw new error_1.WasiError(`id: ${wrap.id} !== expected: ${expected}`, types_1.WasiErrno.EBADF);
135
+ }
136
+ return wrap;
137
+ }
138
+ insert(fd, mappedPath, realPath, type, rightsBase, rightsInheriting, preopen) {
139
+ var _a, _b;
140
+ let index = -1;
141
+ if (this.used >= this.size) {
142
+ const newSize = this.size * 2;
143
+ this.fds.length = newSize;
144
+ index = this.size;
145
+ this.size = newSize;
146
+ }
147
+ else {
148
+ for (let i = 0; i < this.size; ++i) {
149
+ if (this.fds[i] == null) {
150
+ index = i;
151
+ break;
152
+ }
153
+ }
154
+ }
155
+ let entry;
156
+ if (mappedPath === '<stdout>') {
157
+ entry = new StandardOutput((_a = this.print) !== null && _a !== void 0 ? _a : console.log, index, fd, mappedPath, realPath, type, rightsBase, rightsInheriting, preopen);
158
+ }
159
+ else if (mappedPath === '<stderr>') {
160
+ entry = new StandardOutput((_b = this.printErr) !== null && _b !== void 0 ? _b : console.error, index, fd, mappedPath, realPath, type, rightsBase, rightsInheriting, preopen);
161
+ }
162
+ else {
163
+ entry = new FileDescriptor(index, fd, mappedPath, realPath, type, rightsBase, rightsInheriting, preopen);
164
+ }
165
+ this.fds[index] = entry;
166
+ this.used++;
167
+ return entry;
168
+ }
169
+ get(id, base, inheriting) {
170
+ if (id >= this.size) {
171
+ throw new error_1.WasiError('Invalid fd', types_1.WasiErrno.EBADF);
172
+ }
173
+ const entry = this.fds[id];
174
+ if (!entry || entry.id !== id) {
175
+ throw new error_1.WasiError('Bad file descriptor', types_1.WasiErrno.EBADF);
176
+ }
177
+ /* Validate that the fd has the necessary rights. */
178
+ if ((~entry.rightsBase & base) !== BigInt(0) || (~entry.rightsInheriting & inheriting) !== BigInt(0)) {
179
+ throw new error_1.WasiError('Capabilities insufficient', types_1.WasiErrno.ENOTCAPABLE);
180
+ }
181
+ return entry;
182
+ }
183
+ remove(id) {
184
+ if (id >= this.size) {
185
+ throw new error_1.WasiError('Invalid fd', types_1.WasiErrno.EBADF);
186
+ }
187
+ const entry = this.fds[id];
188
+ if (!entry || entry.id !== id) {
189
+ throw new error_1.WasiError('Bad file descriptor', types_1.WasiErrno.EBADF);
190
+ }
191
+ this.fds[id] = undefined;
192
+ this.used--;
193
+ }
194
+ }
195
+ exports.FileDescriptorTable = FileDescriptorTable;
196
+ class SyncTable extends FileDescriptorTable {
197
+ constructor(options) {
198
+ super(options);
199
+ this.fs = options.fs;
200
+ }
201
+ getFileTypeByFd(fd) {
202
+ const stats = this.fs.fstatSync(fd, { bigint: true });
203
+ return toFileType(stats);
204
+ }
205
+ insertPreopen(fd, mappedPath, realPath) {
206
+ const type = this.getFileTypeByFd(fd);
207
+ if (type !== types_1.WasiFileType.DIRECTORY) {
208
+ throw new error_1.WasiError(`Preopen not dir: ["${mappedPath}", "${realPath}"]`, types_1.WasiErrno.ENOTDIR);
209
+ }
210
+ const result = (0, rights_1.getRights)(this.stdio, fd, 0, type);
211
+ return this.insert(fd, mappedPath, realPath, type, result.base, result.inheriting, 1);
212
+ }
213
+ renumber(dst, src) {
214
+ if (dst === src)
215
+ return;
216
+ if (dst >= this.size || src >= this.size) {
217
+ throw new error_1.WasiError('Invalid fd', types_1.WasiErrno.EBADF);
218
+ }
219
+ const dstEntry = this.fds[dst];
220
+ const srcEntry = this.fds[src];
221
+ if (!dstEntry || !srcEntry || dstEntry.id !== dst || srcEntry.id !== src) {
222
+ throw new error_1.WasiError('Invalid fd', types_1.WasiErrno.EBADF);
223
+ }
224
+ this.fs.closeSync(dstEntry.fd);
225
+ this.fds[dst] = this.fds[src];
226
+ this.fds[dst].id = dst;
227
+ this.fds[src] = undefined;
228
+ this.used--;
229
+ }
230
+ }
231
+ exports.SyncTable = SyncTable;
232
+ class AsyncTable extends FileDescriptorTable {
233
+ // eslint-disable-next-line @typescript-eslint/no-useless-constructor
234
+ constructor(options) {
235
+ super(options);
236
+ }
237
+ async getFileTypeByFd(fd) {
238
+ const stats = await fd.stat({ bigint: true });
239
+ return toFileType(stats);
240
+ }
241
+ async insertPreopen(fd, mappedPath, realPath) {
242
+ const type = await this.getFileTypeByFd(fd);
243
+ if (type !== types_1.WasiFileType.DIRECTORY) {
244
+ throw new error_1.WasiError(`Preopen not dir: ["${mappedPath}", "${realPath}"]`, types_1.WasiErrno.ENOTDIR);
245
+ }
246
+ const result = (0, rights_1.getRights)(this.stdio, fd.fd, 0, type);
247
+ return this.insert(fd, mappedPath, realPath, type, result.base, result.inheriting, 1);
248
+ }
249
+ async renumber(dst, src) {
250
+ if (dst === src)
251
+ return;
252
+ if (dst >= this.size || src >= this.size) {
253
+ throw new error_1.WasiError('Invalid fd', types_1.WasiErrno.EBADF);
254
+ }
255
+ const dstEntry = this.fds[dst];
256
+ const srcEntry = this.fds[src];
257
+ if (!dstEntry || !srcEntry || dstEntry.id !== dst || srcEntry.id !== src) {
258
+ throw new error_1.WasiError('Invalid fd', types_1.WasiErrno.EBADF);
259
+ }
260
+ await dstEntry.fd.close();
261
+ this.fds[dst] = this.fds[src];
262
+ this.fds[dst].id = dst;
263
+ this.fds[src] = undefined;
264
+ this.used--;
265
+ }
266
+ }
267
+ exports.AsyncTable = AsyncTable;
268
+ //# sourceMappingURL=fd.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=fs.js.map
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAsyncWASI = exports.WASI = void 0;
4
+ const preview1_1 = require("./preview1");
5
+ const util_1 = require("./util");
6
+ // eslint-disable-next-line spaced-comment
7
+ const kEmptyObject = /*#__PURE__*/ Object.freeze(/*#__PURE__*/ Object.create(null));
8
+ const kExitCode = Symbol('kExitCode');
9
+ const kSetMemory = Symbol('kSetMemory');
10
+ const kStarted = Symbol('kStarted');
11
+ const kInstance = Symbol('kInstance');
12
+ const kBindingName = Symbol('kBindingName');
13
+ function setupInstance(self, instance) {
14
+ (0, util_1.validateObject)(instance, 'instance');
15
+ (0, util_1.validateObject)(instance.exports, 'instance.exports');
16
+ self[kInstance] = instance;
17
+ self[kSetMemory](instance.exports.memory);
18
+ }
19
+ function validateOptions(options) {
20
+ var _a;
21
+ (0, util_1.validateObject)(options, 'options');
22
+ let _WASI;
23
+ if (options.version !== undefined) {
24
+ (0, util_1.validateString)(options.version, 'options.version');
25
+ switch (options.version) {
26
+ case 'unstable':
27
+ _WASI = preview1_1.WASI;
28
+ this[kBindingName] = 'wasi_unstable';
29
+ break;
30
+ case 'preview1':
31
+ _WASI = preview1_1.WASI;
32
+ this[kBindingName] = 'wasi_snapshot_preview1';
33
+ break;
34
+ default:
35
+ throw new TypeError(`unsupported WASI version "${options.version}"`);
36
+ }
37
+ }
38
+ else {
39
+ _WASI = preview1_1.WASI;
40
+ this[kBindingName] = 'wasi_snapshot_preview1';
41
+ }
42
+ if (options.args !== undefined) {
43
+ (0, util_1.validateArray)(options.args, 'options.args');
44
+ }
45
+ const args = ((_a = options.args) !== null && _a !== void 0 ? _a : []).map(String);
46
+ const env = [];
47
+ if (options.env !== undefined) {
48
+ (0, util_1.validateObject)(options.env, 'options.env');
49
+ Object.entries(options.env).forEach(({ 0: key, 1: value }) => {
50
+ if (value !== undefined) {
51
+ env.push(`${key}=${value}`);
52
+ }
53
+ });
54
+ }
55
+ const preopens = [];
56
+ if (options.preopens !== undefined) {
57
+ (0, util_1.validateObject)(options.preopens, 'options.preopens');
58
+ Object.entries(options.preopens).forEach(({ 0: key, 1: value }) => preopens.push({ mappedPath: String(key), realPath: String(value) }));
59
+ }
60
+ if (preopens.length > 0) {
61
+ if (options.fs === undefined) {
62
+ throw new Error('filesystem is disabled, can not preopen directory');
63
+ }
64
+ try {
65
+ (0, util_1.validateObject)(options.fs, 'options.fs');
66
+ }
67
+ catch (_) {
68
+ throw new TypeError('Node.js fs like implementation is not provided');
69
+ }
70
+ }
71
+ // if (options.filesystem !== undefined) {
72
+ // validateObject(options.filesystem, 'options.filesystem')
73
+ // validateString(options.filesystem.type, 'options.filesystem.type')
74
+ // if (options.filesystem.type !== 'memfs' && options.filesystem.type !== 'file-system-access-api') {
75
+ // throw new Error(`Filesystem type ${(options.filesystem as any).type as string} is not supported, only "memfs" and "file-system-access-api" is supported currently`)
76
+ // }
77
+ // try {
78
+ // validateObject(options.filesystem.fs, 'options.filesystem.fs')
79
+ // } catch (_) {
80
+ // throw new Error('Node.js fs like implementation is not provided')
81
+ // }
82
+ // }
83
+ if (options.print !== undefined)
84
+ (0, util_1.validateFunction)(options.print, 'options.print');
85
+ if (options.printErr !== undefined)
86
+ (0, util_1.validateFunction)(options.printErr, 'options.printErr');
87
+ if (options.returnOnExit !== undefined) {
88
+ (0, util_1.validateBoolean)(options.returnOnExit, 'options.returnOnExit');
89
+ }
90
+ // const { stdin = 0, stdout = 1, stderr = 2 } = options
91
+ // validateInt32(stdin, 'options.stdin', 0)
92
+ // validateInt32(stdout, 'options.stdout', 0)
93
+ // validateInt32(stderr, 'options.stderr', 0)
94
+ // const stdio = [stdin, stdout, stderr] as const
95
+ const stdio = [0, 1, 2];
96
+ return {
97
+ args,
98
+ env,
99
+ preopens,
100
+ stdio,
101
+ _WASI
102
+ };
103
+ }
104
+ function initWASI(setMemory, wrap) {
105
+ this[kSetMemory] = setMemory;
106
+ this.wasiImport = wrap;
107
+ this[kStarted] = false;
108
+ this[kExitCode] = 0;
109
+ this[kInstance] = undefined;
110
+ }
111
+ /** @public */
112
+ class WASI {
113
+ constructor(options = kEmptyObject) {
114
+ const { args, env, preopens, stdio, _WASI } = validateOptions.call(this, options);
115
+ const wrap = _WASI.createSync(args, env, preopens, stdio, options.fs, options.print, options.printErr);
116
+ const setMemory = wrap._setMemory;
117
+ delete wrap._setMemory;
118
+ initWASI.call(this, setMemory, wrap);
119
+ if (options.returnOnExit) {
120
+ wrap.proc_exit = wasiReturnOnProcExit.bind(this);
121
+ }
122
+ }
123
+ // Must not export _initialize, must export _start
124
+ start(instance) {
125
+ if (this[kStarted]) {
126
+ throw new Error('WASI instance has already started');
127
+ }
128
+ this[kStarted] = true;
129
+ setupInstance(this, instance);
130
+ const { _start, _initialize } = this[kInstance].exports;
131
+ (0, util_1.validateFunction)(_start, 'instance.exports._start');
132
+ (0, util_1.validateUndefined)(_initialize, 'instance.exports._initialize');
133
+ let ret;
134
+ try {
135
+ ret = _start();
136
+ }
137
+ catch (err) {
138
+ if (err !== kExitCode) {
139
+ throw err;
140
+ }
141
+ }
142
+ if (ret instanceof Promise) {
143
+ return ret.then(() => this[kExitCode], (err) => {
144
+ if (err !== kExitCode) {
145
+ throw err;
146
+ }
147
+ return this[kExitCode];
148
+ });
149
+ }
150
+ return this[kExitCode];
151
+ }
152
+ // Must not export _start, may optionally export _initialize
153
+ initialize(instance) {
154
+ if (this[kStarted]) {
155
+ throw new Error('WASI instance has already started');
156
+ }
157
+ this[kStarted] = true;
158
+ setupInstance(this, instance);
159
+ const { _start, _initialize } = this[kInstance].exports;
160
+ (0, util_1.validateUndefined)(_start, 'instance.exports._start');
161
+ if (_initialize !== undefined) {
162
+ (0, util_1.validateFunction)(_initialize, 'instance.exports._initialize');
163
+ return _initialize();
164
+ }
165
+ }
166
+ getImportObject() {
167
+ return { [this[kBindingName]]: this.wasiImport };
168
+ }
169
+ }
170
+ exports.WASI = WASI;
171
+ function wasiReturnOnProcExit(rval) {
172
+ this[kExitCode] = rval;
173
+ // eslint-disable-next-line @typescript-eslint/no-throw-literal
174
+ throw kExitCode;
175
+ }
176
+ /** @public */
177
+ async function createAsyncWASI(options = kEmptyObject) {
178
+ const _this = Object.create(WASI.prototype);
179
+ const { args, env, preopens, stdio, _WASI } = validateOptions.call(_this, options);
180
+ if (options.asyncify !== undefined) {
181
+ (0, util_1.validateObject)(options.asyncify, 'options.asyncify');
182
+ (0, util_1.validateFunction)(options.asyncify.wrapImportFunction, 'options.asyncify.wrapImportFunction');
183
+ }
184
+ const wrap = await _WASI.createAsync(args, env, preopens, stdio, options.fs, options.print, options.printErr, options.asyncify);
185
+ const setMemory = wrap._setMemory;
186
+ delete wrap._setMemory;
187
+ initWASI.call(_this, setMemory, wrap);
188
+ if (options.returnOnExit) {
189
+ wrap.proc_exit = wasiReturnOnProcExit.bind(_this);
190
+ }
191
+ return _this;
192
+ }
193
+ exports.createAsyncWASI = createAsyncWASI;
194
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.relative = exports.resolve = void 0;
4
+ const util_1 = require("./util");
5
+ const CHAR_DOT = 46; /* . */
6
+ const CHAR_FORWARD_SLASH = 47; /* / */
7
+ function isPosixPathSeparator(code) {
8
+ return code === CHAR_FORWARD_SLASH;
9
+ }
10
+ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
11
+ let res = '';
12
+ let lastSegmentLength = 0;
13
+ let lastSlash = -1;
14
+ let dots = 0;
15
+ let code = 0;
16
+ for (let i = 0; i <= path.length; ++i) {
17
+ if (i < path.length) {
18
+ code = path.charCodeAt(i);
19
+ }
20
+ else if (isPathSeparator(code)) {
21
+ break;
22
+ }
23
+ else {
24
+ code = CHAR_FORWARD_SLASH;
25
+ }
26
+ if (isPathSeparator(code)) {
27
+ if (lastSlash === i - 1 || dots === 1) {
28
+ // NOOP
29
+ }
30
+ else if (dots === 2) {
31
+ if (res.length < 2 || lastSegmentLength !== 2 ||
32
+ res.charCodeAt(res.length - 1) !== CHAR_DOT ||
33
+ res.charCodeAt(res.length - 2) !== CHAR_DOT) {
34
+ if (res.length > 2) {
35
+ const lastSlashIndex = res.indexOf(separator);
36
+ if (lastSlashIndex === -1) {
37
+ res = '';
38
+ lastSegmentLength = 0;
39
+ }
40
+ else {
41
+ res = res.slice(0, lastSlashIndex);
42
+ lastSegmentLength =
43
+ res.length - 1 - res.indexOf(separator);
44
+ }
45
+ lastSlash = i;
46
+ dots = 0;
47
+ continue;
48
+ }
49
+ else if (res.length !== 0) {
50
+ res = '';
51
+ lastSegmentLength = 0;
52
+ lastSlash = i;
53
+ dots = 0;
54
+ continue;
55
+ }
56
+ }
57
+ if (allowAboveRoot) {
58
+ res += res.length > 0 ? `${separator}..` : '..';
59
+ lastSegmentLength = 2;
60
+ }
61
+ }
62
+ else {
63
+ if (res.length > 0) {
64
+ res += `${separator}${path.slice(lastSlash + 1, i)}`;
65
+ }
66
+ else {
67
+ res = path.slice(lastSlash + 1, i);
68
+ }
69
+ lastSegmentLength = i - lastSlash - 1;
70
+ }
71
+ lastSlash = i;
72
+ dots = 0;
73
+ }
74
+ else if (code === CHAR_DOT && dots !== -1) {
75
+ ++dots;
76
+ }
77
+ else {
78
+ dots = -1;
79
+ }
80
+ }
81
+ return res;
82
+ }
83
+ function resolve(...args) {
84
+ let resolvedPath = '';
85
+ let resolvedAbsolute = false;
86
+ for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
87
+ const path = i >= 0 ? args[i] : '/';
88
+ (0, util_1.validateString)(path, 'path');
89
+ // Skip empty entries
90
+ if (path.length === 0) {
91
+ continue;
92
+ }
93
+ resolvedPath = `${path}/${resolvedPath}`;
94
+ resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
95
+ }
96
+ // At this point the path should be resolved to a full absolute path, but
97
+ // handle relative paths to be safe (might happen when process.cwd() fails)
98
+ // Normalize the path
99
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/', isPosixPathSeparator);
100
+ if (resolvedAbsolute) {
101
+ return `/${resolvedPath}`;
102
+ }
103
+ return resolvedPath.length > 0 ? resolvedPath : '.';
104
+ }
105
+ exports.resolve = resolve;
106
+ function relative(from, to) {
107
+ (0, util_1.validateString)(from, 'from');
108
+ (0, util_1.validateString)(to, 'to');
109
+ if (from === to)
110
+ return '';
111
+ // Trim leading forward slashes.
112
+ from = resolve(from);
113
+ to = resolve(to);
114
+ if (from === to)
115
+ return '';
116
+ const fromStart = 1;
117
+ const fromEnd = from.length;
118
+ const fromLen = fromEnd - fromStart;
119
+ const toStart = 1;
120
+ const toLen = to.length - toStart;
121
+ // Compare paths to find the longest common path from root
122
+ const length = (fromLen < toLen ? fromLen : toLen);
123
+ let lastCommonSep = -1;
124
+ let i = 0;
125
+ for (; i < length; i++) {
126
+ const fromCode = from.charCodeAt(fromStart + i);
127
+ if (fromCode !== to.charCodeAt(toStart + i)) {
128
+ break;
129
+ }
130
+ else if (fromCode === CHAR_FORWARD_SLASH) {
131
+ lastCommonSep = i;
132
+ }
133
+ }
134
+ if (i === length) {
135
+ if (toLen > length) {
136
+ if (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) {
137
+ // We get here if `from` is the exact base path for `to`.
138
+ // For example: from='/foo/bar'; to='/foo/bar/baz'
139
+ return to.slice(toStart + i + 1);
140
+ }
141
+ if (i === 0) {
142
+ // We get here if `from` is the root
143
+ // For example: from='/'; to='/foo'
144
+ return to.slice(toStart + i);
145
+ }
146
+ }
147
+ else if (fromLen > length) {
148
+ if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {
149
+ // We get here if `to` is the exact base path for `from`.
150
+ // For example: from='/foo/bar/baz'; to='/foo/bar'
151
+ lastCommonSep = i;
152
+ }
153
+ else if (i === 0) {
154
+ // We get here if `to` is the root.
155
+ // For example: from='/foo/bar'; to='/'
156
+ lastCommonSep = 0;
157
+ }
158
+ }
159
+ }
160
+ let out = '';
161
+ // Generate the relative path based on the path difference between `to`
162
+ // and `from`.
163
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
164
+ if (i === fromEnd ||
165
+ from.charCodeAt(i) === CHAR_FORWARD_SLASH) {
166
+ out += out.length === 0 ? '..' : '/..';
167
+ }
168
+ }
169
+ // Lastly, append the rest of the destination (`to`) path that comes after
170
+ // the common path parts.
171
+ return `${out}${to.slice(toStart + lastCommonSep)}`;
172
+ }
173
+ exports.relative = relative;
174
+ //# sourceMappingURL=path.js.map