@netlify/edge-bundler 2.6.0 → 2.7.0

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 (49) hide show
  1. package/deno/lib/common.ts +3 -6
  2. package/deno/vendor/deno.land/std@0.127.0/_util/assert.ts +15 -0
  3. package/deno/vendor/deno.land/std@0.127.0/_util/os.ts +22 -0
  4. package/deno/vendor/deno.land/std@0.127.0/path/_constants.ts +49 -0
  5. package/deno/vendor/deno.land/std@0.127.0/path/_interface.ts +30 -0
  6. package/deno/vendor/deno.land/std@0.127.0/path/_util.ts +133 -0
  7. package/deno/vendor/deno.land/std@0.127.0/path/common.ts +40 -0
  8. package/deno/vendor/deno.land/std@0.127.0/path/glob.ts +413 -0
  9. package/deno/vendor/deno.land/std@0.127.0/path/mod.ts +35 -0
  10. package/deno/vendor/deno.land/std@0.127.0/path/posix.ts +516 -0
  11. package/deno/vendor/deno.land/std@0.127.0/path/separator.ts +7 -0
  12. package/deno/vendor/deno.land/std@0.127.0/path/win32.ts +1008 -0
  13. package/deno/vendor/deno.land/std@0.98.0/async/deferred.ts +26 -0
  14. package/deno/vendor/deno.land/std@0.98.0/async/delay.ts +9 -0
  15. package/deno/vendor/deno.land/std@0.98.0/async/mod.ts +6 -0
  16. package/deno/vendor/deno.land/std@0.98.0/async/mux_async_iterator.ts +69 -0
  17. package/deno/vendor/deno.land/std@0.98.0/async/pool.ts +68 -0
  18. package/deno/vendor/deno.land/std@0.98.0/async/tee.ts +102 -0
  19. package/deno/vendor/deno.land/x/eszip@v0.28.0/eszip_wasm.generated.js +573 -0
  20. package/deno/vendor/deno.land/x/eszip@v0.28.0/eszip_wasm_bg.wasm +0 -0
  21. package/deno/vendor/deno.land/x/eszip@v0.28.0/loader.ts +67 -0
  22. package/deno/vendor/deno.land/x/eszip@v0.28.0/mod.ts +33 -0
  23. package/deno/vendor/deno.land/x/retry@v2.0.0/deps.ts +5 -0
  24. package/deno/vendor/deno.land/x/retry@v2.0.0/misc.ts +25 -0
  25. package/deno/vendor/deno.land/x/retry@v2.0.0/mod.ts +50 -0
  26. package/deno/vendor/deno.land/x/retry@v2.0.0/retry/decorator.ts +31 -0
  27. package/deno/vendor/deno.land/x/retry@v2.0.0/retry/options.ts +36 -0
  28. package/deno/vendor/deno.land/x/retry@v2.0.0/retry/retry.ts +63 -0
  29. package/deno/vendor/deno.land/x/retry@v2.0.0/retry/tooManyTries.ts +11 -0
  30. package/deno/vendor/deno.land/x/retry@v2.0.0/retry/utils/options.ts +5 -0
  31. package/deno/vendor/deno.land/x/retry@v2.0.0/retry/utils/tools.ts +15 -0
  32. package/deno/vendor/deno.land/x/retry@v2.0.0/retry/utils/untilDefined/decorators.ts +35 -0
  33. package/deno/vendor/deno.land/x/retry@v2.0.0/retry/utils/untilDefined/retry.ts +23 -0
  34. package/deno/vendor/deno.land/x/retry@v2.0.0/retry/utils/untilResponse/decorators.ts +18 -0
  35. package/deno/vendor/deno.land/x/retry@v2.0.0/retry/utils/untilResponse/retry.ts +8 -0
  36. package/deno/vendor/deno.land/x/retry@v2.0.0/retry/utils/untilTruthy/decorators.ts +31 -0
  37. package/deno/vendor/deno.land/x/retry@v2.0.0/retry/utils/untilTruthy/retry.ts +29 -0
  38. package/deno/vendor/deno.land/x/retry@v2.0.0/wait/decorators.ts +36 -0
  39. package/deno/vendor/deno.land/x/retry@v2.0.0/wait/options.ts +10 -0
  40. package/deno/vendor/deno.land/x/retry@v2.0.0/wait/timeoutError.ts +9 -0
  41. package/deno/vendor/deno.land/x/retry@v2.0.0/wait/wait.ts +46 -0
  42. package/deno/vendor/import_map.json +5 -0
  43. package/dist/node/bundler.js +1 -0
  44. package/dist/node/bundler.test.js +41 -6
  45. package/dist/node/feature_flags.d.ts +1 -1
  46. package/dist/node/feature_flags.js +1 -0
  47. package/dist/node/formats/eszip.d.ts +3 -1
  48. package/dist/node/formats/eszip.js +13 -6
  49. package/package.json +1 -1
@@ -0,0 +1,573 @@
1
+ // @generated file from wasmbuild -- do not edit
2
+ // deno-lint-ignore-file
3
+ // deno-fmt-ignore-file
4
+ // source-hash: 0e24dd809865bd2b3c39b005f133376180af8ad2
5
+ let wasm;
6
+
7
+ const heap = new Array(32).fill(undefined);
8
+
9
+ heap.push(undefined, null, true, false);
10
+
11
+ function getObject(idx) {
12
+ return heap[idx];
13
+ }
14
+
15
+ let WASM_VECTOR_LEN = 0;
16
+
17
+ let cachedUint8Memory0;
18
+ function getUint8Memory0() {
19
+ if (cachedUint8Memory0.byteLength === 0) {
20
+ cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
21
+ }
22
+ return cachedUint8Memory0;
23
+ }
24
+
25
+ const cachedTextEncoder = new TextEncoder("utf-8");
26
+
27
+ const encodeString = function (arg, view) {
28
+ return cachedTextEncoder.encodeInto(arg, view);
29
+ };
30
+
31
+ function passStringToWasm0(arg, malloc, realloc) {
32
+ if (realloc === undefined) {
33
+ const buf = cachedTextEncoder.encode(arg);
34
+ const ptr = malloc(buf.length);
35
+ getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
36
+ WASM_VECTOR_LEN = buf.length;
37
+ return ptr;
38
+ }
39
+
40
+ let len = arg.length;
41
+ let ptr = malloc(len);
42
+
43
+ const mem = getUint8Memory0();
44
+
45
+ let offset = 0;
46
+
47
+ for (; offset < len; offset++) {
48
+ const code = arg.charCodeAt(offset);
49
+ if (code > 0x7F) break;
50
+ mem[ptr + offset] = code;
51
+ }
52
+
53
+ if (offset !== len) {
54
+ if (offset !== 0) {
55
+ arg = arg.slice(offset);
56
+ }
57
+ ptr = realloc(ptr, len, len = offset + arg.length * 3);
58
+ const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
59
+ const ret = encodeString(arg, view);
60
+
61
+ offset += ret.written;
62
+ }
63
+
64
+ WASM_VECTOR_LEN = offset;
65
+ return ptr;
66
+ }
67
+
68
+ function isLikeNone(x) {
69
+ return x === undefined || x === null;
70
+ }
71
+
72
+ let cachedInt32Memory0;
73
+ function getInt32Memory0() {
74
+ if (cachedInt32Memory0.byteLength === 0) {
75
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
76
+ }
77
+ return cachedInt32Memory0;
78
+ }
79
+
80
+ let heap_next = heap.length;
81
+
82
+ function dropObject(idx) {
83
+ if (idx < 36) return;
84
+ heap[idx] = heap_next;
85
+ heap_next = idx;
86
+ }
87
+
88
+ function takeObject(idx) {
89
+ const ret = getObject(idx);
90
+ dropObject(idx);
91
+ return ret;
92
+ }
93
+
94
+ const cachedTextDecoder = new TextDecoder("utf-8", {
95
+ ignoreBOM: true,
96
+ fatal: true,
97
+ });
98
+
99
+ cachedTextDecoder.decode();
100
+
101
+ function getStringFromWasm0(ptr, len) {
102
+ return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
103
+ }
104
+
105
+ function addHeapObject(obj) {
106
+ if (heap_next === heap.length) heap.push(heap.length + 1);
107
+ const idx = heap_next;
108
+ heap_next = heap[idx];
109
+
110
+ heap[idx] = obj;
111
+ return idx;
112
+ }
113
+
114
+ const CLOSURE_DTORS = new FinalizationRegistry((state) => {
115
+ wasm.__wbindgen_export_2.get(state.dtor)(state.a, state.b);
116
+ });
117
+
118
+ function makeMutClosure(arg0, arg1, dtor, f) {
119
+ const state = { a: arg0, b: arg1, cnt: 1, dtor };
120
+ const real = (...args) => {
121
+ // First up with a closure we increment the internal reference
122
+ // count. This ensures that the Rust closure environment won't
123
+ // be deallocated while we're invoking it.
124
+ state.cnt++;
125
+ const a = state.a;
126
+ state.a = 0;
127
+ try {
128
+ return f(a, state.b, ...args);
129
+ } finally {
130
+ if (--state.cnt === 0) {
131
+ wasm.__wbindgen_export_2.get(state.dtor)(a, state.b);
132
+ CLOSURE_DTORS.unregister(state);
133
+ } else {
134
+ state.a = a;
135
+ }
136
+ }
137
+ };
138
+ real.original = state;
139
+ CLOSURE_DTORS.register(real, state, state);
140
+ return real;
141
+ }
142
+ function __wbg_adapter_18(arg0, arg1, arg2) {
143
+ wasm
144
+ ._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hd4f05ebc54a3a357(
145
+ arg0,
146
+ arg1,
147
+ addHeapObject(arg2),
148
+ );
149
+ }
150
+
151
+ function passArray8ToWasm0(arg, malloc) {
152
+ const ptr = malloc(arg.length * 1);
153
+ getUint8Memory0().set(arg, ptr / 1);
154
+ WASM_VECTOR_LEN = arg.length;
155
+ return ptr;
156
+ }
157
+ /**
158
+ * Serialize a module graph into eszip.
159
+ * @param {any} roots
160
+ * @param {Function} loader
161
+ * @param {any} import_map_url
162
+ * @returns {Promise<Uint8Array>}
163
+ */
164
+ export function build(roots, loader, import_map_url) {
165
+ const ret = wasm.build(
166
+ addHeapObject(roots),
167
+ addHeapObject(loader),
168
+ addHeapObject(import_map_url),
169
+ );
170
+ return takeObject(ret);
171
+ }
172
+
173
+ function handleError(f, args) {
174
+ try {
175
+ return f.apply(this, args);
176
+ } catch (e) {
177
+ wasm.__wbindgen_exn_store(addHeapObject(e));
178
+ }
179
+ }
180
+ function __wbg_adapter_50(arg0, arg1, arg2, arg3) {
181
+ wasm.wasm_bindgen__convert__closures__invoke2_mut__hccb8632b1071bfde(
182
+ arg0,
183
+ arg1,
184
+ addHeapObject(arg2),
185
+ addHeapObject(arg3),
186
+ );
187
+ }
188
+
189
+ const ParserFinalization = new FinalizationRegistry((ptr) =>
190
+ wasm.__wbg_parser_free(ptr)
191
+ );
192
+ /** */
193
+ export class Parser {
194
+ static __wrap(ptr) {
195
+ const obj = Object.create(Parser.prototype);
196
+ obj.ptr = ptr;
197
+ ParserFinalization.register(obj, obj.ptr, obj);
198
+ return obj;
199
+ }
200
+
201
+ __destroy_into_raw() {
202
+ const ptr = this.ptr;
203
+ this.ptr = 0;
204
+ ParserFinalization.unregister(this);
205
+ return ptr;
206
+ }
207
+
208
+ free() {
209
+ const ptr = this.__destroy_into_raw();
210
+ wasm.__wbg_parser_free(ptr);
211
+ }
212
+ /** */
213
+ constructor() {
214
+ const ret = wasm.parser_new();
215
+ return Parser.__wrap(ret);
216
+ }
217
+ /**
218
+ * Parse from a BYOB readable stream.
219
+ * @param {ReadableStreamBYOBReader} stream
220
+ * @returns {Promise<any>}
221
+ */
222
+ parse(stream) {
223
+ const ret = wasm.parser_parse(this.ptr, addHeapObject(stream));
224
+ return takeObject(ret);
225
+ }
226
+ /**
227
+ * Parse from an in-memory buffer.
228
+ * @param {Uint8Array} buffer
229
+ * @returns {Promise<any>}
230
+ */
231
+ parseBytes(buffer) {
232
+ const ptr0 = passArray8ToWasm0(buffer, wasm.__wbindgen_malloc);
233
+ const len0 = WASM_VECTOR_LEN;
234
+ const ret = wasm.parser_parseBytes(this.ptr, ptr0, len0);
235
+ return takeObject(ret);
236
+ }
237
+ /**
238
+ * Load module sources.
239
+ * @returns {Promise<any>}
240
+ */
241
+ load() {
242
+ const ret = wasm.parser_load(this.ptr);
243
+ return takeObject(ret);
244
+ }
245
+ /**
246
+ * Get a module source.
247
+ * @param {string} specifier
248
+ * @returns {Promise<any>}
249
+ */
250
+ getModuleSource(specifier) {
251
+ const ptr0 = passStringToWasm0(
252
+ specifier,
253
+ wasm.__wbindgen_malloc,
254
+ wasm.__wbindgen_realloc,
255
+ );
256
+ const len0 = WASM_VECTOR_LEN;
257
+ const ret = wasm.parser_getModuleSource(this.ptr, ptr0, len0);
258
+ return takeObject(ret);
259
+ }
260
+ /**
261
+ * Get a module sourcemap.
262
+ * @param {string} specifier
263
+ * @returns {Promise<any>}
264
+ */
265
+ getModuleSourceMap(specifier) {
266
+ const ptr0 = passStringToWasm0(
267
+ specifier,
268
+ wasm.__wbindgen_malloc,
269
+ wasm.__wbindgen_realloc,
270
+ );
271
+ const len0 = WASM_VECTOR_LEN;
272
+ const ret = wasm.parser_getModuleSourceMap(this.ptr, ptr0, len0);
273
+ return takeObject(ret);
274
+ }
275
+ }
276
+
277
+ const imports = {
278
+ __wbindgen_placeholder__: {
279
+ __wbindgen_string_get: function (arg0, arg1) {
280
+ const obj = getObject(arg1);
281
+ const ret = typeof (obj) === "string" ? obj : undefined;
282
+ var ptr0 = isLikeNone(ret)
283
+ ? 0
284
+ : passStringToWasm0(
285
+ ret,
286
+ wasm.__wbindgen_malloc,
287
+ wasm.__wbindgen_realloc,
288
+ );
289
+ var len0 = WASM_VECTOR_LEN;
290
+ getInt32Memory0()[arg0 / 4 + 1] = len0;
291
+ getInt32Memory0()[arg0 / 4 + 0] = ptr0;
292
+ },
293
+ __wbindgen_object_drop_ref: function (arg0) {
294
+ takeObject(arg0);
295
+ },
296
+ __wbindgen_string_new: function (arg0, arg1) {
297
+ const ret = getStringFromWasm0(arg0, arg1);
298
+ return addHeapObject(ret);
299
+ },
300
+ __wbindgen_json_serialize: function (arg0, arg1) {
301
+ const obj = getObject(arg1);
302
+ const ret = JSON.stringify(obj === undefined ? null : obj);
303
+ const ptr0 = passStringToWasm0(
304
+ ret,
305
+ wasm.__wbindgen_malloc,
306
+ wasm.__wbindgen_realloc,
307
+ );
308
+ const len0 = WASM_VECTOR_LEN;
309
+ getInt32Memory0()[arg0 / 4 + 1] = len0;
310
+ getInt32Memory0()[arg0 / 4 + 0] = ptr0;
311
+ },
312
+ __wbg_new_651776e932b7e9c7: function (arg0, arg1) {
313
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
314
+ return addHeapObject(ret);
315
+ },
316
+ __wbindgen_memory: function () {
317
+ const ret = wasm.memory;
318
+ return addHeapObject(ret);
319
+ },
320
+ __wbg_buffer_de1150f91b23aa89: function (arg0) {
321
+ const ret = getObject(arg0).buffer;
322
+ return addHeapObject(ret);
323
+ },
324
+ __wbg_newwithbyteoffsetandlength_9ca61320599a2c84: function (
325
+ arg0,
326
+ arg1,
327
+ arg2,
328
+ ) {
329
+ const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
330
+ return addHeapObject(ret);
331
+ },
332
+ __wbg_new_97cf52648830a70d: function (arg0) {
333
+ const ret = new Uint8Array(getObject(arg0));
334
+ return addHeapObject(ret);
335
+ },
336
+ __wbg_new_2ab697f1555e0dbc: function () {
337
+ const ret = new Array();
338
+ return addHeapObject(ret);
339
+ },
340
+ __wbg_push_811c8b08bf4ff9d5: function (arg0, arg1) {
341
+ const ret = getObject(arg0).push(getObject(arg1));
342
+ return ret;
343
+ },
344
+ __wbg_resolve_f269ce174f88b294: function (arg0) {
345
+ const ret = Promise.resolve(getObject(arg0));
346
+ return addHeapObject(ret);
347
+ },
348
+ __wbg_newwithlength_e833b89f9db02732: function (arg0) {
349
+ const ret = new Uint8Array(arg0 >>> 0);
350
+ return addHeapObject(ret);
351
+ },
352
+ __wbg_read_33fc0c1143d99231: function (arg0, arg1) {
353
+ const ret = getObject(arg0).read(getObject(arg1));
354
+ return addHeapObject(ret);
355
+ },
356
+ __wbg_done_9d9636ea8e221033: function (arg0) {
357
+ const ret = getObject(arg0).done;
358
+ return ret;
359
+ },
360
+ __wbindgen_is_object: function (arg0) {
361
+ const val = getObject(arg0);
362
+ const ret = typeof (val) === "object" && val !== null;
363
+ return ret;
364
+ },
365
+ __wbg_toString_81e19471abb6dc98: function (arg0) {
366
+ const ret = getObject(arg0).toString();
367
+ return addHeapObject(ret);
368
+ },
369
+ __wbg_value_57cc9a30b585d121: function (arg0) {
370
+ const ret = getObject(arg0).value;
371
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
372
+ },
373
+ __wbg_byteLength_cf73ca7a0d44cb85: function (arg0) {
374
+ const ret = getObject(arg0).byteLength;
375
+ return ret;
376
+ },
377
+ __wbg_length_e09c0b925ab8de5d: function (arg0) {
378
+ const ret = getObject(arg0).length;
379
+ return ret;
380
+ },
381
+ __wbg_set_a0172b213e2469e9: function (arg0, arg1, arg2) {
382
+ getObject(arg0).set(getObject(arg1), arg2 >>> 0);
383
+ },
384
+ __wbg_call_8e1338b908441bd2: function () {
385
+ return handleError(function (arg0, arg1, arg2, arg3) {
386
+ const ret = getObject(arg0).call(
387
+ getObject(arg1),
388
+ getObject(arg2),
389
+ getObject(arg3),
390
+ );
391
+ return addHeapObject(ret);
392
+ }, arguments);
393
+ },
394
+ __wbg_new_78403b138428b684: function (arg0, arg1) {
395
+ try {
396
+ var state0 = { a: arg0, b: arg1 };
397
+ var cb0 = (arg0, arg1) => {
398
+ const a = state0.a;
399
+ state0.a = 0;
400
+ try {
401
+ return __wbg_adapter_50(a, state0.b, arg0, arg1);
402
+ } finally {
403
+ state0.a = a;
404
+ }
405
+ };
406
+ const ret = new Promise(cb0);
407
+ return addHeapObject(ret);
408
+ } finally {
409
+ state0.a = state0.b = 0;
410
+ }
411
+ },
412
+ __wbg_new_693216e109162396: function () {
413
+ const ret = new Error();
414
+ return addHeapObject(ret);
415
+ },
416
+ __wbg_stack_0ddaca5d1abfb52f: function (arg0, arg1) {
417
+ const ret = getObject(arg1).stack;
418
+ const ptr0 = passStringToWasm0(
419
+ ret,
420
+ wasm.__wbindgen_malloc,
421
+ wasm.__wbindgen_realloc,
422
+ );
423
+ const len0 = WASM_VECTOR_LEN;
424
+ getInt32Memory0()[arg0 / 4 + 1] = len0;
425
+ getInt32Memory0()[arg0 / 4 + 0] = ptr0;
426
+ },
427
+ __wbg_error_09919627ac0992f5: function (arg0, arg1) {
428
+ try {
429
+ console.error(getStringFromWasm0(arg0, arg1));
430
+ } finally {
431
+ wasm.__wbindgen_free(arg0, arg1);
432
+ }
433
+ },
434
+ __wbg_call_9855a4612eb496cb: function () {
435
+ return handleError(function (arg0, arg1, arg2) {
436
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
437
+ return addHeapObject(ret);
438
+ }, arguments);
439
+ },
440
+ __wbindgen_throw: function (arg0, arg1) {
441
+ throw new Error(getStringFromWasm0(arg0, arg1));
442
+ },
443
+ __wbindgen_cb_drop: function (arg0) {
444
+ const obj = takeObject(arg0).original;
445
+ if (obj.cnt-- == 1) {
446
+ obj.a = 0;
447
+ return true;
448
+ }
449
+ const ret = false;
450
+ return ret;
451
+ },
452
+ __wbg_then_1c698eedca15eed6: function (arg0, arg1) {
453
+ const ret = getObject(arg0).then(getObject(arg1));
454
+ return addHeapObject(ret);
455
+ },
456
+ __wbg_then_4debc41d4fc92ce5: function (arg0, arg1, arg2) {
457
+ const ret = getObject(arg0).then(getObject(arg1), getObject(arg2));
458
+ return addHeapObject(ret);
459
+ },
460
+ __wbindgen_closure_wrapper9485: function (arg0, arg1, arg2) {
461
+ const ret = makeMutClosure(arg0, arg1, 143, __wbg_adapter_18);
462
+ return addHeapObject(ret);
463
+ },
464
+ },
465
+ };
466
+
467
+ const wasm_url = new URL("eszip_wasm_bg.wasm", import.meta.url);
468
+
469
+ /**
470
+ * Decompression callback
471
+ *
472
+ * @callback decompressCallback
473
+ * @param {Uint8Array} compressed
474
+ * @return {Uint8Array} decompressed
475
+ */
476
+
477
+ /** Instantiates an instance of the Wasm module returning its functions.
478
+ * @remarks It is safe to call this multiple times and once successfully
479
+ * loaded it will always return a reference to the same object.
480
+ * @param {decompressCallback=} transform
481
+ */
482
+ export async function instantiate(transform) {
483
+ return (await instantiateWithInstance(transform)).exports;
484
+ }
485
+
486
+ let instanceWithExports;
487
+ let lastLoadPromise;
488
+
489
+ /** Instantiates an instance of the Wasm module along with its exports.
490
+ * @remarks It is safe to call this multiple times and once successfully
491
+ * loaded it will always return a reference to the same object.
492
+ * @param {decompressCallback=} transform
493
+ * @returns {Promise<{
494
+ * instance: WebAssembly.Instance;
495
+ * exports: { build: typeof build; Parser : typeof Parser }
496
+ * }>}
497
+ */
498
+ export function instantiateWithInstance(transform) {
499
+ if (instanceWithExports != null) {
500
+ return Promise.resolve(instanceWithExports);
501
+ }
502
+ if (lastLoadPromise == null) {
503
+ lastLoadPromise = (async () => {
504
+ try {
505
+ const instance = (await instantiateModule(transform)).instance;
506
+ wasm = instance.exports;
507
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
508
+ cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
509
+ instanceWithExports = {
510
+ instance,
511
+ exports: getWasmInstanceExports(),
512
+ };
513
+ return instanceWithExports;
514
+ } finally {
515
+ lastLoadPromise = null;
516
+ }
517
+ })();
518
+ }
519
+ return lastLoadPromise;
520
+ }
521
+
522
+ function getWasmInstanceExports() {
523
+ return { build, Parser };
524
+ }
525
+
526
+ /** Gets if the Wasm module has been instantiated. */
527
+ export function isInstantiated() {
528
+ return instanceWithExports != null;
529
+ }
530
+
531
+ async function instantiateModule(transform) {
532
+ switch (wasm_url.protocol) {
533
+ case "file:": {
534
+ if (typeof Deno !== "object") {
535
+ throw new Error("file urls are not supported in this environment");
536
+ }
537
+
538
+ if ("permissions" in Deno) {
539
+ Deno.permissions.request({ name: "read", path: wasm_url });
540
+ }
541
+ const wasmCode = await Deno.readFile(wasm_url);
542
+ return WebAssembly.instantiate(
543
+ !transform ? wasmCode : transform(wasmCode),
544
+ imports,
545
+ );
546
+ }
547
+ case "https:":
548
+ case "http:": {
549
+ if (typeof Deno === "object" && "permissions" in Deno) {
550
+ Deno.permissions.request({ name: "net", host: wasm_url.host });
551
+ }
552
+ const wasmResponse = await fetch(wasm_url);
553
+ if (transform) {
554
+ const wasmCode = new Uint8Array(await wasmResponse.arrayBuffer());
555
+ return WebAssembly.instantiate(transform(wasmCode), imports);
556
+ }
557
+ if (
558
+ wasmResponse.headers.get("content-type")?.toLowerCase().startsWith(
559
+ "application/wasm",
560
+ )
561
+ ) {
562
+ return WebAssembly.instantiateStreaming(wasmResponse, imports);
563
+ } else {
564
+ return WebAssembly.instantiate(
565
+ await wasmResponse.arrayBuffer(),
566
+ imports,
567
+ );
568
+ }
569
+ }
570
+ default:
571
+ throw new Error(`Unsupported protocol: ${wasm_url.protocol}`);
572
+ }
573
+ }
@@ -0,0 +1,67 @@
1
+ // Adapted from deno_graph
2
+ // https://github.com/denoland/deno_graph/blob/main/lib/loader.ts
3
+
4
+ export interface LoadResponseModule {
5
+ /** A module with code has been loaded. */
6
+ kind: "module";
7
+ /** The string URL of the resource. If there were redirects, the final
8
+ * specifier should be set here, otherwise the requested specifier. */
9
+ specifier: string;
10
+ /** For remote resources, a record of headers should be set, where the key's
11
+ * have been normalized to be lower case values. */
12
+ headers?: Record<string, string>;
13
+ /** The string value of the loaded resources. */
14
+ content: string;
15
+ }
16
+
17
+ export interface LoadResponseExternalBuiltIn {
18
+ /** The loaded module is either _external_ or _built-in_ to the runtime. */
19
+ kind: "external" | "builtIn";
20
+ /** The strung URL of the resource. If there were redirects, the final
21
+ * specifier should be set here, otherwise the requested specifier. */
22
+ specifier: string;
23
+ }
24
+
25
+ export type LoadResponse = LoadResponseModule | LoadResponseExternalBuiltIn;
26
+
27
+ export async function load(
28
+ specifier: string,
29
+ ): Promise<LoadResponse | undefined> {
30
+ const url = new URL(specifier);
31
+ try {
32
+ switch (url.protocol) {
33
+ case "file:": {
34
+ const content = await Deno.readTextFile(url);
35
+ return {
36
+ kind: "module",
37
+ specifier,
38
+ content,
39
+ };
40
+ }
41
+ case "http:":
42
+ case "https:": {
43
+ const response = await fetch(String(url), { redirect: "follow" });
44
+ if (response.status !== 200) {
45
+ // ensure the body is read as to not leak resources
46
+ await response.arrayBuffer();
47
+ return undefined;
48
+ }
49
+ const content = await response.text();
50
+ const headers: Record<string, string> = {};
51
+ for (const [key, value] of response.headers) {
52
+ headers[key.toLowerCase()] = value;
53
+ }
54
+ return {
55
+ kind: "module",
56
+ specifier: response.url,
57
+ headers,
58
+ content,
59
+ };
60
+ }
61
+ default:
62
+ return undefined;
63
+ }
64
+ } catch {
65
+ return undefined;
66
+ }
67
+ }
@@ -0,0 +1,33 @@
1
+ import { load, LoadResponse } from "./loader.ts";
2
+ import {
3
+ instantiate,
4
+ Parser as InternalParser,
5
+ } from "./eszip_wasm.generated.js";
6
+
7
+ export type { LoadResponse } from "./loader.ts";
8
+
9
+ export class Parser extends InternalParser {
10
+ private constructor() {
11
+ super();
12
+ }
13
+
14
+ static async createInstance() {
15
+ // insure instantiate is called
16
+ await instantiate();
17
+ return new Parser();
18
+ }
19
+ }
20
+
21
+ export async function build(
22
+ roots: string[],
23
+ loader: (url: string) => Promise<LoadResponse | undefined> = load,
24
+ importMapUrl?: string,
25
+ ): Promise<Uint8Array> {
26
+ const { build } = await instantiate();
27
+ return build(
28
+ roots,
29
+ (specifier: string) =>
30
+ loader(specifier).catch((err) => Promise.reject(String(err))),
31
+ importMapUrl,
32
+ );
33
+ }
@@ -0,0 +1,5 @@
1
+ // Copyright since 2020, FranckLdx. All rights reserved. MIT license.
2
+ export {
3
+ deferred,
4
+ delay as denoDelay,
5
+ } from "https://deno.land/std@0.98.0/async/mod.ts";
@@ -0,0 +1,25 @@
1
+ // Copyright since 2020, FranckLdx. All rights reserved. MIT license.
2
+ import { deferred } from "./deps.ts";
3
+
4
+ export const asyncDecorator = <T>(fn: () => T) => {
5
+ return (): Promise<T> => {
6
+ const promise = deferred<T>();
7
+ try {
8
+ const result = fn();
9
+ promise.resolve(result);
10
+ } catch (err) {
11
+ promise.reject(err);
12
+ }
13
+ return promise;
14
+ };
15
+ };
16
+
17
+ export const assertDefined = <T>(
18
+ value: T | undefined | null,
19
+ errMsg: string,
20
+ ): value is T => {
21
+ if (value === undefined || value == null) {
22
+ throw new Error(errMsg);
23
+ }
24
+ return true;
25
+ };