wasm-idle 1.1.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +211 -91
  2. package/dist/container/bash-profile.d.ts +80 -0
  3. package/dist/container/bash-profile.js +328 -0
  4. package/dist/{playground/container → container}/binding.d.ts +21 -8
  5. package/dist/{playground/container → container}/binding.js +109 -25
  6. package/dist/{playground/container → container}/clang-runtime.d.ts +11 -7
  7. package/dist/container/clang-runtime.js +561 -0
  8. package/dist/container/client.d.ts +14 -0
  9. package/dist/{playground/container → container}/client.js +2 -6
  10. package/dist/{playground/container → container}/explorer.d.ts +1 -1
  11. package/dist/container/index.d.ts +11 -0
  12. package/dist/container/index.js +11 -0
  13. package/dist/container/owner-worker.d.ts +19 -0
  14. package/dist/container/owner-worker.js +464 -0
  15. package/dist/{playground/container → container}/protocol.d.ts +12 -1
  16. package/dist/{playground/container → container}/runtime-adapter.d.ts +13 -11
  17. package/dist/{playground/container → container}/runtime-adapter.js +104 -41
  18. package/dist/{playground/container → container}/shell-control.d.ts +2 -2
  19. package/dist/{playground/container → container}/shell-control.js +93 -36
  20. package/dist/{playground/container → container}/workspace.d.ts +5 -1
  21. package/dist/index.d.ts +2 -1
  22. package/dist/index.js +1 -0
  23. package/dist/playground/assetBridge.js +5 -2
  24. package/dist/playground/assets.d.ts +8 -0
  25. package/dist/playground/clang.d.ts +5 -1
  26. package/dist/playground/clang.js +61 -5
  27. package/dist/playground/compiledLldb.d.ts +41 -0
  28. package/dist/playground/compiledLldb.js +167 -0
  29. package/dist/playground/d.d.ts +4 -1
  30. package/dist/playground/d.js +78 -9
  31. package/dist/playground/debugDeadline.d.ts +12 -0
  32. package/dist/playground/debugDeadline.js +34 -0
  33. package/dist/playground/debugMailbox.d.ts +12 -0
  34. package/dist/playground/debugMailbox.js +77 -0
  35. package/dist/playground/go.js +9 -4
  36. package/dist/playground/goDebugInstrumentation.js +24 -44
  37. package/dist/playground/java-debug-HUZVAK4F.js +124 -0
  38. package/dist/playground/java-debug-notices.txt +492 -0
  39. package/dist/playground/java.d.ts +17 -1
  40. package/dist/playground/java.js +159 -3
  41. package/dist/playground/javaDebug.d.ts +62 -0
  42. package/dist/playground/javaDebug.js +305 -0
  43. package/dist/playground/javaDebugBridge.d.ts +6 -0
  44. package/dist/playground/javaDebugBridge.js +250 -0
  45. package/dist/playground/javaDebugSource.d.ts +9 -0
  46. package/dist/playground/javaDebugSource.js +4 -0
  47. package/dist/playground/javaRuntimeErrors.js +34 -1
  48. package/dist/playground/lean4Assets.d.ts +1 -25
  49. package/dist/playground/lean4Assets.js +2 -123
  50. package/dist/playground/lfortranAssets.d.ts +2 -2
  51. package/dist/playground/lldbSession.d.ts +24 -2
  52. package/dist/playground/lldbSession.js +322 -59
  53. package/dist/playground/lldbSourcePath.d.ts +2 -0
  54. package/dist/playground/lldbSourcePath.js +9 -0
  55. package/dist/playground/lua.d.ts +20 -1
  56. package/dist/playground/lua.js +190 -8
  57. package/dist/playground/luaDebug.d.ts +1 -0
  58. package/dist/playground/luaDebug.js +1 -0
  59. package/dist/playground/nim.d.ts +1 -0
  60. package/dist/playground/nim.js +8 -0
  61. package/dist/playground/objectivec.d.ts +7 -6
  62. package/dist/playground/objectivec.js +75 -9
  63. package/dist/playground/options.d.ts +10 -4
  64. package/dist/playground/python.d.ts +11 -1
  65. package/dist/playground/python.js +203 -8
  66. package/dist/playground/pythonCompileOptions.d.ts +49 -0
  67. package/dist/playground/pythonCompileOptions.js +40 -0
  68. package/dist/playground/ruby.d.ts +10 -1
  69. package/dist/playground/ruby.js +66 -1
  70. package/dist/playground/rubyDebug.d.ts +21 -0
  71. package/dist/playground/rubyDebug.js +128 -0
  72. package/dist/playground/rust.d.ts +5 -1
  73. package/dist/playground/rust.js +128 -46
  74. package/dist/playground/sandbox.d.ts +8 -1
  75. package/dist/playground/staticRuntimeModuleVersion.d.ts +1 -1
  76. package/dist/playground/staticRuntimeModuleVersion.js +1 -1
  77. package/dist/playground/staticWorkerRuntime.js +8 -2
  78. package/dist/playground/stdinBuffer.d.ts +1 -1
  79. package/dist/playground/stdinBuffer.js +19 -2
  80. package/dist/playground/tinygo.js +7 -0
  81. package/dist/playground/typescript.js +8 -0
  82. package/dist/playground/v.d.ts +3 -2
  83. package/dist/playground/v.js +66 -12
  84. package/dist/playground/wasmC3Version.d.ts +2 -2
  85. package/dist/playground/wasmC3Version.js +2 -2
  86. package/dist/playground/wasmDebugVersion.d.ts +1 -1
  87. package/dist/playground/wasmDebugVersion.js +1 -1
  88. package/dist/playground/wasmLean4Version.d.ts +1 -110
  89. package/dist/playground/wasmLean4Version.js +2 -111
  90. package/dist/playground/wasmLfortranVersion.d.ts +2 -2
  91. package/dist/playground/wasmLfortranVersion.js +2 -2
  92. package/dist/playground/wasmLuaVersion.d.ts +1 -1
  93. package/dist/playground/wasmLuaVersion.js +1 -1
  94. package/dist/playground/wasmPrologVersion.d.ts +17 -17
  95. package/dist/playground/wasmPrologVersion.js +16 -16
  96. package/dist/playground/wasmRustVersion.d.ts +26 -38
  97. package/dist/playground/wasmRustVersion.js +25 -40
  98. package/dist/playground/wasmTypeScriptVersion.d.ts +3 -3
  99. package/dist/playground/wasmTypeScriptVersion.js +3 -3
  100. package/dist/playground/worker/clang.js +1 -1
  101. package/dist/playground/worker/cobol.js +1 -1
  102. package/dist/playground/worker/d.js +51 -2
  103. package/dist/playground/worker/fortran.js +1 -1
  104. package/dist/playground/worker/java.js +188 -35
  105. package/dist/playground/worker/javaDebugEvaluator.d.ts +16 -0
  106. package/dist/playground/worker/javaDebugEvaluator.js +44 -0
  107. package/dist/playground/worker/javaDebugRuntime.d.ts +24 -0
  108. package/dist/playground/worker/javaDebugRuntime.js +315 -0
  109. package/dist/playground/worker/javaOutput.d.ts +11 -0
  110. package/dist/playground/worker/javaOutput.js +54 -0
  111. package/dist/playground/worker/lua.js +13 -0
  112. package/dist/playground/worker/python.js +81 -23
  113. package/dist/playground/worker/pythonCompile.d.ts +4 -0
  114. package/dist/playground/worker/pythonCompile.js +122 -0
  115. package/dist/playground/worker/ruby.js +13 -0
  116. package/dist/playground/worker/rubyDebugPreview.d.ts +2 -0
  117. package/dist/playground/worker/rubyDebugPreview.js +80 -0
  118. package/dist/playground/worker/rubyTracepoint.d.ts +16 -0
  119. package/dist/playground/worker/rubyTracepoint.js +162 -0
  120. package/dist/playground/worker/rust.js +4 -1
  121. package/dist/playground/worker/v.js +30 -5
  122. package/dist/playground/zig.js +4 -0
  123. package/dist/pythonCompiler.d.ts +8 -0
  124. package/dist/pythonCompiler.js +52 -0
  125. package/package.json +76 -28
  126. package/dist/playground/container/ContainerExplorer.svelte +0 -307
  127. package/dist/playground/container/ContainerExplorer.svelte.d.ts +0 -14
  128. package/dist/playground/container/clang-runtime.js +0 -343
  129. package/dist/playground/container/client.d.ts +0 -15
  130. package/dist/playground/container/owner.worker.d.ts +0 -1
  131. package/dist/playground/container/owner.worker.js +0 -390
  132. package/dist/playground/container/release.d.ts +0 -31
  133. package/dist/playground/container/release.js +0 -612
  134. /package/dist/{playground/container → container}/explorer.js +0 -0
  135. /package/dist/{playground/container → container}/protocol.js +0 -0
  136. /package/dist/{playground/container → container}/workspace.js +0 -0
@@ -1,31 +1,31 @@
1
- import { createContainerWorkerClient } from './client';
1
+ import { createContainerWorkerClient } from './client.js';
2
2
  const copyFiles = (files) => files.map((file) => ({
3
3
  path: file.path,
4
4
  content: typeof file.content === 'string' ? file.content : Uint8Array.from(file.content)
5
5
  }));
6
6
  const bytes = (content) => typeof content === 'string' ? new TextEncoder().encode(content) : content;
7
7
  const equal = (left, right) => {
8
+ if (left === right)
9
+ return true;
8
10
  const a = bytes(left), b = bytes(right);
9
11
  return a.length === b.length && a.every((byte, index) => byte === b[index]);
10
12
  };
11
- function sameFiles(left, right) {
12
- return (left.length === right.length &&
13
- left.every((file) => {
14
- const other = right.find((candidate) => candidate.path === file.path);
15
- return other && equal(file.content, other.content);
16
- }));
17
- }
18
13
  /** Existing Terminal/Debug controls use this facade; every execution belongs to the owner Container. */
19
14
  export function createContainerPlaygroundBinding(runtimeAssets, options) {
15
+ if (!options.workerFactory && !options.clientFactory)
16
+ throw new TypeError('A container owner workerFactory is required');
20
17
  let client, disposed = false;
21
18
  const sandboxes = new Map();
22
19
  const published = new Map();
23
20
  const changes = new Set();
24
21
  const queues = new Map();
22
+ const reads = new Map();
23
+ const readQueues = new Map();
25
24
  let shellOutput;
26
25
  let shellError;
27
26
  let shellConnection;
28
27
  let requestedShellLanguage;
28
+ let terminalExecution = false;
29
29
  const decoders = new Map();
30
30
  const decoder = (key) => {
31
31
  let value = decoders.get(key);
@@ -43,7 +43,8 @@ export function createContainerPlaygroundBinding(runtimeAssets, options) {
43
43
  createContainerWorkerClient({
44
44
  runtimeAssets,
45
45
  applicationRootURL: options.applicationRootURL,
46
- workspaceId: options.workspaceId
46
+ workspaceId: options.workspaceId,
47
+ workerFactory: options.workerFactory
47
48
  });
48
49
  client.onEvent((event) => {
49
50
  if (event.name === 'workspace') {
@@ -77,6 +78,18 @@ export function createContainerPlaygroundBinding(runtimeAssets, options) {
77
78
  });
78
79
  return client;
79
80
  };
81
+ const cleanupOwner = async (method, args = []) => {
82
+ if (!client || disposed)
83
+ return;
84
+ try {
85
+ await client.call(method, args);
86
+ }
87
+ catch (error) {
88
+ // Terminal cleanup can race the parent disposing the complete owner.
89
+ if (!disposed)
90
+ throw error;
91
+ }
92
+ };
80
93
  const syncWorkspace = (language, files) => {
81
94
  const snapshot = copyFiles(files);
82
95
  const previous = queues.get(language) ?? Promise.resolve();
@@ -84,14 +97,36 @@ export function createContainerPlaygroundBinding(runtimeAssets, options) {
84
97
  .catch(() => { })
85
98
  .then(async () => {
86
99
  const baseline = published.get(language);
87
- if (baseline && sameFiles(baseline, snapshot))
88
- return;
89
- await connection().call('syncWorkspace', [
90
- language,
91
- snapshot,
92
- baseline && copyFiles(baseline)
93
- ]);
94
- published.set(language, copyFiles(snapshot));
100
+ if (baseline) {
101
+ const before = new Map(baseline.map((file) => [file.path, file]));
102
+ const changed = [];
103
+ const expected = [];
104
+ for (const file of snapshot) {
105
+ const previous = before.get(file.path);
106
+ before.delete(file.path);
107
+ if (previous && equal(previous.content, file.content))
108
+ continue;
109
+ changed.push(file);
110
+ if (previous)
111
+ expected.push(previous);
112
+ }
113
+ expected.push(...before.values());
114
+ if (!changed.length && !expected.length)
115
+ return;
116
+ await connection().call('syncWorkspaceDelta', [
117
+ language,
118
+ changed,
119
+ expected,
120
+ snapshot.map((file) => ({
121
+ path: file.path,
122
+ bytes: bytes(file.content).byteLength
123
+ }))
124
+ ]);
125
+ }
126
+ else
127
+ await connection().call('syncWorkspace', [language, snapshot, undefined]);
128
+ // snapshot already owns its bytes, including while queued behind another write.
129
+ published.set(language, snapshot);
95
130
  });
96
131
  queues.set(language, next);
97
132
  return next;
@@ -104,7 +139,10 @@ export function createContainerPlaygroundBinding(runtimeAssets, options) {
104
139
  const language = requestedShellLanguage ?? options.getLanguage?.() ?? 'CPP';
105
140
  await queues.get(language)?.catch(() => { });
106
141
  await connection().call('shellStart', [
107
- { cwd: `/workspace/${language}`, env: { PS1: '\\w $ ' } }
142
+ {
143
+ cwd: `/workspace/${language}`,
144
+ env: { PS1: '\\[\\e[1;34m\\]\\w\\[\\e[0m\\] $ ' }
145
+ }
108
146
  ]);
109
147
  })());
110
148
  },
@@ -121,11 +159,29 @@ export function createContainerPlaygroundBinding(runtimeAssets, options) {
121
159
  await connection().call('shellInterrupt');
122
160
  },
123
161
  async dispose() {
124
- if (client && !disposed)
125
- await client.call('shellDispose');
162
+ await cleanupOwner('shellDispose');
126
163
  }
127
164
  };
128
165
  const binding = {
166
+ async beginTerminalExecution() {
167
+ if (terminalExecution || !shellConnection || disposed)
168
+ return;
169
+ // A shell unavailable without cross-origin isolation must not block batch Run.
170
+ try {
171
+ await shellConnection;
172
+ }
173
+ catch {
174
+ return;
175
+ }
176
+ await connection().call('shellSuspend');
177
+ terminalExecution = true;
178
+ },
179
+ async endTerminalExecution() {
180
+ if (!terminalExecution)
181
+ return;
182
+ terminalExecution = false;
183
+ await cleanupOwner('shellResume');
184
+ },
129
185
  async setShellDirectory(language) {
130
186
  if (!/^[A-Z][A-Z0-9_]*$/.test(language))
131
187
  throw new TypeError('Invalid shell language');
@@ -165,7 +221,7 @@ export function createContainerPlaygroundBinding(runtimeAssets, options) {
165
221
  }
166
222
  },
167
223
  async clear() {
168
- await invoke('clear');
224
+ await cleanupOwner('clear', [language]);
169
225
  },
170
226
  async restart() {
171
227
  await invoke('restart');
@@ -177,8 +233,7 @@ export function createContainerPlaygroundBinding(runtimeAssets, options) {
177
233
  await invoke('stop');
178
234
  },
179
235
  async dispose() {
180
- if (client && !disposed)
181
- await invoke('clear');
236
+ await cleanupOwner('clear', [language]);
182
237
  },
183
238
  write(text) {
184
239
  void invoke('write', [text]).catch((error) => shellError?.(error));
@@ -191,7 +246,10 @@ export function createContainerPlaygroundBinding(runtimeAssets, options) {
191
246
  'debugCommand',
192
247
  'debugPause',
193
248
  'setBreakpoints',
249
+ 'setSourceBreakpoints',
194
250
  'debugEvaluate',
251
+ 'debugEvaluateValue',
252
+ 'debugSetSteppingOptions',
195
253
  'debugVariables',
196
254
  'debugScopes',
197
255
  'debugFrameScopes',
@@ -215,8 +273,32 @@ export function createContainerPlaygroundBinding(runtimeAssets, options) {
215
273
  async cancelPrewarm() { },
216
274
  syncWorkspace,
217
275
  async readWorkspace(language) {
218
- await queues.get(language)?.catch(() => { });
219
- return await connection().call('readWorkspace', [language]);
276
+ const previous = readQueues.get(language);
277
+ const next = (async () => {
278
+ await previous?.catch(() => { });
279
+ await queues.get(language)?.catch(() => { });
280
+ const baseline = reads.get(language);
281
+ const delta = await connection().call('readWorkspaceDelta', [language, baseline?.revision]);
282
+ if (disposed)
283
+ throw new Error('Container playground has been disposed');
284
+ const files = new Map(delta.reset ? [] : baseline?.files);
285
+ for (const path of delta.deleted)
286
+ files.delete(path);
287
+ for (const file of delta.files)
288
+ files.set(file.path, file);
289
+ reads.set(language, { revision: delta.revision, files });
290
+ // Match the owner's sorted directory traversal after incremental additions.
291
+ return copyFiles([...files.values()].sort((left, right) => {
292
+ const a = left.path.split('/'), b = right.path.split('/');
293
+ for (let index = 0; index < Math.min(a.length, b.length); index++) {
294
+ if (a[index] !== b[index])
295
+ return a[index] < b[index] ? -1 : 1;
296
+ }
297
+ return a.length - b.length;
298
+ }));
299
+ })();
300
+ readQueues.set(language, next);
301
+ return await next;
220
302
  },
221
303
  async listWorkspaceFiles() {
222
304
  return await connection().call('listWorkspaceFiles');
@@ -239,6 +321,8 @@ export function createContainerPlaygroundBinding(runtimeAssets, options) {
239
321
  return;
240
322
  disposed = true;
241
323
  changes.clear();
324
+ reads.clear();
325
+ readQueues.clear();
242
326
  await client?.dispose();
243
327
  }
244
328
  };
@@ -1,14 +1,16 @@
1
- import type { Container } from '@wasm-idle/container';
2
- import { type SandboxExecutionOptions } from '../options';
1
+ import type { Container, HostCommandInvocation } from '@wasm-idle/container';
2
+ import { type SandboxExecutionOptions } from '../playground/options.js';
3
3
  import type { ProgressLike } from '@wasm-idle/core';
4
- import type { ContainerWorkerEvent } from './protocol';
5
- import type { WebsiteRuntimeAdapter } from './runtime-adapter';
4
+ import type { ContainerWorkerEvent } from './protocol.js';
5
+ import type { WebsiteRuntimeAdapter } from './runtime-adapter.js';
6
6
  type Profile = {
7
7
  container: Container;
8
- prepareCommand(invocation: unknown, signal: AbortSignal): Promise<void>;
8
+ sysrootProfile?: 'full' | 'c-base-v1';
9
+ prepareCommand(invocation: HostCommandInvocation, signal: AbortSignal): Promise<void>;
10
+ prepareClang?(profile: 'c' | 'full', signal: AbortSignal): Promise<readonly string[]>;
9
11
  };
10
12
  /** The Run button uses the same real Clang command and artifacts as Bash. Debug uses its qualified backend. */
11
- export declare class WebsiteClangRuntime {
13
+ export declare class ContainerClangRuntime {
12
14
  #private;
13
15
  private readonly profile;
14
16
  private readonly files;
@@ -16,6 +18,8 @@ export declare class WebsiteClangRuntime {
16
18
  constructor(profile: Profile, files: WebsiteRuntimeAdapter, emit: (event: ContainerWorkerEvent) => void);
17
19
  private queue;
18
20
  private key;
21
+ private currentProgram;
22
+ private spawn;
19
23
  private drain;
20
24
  private success;
21
25
  private headerKey;
@@ -35,4 +39,4 @@ export declare class WebsiteClangRuntime {
35
39
  }[];
36
40
  dispose(): Promise<void>;
37
41
  }
38
- export {};
42
+ export { ContainerClangRuntime as WebsiteClangRuntime };