@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.
- package/README.md +26 -0
- package/dist/.ir-build-stamp.json +6 -0
- package/dist/base-DBh7xJX9.mjs +48 -0
- package/dist/base-DelKLlDk.js +50 -0
- package/dist/clients/base.d.ts +34 -0
- package/dist/clients/event-emitter.d.ts +10 -0
- package/dist/clients/iframe-factory.d.ts +27 -0
- package/dist/clients/index.d.ts +4 -0
- package/dist/clients/node/client.utils.d.ts +7 -0
- package/dist/clients/node/iframe.utils.d.ts +3 -0
- package/dist/clients/node/index.d.ts +49 -0
- package/dist/clients/node/index.js +631 -0
- package/dist/clients/node/index.mjs +629 -0
- package/dist/clients/node/inject-scripts/historyListener.d.ts +5 -0
- package/dist/clients/node/inject-scripts/index.d.ts +1 -0
- package/dist/clients/node/inject-scripts/resize.d.ts +5 -0
- package/dist/clients/node/taskManager.d.ts +20 -0
- package/dist/clients/node/types.d.ts +63 -0
- package/dist/clients/runtime/file-resolver-protocol.d.ts +17 -0
- package/dist/clients/runtime/iframe-protocol.d.ts +17 -0
- package/dist/clients/runtime/immutable-fetch-protocol.d.ts +39 -0
- package/dist/clients/runtime/index.d.ts +76 -0
- package/dist/clients/runtime/index.js +1046 -0
- package/dist/clients/runtime/index.mjs +1044 -0
- package/dist/clients/runtime/mime.d.ts +1 -0
- package/dist/clients/runtime/types.d.ts +129 -0
- package/dist/clients/runtime/utils.d.ts +8 -0
- package/dist/clients/static/index.d.ts +25 -0
- package/dist/clients/static/utils.d.ts +5 -0
- package/dist/consoleHook-DQVWjDRE.mjs +230 -0
- package/dist/consoleHook-znXctRzh.js +236 -0
- package/dist/fs/SandpackFS.d.ts +116 -0
- package/dist/iframe-factory-BcC-S_XQ.js +54 -0
- package/dist/iframe-factory-DybmkzJZ.mjs +51 -0
- package/dist/index--fILWAw8.js +210 -0
- package/dist/index-rbhm_KmF.mjs +208 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +53 -0
- package/dist/index.mjs +40 -0
- package/dist/inject-scripts/consoleHook.d.ts +6 -0
- package/dist/types-BFONOA2L.mjs +531 -0
- package/dist/types-BIIEoWr6.js +534 -0
- package/dist/types.d.ts +348 -0
- package/dist/utils-BiVyytui.js +262 -0
- package/dist/utils-DG1HA4RZ.mjs +250 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.js +13 -0
- package/dist/utils.mjs +2 -0
- package/package.json +82 -0
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('./utils-BiVyytui.js');
|
|
4
|
+
var core = require('@zenfs/core');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Path (within the SandpackFS) of the sidecar metadata file. Anything below
|
|
8
|
+
* `/.sandpack/` is treated as internal and excluded from {@link SandpackFS.list}.
|
|
9
|
+
*/
|
|
10
|
+
var META_PATH = "/.sandpack/meta.json";
|
|
11
|
+
var META_DIR = "/.sandpack";
|
|
12
|
+
var mountCounter = 0;
|
|
13
|
+
var normalize = function (path) {
|
|
14
|
+
return path.startsWith("/") ? path : "/".concat(path);
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* A filesystem-shaped handle over the files Sandpack renders. It wraps a
|
|
18
|
+
* ZenFS @see FileSystem mounted at a unique path prefix so multiple
|
|
19
|
+
* `SandpackProvider` instances stay isolated.
|
|
20
|
+
*
|
|
21
|
+
* All reads / writes are async. Changes emit a single coalesced notification
|
|
22
|
+
* (watcher or explicit helper calls) so React can subscribe via
|
|
23
|
+
* `useSyncExternalStore`.
|
|
24
|
+
*/
|
|
25
|
+
var SandpackFS = /** @class */ (function () {
|
|
26
|
+
function SandpackFS(fsContext, remotePortFactory,
|
|
27
|
+
// Invoked after a LOCAL editor write (writeFile) lands in the backing fs,
|
|
28
|
+
// with the normalized repo-relative path. The host uses it to record overlay
|
|
29
|
+
// provenance (COW_OVERLAY_PROVENANCE_SPEC §5 — the writer declares intent);
|
|
30
|
+
// iframe writes go through `remotePortFactory`/`handleRemoteChange` instead.
|
|
31
|
+
onWrite) {
|
|
32
|
+
this.fsContext = fsContext;
|
|
33
|
+
this.remotePortFactory = remotePortFactory;
|
|
34
|
+
this.onWrite = onWrite;
|
|
35
|
+
this.listeners = new Set();
|
|
36
|
+
this.metaCache = {};
|
|
37
|
+
this.sidecarEnvironment = undefined;
|
|
38
|
+
this.sidecarMode = undefined;
|
|
39
|
+
this.disposed = false;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create the `MessagePort` shared with the child iframe, wiring the iframe's
|
|
43
|
+
* write notifications back into this instance. The host's factory forwards
|
|
44
|
+
* `onRemoteChange` to `exportZenFS`, which calls it whenever the iframe writes
|
|
45
|
+
* a file over the Port — surfaced here as an `external` change.
|
|
46
|
+
*/
|
|
47
|
+
SandpackFS.prototype.connectRemote = function () {
|
|
48
|
+
var _this = this;
|
|
49
|
+
return this.remotePortFactory(function (path) { return _this.handleRemoteChange(path); });
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Create a new filesystem backed by an InMemory store and seed it with the
|
|
53
|
+
* given files.
|
|
54
|
+
*/
|
|
55
|
+
SandpackFS.fromFiles = function () {
|
|
56
|
+
return utils.__awaiter(this, arguments, void 0, function (files, options, remotePortFactory, onWrite) {
|
|
57
|
+
var id, prefix, backend, ctxt, instance;
|
|
58
|
+
if (files === void 0) { files = {}; }
|
|
59
|
+
if (options === void 0) { options = {}; }
|
|
60
|
+
return utils.__generator(this, function (_a) {
|
|
61
|
+
switch (_a.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
id = ++mountCounter;
|
|
64
|
+
prefix = "/__sandpack_".concat(id);
|
|
65
|
+
return [4 /*yield*/, core.resolveMountConfig({ backend: core.InMemory })];
|
|
66
|
+
case 1:
|
|
67
|
+
backend = _a.sent();
|
|
68
|
+
core.mount(prefix, backend);
|
|
69
|
+
ctxt = core.bindContext({ root: prefix });
|
|
70
|
+
instance = new SandpackFS(ctxt, remotePortFactory, onWrite);
|
|
71
|
+
if (options.environment !== undefined) {
|
|
72
|
+
instance.sidecarEnvironment = options.environment;
|
|
73
|
+
}
|
|
74
|
+
if (options.mode !== undefined) {
|
|
75
|
+
instance.sidecarMode = options.mode;
|
|
76
|
+
}
|
|
77
|
+
return [4 /*yield*/, instance.writeInitial(files)];
|
|
78
|
+
case 2:
|
|
79
|
+
_a.sent();
|
|
80
|
+
return [2 /*return*/, instance];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Adopt an existing ZenFS filesystem. The caller is responsible for its
|
|
87
|
+
* lifecycle - {@link dispose} will unmount but not destroy the underlying
|
|
88
|
+
* store.
|
|
89
|
+
*/
|
|
90
|
+
SandpackFS.fromFileSystemContext = function (
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
|
+
fsContext, remotePortFactory, onWrite) {
|
|
93
|
+
return utils.__awaiter(this, void 0, void 0, function () {
|
|
94
|
+
var instance;
|
|
95
|
+
return utils.__generator(this, function (_a) {
|
|
96
|
+
switch (_a.label) {
|
|
97
|
+
case 0:
|
|
98
|
+
instance = new SandpackFS(fsContext, remotePortFactory, onWrite);
|
|
99
|
+
return [4 /*yield*/, instance.ensureMetaDir()];
|
|
100
|
+
case 1:
|
|
101
|
+
_a.sent();
|
|
102
|
+
return [4 /*yield*/, instance.refreshMetaCache()];
|
|
103
|
+
case 2:
|
|
104
|
+
_a.sent();
|
|
105
|
+
return [2 /*return*/, instance];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
// ------------------------------------------------------------------
|
|
111
|
+
// Core file ops
|
|
112
|
+
// ------------------------------------------------------------------
|
|
113
|
+
/**
|
|
114
|
+
* Return every visible file path (leading `/`). Metadata sidecar and
|
|
115
|
+
* everything under `/.sandpack/` is excluded.
|
|
116
|
+
*/
|
|
117
|
+
SandpackFS.prototype.list = function () {
|
|
118
|
+
return utils.__awaiter(this, void 0, void 0, function () {
|
|
119
|
+
var paths;
|
|
120
|
+
return utils.__generator(this, function (_a) {
|
|
121
|
+
switch (_a.label) {
|
|
122
|
+
case 0:
|
|
123
|
+
paths = [];
|
|
124
|
+
return [4 /*yield*/, this.walk("/", paths)];
|
|
125
|
+
case 1:
|
|
126
|
+
_a.sent();
|
|
127
|
+
paths.sort();
|
|
128
|
+
return [2 /*return*/, paths];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
SandpackFS.prototype.readFile = function (path) {
|
|
134
|
+
return utils.__awaiter(this, void 0, void 0, function () {
|
|
135
|
+
return utils.__generator(this, function (_a) {
|
|
136
|
+
switch (_a.label) {
|
|
137
|
+
case 0: return [4 /*yield*/, this.fsContext.fs.promises.readFile(this.toAbs(path), "utf8")];
|
|
138
|
+
case 1: return [2 /*return*/, (_a.sent())];
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
SandpackFS.prototype.writeFile = function (path, content) {
|
|
144
|
+
return utils.__awaiter(this, void 0, void 0, function () {
|
|
145
|
+
var abs, normalized;
|
|
146
|
+
var _a;
|
|
147
|
+
return utils.__generator(this, function (_b) {
|
|
148
|
+
switch (_b.label) {
|
|
149
|
+
case 0:
|
|
150
|
+
abs = this.toAbs(path);
|
|
151
|
+
return [4 /*yield*/, this.ensureParent(abs)];
|
|
152
|
+
case 1:
|
|
153
|
+
_b.sent();
|
|
154
|
+
return [4 /*yield*/, this.fsContext.fs.promises.writeFile(abs, content)];
|
|
155
|
+
case 2:
|
|
156
|
+
_b.sent();
|
|
157
|
+
normalized = normalize(path);
|
|
158
|
+
this.notify({ path: normalized, external: false });
|
|
159
|
+
// A local editor write — declare it to the host's provenance recorder.
|
|
160
|
+
(_a = this.onWrite) === null || _a === void 0 ? void 0 : _a.call(this, normalized);
|
|
161
|
+
return [2 /*return*/];
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
SandpackFS.prototype.unlink = function (path) {
|
|
167
|
+
return utils.__awaiter(this, void 0, void 0, function () {
|
|
168
|
+
var normalized;
|
|
169
|
+
return utils.__generator(this, function (_a) {
|
|
170
|
+
switch (_a.label) {
|
|
171
|
+
case 0: return [4 /*yield*/, this.fsContext.fs.promises.unlink(this.toAbs(path))];
|
|
172
|
+
case 1:
|
|
173
|
+
_a.sent();
|
|
174
|
+
normalized = normalize(path);
|
|
175
|
+
if (!(normalized in this.metaCache)) return [3 /*break*/, 3];
|
|
176
|
+
delete this.metaCache[normalized];
|
|
177
|
+
return [4 /*yield*/, this.persistMeta()];
|
|
178
|
+
case 2:
|
|
179
|
+
_a.sent();
|
|
180
|
+
_a.label = 3;
|
|
181
|
+
case 3:
|
|
182
|
+
this.notify({ path: normalized, external: false });
|
|
183
|
+
return [2 /*return*/];
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
SandpackFS.prototype.exists = function (path) {
|
|
189
|
+
return utils.__awaiter(this, void 0, void 0, function () {
|
|
190
|
+
return utils.__generator(this, function (_b) {
|
|
191
|
+
switch (_b.label) {
|
|
192
|
+
case 0:
|
|
193
|
+
_b.trys.push([0, 2, , 3]);
|
|
194
|
+
return [4 /*yield*/, this.fsContext.fs.promises.stat(this.toAbs(path))];
|
|
195
|
+
case 1:
|
|
196
|
+
_b.sent();
|
|
197
|
+
return [2 /*return*/, true];
|
|
198
|
+
case 2:
|
|
199
|
+
_b.sent();
|
|
200
|
+
return [2 /*return*/, false];
|
|
201
|
+
case 3: return [2 /*return*/];
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
// ------------------------------------------------------------------
|
|
207
|
+
// Metadata
|
|
208
|
+
// ------------------------------------------------------------------
|
|
209
|
+
SandpackFS.prototype.getAllMetadata = function () {
|
|
210
|
+
return utils.__assign({}, this.metaCache);
|
|
211
|
+
};
|
|
212
|
+
SandpackFS.prototype.getMetadata = function (path) {
|
|
213
|
+
var _a;
|
|
214
|
+
return utils.__assign({}, ((_a = this.metaCache[normalize(path)]) !== null && _a !== void 0 ? _a : {}));
|
|
215
|
+
};
|
|
216
|
+
SandpackFS.prototype.setMetadata = function (path, patch) {
|
|
217
|
+
return utils.__awaiter(this, void 0, void 0, function () {
|
|
218
|
+
var key, next;
|
|
219
|
+
var _a;
|
|
220
|
+
return utils.__generator(this, function (_b) {
|
|
221
|
+
switch (_b.label) {
|
|
222
|
+
case 0:
|
|
223
|
+
key = normalize(path);
|
|
224
|
+
next = utils.__assign(utils.__assign({}, ((_a = this.metaCache[key]) !== null && _a !== void 0 ? _a : {})), patch);
|
|
225
|
+
Object.keys(next).forEach(function (k) {
|
|
226
|
+
if (next[k] === undefined) {
|
|
227
|
+
delete next[k];
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
if (Object.keys(next).length === 0) {
|
|
231
|
+
delete this.metaCache[key];
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
this.metaCache[key] = next;
|
|
235
|
+
}
|
|
236
|
+
return [4 /*yield*/, this.persistMeta()];
|
|
237
|
+
case 1:
|
|
238
|
+
_b.sent();
|
|
239
|
+
this.notify({ path: key, external: false });
|
|
240
|
+
return [2 /*return*/];
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
SandpackFS.prototype.getEnvironment = function () {
|
|
246
|
+
return this.sidecarEnvironment;
|
|
247
|
+
};
|
|
248
|
+
SandpackFS.prototype.setEnvironment = function (environment) {
|
|
249
|
+
return utils.__awaiter(this, void 0, void 0, function () {
|
|
250
|
+
return utils.__generator(this, function (_a) {
|
|
251
|
+
switch (_a.label) {
|
|
252
|
+
case 0:
|
|
253
|
+
this.sidecarEnvironment = environment;
|
|
254
|
+
return [4 /*yield*/, this.persistMeta()];
|
|
255
|
+
case 1:
|
|
256
|
+
_a.sent();
|
|
257
|
+
return [2 /*return*/];
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
SandpackFS.prototype.getMode = function () {
|
|
263
|
+
return this.sidecarMode;
|
|
264
|
+
};
|
|
265
|
+
SandpackFS.prototype.setMode = function (mode) {
|
|
266
|
+
return utils.__awaiter(this, void 0, void 0, function () {
|
|
267
|
+
return utils.__generator(this, function (_a) {
|
|
268
|
+
switch (_a.label) {
|
|
269
|
+
case 0:
|
|
270
|
+
this.sidecarMode = mode;
|
|
271
|
+
return [4 /*yield*/, this.persistMeta()];
|
|
272
|
+
case 1:
|
|
273
|
+
_a.sent();
|
|
274
|
+
return [2 /*return*/];
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
// ------------------------------------------------------------------
|
|
280
|
+
// Change detection
|
|
281
|
+
// ------------------------------------------------------------------
|
|
282
|
+
/**
|
|
283
|
+
* Subscribe to any mutation. Each change carries its `path` and an `external`
|
|
284
|
+
* flag (`true` = written by the child iframe, `false` = a local edit). See
|
|
285
|
+
* {@link SandpackFSChange}.
|
|
286
|
+
*/
|
|
287
|
+
SandpackFS.prototype.onChange = function (cb) {
|
|
288
|
+
var _this = this;
|
|
289
|
+
this.listeners.add(cb);
|
|
290
|
+
return function () {
|
|
291
|
+
_this.listeners.delete(cb);
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Record a write made by the child iframe (relayed from the `attachFS`
|
|
296
|
+
* boundary in the host). Surfaces as an `external` change so the editor can
|
|
297
|
+
* reflect it — distinct from local edits, which never reach here.
|
|
298
|
+
*/
|
|
299
|
+
SandpackFS.prototype.handleRemoteChange = function (path) {
|
|
300
|
+
if (this.disposed)
|
|
301
|
+
return;
|
|
302
|
+
this.notify({ path: normalize(path), external: true });
|
|
303
|
+
};
|
|
304
|
+
// ------------------------------------------------------------------
|
|
305
|
+
// Internals
|
|
306
|
+
// ------------------------------------------------------------------
|
|
307
|
+
SandpackFS.prototype.toAbs = function (path) {
|
|
308
|
+
return normalize(path);
|
|
309
|
+
};
|
|
310
|
+
SandpackFS.prototype.notify = function (change) {
|
|
311
|
+
this.listeners.forEach(function (listener) {
|
|
312
|
+
try {
|
|
313
|
+
listener(change);
|
|
314
|
+
}
|
|
315
|
+
catch (err) {
|
|
316
|
+
console.error("[sandpack-client]: SandpackFS listener threw", err);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
};
|
|
320
|
+
SandpackFS.prototype.ensureMetaDir = function () {
|
|
321
|
+
return utils.__awaiter(this, void 0, void 0, function () {
|
|
322
|
+
return utils.__generator(this, function (_b) {
|
|
323
|
+
switch (_b.label) {
|
|
324
|
+
case 0:
|
|
325
|
+
_b.trys.push([0, 2, , 3]);
|
|
326
|
+
return [4 /*yield*/, this.fsContext.fs.promises.mkdir(META_DIR, {
|
|
327
|
+
recursive: true,
|
|
328
|
+
})];
|
|
329
|
+
case 1:
|
|
330
|
+
_b.sent();
|
|
331
|
+
return [3 /*break*/, 3];
|
|
332
|
+
case 2:
|
|
333
|
+
_b.sent();
|
|
334
|
+
return [3 /*break*/, 3];
|
|
335
|
+
case 3: return [2 /*return*/];
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
};
|
|
340
|
+
SandpackFS.prototype.ensureParent = function (absPath) {
|
|
341
|
+
return utils.__awaiter(this, void 0, void 0, function () {
|
|
342
|
+
var lastSlash, dir;
|
|
343
|
+
return utils.__generator(this, function (_b) {
|
|
344
|
+
switch (_b.label) {
|
|
345
|
+
case 0:
|
|
346
|
+
lastSlash = absPath.lastIndexOf("/");
|
|
347
|
+
if (lastSlash <= 0)
|
|
348
|
+
return [2 /*return*/];
|
|
349
|
+
dir = absPath.slice(0, lastSlash);
|
|
350
|
+
if (!dir || dir === "/")
|
|
351
|
+
return [2 /*return*/];
|
|
352
|
+
_b.label = 1;
|
|
353
|
+
case 1:
|
|
354
|
+
_b.trys.push([1, 3, , 4]);
|
|
355
|
+
return [4 /*yield*/, this.fsContext.fs.promises.mkdir(dir, { recursive: true })];
|
|
356
|
+
case 2:
|
|
357
|
+
_b.sent();
|
|
358
|
+
return [3 /*break*/, 4];
|
|
359
|
+
case 3:
|
|
360
|
+
_b.sent();
|
|
361
|
+
return [3 /*break*/, 4];
|
|
362
|
+
case 4: return [2 /*return*/];
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
SandpackFS.prototype.walk = function (relDir, out) {
|
|
368
|
+
return utils.__awaiter(this, void 0, void 0, function () {
|
|
369
|
+
var absDir, entries, _i, entries_1, entry, relPath, absEntry, isDir, stat;
|
|
370
|
+
return utils.__generator(this, function (_c) {
|
|
371
|
+
switch (_c.label) {
|
|
372
|
+
case 0:
|
|
373
|
+
absDir = this.toAbs(relDir);
|
|
374
|
+
_c.label = 1;
|
|
375
|
+
case 1:
|
|
376
|
+
_c.trys.push([1, 3, , 4]);
|
|
377
|
+
return [4 /*yield*/, this.fsContext.fs.promises.readdir(absDir)];
|
|
378
|
+
case 2:
|
|
379
|
+
entries = (_c.sent());
|
|
380
|
+
return [3 /*break*/, 4];
|
|
381
|
+
case 3:
|
|
382
|
+
_c.sent();
|
|
383
|
+
return [2 /*return*/];
|
|
384
|
+
case 4:
|
|
385
|
+
_i = 0, entries_1 = entries;
|
|
386
|
+
_c.label = 5;
|
|
387
|
+
case 5:
|
|
388
|
+
if (!(_i < entries_1.length)) return [3 /*break*/, 13];
|
|
389
|
+
entry = entries_1[_i];
|
|
390
|
+
relPath = (relDir === "/" ? "" : relDir) + "/" + entry;
|
|
391
|
+
if (relPath.startsWith(META_DIR))
|
|
392
|
+
return [3 /*break*/, 12];
|
|
393
|
+
absEntry = this.toAbs(relPath);
|
|
394
|
+
isDir = false;
|
|
395
|
+
_c.label = 6;
|
|
396
|
+
case 6:
|
|
397
|
+
_c.trys.push([6, 8, , 9]);
|
|
398
|
+
return [4 /*yield*/, this.fsContext.fs.promises.stat(absEntry)];
|
|
399
|
+
case 7:
|
|
400
|
+
stat = _c.sent();
|
|
401
|
+
isDir = stat.isDirectory();
|
|
402
|
+
return [3 /*break*/, 9];
|
|
403
|
+
case 8:
|
|
404
|
+
_c.sent();
|
|
405
|
+
return [3 /*break*/, 12];
|
|
406
|
+
case 9:
|
|
407
|
+
if (!isDir) return [3 /*break*/, 11];
|
|
408
|
+
return [4 /*yield*/, this.walk(relPath, out)];
|
|
409
|
+
case 10:
|
|
410
|
+
_c.sent();
|
|
411
|
+
return [3 /*break*/, 12];
|
|
412
|
+
case 11:
|
|
413
|
+
out.push(relPath);
|
|
414
|
+
_c.label = 12;
|
|
415
|
+
case 12:
|
|
416
|
+
_i++;
|
|
417
|
+
return [3 /*break*/, 5];
|
|
418
|
+
case 13: return [2 /*return*/];
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
};
|
|
423
|
+
SandpackFS.prototype.writeInitial = function (files) {
|
|
424
|
+
return utils.__awaiter(this, void 0, void 0, function () {
|
|
425
|
+
var meta, _i, _a, _b, rawPath, entry, path, abs, fileMeta;
|
|
426
|
+
return utils.__generator(this, function (_c) {
|
|
427
|
+
switch (_c.label) {
|
|
428
|
+
case 0: return [4 /*yield*/, this.ensureMetaDir()];
|
|
429
|
+
case 1:
|
|
430
|
+
_c.sent();
|
|
431
|
+
meta = {};
|
|
432
|
+
_i = 0, _a = Object.entries(files);
|
|
433
|
+
_c.label = 2;
|
|
434
|
+
case 2:
|
|
435
|
+
if (!(_i < _a.length)) return [3 /*break*/, 6];
|
|
436
|
+
_b = _a[_i], rawPath = _b[0], entry = _b[1];
|
|
437
|
+
path = normalize(rawPath);
|
|
438
|
+
abs = this.toAbs(path);
|
|
439
|
+
return [4 /*yield*/, this.ensureParent(abs)];
|
|
440
|
+
case 3:
|
|
441
|
+
_c.sent();
|
|
442
|
+
return [4 /*yield*/, this.fsContext.fs.promises.writeFile(abs, entry.code)];
|
|
443
|
+
case 4:
|
|
444
|
+
_c.sent();
|
|
445
|
+
fileMeta = {};
|
|
446
|
+
if (entry.hidden !== undefined)
|
|
447
|
+
fileMeta.hidden = entry.hidden;
|
|
448
|
+
if (entry.active !== undefined)
|
|
449
|
+
fileMeta.active = entry.active;
|
|
450
|
+
if (entry.readOnly !== undefined)
|
|
451
|
+
fileMeta.readOnly = entry.readOnly;
|
|
452
|
+
if (Object.keys(fileMeta).length > 0)
|
|
453
|
+
meta[path] = fileMeta;
|
|
454
|
+
_c.label = 5;
|
|
455
|
+
case 5:
|
|
456
|
+
_i++;
|
|
457
|
+
return [3 /*break*/, 2];
|
|
458
|
+
case 6:
|
|
459
|
+
this.metaCache = meta;
|
|
460
|
+
return [4 /*yield*/, this.persistMeta()];
|
|
461
|
+
case 7:
|
|
462
|
+
_c.sent();
|
|
463
|
+
return [2 /*return*/];
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
};
|
|
468
|
+
SandpackFS.prototype.persistMeta = function () {
|
|
469
|
+
return utils.__awaiter(this, void 0, void 0, function () {
|
|
470
|
+
var sidecar;
|
|
471
|
+
return utils.__generator(this, function (_a) {
|
|
472
|
+
switch (_a.label) {
|
|
473
|
+
case 0: return [4 /*yield*/, this.ensureMetaDir()];
|
|
474
|
+
case 1:
|
|
475
|
+
_a.sent();
|
|
476
|
+
sidecar = { files: this.metaCache };
|
|
477
|
+
if (this.sidecarEnvironment !== undefined) {
|
|
478
|
+
sidecar.environment = this.sidecarEnvironment;
|
|
479
|
+
}
|
|
480
|
+
if (this.sidecarMode !== undefined) {
|
|
481
|
+
sidecar.mode = this.sidecarMode;
|
|
482
|
+
}
|
|
483
|
+
return [4 /*yield*/, this.fsContext.fs.promises.writeFile(this.toAbs(META_PATH), JSON.stringify(sidecar))];
|
|
484
|
+
case 2:
|
|
485
|
+
_a.sent();
|
|
486
|
+
return [2 /*return*/];
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
};
|
|
491
|
+
SandpackFS.prototype.refreshMetaCache = function () {
|
|
492
|
+
return utils.__awaiter(this, void 0, void 0, function () {
|
|
493
|
+
var raw, parsed;
|
|
494
|
+
return utils.__generator(this, function (_b) {
|
|
495
|
+
switch (_b.label) {
|
|
496
|
+
case 0:
|
|
497
|
+
_b.trys.push([0, 2, , 3]);
|
|
498
|
+
return [4 /*yield*/, this.fsContext.fs.promises.readFile(this.toAbs(META_PATH), "utf8")];
|
|
499
|
+
case 1:
|
|
500
|
+
raw = (_b.sent());
|
|
501
|
+
parsed = JSON.parse(raw);
|
|
502
|
+
if ("files" in parsed && typeof parsed.files === "object") {
|
|
503
|
+
this.metaCache = parsed.files;
|
|
504
|
+
this.sidecarEnvironment = parsed.environment;
|
|
505
|
+
this.sidecarMode = parsed.mode;
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
// Legacy format: plain FileMetaMap
|
|
509
|
+
this.metaCache = parsed;
|
|
510
|
+
}
|
|
511
|
+
return [3 /*break*/, 3];
|
|
512
|
+
case 2:
|
|
513
|
+
_b.sent();
|
|
514
|
+
this.metaCache = {};
|
|
515
|
+
return [3 /*break*/, 3];
|
|
516
|
+
case 3: return [2 /*return*/];
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
};
|
|
521
|
+
return SandpackFS;
|
|
522
|
+
}());
|
|
523
|
+
|
|
524
|
+
exports.SandpackLogLevel = void 0;
|
|
525
|
+
(function (SandpackLogLevel) {
|
|
526
|
+
SandpackLogLevel[SandpackLogLevel["None"] = 0] = "None";
|
|
527
|
+
SandpackLogLevel[SandpackLogLevel["Error"] = 10] = "Error";
|
|
528
|
+
SandpackLogLevel[SandpackLogLevel["Warning"] = 20] = "Warning";
|
|
529
|
+
SandpackLogLevel[SandpackLogLevel["Info"] = 30] = "Info";
|
|
530
|
+
SandpackLogLevel[SandpackLogLevel["Debug"] = 40] = "Debug";
|
|
531
|
+
})(exports.SandpackLogLevel || (exports.SandpackLogLevel = {}));
|
|
532
|
+
|
|
533
|
+
exports.META_PATH = META_PATH;
|
|
534
|
+
exports.SandpackFS = SandpackFS;
|