@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,250 @@
1
+ import { invariant } from 'outvariant';
2
+
3
+ /******************************************************************************
4
+ Copyright (c) Microsoft Corporation.
5
+
6
+ Permission to use, copy, modify, and/or distribute this software for any
7
+ purpose with or without fee is hereby granted.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
16
+ ***************************************************************************** */
17
+ /* globalThis Reflect, Promise, SuppressedError, Symbol, Iterator */
18
+
19
+ var extendStatics = function(d, b) {
20
+ extendStatics = Object.setPrototypeOf ||
21
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
22
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
23
+ return extendStatics(d, b);
24
+ };
25
+
26
+ function __extends(d, b) {
27
+ if (typeof b !== "function" && b !== null)
28
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29
+ extendStatics(d, b);
30
+ function __() { this.constructor = d; }
31
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
32
+ }
33
+
34
+ var __assign = function() {
35
+ __assign = Object.assign || function __assign(t) {
36
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
37
+ s = arguments[i];
38
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
39
+ }
40
+ return t;
41
+ };
42
+ return __assign.apply(this, arguments);
43
+ };
44
+
45
+ function __rest(s, e) {
46
+ var t = {};
47
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
48
+ t[p] = s[p];
49
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
50
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
51
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
52
+ t[p[i]] = s[p[i]];
53
+ }
54
+ return t;
55
+ }
56
+
57
+ function __awaiter(thisArg, _arguments, P, generator) {
58
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
59
+ return new (P || (P = Promise))(function (resolve, reject) {
60
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
61
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
62
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
63
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
64
+ });
65
+ }
66
+
67
+ function __generator(thisArg, body) {
68
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
69
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
70
+ function verb(n) { return function (v) { return step([n, v]); }; }
71
+ function step(op) {
72
+ if (f) throw new TypeError("Generator is already executing.");
73
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
74
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
75
+ if (y = 0, t) op = [op[0] & 2, t.value];
76
+ switch (op[0]) {
77
+ case 0: case 1: t = op; break;
78
+ case 4: _.label++; return { value: op[1], done: false };
79
+ case 5: _.label++; y = op[1]; op = [0]; continue;
80
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
81
+ default:
82
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
83
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
84
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
85
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
86
+ if (t[2]) _.ops.pop();
87
+ _.trys.pop(); continue;
88
+ }
89
+ op = body.call(thisArg, _);
90
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
91
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
92
+ }
93
+ }
94
+
95
+ function __spreadArray(to, from, pack) {
96
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
97
+ if (ar || !(i in from)) {
98
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
99
+ ar[i] = from[i];
100
+ }
101
+ }
102
+ return to.concat(ar || Array.prototype.slice.call(from));
103
+ }
104
+
105
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
106
+ var e = new Error(message);
107
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
108
+ };
109
+
110
+ var createError = function (message) {
111
+ return "[sandpack-client]: ".concat(message);
112
+ };
113
+ function nullthrows(value, err) {
114
+ if (err === void 0) { err = "Value is nullish"; }
115
+ invariant(value != null, createError(err));
116
+ return value;
117
+ }
118
+ var DEPENDENCY_ERROR_MESSAGE = "\"dependencies\" was not specified - provide either a package.json or a \"dependencies\" value";
119
+ var ENTRY_ERROR_MESSAGE = "\"entry\" was not specified - provide either a package.json with the \"main\" field or an \"entry\" value";
120
+ function createPackageJSON(dependencies, devDependencies, entry) {
121
+ if (dependencies === void 0) { dependencies = {}; }
122
+ if (devDependencies === void 0) { devDependencies = {}; }
123
+ if (entry === void 0) { entry = "/index.js"; }
124
+ return JSON.stringify({
125
+ name: "sandpack-project",
126
+ main: entry,
127
+ dependencies: dependencies,
128
+ devDependencies: devDependencies,
129
+ }, null, 2);
130
+ }
131
+ /**
132
+ * Ensures a `/package.json` exists inside a plain {@link SandpackFilesInput}
133
+ * map (pre-filesystem), merging any supplied dependency / entry overrides.
134
+ * Useful in pure planners like `getSandpackStateFromProps` so callers can decide
135
+ * what to seed the filesystem with before any I/O happens.
136
+ *
137
+ * (The former filesystem-mutating variant `addPackageJSONIfNeeded(fs, …)` was
138
+ * removed with BOOT_SCAFFOLDING_SPEC §3: the resolved package.json is delivered
139
+ * to the bundler out-of-band, so no synthesized copy is written into the CoW.)
140
+ */
141
+ function addPackageJSONIfNeededToMap(files, dependencies, devDependencies, entry) {
142
+ var _a, _b;
143
+ var next = __assign({}, files);
144
+ if (!next["/package.json"]) {
145
+ nullthrows(dependencies, DEPENDENCY_ERROR_MESSAGE);
146
+ nullthrows(entry, ENTRY_ERROR_MESSAGE);
147
+ next["/package.json"] = {
148
+ code: createPackageJSON(dependencies, devDependencies, entry),
149
+ };
150
+ return next;
151
+ }
152
+ var pkg = JSON.parse(next["/package.json"].code);
153
+ if (!dependencies && !pkg.dependencies) {
154
+ throw new Error(createError(ENTRY_ERROR_MESSAGE));
155
+ }
156
+ if (dependencies) {
157
+ pkg.dependencies = __assign(__assign({}, ((_a = pkg.dependencies) !== null && _a !== void 0 ? _a : {})), dependencies);
158
+ }
159
+ if (devDependencies) {
160
+ pkg.devDependencies = __assign(__assign({}, ((_b = pkg.devDependencies) !== null && _b !== void 0 ? _b : {})), devDependencies);
161
+ }
162
+ if (entry) {
163
+ pkg.main = entry;
164
+ }
165
+ next["/package.json"] = { code: JSON.stringify(pkg, null, 2) };
166
+ return next;
167
+ }
168
+ function extractErrorDetails(msg) {
169
+ var _a;
170
+ if (msg.title === "SyntaxError") {
171
+ var title = msg.title, path = msg.path, message = msg.message, line = msg.line, column = msg.column;
172
+ return { title: title, path: path, message: message, line: line, column: column };
173
+ }
174
+ var relevantStackFrame = getRelevantStackFrame((_a = msg.payload) === null || _a === void 0 ? void 0 : _a.frames);
175
+ if (!relevantStackFrame) {
176
+ return { message: msg.message };
177
+ }
178
+ var errorInCode = getErrorInOriginalCode(relevantStackFrame);
179
+ var errorLocation = getErrorLocation(relevantStackFrame);
180
+ var errorMessage = formatErrorMessage(relevantStackFrame._originalFileName, msg.message, errorLocation, errorInCode);
181
+ return {
182
+ message: errorMessage,
183
+ title: msg.title,
184
+ path: relevantStackFrame._originalFileName,
185
+ line: relevantStackFrame._originalLineNumber,
186
+ column: relevantStackFrame._originalColumnNumber,
187
+ };
188
+ }
189
+ function getRelevantStackFrame(frames) {
190
+ if (!frames) {
191
+ return;
192
+ }
193
+ return frames.find(function (frame) { return !!frame._originalFileName; });
194
+ }
195
+ function getErrorLocation(errorFrame) {
196
+ return errorFrame
197
+ ? " (".concat(errorFrame._originalLineNumber, ":").concat(errorFrame._originalColumnNumber, ")")
198
+ : "";
199
+ }
200
+ function getErrorInOriginalCode(errorFrame) {
201
+ var lastScriptLine = errorFrame._originalScriptCode[errorFrame._originalScriptCode.length - 1];
202
+ var numberOfLineNumberCharacters = lastScriptLine.lineNumber.toString().length;
203
+ var leadingCharacterOffset = 2;
204
+ var barSeparatorCharacterOffset = 3;
205
+ var extraLineLeadingSpaces = leadingCharacterOffset +
206
+ numberOfLineNumberCharacters +
207
+ barSeparatorCharacterOffset +
208
+ errorFrame._originalColumnNumber;
209
+ return errorFrame._originalScriptCode.reduce(function (result, scriptLine) {
210
+ var leadingChar = scriptLine.highlight ? ">" : " ";
211
+ var lineNumber = scriptLine.lineNumber.toString().length === numberOfLineNumberCharacters
212
+ ? "".concat(scriptLine.lineNumber)
213
+ : " ".concat(scriptLine.lineNumber);
214
+ var extraLine = scriptLine.highlight
215
+ ? "\n" + " ".repeat(extraLineLeadingSpaces) + "^"
216
+ : "";
217
+ return (result + // accumulator
218
+ "\n" +
219
+ leadingChar + // > or " "
220
+ " " +
221
+ lineNumber + // line number on equal number of characters
222
+ " | " +
223
+ scriptLine.content + // code
224
+ extraLine // line under the highlighed line to show the column index
225
+ );
226
+ }, "");
227
+ }
228
+ function formatErrorMessage(filePath, message, location, errorInCode) {
229
+ return "".concat(filePath, ": ").concat(message).concat(location, "\n").concat(errorInCode);
230
+ }
231
+ /* eslint-disable @typescript-eslint/no-explicit-any */
232
+ var normalizePath = function (path) {
233
+ if (typeof path === "string") {
234
+ return (path.startsWith("/") ? path : "/".concat(path));
235
+ }
236
+ if (Array.isArray(path)) {
237
+ return path.map(function (p) { return (p.startsWith("/") ? p : "/".concat(p)); });
238
+ }
239
+ if (typeof path === "object" && path !== null) {
240
+ return Object.entries(path).reduce(function (acc, _a) {
241
+ var key = _a[0], content = _a[1];
242
+ var fileName = key.startsWith("/") ? key : "/".concat(key);
243
+ acc[fileName] = content;
244
+ return acc;
245
+ }, {});
246
+ }
247
+ return null;
248
+ };
249
+
250
+ export { __awaiter as _, __generator as a, addPackageJSONIfNeededToMap as b, createError as c, createPackageJSON as d, extractErrorDetails as e, nullthrows as f, __extends as g, __assign as h, __rest as i, __spreadArray as j, normalizePath as n };
@@ -0,0 +1,18 @@
1
+ import type { SandpackFilesInput } from "./fs/SandpackFS";
2
+ import type { Dependencies, SandpackErrorMessage, SandpackError } from "./types";
3
+ export declare const createError: (message: string) => string;
4
+ export declare function nullthrows<T>(value?: T | null, err?: string): T;
5
+ export declare function createPackageJSON(dependencies?: Dependencies, devDependencies?: Dependencies, entry?: string): string;
6
+ /**
7
+ * Ensures a `/package.json` exists inside a plain {@link SandpackFilesInput}
8
+ * map (pre-filesystem), merging any supplied dependency / entry overrides.
9
+ * Useful in pure planners like `getSandpackStateFromProps` so callers can decide
10
+ * what to seed the filesystem with before any I/O happens.
11
+ *
12
+ * (The former filesystem-mutating variant `addPackageJSONIfNeeded(fs, …)` was
13
+ * removed with BOOT_SCAFFOLDING_SPEC §3: the resolved package.json is delivered
14
+ * to the bundler out-of-band, so no synthesized copy is written into the CoW.)
15
+ */
16
+ export declare function addPackageJSONIfNeededToMap(files: SandpackFilesInput, dependencies?: Dependencies, devDependencies?: Dependencies, entry?: string): SandpackFilesInput;
17
+ export declare function extractErrorDetails(msg: SandpackErrorMessage): SandpackError;
18
+ export declare const normalizePath: <R>(path: R) => R;
package/dist/utils.js ADDED
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var utils = require('./utils-BiVyytui.js');
4
+ require('outvariant');
5
+
6
+
7
+
8
+ exports.addPackageJSONIfNeededToMap = utils.addPackageJSONIfNeededToMap;
9
+ exports.createError = utils.createError;
10
+ exports.createPackageJSON = utils.createPackageJSON;
11
+ exports.extractErrorDetails = utils.extractErrorDetails;
12
+ exports.normalizePath = utils.normalizePath;
13
+ exports.nullthrows = utils.nullthrows;
package/dist/utils.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export { b as addPackageJSONIfNeededToMap, c as createError, d as createPackageJSON, e as extractErrorDetails, n as normalizePath, f as nullthrows } from './utils-DG1HA4RZ.mjs';
2
+ import 'outvariant';
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@immediately-run/sandpack-client",
3
+ "version": "2.19.8",
4
+ "description": "",
5
+ "keywords": [],
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/immediately-run/immediately-run-sandpack.git",
9
+ "directory": "sandpack-client"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "license": "Apache-2.0",
15
+ "author": "CodeSandbox",
16
+ "sideEffects": false,
17
+ "main": "./dist/index.js",
18
+ "module": "./dist/index.mjs",
19
+ "types": "./dist/index.d.ts",
20
+ "exports": {
21
+ "./clients/runtime": {
22
+ "types": "./dist/clients/runtime/index.d.ts",
23
+ "import": "./dist/clients/runtime/index.mjs",
24
+ "require": "./dist/clients/runtime/index.js"
25
+ },
26
+ "./clients/node": {
27
+ "types": "./dist/clients/node/index.d.ts",
28
+ "import": "./dist/clients/node/index.mjs",
29
+ "require": "./dist/clients/node/index.js"
30
+ },
31
+ "./clients/static": {
32
+ "types": "./dist/clients/static/index.d.ts",
33
+ "import": "./dist/clients/static/index.mjs",
34
+ "require": "./dist/clients/static/index.js"
35
+ },
36
+ "./utils": {
37
+ "types": "./dist/utils.d.ts",
38
+ "import": "./dist/utils.mjs",
39
+ "require": "./dist/utils.js"
40
+ },
41
+ ".": {
42
+ "types": "./dist/index.d.ts",
43
+ "import": "./dist/index.mjs",
44
+ "require": "./dist/index.js"
45
+ }
46
+ },
47
+ "scripts": {
48
+ "clean": "rm -rf dist sandpack src/clients/node/inject-scripts/dist",
49
+ "prebuild": "yarn run clean",
50
+ "test": "jest . --transformIgnorePatterns \"node_modules/(?!@zenfs)/\"",
51
+ "lint": "eslint '**/*.ts?(x)' --fix",
52
+ "build": "rollup -c --bundleConfigAsCjs",
53
+ "build:publish": "yarn build && gulp",
54
+ "build:bundler": "gulp",
55
+ "format": "prettier --write '**/*.{ts,tsx,js,jsx}'",
56
+ "format:check": "prettier --check '**/*.{ts,tsx}'",
57
+ "dev": "yarn build -- --watch"
58
+ },
59
+ "files": [
60
+ "dist",
61
+ "esm",
62
+ "sandpack",
63
+ "package.json",
64
+ "README.md"
65
+ ],
66
+ "dependencies": {
67
+ "@codesandbox/nodebox": "0.1.8",
68
+ "@zenfs/core": "~2.3.11",
69
+ "buffer": "^6.0.3",
70
+ "dequal": "^2.0.3",
71
+ "mime-db": "^1.53.0",
72
+ "outvariant": "^1.4.3",
73
+ "static-browser-server": "1.0.3"
74
+ },
75
+ "devDependencies": {
76
+ "@types/mime-db": "^1.43.6",
77
+ "@types/node": "^22.10.2",
78
+ "del": "^6.1.1",
79
+ "gulp": "^5.0.0",
80
+ "typescript": "^5.7.2"
81
+ }
82
+ }