@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
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import type { SandpackNodeMessage } from "./clients/node/types";
|
|
2
|
+
import type { SandpackRuntimeMessage } from "./clients/runtime/types";
|
|
3
|
+
import type { SandpackFS } from "./fs/SandpackFS";
|
|
4
|
+
/**
|
|
5
|
+
* Host-pinned SDK artifact integrity (SDK_PACKAGING_SPEC §5.2), keyed
|
|
6
|
+
* module → concrete version → `{ relPath: 'sha384-<base64>' }`. The host (the
|
|
7
|
+
* TCB) supplies it; the runtime client forwards it verbatim into the
|
|
8
|
+
* register-frame handshake, and the bundler verifies fetched SDK bytes against
|
|
9
|
+
* it BEFORE evaluation, failing the boot closed on any mismatch. Absent ⇒
|
|
10
|
+
* verification is skipped (the pin is not wired) rather than self-attesting
|
|
11
|
+
* against the origin's own manifest.
|
|
12
|
+
*/
|
|
13
|
+
export type SdkIntegrity = Record<string, Record<string, Record<string, string>>>;
|
|
14
|
+
export interface ClientOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Paths to external resources
|
|
17
|
+
*/
|
|
18
|
+
externalResources?: string[];
|
|
19
|
+
/**
|
|
20
|
+
* Location of the bundler.
|
|
21
|
+
*/
|
|
22
|
+
bundlerURL?: string;
|
|
23
|
+
/**
|
|
24
|
+
* URL of the Babel transpiler worker script, served **same-origin with the
|
|
25
|
+
* parent page** (not the bundler origin). The runtime client spawns this
|
|
26
|
+
* worker itself and connects it to the sandboxed iframe over a `MessagePort`,
|
|
27
|
+
* so the iframe no longer needs to load a worker (and can drop
|
|
28
|
+
* `allow-same-origin`). Required for the runtime client to transpile.
|
|
29
|
+
*/
|
|
30
|
+
babelWorkerURL?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Level of logging to do in the bundler
|
|
33
|
+
*/
|
|
34
|
+
logLevel?: SandpackLogLevel;
|
|
35
|
+
/**
|
|
36
|
+
* Relative path that the iframe loads (eg: /about)
|
|
37
|
+
*/
|
|
38
|
+
startRoute?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Width of iframe.
|
|
41
|
+
*/
|
|
42
|
+
width?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Height of iframe.
|
|
45
|
+
*/
|
|
46
|
+
height?: string;
|
|
47
|
+
/**
|
|
48
|
+
* If we should skip the third step: evaluation.
|
|
49
|
+
*/
|
|
50
|
+
skipEval?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Boolean flags to trigger certain UI elements in the bundler
|
|
53
|
+
*/
|
|
54
|
+
showOpenInCodeSandbox?: boolean;
|
|
55
|
+
showErrorScreen?: boolean;
|
|
56
|
+
showLoadingScreen?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* The bundler will clear the console if you set this to true, everytime the iframe refreshes / starts the first compile
|
|
59
|
+
*/
|
|
60
|
+
clearConsoleOnFirstCompile?: boolean;
|
|
61
|
+
reactDevTools?: ReactDevToolsMode;
|
|
62
|
+
/**
|
|
63
|
+
* The custom private npm registry setting makes it possible
|
|
64
|
+
* to retrieve npm packages from your own npm registry.
|
|
65
|
+
*/
|
|
66
|
+
customNpmRegistries?: NpmRegistry[];
|
|
67
|
+
/**
|
|
68
|
+
* CodeSandbox sandbox id: used internally by codesandbox
|
|
69
|
+
*/
|
|
70
|
+
sandboxId?: string;
|
|
71
|
+
/**
|
|
72
|
+
* CodeSandbox team id: with this information, bundler can connect to CodeSandbox
|
|
73
|
+
* and unlock a few capabilities
|
|
74
|
+
*/
|
|
75
|
+
teamId?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Enable the service worker feature for sandpack-bundler
|
|
78
|
+
*/
|
|
79
|
+
experimental_enableServiceWorker?: boolean;
|
|
80
|
+
experimental_stableServiceWorkerId?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Host-pinned SDK artifact integrity hashes (SDK_PACKAGING_SPEC §5.2).
|
|
83
|
+
* Forwarded verbatim into the register-frame handshake; the bundler verifies
|
|
84
|
+
* fetched SDK bytes against it before evaluation. Absent ⇒ verification
|
|
85
|
+
* skipped.
|
|
86
|
+
*/
|
|
87
|
+
sdkIntegrity?: SdkIntegrity;
|
|
88
|
+
/**
|
|
89
|
+
* The dirty set (PRETRANSPILED_ARTIFACTS_SPEC §5.2): repo-relative paths in the
|
|
90
|
+
* COW writable layer (edited in a previous session) plus the journal's deleted
|
|
91
|
+
* set. Forwarded verbatim into the register-frame handshake so the bundler
|
|
92
|
+
* never seeds a pre-transpiled artifact for a path whose `/app` content no
|
|
93
|
+
* longer matches the zip. Absent ⇒ nothing dirty.
|
|
94
|
+
*/
|
|
95
|
+
dirtyPaths?: string[];
|
|
96
|
+
/**
|
|
97
|
+
* R3-49b ZenFS batch hydration: a bulk snapshot of the mounted tree (`/app`
|
|
98
|
+
* source + bundled `/node_modules` package msgpack) forwarded verbatim into the
|
|
99
|
+
* register-frame handshake. The bundler hydrates its read caches before the first
|
|
100
|
+
* compile so reads come from memory instead of one Port round-trip per file
|
|
101
|
+
* (`loadNodeModules` — ~99% of cold boot). Absent ⇒ reads cross the Port as before.
|
|
102
|
+
*/
|
|
103
|
+
fsSnapshot?: FsSnapshot;
|
|
104
|
+
/**
|
|
105
|
+
* The chrome region this app instance occupies, e.g. `"panel.agent"` or
|
|
106
|
+
* `"stage.conversation"` (R3-114). Forwarded verbatim into the register-frame
|
|
107
|
+
* handshake so the bundler can surface it on the `__immediatelyRun__` runtime
|
|
108
|
+
* global for the SDK's `getRegion()`/`useRegion()`. Descriptive only — it grants
|
|
109
|
+
* and gates nothing. Absent ⇒ the app reads no region (`getRegion()` → null).
|
|
110
|
+
*/
|
|
111
|
+
region?: string;
|
|
112
|
+
}
|
|
113
|
+
/** A batch-hydration snapshot entry list: each entry is a sandbox `/app`-rooted path
|
|
114
|
+
* + its content (text for source, bytes for the bundled package msgpack). R3-49b. */
|
|
115
|
+
export type FsSnapshot = Array<{
|
|
116
|
+
path: string;
|
|
117
|
+
content: string | Uint8Array;
|
|
118
|
+
}>;
|
|
119
|
+
export interface SandboxSetup {
|
|
120
|
+
/**
|
|
121
|
+
* The Sandpack filesystem used as the source of truth for file contents and
|
|
122
|
+
* UI metadata. Create one via {@link SandpackFS.fromFiles} or
|
|
123
|
+
* {@link SandpackFS.fromFileSystem}.
|
|
124
|
+
*/
|
|
125
|
+
fs: SandpackFS;
|
|
126
|
+
dependencies?: Dependencies;
|
|
127
|
+
devDependencies?: Dependencies;
|
|
128
|
+
entry?: string;
|
|
129
|
+
/**
|
|
130
|
+
* What template we use, if not defined we infer the template from the dependencies or files.
|
|
131
|
+
*
|
|
132
|
+
*/
|
|
133
|
+
template?: SandpackTemplate;
|
|
134
|
+
/**
|
|
135
|
+
* Only use unpkg for fetching the dependencies, no preprocessing. It's slower, but doesn't talk
|
|
136
|
+
* to AWS.
|
|
137
|
+
*/
|
|
138
|
+
disableDependencyPreprocessing?: boolean;
|
|
139
|
+
}
|
|
140
|
+
export interface Module {
|
|
141
|
+
code: string;
|
|
142
|
+
path: string;
|
|
143
|
+
}
|
|
144
|
+
export type Modules = Record<string, {
|
|
145
|
+
code: string;
|
|
146
|
+
path: string;
|
|
147
|
+
}>;
|
|
148
|
+
export type Dependencies = Record<string, string>;
|
|
149
|
+
export type ReactDevToolsMode = "latest" | "legacy";
|
|
150
|
+
export interface ModuleSource {
|
|
151
|
+
fileName: string;
|
|
152
|
+
compiledCode: string;
|
|
153
|
+
sourceMap: unknown | undefined;
|
|
154
|
+
}
|
|
155
|
+
export declare enum SandpackLogLevel {
|
|
156
|
+
None = 0,
|
|
157
|
+
Error = 10,
|
|
158
|
+
Warning = 20,
|
|
159
|
+
Info = 30,
|
|
160
|
+
Debug = 40
|
|
161
|
+
}
|
|
162
|
+
export interface ErrorStackFrame {
|
|
163
|
+
columnNumber: number;
|
|
164
|
+
fileName: string;
|
|
165
|
+
functionName: string;
|
|
166
|
+
lineNumber: number;
|
|
167
|
+
_originalColumnNumber: number;
|
|
168
|
+
_originalFileName: string;
|
|
169
|
+
_originalFunctionName: string;
|
|
170
|
+
_originalLineNumber: number;
|
|
171
|
+
_originalScriptCode: Array<{
|
|
172
|
+
lineNumber: number;
|
|
173
|
+
content: string;
|
|
174
|
+
highlight: boolean;
|
|
175
|
+
}>;
|
|
176
|
+
}
|
|
177
|
+
export interface TranspiledModule {
|
|
178
|
+
module: Module;
|
|
179
|
+
query: string;
|
|
180
|
+
source: ModuleSource | undefined;
|
|
181
|
+
assets: Record<string, ModuleSource>;
|
|
182
|
+
isEntry: boolean;
|
|
183
|
+
isTestFile: boolean;
|
|
184
|
+
childModules: string[];
|
|
185
|
+
/**
|
|
186
|
+
* All extra modules emitted by the loader
|
|
187
|
+
*/
|
|
188
|
+
emittedAssets: ModuleSource[];
|
|
189
|
+
initiators: string[];
|
|
190
|
+
dependencies: string[];
|
|
191
|
+
asyncDependencies: string[];
|
|
192
|
+
transpilationDependencies: string[];
|
|
193
|
+
transpilationInitiators: string[];
|
|
194
|
+
}
|
|
195
|
+
export interface BundlerState {
|
|
196
|
+
entry: string;
|
|
197
|
+
transpiledModules: Record<string, TranspiledModule>;
|
|
198
|
+
}
|
|
199
|
+
export type SandpackMessage = SandpackRuntimeMessage | SandpackNodeMessage;
|
|
200
|
+
export type ListenerFunction = (msg: SandpackMessage) => void;
|
|
201
|
+
export type UnsubscribeFunction = () => void;
|
|
202
|
+
export type Listen = (listener: ListenerFunction, clientId?: string) => UnsubscribeFunction;
|
|
203
|
+
export type Dispatch = (msg: SandpackMessage, clientId?: string) => void;
|
|
204
|
+
export interface SandpackError {
|
|
205
|
+
message: string;
|
|
206
|
+
line?: number;
|
|
207
|
+
column?: number;
|
|
208
|
+
path?: string;
|
|
209
|
+
title?: string;
|
|
210
|
+
}
|
|
211
|
+
export interface SandpackErrorMessage {
|
|
212
|
+
title: string;
|
|
213
|
+
path: string;
|
|
214
|
+
message: string;
|
|
215
|
+
line: number;
|
|
216
|
+
column: number;
|
|
217
|
+
payload: {
|
|
218
|
+
frames?: ErrorStackFrame[];
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
export type ClientStatus = "initializing" | "installing-dependencies" | "transpiling" | "evaluating" | "running-tests" | "idle" | "done";
|
|
222
|
+
export type SandpackMessageConsoleMethods = "log" | "debug" | "info" | "warn" | "error" | "table" | "clear" | "time" | "timeEnd" | "count" | "assert";
|
|
223
|
+
export interface BaseSandpackMessage {
|
|
224
|
+
type: string;
|
|
225
|
+
$id?: number;
|
|
226
|
+
codesandbox?: boolean;
|
|
227
|
+
/**
|
|
228
|
+
* Transferable objects (e.g. a `MessagePort`) to hand to the iframe alongside
|
|
229
|
+
* this message. Stripped from the payload and passed as the `postMessage`
|
|
230
|
+
* transfer list by `IFrameProtocol.dispatch`. Used by `mount-add` to share a
|
|
231
|
+
* mount's filesystem port with the sandbox.
|
|
232
|
+
*/
|
|
233
|
+
_transfer?: Transferable[];
|
|
234
|
+
}
|
|
235
|
+
export interface BaseProtocolMessage {
|
|
236
|
+
type: string;
|
|
237
|
+
msgId: string;
|
|
238
|
+
}
|
|
239
|
+
export interface ProtocolErrorMessage extends BaseProtocolMessage {
|
|
240
|
+
error: {
|
|
241
|
+
message: string;
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
export interface ProtocolResultMessage extends BaseProtocolMessage {
|
|
245
|
+
result: any;
|
|
246
|
+
}
|
|
247
|
+
export interface ProtocolRequestMessage extends BaseProtocolMessage {
|
|
248
|
+
method: string;
|
|
249
|
+
params: any[];
|
|
250
|
+
}
|
|
251
|
+
export interface NpmRegistry {
|
|
252
|
+
enabledScopes: string[];
|
|
253
|
+
limitToScopes: boolean;
|
|
254
|
+
registryUrl: string;
|
|
255
|
+
/**
|
|
256
|
+
* It must be `false` if you're providing a sef-host solution,
|
|
257
|
+
* otherwise, it'll try to proxy from CodeSandbox Proxy
|
|
258
|
+
*/
|
|
259
|
+
proxyEnabled: boolean;
|
|
260
|
+
registryAuthToken?: string;
|
|
261
|
+
}
|
|
262
|
+
type TestStatus = "running" | "pass" | "fail";
|
|
263
|
+
export type TestError = Error & {
|
|
264
|
+
matcherResult?: boolean;
|
|
265
|
+
mappedErrors?: Array<{
|
|
266
|
+
fileName: string;
|
|
267
|
+
_originalFunctionName: string;
|
|
268
|
+
_originalColumnNumber: number;
|
|
269
|
+
_originalLineNumber: number;
|
|
270
|
+
_originalScriptCode: Array<{
|
|
271
|
+
lineNumber: number;
|
|
272
|
+
content: string;
|
|
273
|
+
highlight: boolean;
|
|
274
|
+
}> | null;
|
|
275
|
+
}>;
|
|
276
|
+
};
|
|
277
|
+
export interface Test {
|
|
278
|
+
name: string;
|
|
279
|
+
blocks: string[];
|
|
280
|
+
status: TestStatus;
|
|
281
|
+
path: string;
|
|
282
|
+
errors: TestError[];
|
|
283
|
+
duration?: number | undefined;
|
|
284
|
+
}
|
|
285
|
+
export type SandboxTestMessage = RunAllTests | RunTests | ClearJestErrors | ({
|
|
286
|
+
type: "test";
|
|
287
|
+
} & (InitializedTestsMessage | TestCountMessage | TotalTestStartMessage | TotalTestEndMessage | AddFileMessage | RemoveFileMessage | FileErrorMessage | DescribeStartMessage | DescribeEndMessage | AddTestMessage | TestStartMessage | TestEndMessage));
|
|
288
|
+
interface InitializedTestsMessage {
|
|
289
|
+
event: "initialize_tests";
|
|
290
|
+
}
|
|
291
|
+
interface ClearJestErrors {
|
|
292
|
+
type: "action";
|
|
293
|
+
action: "clear-errors";
|
|
294
|
+
source: "jest";
|
|
295
|
+
path: string;
|
|
296
|
+
}
|
|
297
|
+
interface TestCountMessage {
|
|
298
|
+
event: "test_count";
|
|
299
|
+
count: number;
|
|
300
|
+
}
|
|
301
|
+
interface TotalTestStartMessage {
|
|
302
|
+
event: "total_test_start";
|
|
303
|
+
}
|
|
304
|
+
interface TotalTestEndMessage {
|
|
305
|
+
event: "total_test_end";
|
|
306
|
+
}
|
|
307
|
+
interface AddFileMessage {
|
|
308
|
+
event: "add_file";
|
|
309
|
+
path: string;
|
|
310
|
+
}
|
|
311
|
+
interface RemoveFileMessage {
|
|
312
|
+
event: "remove_file";
|
|
313
|
+
path: string;
|
|
314
|
+
}
|
|
315
|
+
interface FileErrorMessage {
|
|
316
|
+
event: "file_error";
|
|
317
|
+
path: string;
|
|
318
|
+
error: TestError;
|
|
319
|
+
}
|
|
320
|
+
interface DescribeStartMessage {
|
|
321
|
+
event: "describe_start";
|
|
322
|
+
blockName: string;
|
|
323
|
+
}
|
|
324
|
+
interface DescribeEndMessage {
|
|
325
|
+
event: "describe_end";
|
|
326
|
+
}
|
|
327
|
+
interface AddTestMessage {
|
|
328
|
+
event: "add_test";
|
|
329
|
+
testName: string;
|
|
330
|
+
path: string;
|
|
331
|
+
}
|
|
332
|
+
interface TestStartMessage {
|
|
333
|
+
event: "test_start";
|
|
334
|
+
test: Test;
|
|
335
|
+
}
|
|
336
|
+
interface TestEndMessage {
|
|
337
|
+
event: "test_end";
|
|
338
|
+
test: Test;
|
|
339
|
+
}
|
|
340
|
+
interface RunAllTests {
|
|
341
|
+
type: "run-all-tests";
|
|
342
|
+
}
|
|
343
|
+
interface RunTests {
|
|
344
|
+
type: "run-tests";
|
|
345
|
+
path: string;
|
|
346
|
+
}
|
|
347
|
+
export type SandpackTemplate = "angular-cli" | "create-react-app" | "create-react-app-typescript" | "svelte" | "parcel" | "vue-cli" | "static" | "solid" | "nextjs" | "node";
|
|
348
|
+
export {};
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var outvariant = require('outvariant');
|
|
4
|
+
|
|
5
|
+
/******************************************************************************
|
|
6
|
+
Copyright (c) Microsoft Corporation.
|
|
7
|
+
|
|
8
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
9
|
+
purpose with or without fee is hereby granted.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
+
***************************************************************************** */
|
|
19
|
+
/* globalThis Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
20
|
+
|
|
21
|
+
var extendStatics = function(d, b) {
|
|
22
|
+
extendStatics = Object.setPrototypeOf ||
|
|
23
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
24
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
25
|
+
return extendStatics(d, b);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function __extends(d, b) {
|
|
29
|
+
if (typeof b !== "function" && b !== null)
|
|
30
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
31
|
+
extendStatics(d, b);
|
|
32
|
+
function __() { this.constructor = d; }
|
|
33
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
exports.__assign = function() {
|
|
37
|
+
exports.__assign = Object.assign || function __assign(t) {
|
|
38
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
39
|
+
s = arguments[i];
|
|
40
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
41
|
+
}
|
|
42
|
+
return t;
|
|
43
|
+
};
|
|
44
|
+
return exports.__assign.apply(this, arguments);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function __rest(s, e) {
|
|
48
|
+
var t = {};
|
|
49
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
50
|
+
t[p] = s[p];
|
|
51
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
52
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
53
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
54
|
+
t[p[i]] = s[p[i]];
|
|
55
|
+
}
|
|
56
|
+
return t;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
60
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
61
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
62
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
63
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
64
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
65
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function __generator(thisArg, body) {
|
|
70
|
+
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);
|
|
71
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
72
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
73
|
+
function step(op) {
|
|
74
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
75
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
76
|
+
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;
|
|
77
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
78
|
+
switch (op[0]) {
|
|
79
|
+
case 0: case 1: t = op; break;
|
|
80
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
81
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
82
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
83
|
+
default:
|
|
84
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
85
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
86
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
87
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
88
|
+
if (t[2]) _.ops.pop();
|
|
89
|
+
_.trys.pop(); continue;
|
|
90
|
+
}
|
|
91
|
+
op = body.call(thisArg, _);
|
|
92
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
93
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function __spreadArray(to, from, pack) {
|
|
98
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
99
|
+
if (ar || !(i in from)) {
|
|
100
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
101
|
+
ar[i] = from[i];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
108
|
+
var e = new Error(message);
|
|
109
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
var createError = function (message) {
|
|
113
|
+
return "[sandpack-client]: ".concat(message);
|
|
114
|
+
};
|
|
115
|
+
function nullthrows(value, err) {
|
|
116
|
+
if (err === void 0) { err = "Value is nullish"; }
|
|
117
|
+
outvariant.invariant(value != null, createError(err));
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
var DEPENDENCY_ERROR_MESSAGE = "\"dependencies\" was not specified - provide either a package.json or a \"dependencies\" value";
|
|
121
|
+
var ENTRY_ERROR_MESSAGE = "\"entry\" was not specified - provide either a package.json with the \"main\" field or an \"entry\" value";
|
|
122
|
+
function createPackageJSON(dependencies, devDependencies, entry) {
|
|
123
|
+
if (dependencies === void 0) { dependencies = {}; }
|
|
124
|
+
if (devDependencies === void 0) { devDependencies = {}; }
|
|
125
|
+
if (entry === void 0) { entry = "/index.js"; }
|
|
126
|
+
return JSON.stringify({
|
|
127
|
+
name: "sandpack-project",
|
|
128
|
+
main: entry,
|
|
129
|
+
dependencies: dependencies,
|
|
130
|
+
devDependencies: devDependencies,
|
|
131
|
+
}, null, 2);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Ensures a `/package.json` exists inside a plain {@link SandpackFilesInput}
|
|
135
|
+
* map (pre-filesystem), merging any supplied dependency / entry overrides.
|
|
136
|
+
* Useful in pure planners like `getSandpackStateFromProps` so callers can decide
|
|
137
|
+
* what to seed the filesystem with before any I/O happens.
|
|
138
|
+
*
|
|
139
|
+
* (The former filesystem-mutating variant `addPackageJSONIfNeeded(fs, …)` was
|
|
140
|
+
* removed with BOOT_SCAFFOLDING_SPEC §3: the resolved package.json is delivered
|
|
141
|
+
* to the bundler out-of-band, so no synthesized copy is written into the CoW.)
|
|
142
|
+
*/
|
|
143
|
+
function addPackageJSONIfNeededToMap(files, dependencies, devDependencies, entry) {
|
|
144
|
+
var _a, _b;
|
|
145
|
+
var next = exports.__assign({}, files);
|
|
146
|
+
if (!next["/package.json"]) {
|
|
147
|
+
nullthrows(dependencies, DEPENDENCY_ERROR_MESSAGE);
|
|
148
|
+
nullthrows(entry, ENTRY_ERROR_MESSAGE);
|
|
149
|
+
next["/package.json"] = {
|
|
150
|
+
code: createPackageJSON(dependencies, devDependencies, entry),
|
|
151
|
+
};
|
|
152
|
+
return next;
|
|
153
|
+
}
|
|
154
|
+
var pkg = JSON.parse(next["/package.json"].code);
|
|
155
|
+
if (!dependencies && !pkg.dependencies) {
|
|
156
|
+
throw new Error(createError(ENTRY_ERROR_MESSAGE));
|
|
157
|
+
}
|
|
158
|
+
if (dependencies) {
|
|
159
|
+
pkg.dependencies = exports.__assign(exports.__assign({}, ((_a = pkg.dependencies) !== null && _a !== void 0 ? _a : {})), dependencies);
|
|
160
|
+
}
|
|
161
|
+
if (devDependencies) {
|
|
162
|
+
pkg.devDependencies = exports.__assign(exports.__assign({}, ((_b = pkg.devDependencies) !== null && _b !== void 0 ? _b : {})), devDependencies);
|
|
163
|
+
}
|
|
164
|
+
if (entry) {
|
|
165
|
+
pkg.main = entry;
|
|
166
|
+
}
|
|
167
|
+
next["/package.json"] = { code: JSON.stringify(pkg, null, 2) };
|
|
168
|
+
return next;
|
|
169
|
+
}
|
|
170
|
+
function extractErrorDetails(msg) {
|
|
171
|
+
var _a;
|
|
172
|
+
if (msg.title === "SyntaxError") {
|
|
173
|
+
var title = msg.title, path = msg.path, message = msg.message, line = msg.line, column = msg.column;
|
|
174
|
+
return { title: title, path: path, message: message, line: line, column: column };
|
|
175
|
+
}
|
|
176
|
+
var relevantStackFrame = getRelevantStackFrame((_a = msg.payload) === null || _a === void 0 ? void 0 : _a.frames);
|
|
177
|
+
if (!relevantStackFrame) {
|
|
178
|
+
return { message: msg.message };
|
|
179
|
+
}
|
|
180
|
+
var errorInCode = getErrorInOriginalCode(relevantStackFrame);
|
|
181
|
+
var errorLocation = getErrorLocation(relevantStackFrame);
|
|
182
|
+
var errorMessage = formatErrorMessage(relevantStackFrame._originalFileName, msg.message, errorLocation, errorInCode);
|
|
183
|
+
return {
|
|
184
|
+
message: errorMessage,
|
|
185
|
+
title: msg.title,
|
|
186
|
+
path: relevantStackFrame._originalFileName,
|
|
187
|
+
line: relevantStackFrame._originalLineNumber,
|
|
188
|
+
column: relevantStackFrame._originalColumnNumber,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function getRelevantStackFrame(frames) {
|
|
192
|
+
if (!frames) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
return frames.find(function (frame) { return !!frame._originalFileName; });
|
|
196
|
+
}
|
|
197
|
+
function getErrorLocation(errorFrame) {
|
|
198
|
+
return errorFrame
|
|
199
|
+
? " (".concat(errorFrame._originalLineNumber, ":").concat(errorFrame._originalColumnNumber, ")")
|
|
200
|
+
: "";
|
|
201
|
+
}
|
|
202
|
+
function getErrorInOriginalCode(errorFrame) {
|
|
203
|
+
var lastScriptLine = errorFrame._originalScriptCode[errorFrame._originalScriptCode.length - 1];
|
|
204
|
+
var numberOfLineNumberCharacters = lastScriptLine.lineNumber.toString().length;
|
|
205
|
+
var leadingCharacterOffset = 2;
|
|
206
|
+
var barSeparatorCharacterOffset = 3;
|
|
207
|
+
var extraLineLeadingSpaces = leadingCharacterOffset +
|
|
208
|
+
numberOfLineNumberCharacters +
|
|
209
|
+
barSeparatorCharacterOffset +
|
|
210
|
+
errorFrame._originalColumnNumber;
|
|
211
|
+
return errorFrame._originalScriptCode.reduce(function (result, scriptLine) {
|
|
212
|
+
var leadingChar = scriptLine.highlight ? ">" : " ";
|
|
213
|
+
var lineNumber = scriptLine.lineNumber.toString().length === numberOfLineNumberCharacters
|
|
214
|
+
? "".concat(scriptLine.lineNumber)
|
|
215
|
+
: " ".concat(scriptLine.lineNumber);
|
|
216
|
+
var extraLine = scriptLine.highlight
|
|
217
|
+
? "\n" + " ".repeat(extraLineLeadingSpaces) + "^"
|
|
218
|
+
: "";
|
|
219
|
+
return (result + // accumulator
|
|
220
|
+
"\n" +
|
|
221
|
+
leadingChar + // > or " "
|
|
222
|
+
" " +
|
|
223
|
+
lineNumber + // line number on equal number of characters
|
|
224
|
+
" | " +
|
|
225
|
+
scriptLine.content + // code
|
|
226
|
+
extraLine // line under the highlighed line to show the column index
|
|
227
|
+
);
|
|
228
|
+
}, "");
|
|
229
|
+
}
|
|
230
|
+
function formatErrorMessage(filePath, message, location, errorInCode) {
|
|
231
|
+
return "".concat(filePath, ": ").concat(message).concat(location, "\n").concat(errorInCode);
|
|
232
|
+
}
|
|
233
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
234
|
+
var normalizePath = function (path) {
|
|
235
|
+
if (typeof path === "string") {
|
|
236
|
+
return (path.startsWith("/") ? path : "/".concat(path));
|
|
237
|
+
}
|
|
238
|
+
if (Array.isArray(path)) {
|
|
239
|
+
return path.map(function (p) { return (p.startsWith("/") ? p : "/".concat(p)); });
|
|
240
|
+
}
|
|
241
|
+
if (typeof path === "object" && path !== null) {
|
|
242
|
+
return Object.entries(path).reduce(function (acc, _a) {
|
|
243
|
+
var key = _a[0], content = _a[1];
|
|
244
|
+
var fileName = key.startsWith("/") ? key : "/".concat(key);
|
|
245
|
+
acc[fileName] = content;
|
|
246
|
+
return acc;
|
|
247
|
+
}, {});
|
|
248
|
+
}
|
|
249
|
+
return null;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
exports.__awaiter = __awaiter;
|
|
253
|
+
exports.__extends = __extends;
|
|
254
|
+
exports.__generator = __generator;
|
|
255
|
+
exports.__rest = __rest;
|
|
256
|
+
exports.__spreadArray = __spreadArray;
|
|
257
|
+
exports.addPackageJSONIfNeededToMap = addPackageJSONIfNeededToMap;
|
|
258
|
+
exports.createError = createError;
|
|
259
|
+
exports.createPackageJSON = createPackageJSON;
|
|
260
|
+
exports.extractErrorDetails = extractErrorDetails;
|
|
261
|
+
exports.normalizePath = normalizePath;
|
|
262
|
+
exports.nullthrows = nullthrows;
|