@immediately-run/sandpack-client 2.19.8

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/README.md +26 -0
  2. package/dist/.ir-build-stamp.json +6 -0
  3. package/dist/base-DBh7xJX9.mjs +48 -0
  4. package/dist/base-DelKLlDk.js +50 -0
  5. package/dist/clients/base.d.ts +34 -0
  6. package/dist/clients/event-emitter.d.ts +10 -0
  7. package/dist/clients/iframe-factory.d.ts +27 -0
  8. package/dist/clients/index.d.ts +4 -0
  9. package/dist/clients/node/client.utils.d.ts +7 -0
  10. package/dist/clients/node/iframe.utils.d.ts +3 -0
  11. package/dist/clients/node/index.d.ts +49 -0
  12. package/dist/clients/node/index.js +631 -0
  13. package/dist/clients/node/index.mjs +629 -0
  14. package/dist/clients/node/inject-scripts/historyListener.d.ts +5 -0
  15. package/dist/clients/node/inject-scripts/index.d.ts +1 -0
  16. package/dist/clients/node/inject-scripts/resize.d.ts +5 -0
  17. package/dist/clients/node/taskManager.d.ts +20 -0
  18. package/dist/clients/node/types.d.ts +63 -0
  19. package/dist/clients/runtime/file-resolver-protocol.d.ts +17 -0
  20. package/dist/clients/runtime/iframe-protocol.d.ts +17 -0
  21. package/dist/clients/runtime/immutable-fetch-protocol.d.ts +39 -0
  22. package/dist/clients/runtime/index.d.ts +76 -0
  23. package/dist/clients/runtime/index.js +1046 -0
  24. package/dist/clients/runtime/index.mjs +1044 -0
  25. package/dist/clients/runtime/mime.d.ts +1 -0
  26. package/dist/clients/runtime/types.d.ts +129 -0
  27. package/dist/clients/runtime/utils.d.ts +8 -0
  28. package/dist/clients/static/index.d.ts +25 -0
  29. package/dist/clients/static/utils.d.ts +5 -0
  30. package/dist/consoleHook-DQVWjDRE.mjs +230 -0
  31. package/dist/consoleHook-znXctRzh.js +236 -0
  32. package/dist/fs/SandpackFS.d.ts +116 -0
  33. package/dist/iframe-factory-BcC-S_XQ.js +54 -0
  34. package/dist/iframe-factory-DybmkzJZ.mjs +51 -0
  35. package/dist/index--fILWAw8.js +210 -0
  36. package/dist/index-rbhm_KmF.mjs +208 -0
  37. package/dist/index.d.ts +4 -0
  38. package/dist/index.js +53 -0
  39. package/dist/index.mjs +40 -0
  40. package/dist/inject-scripts/consoleHook.d.ts +6 -0
  41. package/dist/types-BFONOA2L.mjs +531 -0
  42. package/dist/types-BIIEoWr6.js +534 -0
  43. package/dist/types.d.ts +348 -0
  44. package/dist/utils-BiVyytui.js +262 -0
  45. package/dist/utils-DG1HA4RZ.mjs +250 -0
  46. package/dist/utils.d.ts +18 -0
  47. package/dist/utils.js +13 -0
  48. package/dist/utils.mjs +2 -0
  49. package/package.json +82 -0
@@ -0,0 +1,1046 @@
1
+ 'use strict';
2
+
3
+ var utils = require('../../utils-BiVyytui.js');
4
+ var dequal = require('dequal');
5
+ var types = require('../../types-BIIEoWr6.js');
6
+ var base = require('../../base-DelKLlDk.js');
7
+ var iframeFactory = require('../../iframe-factory-BcC-S_XQ.js');
8
+ var mimeDB = require('mime-db');
9
+ require('outvariant');
10
+ require('@zenfs/core');
11
+
12
+ /**
13
+ * This file is a copy of the resolver from the `codesandbox-api` package.
14
+ * We wanted to avoid to reference codesandbox-api because of the code that runs on load in the package.
15
+ * The plan is to take some time and refactor codesandbox-api into what it was supposed to be in the first place,
16
+ * an abstraction over the actions that can be dispatched between the bundler and the iframe.
17
+ */
18
+ var Protocol = /** @class */ (function () {
19
+ function Protocol(type, handleMessage, protocol) {
20
+ var _this = this;
21
+ this.type = type;
22
+ this.handleMessage = handleMessage;
23
+ this.protocol = protocol;
24
+ this._disposeMessageListener = this.protocol.channelListen(function (msg) { return utils.__awaiter(_this, void 0, void 0, function () {
25
+ var message, result, response, err_1, response;
26
+ return utils.__generator(this, function (_a) {
27
+ switch (_a.label) {
28
+ case 0:
29
+ if (!(msg.type === this.getTypeId() && msg.method)) return [3 /*break*/, 4];
30
+ message = msg;
31
+ _a.label = 1;
32
+ case 1:
33
+ _a.trys.push([1, 3, , 4]);
34
+ return [4 /*yield*/, this.handleMessage(message)];
35
+ case 2:
36
+ result = _a.sent();
37
+ response = {
38
+ type: this.getTypeId(),
39
+ msgId: message.msgId,
40
+ result: result,
41
+ };
42
+ this.protocol.dispatch(response);
43
+ return [3 /*break*/, 4];
44
+ case 3:
45
+ err_1 = _a.sent();
46
+ response = {
47
+ type: this.getTypeId(),
48
+ msgId: message.msgId,
49
+ error: {
50
+ message: err_1.message,
51
+ },
52
+ };
53
+ this.protocol.dispatch(response);
54
+ return [3 /*break*/, 4];
55
+ case 4: return [2 /*return*/];
56
+ }
57
+ });
58
+ }); });
59
+ }
60
+ Protocol.prototype.getTypeId = function () {
61
+ return "protocol-".concat(this.type);
62
+ };
63
+ Protocol.prototype.dispose = function () {
64
+ this._disposeMessageListener();
65
+ };
66
+ return Protocol;
67
+ }());
68
+
69
+ var IFrameProtocol = /** @class */ (function () {
70
+ function IFrameProtocol(iframe, origin) {
71
+ // React to messages from any iframe
72
+ this.globalListeners = {};
73
+ this.globalListenersCount = 0;
74
+ // React to messages from the iframe owned by this instance
75
+ this.channelListeners = {};
76
+ this.channelListenersCount = 0;
77
+ // Random number to identify this instance of the client when messages are coming from multiple iframes
78
+ this.channelId = Math.floor(Math.random() * 1000000);
79
+ this.frameWindow = iframe.contentWindow;
80
+ this.origin = '*'; //origin;
81
+ this.globalListeners = [];
82
+ this.channelListeners = [];
83
+ this.eventListener = this.eventListener.bind(this);
84
+ if (typeof window !== "undefined") {
85
+ window.addEventListener("message", this.eventListener);
86
+ }
87
+ }
88
+ IFrameProtocol.prototype.cleanup = function () {
89
+ window.removeEventListener("message", this.eventListener);
90
+ this.globalListeners = {};
91
+ this.channelListeners = {};
92
+ this.globalListenersCount = 0;
93
+ this.channelListenersCount = 0;
94
+ };
95
+ // Sends the channelId and triggers an iframeHandshake promise to resolve,
96
+ // so the iframe can start listening for messages (based on the id).
97
+ // `config` carries the bundler's bootstrap configuration (template/logLevel/
98
+ // recompileDelay) — the bundler watches the shared filesystem itself and no
99
+ // longer receives a `compile` message, so it needs this delivered once here.
100
+ IFrameProtocol.prototype.register = function (port, config, babelPort) {
101
+ if (!this.frameWindow) {
102
+ return;
103
+ }
104
+ console.log("[IFrameProtocol] Registering iframe with channelId", this.channelId, this);
105
+ // Order matters: the bundler reads ports[0] as the fs port and ports[1] as
106
+ // the Babel worker port. `filter` keeps that order as long as the fs port
107
+ // is always present (it is, in normal operation).
108
+ var ports = [port, babelPort].filter(function (p) { return p != null; });
109
+ this.frameWindow.postMessage(utils.__assign({ type: "register-frame", origin: document.location.origin, id: this.channelId }, config), this.origin, ports);
110
+ };
111
+ // Messages are dispatched from the client directly to the instance iframe
112
+ IFrameProtocol.prototype.dispatch = function (message) {
113
+ if (!this.frameWindow) {
114
+ return;
115
+ }
116
+ // `_transfer` (e.g. a MessagePort for a mount's filesystem) must be passed
117
+ // as the postMessage transfer list, not as a serialized payload field.
118
+ var _transfer = message._transfer, payload = utils.__rest(message, ["_transfer"]);
119
+ this.frameWindow.postMessage(utils.__assign({ $id: this.channelId, codesandbox: true }, payload), this.origin, _transfer !== null && _transfer !== void 0 ? _transfer : []);
120
+ };
121
+ // Add a listener that is called on any message coming from an iframe in the page
122
+ // This is needed for the `initialize` message which comes without a channelId
123
+ IFrameProtocol.prototype.globalListen = function (listener) {
124
+ var _this = this;
125
+ if (typeof listener !== "function") {
126
+ return function () {
127
+ return;
128
+ };
129
+ }
130
+ var listenerId = this.globalListenersCount;
131
+ this.globalListeners[listenerId] = listener;
132
+ this.globalListenersCount++;
133
+ return function () {
134
+ delete _this.globalListeners[listenerId];
135
+ };
136
+ };
137
+ // Add a listener that is called on any message coming from an iframe with the instance channelId
138
+ // All other messages (eg: from other iframes) are ignored
139
+ IFrameProtocol.prototype.channelListen = function (listener) {
140
+ var _this = this;
141
+ if (typeof listener !== "function") {
142
+ return function () {
143
+ return;
144
+ };
145
+ }
146
+ var listenerId = this.channelListenersCount;
147
+ this.channelListeners[listenerId] = listener;
148
+ this.channelListenersCount++;
149
+ return function () {
150
+ delete _this.channelListeners[listenerId];
151
+ };
152
+ };
153
+ // Handles message windows coming from iframes
154
+ IFrameProtocol.prototype.eventListener = function (evt) {
155
+ // skip events originating from different iframes
156
+ if (evt.source !== this.frameWindow) {
157
+ return;
158
+ }
159
+ var message = evt.data;
160
+ if (!message.codesandbox) {
161
+ return;
162
+ }
163
+ Object.values(this.globalListeners).forEach(function (listener) {
164
+ return listener(message);
165
+ });
166
+ if (message.$id !== this.channelId) {
167
+ return;
168
+ }
169
+ Object.values(this.channelListeners).forEach(function (listener) {
170
+ return listener(message);
171
+ });
172
+ };
173
+ return IFrameProtocol;
174
+ }());
175
+
176
+ /**
177
+ * Parent-side fetch + cache for immutable, exact-versioned module URLs.
178
+ *
179
+ * The bundler iframe runs at an opaque origin (sandboxed without
180
+ * `allow-same-origin`), so it has no persistent storage of any kind — its own
181
+ * Cache API is unavailable. It therefore forwards immutable-URL fetches here
182
+ * over the iframe protocol (`protocol-immutable-fetch`), and the parent — a
183
+ * real origin — serves them cache-first from a persistent Cache API cache.
184
+ *
185
+ * Security: the handler only fetches URLs matching {@link IMMUTABLE_URL_ALLOWLIST}.
186
+ * The iframe runs untrusted code, and an unrestricted parent-side fetch proxy
187
+ * would let it read arbitrary cross-origin responses with the parent's network
188
+ * context (a CORS bypass). The allowlist mirrors the prefixes the bundler
189
+ * registers via `registerImmutableUrlPrefix` (see sandpack-bundler
190
+ * `src/utils/fetch.ts`) — keep the two in sync.
191
+ */
192
+ /**
193
+ * URL prefixes whose responses never change for a given URL (the URL encodes
194
+ * the exact content version). Only these may be fetched on the iframe's
195
+ * behalf, and they are safe to cache forever.
196
+ */
197
+ var IMMUTABLE_URL_ALLOWLIST = [
198
+ // Module CDN, exact-versioned package bundles. (NOT /dep_tree/, which
199
+ // resolves semver ranges and changes as new versions publish.)
200
+ "https://sandpack-cdn-staging.blazingly.io/package/",
201
+ // unpkg files, requested by the bundler at registry-resolved exact versions.
202
+ "https://unpkg.com/",
203
+ // Self-hosted, versioned @immediately-run/sdk builds (SDK_PACKAGING_SPEC
204
+ // §5/§11, Option A). The /v/<version>/ path encodes the exact version, so
205
+ // responses are immutable; the bundler fetches these when an app opts the SDK
206
+ // into immediately.run.resolveFromRegistry. Keep in sync with the prefix the
207
+ // bundler registers via registerImmutableUrlPrefix (sandbox bundler.ts).
208
+ "https://immediately-run.github.io/immediately-run-sdk/v/",
209
+ ];
210
+ var IMMUTABLE_CACHE_NAME = "sandpack-immutable-fetch-v1";
211
+ var serializeResponse = function (res) { return utils.__awaiter(void 0, void 0, void 0, function () {
212
+ var _a;
213
+ var _b;
214
+ return utils.__generator(this, function (_c) {
215
+ switch (_c.label) {
216
+ case 0:
217
+ _a = {
218
+ status: res.status,
219
+ contentType: (_b = res.headers.get("content-type")) !== null && _b !== void 0 ? _b : ""
220
+ };
221
+ return [4 /*yield*/, res.arrayBuffer()];
222
+ case 1: return [2 /*return*/, (_a.body = _c.sent(),
223
+ _a)];
224
+ }
225
+ });
226
+ }); };
227
+ // CacheStorage may be unavailable (insecure context) or fail (storage
228
+ // pressure); degrade to a plain fetch rather than failing the request.
229
+ var openCache = function () { return utils.__awaiter(void 0, void 0, void 0, function () {
230
+ return utils.__generator(this, function (_b) {
231
+ switch (_b.label) {
232
+ case 0:
233
+ _b.trys.push([0, 2, , 3]);
234
+ return [4 /*yield*/, caches.open(IMMUTABLE_CACHE_NAME)];
235
+ case 1: return [2 /*return*/, _b.sent()];
236
+ case 2:
237
+ _b.sent();
238
+ return [2 /*return*/, undefined];
239
+ case 3: return [2 /*return*/];
240
+ }
241
+ });
242
+ }); };
243
+ /** SHA-384 of bytes, formatted `sha384-<base64>` (SRI style). */
244
+ var sha384 = function (body) { return utils.__awaiter(void 0, void 0, void 0, function () {
245
+ var digest, bin, view, i;
246
+ return utils.__generator(this, function (_a) {
247
+ switch (_a.label) {
248
+ case 0: return [4 /*yield*/, crypto.subtle.digest("SHA-384", body)];
249
+ case 1:
250
+ digest = _a.sent();
251
+ bin = "";
252
+ view = new Uint8Array(digest);
253
+ for (i = 0; i < view.length; i++)
254
+ bin += String.fromCharCode(view[i]);
255
+ return [2 /*return*/, "sha384-".concat(btoa(bin))];
256
+ }
257
+ });
258
+ }); };
259
+ /**
260
+ * Does `body` match the caller-supplied `integrity` (an `sha384-<base64>` SRI
261
+ * hash)? Returns true when no integrity was supplied (nothing to check).
262
+ */
263
+ var matchesIntegrity = function (body, integrity) { return utils.__awaiter(void 0, void 0, void 0, function () {
264
+ return utils.__generator(this, function (_b) {
265
+ switch (_b.label) {
266
+ case 0:
267
+ if (!integrity)
268
+ return [2 /*return*/, true];
269
+ _b.label = 1;
270
+ case 1:
271
+ _b.trys.push([1, 3, , 4]);
272
+ return [4 /*yield*/, sha384(body)];
273
+ case 2: return [2 /*return*/, (_b.sent()) === integrity];
274
+ case 3:
275
+ _b.sent();
276
+ // crypto unavailable → can't verify; treat as a non-match so we neither
277
+ // serve nor persist bytes we couldn't validate (fail safe).
278
+ return [2 /*return*/, false];
279
+ case 4: return [2 /*return*/];
280
+ }
281
+ });
282
+ }); };
283
+ /**
284
+ * `protocol-immutable-fetch` handler: serve an allowlisted immutable URL,
285
+ * cache-first from the persistent parent-side cache.
286
+ *
287
+ * INTEGRITY-AWARE CACHING (cache-poisoning prevention). When the caller passes
288
+ * the expected SHA-384 (`integrity`), the cache is never allowed to serve or
289
+ * persist bytes that don't match it:
290
+ * - verify-on-read: a cache HIT whose bytes no longer match the expected hash
291
+ * (the host re-pinned the version under the cached bytes) is EVICTED and the
292
+ * URL refetched, so a stale/poisoned entry self-heals instead of failing the
293
+ * consumer forever.
294
+ * - verify-before-cache: freshly fetched bytes are only stored when they match.
295
+ * Mismatched bytes are returned (so the consumer's own check fails closed with
296
+ * a clear error) but NEVER cached, so a bad upstream window can't poison the
297
+ * cache. Without an `integrity` argument the URL is cached by URL as before.
298
+ */
299
+ function handleImmutableFetch(url, integrity) {
300
+ return utils.__awaiter(this, void 0, void 0, function () {
301
+ var expected, cache, hit, body, res, result, _a;
302
+ return utils.__generator(this, function (_b) {
303
+ switch (_b.label) {
304
+ case 0:
305
+ if (typeof url !== "string" ||
306
+ !IMMUTABLE_URL_ALLOWLIST.some(function (prefix) { return url.startsWith(prefix); })) {
307
+ throw new Error("URL not allowed for immutable fetch: ".concat(String(url)));
308
+ }
309
+ expected = typeof integrity === "string" ? integrity : undefined;
310
+ return [4 /*yield*/, openCache()];
311
+ case 1:
312
+ cache = _b.sent();
313
+ if (!cache) return [3 /*break*/, 6];
314
+ return [4 /*yield*/, cache.match(url).catch(function () { return undefined; })];
315
+ case 2:
316
+ hit = _b.sent();
317
+ if (!hit) return [3 /*break*/, 6];
318
+ return [4 /*yield*/, hit.clone().arrayBuffer()];
319
+ case 3:
320
+ body = _b.sent();
321
+ return [4 /*yield*/, matchesIntegrity(body, expected)];
322
+ case 4:
323
+ if (_b.sent()) {
324
+ return [2 /*return*/, serializeResponse(hit)];
325
+ }
326
+ // Stale/poisoned entry: drop it and fall through to a fresh fetch.
327
+ return [4 /*yield*/, cache.delete(url).catch(function () { })];
328
+ case 5:
329
+ // Stale/poisoned entry: drop it and fall through to a fresh fetch.
330
+ _b.sent();
331
+ _b.label = 6;
332
+ case 6: return [4 /*yield*/, fetch(url)];
333
+ case 7:
334
+ res = _b.sent();
335
+ if (!res.ok) {
336
+ throw new Error("Immutable fetch failed with status ".concat(res.status, ": ").concat(url));
337
+ }
338
+ return [4 /*yield*/, serializeResponse(res)];
339
+ case 8:
340
+ result = _b.sent();
341
+ _a = cache;
342
+ if (!_a) return [3 /*break*/, 10];
343
+ return [4 /*yield*/, matchesIntegrity(result.body, expected)];
344
+ case 9:
345
+ _a = (_b.sent());
346
+ _b.label = 10;
347
+ case 10:
348
+ if (!_a) return [3 /*break*/, 12];
349
+ // Only persist verified bytes. A failed put (quota) only costs the entry.
350
+ return [4 /*yield*/, cache
351
+ .put(url, new Response(result.body.slice(0), { status: result.status, headers: { "content-type": result.contentType } }))
352
+ .catch(function () { })];
353
+ case 11:
354
+ // Only persist verified bytes. A failed put (quota) only costs the entry.
355
+ _b.sent();
356
+ _b.label = 12;
357
+ case 12: return [2 /*return*/, result];
358
+ }
359
+ });
360
+ });
361
+ }
362
+
363
+ var extensionMap = new Map();
364
+ var entries = Object.entries(mimeDB);
365
+ for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
366
+ var _a$1 = entries_1[_i], mimetype = _a$1[0], entry = _a$1[1];
367
+ // eslint-disable-next-line
368
+ // @ts-ignore
369
+ if (!entry.extensions) {
370
+ continue;
371
+ }
372
+ // eslint-disable-next-line
373
+ // @ts-ignore
374
+ var extensions = entry.extensions;
375
+ if (extensions.length) {
376
+ for (var _b = 0, extensions_1 = extensions; _b < extensions_1.length; _b++) {
377
+ var ext = extensions_1[_b];
378
+ extensionMap.set(ext, mimetype);
379
+ }
380
+ }
381
+ }
382
+ var EXTENSIONS_MAP = extensionMap;
383
+
384
+ var CHANNEL_NAME = "$CSB_RELAY";
385
+
386
+ var MAX_CLIENT_DEPENDENCY_COUNT = 50;
387
+ function getTemplate(pkg,
388
+ /* eslint-disable @typescript-eslint/no-explicit-any */
389
+ modules) {
390
+ if (!pkg) {
391
+ return "static";
392
+ }
393
+ var _a = pkg.dependencies, dependencies = _a === void 0 ? {} : _a, _b = pkg.devDependencies, devDependencies = _b === void 0 ? {} : _b;
394
+ var totalDependencies = utils.__spreadArray(utils.__spreadArray([], Object.keys(dependencies), true), Object.keys(devDependencies), true);
395
+ var moduleNames = Object.keys(modules);
396
+ var adonis = ["@adonisjs/framework", "@adonisjs/core"];
397
+ if (totalDependencies.some(function (dep) { return adonis.indexOf(dep) > -1; })) {
398
+ return "adonis";
399
+ }
400
+ var nuxt = ["nuxt", "nuxt-edge", "nuxt-ts", "nuxt-ts-edge", "nuxt3"];
401
+ if (totalDependencies.some(function (dep) { return nuxt.indexOf(dep) > -1; })) {
402
+ return "nuxt";
403
+ }
404
+ if (totalDependencies.indexOf("next") > -1) {
405
+ return "next";
406
+ }
407
+ var apollo = [
408
+ "apollo-server",
409
+ "apollo-server-express",
410
+ "apollo-server-hapi",
411
+ "apollo-server-koa",
412
+ "apollo-server-lambda",
413
+ "apollo-server-micro",
414
+ ];
415
+ if (totalDependencies.some(function (dep) { return apollo.indexOf(dep) > -1; })) {
416
+ return "apollo";
417
+ }
418
+ if (totalDependencies.indexOf("mdx-deck") > -1) {
419
+ return "mdx-deck";
420
+ }
421
+ if (totalDependencies.indexOf("gridsome") > -1) {
422
+ return "gridsome";
423
+ }
424
+ if (totalDependencies.indexOf("vuepress") > -1) {
425
+ return "vuepress";
426
+ }
427
+ if (totalDependencies.indexOf("ember-cli") > -1) {
428
+ return "ember";
429
+ }
430
+ if (totalDependencies.indexOf("sapper") > -1) {
431
+ return "sapper";
432
+ }
433
+ if (totalDependencies.indexOf("gatsby") > -1) {
434
+ return "gatsby";
435
+ }
436
+ if (totalDependencies.indexOf("quasar") > -1) {
437
+ return "quasar";
438
+ }
439
+ if (totalDependencies.indexOf("@docusaurus/core") > -1) {
440
+ return "docusaurus";
441
+ }
442
+ if (totalDependencies.indexOf("remix") > -1) {
443
+ return "remix";
444
+ }
445
+ if (totalDependencies.indexOf("astro") > -1) {
446
+ return "node";
447
+ }
448
+ // CLIENT
449
+ if (moduleNames.some(function (m) { return m.endsWith(".re"); })) {
450
+ return "reason";
451
+ }
452
+ var parcel = ["parcel-bundler", "parcel"];
453
+ if (totalDependencies.some(function (dep) { return parcel.indexOf(dep) > -1; })) {
454
+ return "parcel";
455
+ }
456
+ var dojo = ["@dojo/core", "@dojo/framework"];
457
+ if (totalDependencies.some(function (dep) { return dojo.indexOf(dep) > -1; })) {
458
+ return "@dojo/cli-create-app";
459
+ }
460
+ if (totalDependencies.indexOf("@nestjs/core") > -1 ||
461
+ totalDependencies.indexOf("@nestjs/common") > -1) {
462
+ return "nest";
463
+ }
464
+ if (totalDependencies.indexOf("react-styleguidist") > -1) {
465
+ return "styleguidist";
466
+ }
467
+ if (totalDependencies.indexOf("react-scripts") > -1) {
468
+ return "create-react-app";
469
+ }
470
+ if (totalDependencies.indexOf("react-scripts-ts") > -1) {
471
+ return "create-react-app-typescript";
472
+ }
473
+ if (totalDependencies.indexOf("@angular/core") > -1) {
474
+ return "angular-cli";
475
+ }
476
+ if (totalDependencies.indexOf("preact-cli") > -1) {
477
+ return "preact-cli";
478
+ }
479
+ if (totalDependencies.indexOf("@sveltech/routify") > -1 ||
480
+ totalDependencies.indexOf("@roxi/routify") > -1) {
481
+ return "node";
482
+ }
483
+ if (totalDependencies.indexOf("vite") > -1) {
484
+ return "node";
485
+ }
486
+ if (totalDependencies.indexOf("@frontity/core") > -1) {
487
+ return "node";
488
+ }
489
+ if (totalDependencies.indexOf("svelte") > -1) {
490
+ return "svelte";
491
+ }
492
+ if (totalDependencies.indexOf("vue") > -1) {
493
+ return "vue-cli";
494
+ }
495
+ if (totalDependencies.indexOf("cx") > -1) {
496
+ return "cxjs";
497
+ }
498
+ var nodeDeps = [
499
+ "express",
500
+ "koa",
501
+ "nodemon",
502
+ "ts-node",
503
+ "@tensorflow/tfjs-node",
504
+ "webpack-dev-server",
505
+ "snowpack",
506
+ ];
507
+ if (totalDependencies.some(function (dep) { return nodeDeps.indexOf(dep) > -1; })) {
508
+ return "node";
509
+ }
510
+ if (Object.keys(dependencies).length >= MAX_CLIENT_DEPENDENCY_COUNT) {
511
+ // The dependencies are too much for client sandboxes to handle
512
+ return "node";
513
+ }
514
+ return undefined;
515
+ }
516
+ function getExtension(filepath) {
517
+ var parts = filepath.split(".");
518
+ if (parts.length <= 1) {
519
+ return "";
520
+ }
521
+ else {
522
+ var ext = parts[parts.length - 1];
523
+ return ext;
524
+ }
525
+ }
526
+
527
+ var _a;
528
+ var SUFFIX_PLACEHOLDER = "-{{suffix}}";
529
+ var BUNDLER_URL = "https://".concat((_a = "2.19.8") === null || _a === void 0 ? void 0 : _a.replace(/\./g, "-")).concat(SUFFIX_PLACEHOLDER, "-sandpack.codesandbox.io/");
530
+ var SandpackRuntime = /** @class */ (function (_super) {
531
+ utils.__extends(SandpackRuntime, _super);
532
+ function SandpackRuntime(selector, sandboxSetup, options) {
533
+ if (options === void 0) { options = {}; }
534
+ var _this = _super.call(this, selector, sandboxSetup, options) || this;
535
+ /** Parent-owned Babel transpiler worker, connected to the iframe by port. */
536
+ _this.babelWorker = null;
537
+ _this.getTranspilerContext = function () {
538
+ return new Promise(function (resolve) {
539
+ var unsubscribe = _this.listen(function (message) {
540
+ if (message.type === "transpiler-context") {
541
+ resolve(message.data);
542
+ unsubscribe();
543
+ }
544
+ });
545
+ _this.dispatch({ type: "get-transpiler-context" });
546
+ });
547
+ };
548
+ _this.getTranspiledFiles = function () {
549
+ return new Promise(function (resolve) {
550
+ var unsubscribe = _this.listen(function (message) {
551
+ if (message.type === "all-modules") {
552
+ resolve(message.data);
553
+ unsubscribe();
554
+ }
555
+ });
556
+ _this.dispatch({ type: "get-modules" });
557
+ });
558
+ };
559
+ _this.bundlerURL = _this.createBundlerURL();
560
+ _this.bundlerState = undefined;
561
+ _this.errors = [];
562
+ _this.status = "initializing";
563
+ _this.fs = sandboxSetup.fs;
564
+ if (typeof selector === "string") {
565
+ _this.selector = selector;
566
+ var element = document.querySelector(selector);
567
+ utils.nullthrows(element, "The element '".concat(selector, "' was not found"));
568
+ _this.element = element;
569
+ // Opaque-origin app iframe via the single factory (G1/T1). No
570
+ // `allow-same-origin`: the iframe runs untrusted code at an opaque origin
571
+ // so it can't read domain-scoped cookies, register service workers, or
572
+ // touch shared storage on the bundler origin. The Babel worker that used
573
+ // to require same-origin is now owned by the parent and reached over a
574
+ // transferred `MessagePort` (see `createBabelWorkerPort`).
575
+ _this.iframe = iframeFactory.createSandboxedIframe();
576
+ _this.initializeElement();
577
+ }
578
+ else {
579
+ _this.element = selector;
580
+ _this.iframe = selector;
581
+ }
582
+ // Set-and-assert: a host-provided iframe is hardened here, and any iframe
583
+ // (created or passed) is verified to carry no `allow-same-origin`.
584
+ iframeFactory.ensureSandboxed(_this.iframe);
585
+ _this.setLocationURLIntoIFrame();
586
+ _this.iframeProtocol = new IFrameProtocol(_this.iframe, _this.bundlerURL);
587
+ _this.unsubscribeGlobalListener = _this.iframeProtocol.globalListen(function (mes) {
588
+ if (mes.type !== "initialized" || !_this.iframe.contentWindow) {
589
+ return;
590
+ }
591
+ // this may not work with a boundedcontext, it may require an actual FS instance
592
+ var remotePortPromise = _this.fs.connectRemote();
593
+ remotePortPromise.then(function (remotePort) { return utils.__awaiter(_this, void 0, void 0, function () {
594
+ var config, babelPort;
595
+ var _this = this;
596
+ return utils.__generator(this, function (_a) {
597
+ switch (_a.label) {
598
+ case 0:
599
+ /**
600
+ * Lazy file resolution over the iframe protocol, backed by the
601
+ * {@link SandpackFS} passed on construction. Created before `register`
602
+ * so it's ready for the bundler's lazy file reads as soon as the
603
+ * bundler has the fs port.
604
+ */
605
+ this.fileResolverProtocol = new Protocol("fs", function (data) { return utils.__awaiter(_this, void 0, void 0, function () {
606
+ return utils.__generator(this, function (_a) {
607
+ if (data.method === "isFile") {
608
+ return [2 /*return*/, this.sandboxSetup.fs.exists(data.params[0])];
609
+ }
610
+ else if (data.method === "readFile") {
611
+ return [2 /*return*/, this.sandboxSetup.fs.readFile(data.params[0])];
612
+ }
613
+ else {
614
+ throw new Error("Method not supported");
615
+ }
616
+ });
617
+ }); }, this.iframeProtocol);
618
+ /**
619
+ * Parent-side fetch + persistent cache for immutable module URLs.
620
+ * The iframe's opaque origin has no storage, so it forwards these
621
+ * here (see immutable-fetch-protocol.ts for the allowlist).
622
+ */
623
+ this.immutableFetchProtocol = new Protocol("immutable-fetch", function (data) { return utils.__awaiter(_this, void 0, void 0, function () {
624
+ return utils.__generator(this, function (_a) {
625
+ if (data.method !== "fetch") {
626
+ throw new Error("Method not supported");
627
+ }
628
+ // params[1] is an optional `sha384-…` integrity the caller pins
629
+ // for this URL (SDK files); the cache verifies against it.
630
+ return [2 /*return*/, handleImmutableFetch(data.params[0], data.params[1])];
631
+ });
632
+ }); }, this.iframeProtocol);
633
+ return [4 /*yield*/, this.computeInitConfig()];
634
+ case 1:
635
+ config = _a.sent();
636
+ babelPort = this.createBabelWorkerPort();
637
+ this.iframeProtocol.register(remotePort, config, babelPort);
638
+ return [2 /*return*/];
639
+ }
640
+ });
641
+ }); });
642
+ });
643
+ _this.unsubscribeChannelListener = _this.iframeProtocol.channelListen(function (mes) {
644
+ switch (mes.type) {
645
+ case "start": {
646
+ _this.errors = [];
647
+ break;
648
+ }
649
+ case "status": {
650
+ _this.status = mes.status;
651
+ break;
652
+ }
653
+ case "action": {
654
+ if (mes.action === "show-error") {
655
+ _this.errors = utils.__spreadArray(utils.__spreadArray([], _this.errors, true), [utils.extractErrorDetails(mes)], false);
656
+ }
657
+ break;
658
+ }
659
+ case "done": {
660
+ _this.status = "done";
661
+ break;
662
+ }
663
+ case "state": {
664
+ _this.bundlerState = mes.state;
665
+ break;
666
+ }
667
+ }
668
+ });
669
+ if (options.experimental_enableServiceWorker) {
670
+ _this.serviceWorkerHandshake();
671
+ }
672
+ return _this;
673
+ }
674
+ SandpackRuntime.prototype.createBundlerURL = function () {
675
+ var _a;
676
+ var bundlerURL = this.options.bundlerURL || BUNDLER_URL;
677
+ // if it's a custom, skip the rest
678
+ if (this.options.bundlerURL) {
679
+ return bundlerURL;
680
+ }
681
+ if (this.options.teamId) {
682
+ bundlerURL =
683
+ bundlerURL.replace("https://", "https://" + this.options.teamId + "-") +
684
+ "?cache=".concat(Date.now());
685
+ }
686
+ if (this.options.experimental_enableServiceWorker) {
687
+ var suffixes = [];
688
+ suffixes.push(Math.random().toString(36).slice(4));
689
+ bundlerURL = bundlerURL.replace(SUFFIX_PLACEHOLDER, "-".concat((_a = this.options.experimental_stableServiceWorkerId) !== null && _a !== void 0 ? _a : suffixes.join("-")));
690
+ }
691
+ else {
692
+ bundlerURL = bundlerURL.replace(SUFFIX_PLACEHOLDER, "");
693
+ }
694
+ return bundlerURL;
695
+ };
696
+ /**
697
+ * Creates (or recreates) the parent-owned Babel transpiler worker and returns
698
+ * the `MessagePort` to transfer into the iframe. The iframe can no longer run
699
+ * its own worker — without `allow-same-origin` it has an opaque origin, and a
700
+ * same-origin worker script won't load there — so transpilation happens in
701
+ * this worker on the parent's real origin. Per-transform traffic then flows
702
+ * iframe<->worker directly over the entangled ports; the parent doesn't relay.
703
+ */
704
+ SandpackRuntime.prototype.createBabelWorkerPort = function () {
705
+ var _a;
706
+ var workerURL = this.options.babelWorkerURL;
707
+ if (!workerURL) {
708
+ console.warn("[SandpackRuntime] No `babelWorkerURL` configured — the bundler cannot transpile without a Babel worker.");
709
+ return undefined;
710
+ }
711
+ // A reload re-runs this handshake; terminate the previous worker first so
712
+ // we don't leak one per reload.
713
+ (_a = this.babelWorker) === null || _a === void 0 ? void 0 : _a.terminate();
714
+ // Classic (not module) worker: the bundled worker lazily loads its Babel
715
+ // plugin/preset chunks via importScripts(), which a `{ type: "module" }`
716
+ // worker forbids. The worker artifact is built with outputFormat "globalThis"
717
+ // to match (see sandpack-bundler's babelWorker Parcel target).
718
+ var worker = new Worker(workerURL);
719
+ this.babelWorker = worker;
720
+ var channel = new MessageChannel();
721
+ // Hand the worker one end; it binds its message bus to this port on receipt.
722
+ worker.postMessage({ type: "connect" }, [channel.port1]);
723
+ return channel.port2;
724
+ };
725
+ SandpackRuntime.prototype.serviceWorkerHandshake = function () {
726
+ var _this = this;
727
+ var channel = new MessageChannel();
728
+ var iframeContentWindow = this.iframe.contentWindow;
729
+ if (!iframeContentWindow) {
730
+ throw new Error("Could not get iframe contentWindow");
731
+ }
732
+ var port = channel.port1;
733
+ port.onmessage = function (evt) {
734
+ if (typeof evt.data === "object" && evt.data.$channel === CHANNEL_NAME) {
735
+ switch (evt.data.$type) {
736
+ case "preview/ready":
737
+ // no op for now
738
+ break;
739
+ case "preview/request":
740
+ _this.handleWorkerRequest(evt.data, port);
741
+ break;
742
+ }
743
+ }
744
+ };
745
+ var sendMessage = function () {
746
+ var initMsg = {
747
+ $channel: CHANNEL_NAME,
748
+ $type: "preview/init",
749
+ };
750
+ iframeContentWindow.postMessage(initMsg, "*", [channel.port2]);
751
+ _this.iframe.removeEventListener("load", sendMessage);
752
+ };
753
+ this.iframe.addEventListener("load", sendMessage);
754
+ };
755
+ SandpackRuntime.prototype.handleWorkerRequest = function (request, port) {
756
+ return utils.__awaiter(this, void 0, void 0, function () {
757
+ var notFound, filepath_1, headers, body, modulesFromManager, match, extension, foundMimetype, responseMessage, err_1;
758
+ return utils.__generator(this, function (_a) {
759
+ switch (_a.label) {
760
+ case 0:
761
+ notFound = function () {
762
+ var responseMessage = {
763
+ $channel: CHANNEL_NAME,
764
+ $type: "preview/response",
765
+ id: request.id,
766
+ headers: {
767
+ "Content-Type": "text/html; charset=utf-8",
768
+ },
769
+ status: 404,
770
+ body: "File not found",
771
+ };
772
+ port.postMessage(responseMessage);
773
+ };
774
+ _a.label = 1;
775
+ case 1:
776
+ _a.trys.push([1, 7, , 8]);
777
+ filepath_1 = new URL(request.url, this.bundlerURL).pathname;
778
+ headers = {};
779
+ body = void 0;
780
+ return [4 /*yield*/, this.sandboxSetup.fs.exists(filepath_1)];
781
+ case 2:
782
+ if (!_a.sent()) return [3 /*break*/, 4];
783
+ return [4 /*yield*/, this.sandboxSetup.fs.readFile(filepath_1)];
784
+ case 3:
785
+ body = _a.sent();
786
+ return [3 /*break*/, 6];
787
+ case 4: return [4 /*yield*/, this.getTranspiledFiles()];
788
+ case 5:
789
+ modulesFromManager = _a.sent();
790
+ match = modulesFromManager.find(function (item) {
791
+ return item.path.endsWith(filepath_1);
792
+ });
793
+ if (match) {
794
+ body = match.code;
795
+ }
796
+ _a.label = 6;
797
+ case 6:
798
+ if (body === undefined) {
799
+ notFound();
800
+ return [2 /*return*/];
801
+ }
802
+ if (!headers["Content-Type"]) {
803
+ extension = getExtension(filepath_1);
804
+ foundMimetype = EXTENSIONS_MAP.get(extension);
805
+ if (foundMimetype) {
806
+ headers["Content-Type"] = foundMimetype;
807
+ }
808
+ }
809
+ responseMessage = {
810
+ $channel: CHANNEL_NAME,
811
+ $type: "preview/response",
812
+ id: request.id,
813
+ headers: headers,
814
+ status: 200,
815
+ body: body,
816
+ };
817
+ port.postMessage(responseMessage);
818
+ return [3 /*break*/, 8];
819
+ case 7:
820
+ err_1 = _a.sent();
821
+ console.error(err_1);
822
+ notFound();
823
+ return [3 /*break*/, 8];
824
+ case 8: return [2 /*return*/];
825
+ }
826
+ });
827
+ });
828
+ };
829
+ SandpackRuntime.prototype.setLocationURLIntoIFrame = function () {
830
+ var _a;
831
+ var urlSource = this.options.startRoute
832
+ ? new URL(this.options.startRoute, this.bundlerURL).toString()
833
+ : this.bundlerURL;
834
+ (_a = this.iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.location.replace(urlSource);
835
+ this.iframe.src = urlSource;
836
+ };
837
+ SandpackRuntime.prototype.destroy = function () {
838
+ var _a, _b, _c, _d;
839
+ this.unsubscribeChannelListener();
840
+ this.unsubscribeGlobalListener();
841
+ (_a = this.unsubscribeFsWatcher) === null || _a === void 0 ? void 0 : _a.call(this);
842
+ (_b = this.fileResolverProtocol) === null || _b === void 0 ? void 0 : _b.dispose();
843
+ (_c = this.immutableFetchProtocol) === null || _c === void 0 ? void 0 : _c.dispose();
844
+ (_d = this.babelWorker) === null || _d === void 0 ? void 0 : _d.terminate();
845
+ this.iframeProtocol.cleanup();
846
+ };
847
+ SandpackRuntime.prototype.updateOptions = function (options) {
848
+ if (!dequal.dequal(this.options, options)) {
849
+ this.options = options;
850
+ this.updateSandbox();
851
+ }
852
+ };
853
+ /**
854
+ * Updates the local sandbox state. The bundler watches the shared filesystem
855
+ * itself, so there is nothing to push to the iframe here — a file mutation
856
+ * triggers a rebuild on the bundler side without a `compile` message. A
857
+ * template/environment change is handled by re-registering the client (see
858
+ * `useClient`'s `watchFileChanges` effect), which re-runs `computeInitConfig`.
859
+ */
860
+ SandpackRuntime.prototype.updateSandbox = function (sandboxSetup) {
861
+ if (sandboxSetup === void 0) { sandboxSetup = this.sandboxSetup; }
862
+ this.sandboxSetup = utils.__assign(utils.__assign({}, this.sandboxSetup), sandboxSetup);
863
+ };
864
+ /**
865
+ * Computes the bundler's bootstrap config. Delivered once via the
866
+ * `register-frame` handshake (see the `initialized` handler) instead of a
867
+ * `compile` message, since the bundler now self-watches the filesystem.
868
+ */
869
+ SandpackRuntime.prototype.computeInitConfig = function () {
870
+ return utils.__awaiter(this, void 0, void 0, function () {
871
+ var fs, packageJSON, _a, _b, e_1, fileNames, fileNameMap;
872
+ var _c;
873
+ return utils.__generator(this, function (_d) {
874
+ switch (_d.label) {
875
+ case 0:
876
+ fs = this.sandboxSetup.fs;
877
+ packageJSON = JSON.parse(utils.createPackageJSON(this.sandboxSetup.dependencies, this.sandboxSetup.devDependencies, this.sandboxSetup.entry));
878
+ _d.label = 1;
879
+ case 1:
880
+ _d.trys.push([1, 5, , 6]);
881
+ return [4 /*yield*/, fs.exists("/package.json")];
882
+ case 2:
883
+ if (!_d.sent()) return [3 /*break*/, 4];
884
+ _b = (_a = JSON).parse;
885
+ return [4 /*yield*/, fs.readFile("/package.json")];
886
+ case 3:
887
+ packageJSON = _b.apply(_a, [_d.sent()]);
888
+ _d.label = 4;
889
+ case 4: return [3 /*break*/, 6];
890
+ case 5:
891
+ e_1 = _d.sent();
892
+ console.error(utils.createError("could not parse package.json file: " + e_1.message));
893
+ return [3 /*break*/, 6];
894
+ case 6: return [4 /*yield*/, fs.list()];
895
+ case 7:
896
+ fileNames = _d.sent();
897
+ fileNameMap = Object.fromEntries(fileNames.map(function (p) { return [p, true]; }));
898
+ return [2 /*return*/, {
899
+ template: this.sandboxSetup.template || getTemplate(packageJSON, fileNameMap),
900
+ logLevel: (_c = this.options.logLevel) !== null && _c !== void 0 ? _c : types.SandpackLogLevel.Info,
901
+ // Host-pinned SDK integrity hashes (SDK_PACKAGING_SPEC §5.2), forwarded
902
+ // verbatim into register-frame for the bundler to verify against. The host
903
+ // sets it via client options; absent → the bundler skips verification.
904
+ sdkIntegrity: this.options.sdkIntegrity,
905
+ // The §5.2 dirty set, forwarded verbatim into register-frame so the bundler
906
+ // skips seeding artifacts for paths edited in a previous session. Absent ⇒
907
+ // nothing dirty.
908
+ dirtyPaths: this.options.dirtyPaths,
909
+ // R3-49b batch-hydration snapshot, forwarded verbatim into register-frame so
910
+ // the bundler hydrates its read caches before the first compile. Absent ⇒
911
+ // reads cross the Port as before.
912
+ fsSnapshot: this.options.fsSnapshot,
913
+ // The chrome region this frame occupies (R3-114), forwarded verbatim into
914
+ // register-frame so the bundler surfaces it on the runtime globalThis for the
915
+ // SDK's getRegion(). Absent ⇒ the app reads no region.
916
+ region: this.options.region,
917
+ // BOOT_SCAFFOLDING_SPEC §3 — the resolved root package.json, forwarded
918
+ // out-of-band so the bundler reads it from config instead of the FS and no
919
+ // synthesized `package.json` is written into the CoW writable layer. This
920
+ // is the same object `getTemplate` consumes above (the repo's file when
921
+ // present, else the setup-derived default).
922
+ packageJSON: packageJSON,
923
+ }];
924
+ }
925
+ });
926
+ });
927
+ };
928
+ /**
929
+ * Relays the set of changed file paths to the bundler so it can re-bundle.
930
+ * The bundler can't observe parent-side writes to the shared filesystem on
931
+ * its own: zenfs's `Port` backend doesn't forward watch events across the
932
+ * iframe boundary. This lightweight signal replaces the old per-change
933
+ * `compile` message — it carries only paths, not template/options/config.
934
+ */
935
+ SandpackRuntime.prototype.notifyFilesChanged = function (paths) {
936
+ if (!paths.length) {
937
+ return;
938
+ }
939
+ this.dispatch({ type: "fs-change", paths: paths });
940
+ };
941
+ SandpackRuntime.prototype.dispatch = function (message) {
942
+ /**
943
+ * Intercept "refresh" dispatch: this will make sure
944
+ * that the iframe is still in the location it's supposed to be.
945
+ * External links inside the iframe will change the location and
946
+ * prevent the user from navigating back.
947
+ */
948
+ if (message.type === "refresh") {
949
+ this.setLocationURLIntoIFrame();
950
+ if (this.options.experimental_enableServiceWorker) {
951
+ this.serviceWorkerHandshake();
952
+ }
953
+ }
954
+ this.iframeProtocol.dispatch(message);
955
+ };
956
+ SandpackRuntime.prototype.listen = function (listener) {
957
+ return this.iframeProtocol.channelListen(listener);
958
+ };
959
+ /**
960
+ * Get the URL of the contents of the current sandbox
961
+ */
962
+ SandpackRuntime.prototype.getCodeSandboxURL = function () {
963
+ return utils.__awaiter(this, void 0, void 0, function () {
964
+ var snapshot, paramFiles, res, sandboxId;
965
+ return utils.__generator(this, function (_a) {
966
+ switch (_a.label) {
967
+ case 0: return [4 /*yield*/, snapshotFS(this.sandboxSetup.fs)];
968
+ case 1:
969
+ snapshot = _a.sent();
970
+ paramFiles = Object.keys(snapshot).reduce(function (prev, next) {
971
+ var _a;
972
+ return (utils.__assign(utils.__assign({}, prev), (_a = {}, _a[next.replace("/", "")] = {
973
+ content: snapshot[next],
974
+ isBinary: false,
975
+ }, _a)));
976
+ }, {});
977
+ return [4 /*yield*/, fetch("https://codesandbox.io/api/v1/sandboxes/define?json=1", {
978
+ method: "POST",
979
+ body: JSON.stringify({ files: paramFiles }),
980
+ headers: {
981
+ Accept: "application/json",
982
+ "Content-Type": "application/json",
983
+ },
984
+ })];
985
+ case 2:
986
+ res = _a.sent();
987
+ return [4 /*yield*/, res.json()];
988
+ case 3:
989
+ sandboxId = (_a.sent()).sandbox_id;
990
+ return [2 /*return*/, {
991
+ sandboxId: sandboxId,
992
+ editorUrl: "https://codesandbox.io/s/".concat(sandboxId),
993
+ embedUrl: "https://codesandbox.io/embed/".concat(sandboxId),
994
+ }];
995
+ }
996
+ });
997
+ });
998
+ };
999
+ SandpackRuntime.prototype.initializeElement = function () {
1000
+ this.iframe.style.border = "0";
1001
+ this.iframe.style.width = this.options.width || "100%";
1002
+ this.iframe.style.height = this.options.height || "100%";
1003
+ this.iframe.style.overflow = "hidden";
1004
+ utils.nullthrows(this.element.parentNode, "The given iframe does not have a parent.");
1005
+ this.element.parentNode.replaceChild(this.iframe, this.element);
1006
+ };
1007
+ return SandpackRuntime;
1008
+ }(base.SandpackClient));
1009
+ /**
1010
+ * Read every tracked file from the filesystem into a plain `{ path: code }`
1011
+ * snapshot. Used wherever the bundler protocol still expects a flat module
1012
+ * map (the iframe `compile` payload, Open-in-CodeSandbox, etc.).
1013
+ */
1014
+ function snapshotFS(fs) {
1015
+ return utils.__awaiter(this, void 0, void 0, function () {
1016
+ var paths, out;
1017
+ var _this = this;
1018
+ return utils.__generator(this, function (_a) {
1019
+ switch (_a.label) {
1020
+ case 0: return [4 /*yield*/, fs.list()];
1021
+ case 1:
1022
+ paths = _a.sent();
1023
+ out = {};
1024
+ return [4 /*yield*/, Promise.all(paths.map(function (path) { return utils.__awaiter(_this, void 0, void 0, function () {
1025
+ var _a, _b;
1026
+ return utils.__generator(this, function (_c) {
1027
+ switch (_c.label) {
1028
+ case 0:
1029
+ _a = out;
1030
+ _b = path;
1031
+ return [4 /*yield*/, fs.readFile(path)];
1032
+ case 1:
1033
+ _a[_b] = _c.sent();
1034
+ return [2 /*return*/];
1035
+ }
1036
+ });
1037
+ }); }))];
1038
+ case 2:
1039
+ _a.sent();
1040
+ return [2 /*return*/, out];
1041
+ }
1042
+ });
1043
+ });
1044
+ }
1045
+
1046
+ exports.SandpackRuntime = SandpackRuntime;