@innovatorved/code-lab 0.3.2 → 0.5.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 (164) hide show
  1. package/ARCHITECTURE.md +5 -3
  2. package/CHANGELOG.md +41 -0
  3. package/README.md +53 -175
  4. package/dist/apps/web/src/index.d.ts +34 -0
  5. package/dist/code-lab-sql.css +482 -0
  6. package/dist/code-lab-sql.d.ts +179 -0
  7. package/dist/code-lab-sql.esm.js +542 -0
  8. package/dist/code-lab-sql.umd.js +531 -0
  9. package/dist/code-lab.css +1799 -98
  10. package/dist/code-lab.d.ts +110 -15
  11. package/dist/code-lab.esm.js +49678 -23253
  12. package/dist/code-lab.js +49648 -23251
  13. package/dist/code-lab.umd.js +75766 -0
  14. package/dist/diagnostics.d.ts +3 -0
  15. package/dist/extensions/cpp.esm.js +19504 -3788
  16. package/dist/extensions/cpp.js +19501 -3785
  17. package/dist/extensions/guided-lab.esm.js +19401 -3725
  18. package/dist/extensions/guided-lab.js +19400 -3724
  19. package/dist/extensions/python.d.ts +1 -0
  20. package/dist/extensions/python.esm.js +19597 -3788
  21. package/dist/extensions/python.js +19597 -3788
  22. package/dist/extensions/umbrella.d.ts +5 -0
  23. package/dist/index.d.ts +1 -1
  24. package/dist/modular-kernel.d.ts +11 -0
  25. package/dist/packages/commands/src/index.d.ts +96 -0
  26. package/dist/packages/core/src/di.d.ts +36 -0
  27. package/dist/packages/core/src/disposable.d.ts +27 -0
  28. package/dist/packages/core/src/errors.d.ts +69 -0
  29. package/dist/packages/core/src/events.d.ts +38 -0
  30. package/dist/packages/core/src/index.d.ts +6 -0
  31. package/dist/packages/core/src/path.d.ts +14 -0
  32. package/dist/packages/core/src/registry.d.ts +23 -0
  33. package/dist/packages/editor/src/index.d.ts +118 -0
  34. package/dist/packages/fs/src/backends.d.ts +37 -0
  35. package/dist/packages/fs/src/index.d.ts +3 -0
  36. package/dist/packages/fs/src/types.d.ts +40 -0
  37. package/dist/packages/fs/src/vfs-service.d.ts +33 -0
  38. package/dist/packages/preview/src/index.d.ts +34 -0
  39. package/dist/packages/runtime/src/index.d.ts +47 -0
  40. package/dist/packages/settings/src/builtin-schemas.d.ts +15 -0
  41. package/dist/packages/settings/src/configuration-service.d.ts +107 -0
  42. package/dist/packages/settings/src/index.d.ts +4 -0
  43. package/dist/packages/settings/src/jsonc.d.ts +20 -0
  44. package/dist/packages/settings/src/schema.d.ts +28 -0
  45. package/dist/packages/sql/src/completions.d.ts +8 -0
  46. package/dist/packages/sql/src/diagnostics.d.ts +2 -0
  47. package/dist/packages/sql/src/formatter.d.ts +2 -0
  48. package/dist/packages/sql/src/index.d.ts +7 -0
  49. package/dist/packages/sql/src/sql-editor.d.ts +2 -0
  50. package/dist/packages/sql/src/styles.d.ts +2 -0
  51. package/dist/packages/sql/src/tokenizer.d.ts +13 -0
  52. package/dist/packages/sql/src/types.d.ts +130 -0
  53. package/dist/packages/terminal/src/index.d.ts +54 -0
  54. package/dist/packages/ui/src/index.d.ts +4 -0
  55. package/dist/packages/ui/src/observability.d.ts +22 -0
  56. package/dist/packages/ui/src/plugin-registry.d.ts +90 -0
  57. package/dist/packages/ui/src/settings-dialog.d.ts +53 -0
  58. package/dist/packages/ui/src/themes.d.ts +40 -0
  59. package/dist/preview-sw.js +53 -12
  60. package/dist/runtime.d.ts +3 -3
  61. package/dist/runtime.esm.js +467 -44
  62. package/dist/runtime.js +465 -44
  63. package/dist/schemas.d.ts +234 -814
  64. package/dist/schemas.esm.js +19401 -3725
  65. package/dist/schemas.js +19404 -3728
  66. package/dist/scm.d.ts +92 -11
  67. package/dist/shell.d.ts +1 -1
  68. package/dist/shell.esm.js +1300 -151
  69. package/dist/shell.js +1300 -151
  70. package/dist/storage.d.ts +47 -0
  71. package/dist/terminal.esm.js +62 -3
  72. package/dist/terminal.js +62 -3
  73. package/dist/workbench/diff-editor.d.ts +1 -0
  74. package/dist/workbench/index.d.ts +1 -1
  75. package/dist/workbench/styles.d.ts +1 -1
  76. package/package.json +38 -9
  77. package/packages/commands/README.md +7 -0
  78. package/packages/commands/package.json +16 -0
  79. package/packages/commands/src/index.ts +467 -0
  80. package/packages/commands/tsconfig.json +22 -0
  81. package/packages/core/README.md +12 -0
  82. package/packages/core/package.json +13 -0
  83. package/packages/core/src/di.ts +147 -0
  84. package/packages/core/src/disposable.ts +112 -0
  85. package/packages/core/src/errors.ts +205 -0
  86. package/packages/core/src/events.ts +157 -0
  87. package/packages/core/src/index.ts +49 -0
  88. package/packages/core/src/path.ts +118 -0
  89. package/packages/core/src/registry.ts +61 -0
  90. package/packages/core/tsconfig.json +19 -0
  91. package/packages/editor/README.md +9 -0
  92. package/packages/editor/package.json +18 -0
  93. package/packages/editor/src/index.ts +344 -0
  94. package/packages/editor/tsconfig.json +24 -0
  95. package/packages/fs/README.md +7 -0
  96. package/packages/fs/package.json +16 -0
  97. package/packages/fs/src/backends.ts +301 -0
  98. package/packages/fs/src/index.ts +18 -0
  99. package/packages/fs/src/types.ts +44 -0
  100. package/packages/fs/src/vfs-service.ts +257 -0
  101. package/packages/fs/tsconfig.json +22 -0
  102. package/packages/preview/README.md +3 -0
  103. package/packages/preview/package.json +16 -0
  104. package/packages/preview/src/index.ts +125 -0
  105. package/packages/preview/tsconfig.json +22 -0
  106. package/packages/runtime/README.md +3 -0
  107. package/packages/runtime/package.json +17 -0
  108. package/packages/runtime/src/index.ts +134 -0
  109. package/packages/runtime/tsconfig.json +23 -0
  110. package/packages/settings/README.md +7 -0
  111. package/packages/settings/package.json +16 -0
  112. package/packages/settings/src/builtin-schemas.ts +246 -0
  113. package/packages/settings/src/configuration-service.ts +609 -0
  114. package/packages/settings/src/index.ts +38 -0
  115. package/packages/settings/src/jsonc.ts +189 -0
  116. package/packages/settings/src/schema.ts +164 -0
  117. package/packages/settings/tsconfig.json +22 -0
  118. package/packages/sql/README.md +12 -0
  119. package/packages/sql/package.json +13 -0
  120. package/packages/sql/src/completions.ts +359 -0
  121. package/packages/sql/src/diagnostics.ts +200 -0
  122. package/packages/sql/src/formatter.ts +271 -0
  123. package/packages/sql/src/index.ts +54 -0
  124. package/packages/sql/src/sql-editor.ts +802 -0
  125. package/packages/sql/src/styles.ts +501 -0
  126. package/packages/sql/src/tokenizer.ts +457 -0
  127. package/packages/sql/src/types.ts +148 -0
  128. package/packages/sql/tsconfig.json +19 -0
  129. package/packages/terminal/README.md +3 -0
  130. package/packages/terminal/package.json +16 -0
  131. package/packages/terminal/src/index.ts +183 -0
  132. package/packages/terminal/tsconfig.json +22 -0
  133. package/packages/ui/README.md +8 -0
  134. package/packages/ui/package.json +18 -0
  135. package/packages/ui/src/index.ts +40 -0
  136. package/packages/ui/src/observability.ts +175 -0
  137. package/packages/ui/src/plugin-registry.ts +289 -0
  138. package/packages/ui/src/settings-dialog.ts +575 -0
  139. package/packages/ui/src/themes.ts +267 -0
  140. package/packages/ui/tsconfig.json +24 -0
  141. package/src/code-lab.css +1799 -98
  142. package/src/diagnostics.ts +139 -7
  143. package/src/extensions/cpp.ts +88 -45
  144. package/src/extensions/python.ts +186 -53
  145. package/src/extensions/umbrella.ts +5 -0
  146. package/src/index.ts +1 -1
  147. package/src/modular-kernel.ts +11 -0
  148. package/src/preview-sw.js +52 -11
  149. package/src/runtime.ts +466 -46
  150. package/src/schemas.ts +62 -62
  151. package/src/scm.ts +781 -58
  152. package/src/shell.ts +1299 -151
  153. package/src/storage.ts +336 -3
  154. package/src/terminal.ts +60 -2
  155. package/src/workbench/diff-editor.ts +66 -6
  156. package/src/workbench/icons.ts +12 -2
  157. package/src/workbench/styles.ts +25 -19
  158. package/src/workbench.ts +17059 -6673
  159. package/dist/runtime/index.d.ts +0 -4
  160. package/dist/shell/coreutils/compilers-cli.d.ts +0 -24
  161. package/dist/shell/index.d.ts +0 -4
  162. package/src/runtime/index.ts +0 -5
  163. package/src/shell/coreutils/compilers-cli.ts +0 -103
  164. package/src/shell/index.ts +0 -5
package/src/runtime.ts CHANGED
@@ -1118,7 +1118,13 @@ function __initVirtualRuntime(rootScope) {
1118
1118
  });
1119
1119
  }
1120
1120
 
1121
+ let _activeStdin = '';
1122
+
1121
1123
  const fsShim = {
1124
+ _setActiveStdin(text) {
1125
+ _activeStdin = text !== undefined && text !== null ? String(text) : '';
1126
+ },
1127
+
1122
1128
  existsSync(p) {
1123
1129
  try {
1124
1130
  const np = normPath(p);
@@ -1343,6 +1349,11 @@ function __initVirtualRuntime(rootScope) {
1343
1349
  },
1344
1350
 
1345
1351
  readFileSync(p, opts) {
1352
+ if (p === 0 || p === '/dev/stdin') {
1353
+ const stdinBuf = VirtualBuffer.from(String(_activeStdin || ''), 'utf8');
1354
+ const encoding = typeof opts === 'string' ? opts : (opts && opts.encoding);
1355
+ return encoding ? stdinBuf.toString(encoding) : stdinBuf;
1356
+ }
1346
1357
  const np = normPath(p);
1347
1358
  if (dirs.has(np)) throw fsError('EISDIR', 'read', p, 'illegal operation on a directory');
1348
1359
  const inode = files.get(np);
@@ -1702,6 +1713,10 @@ function __initVirtualRuntime(rootScope) {
1702
1713
 
1703
1714
  items.sort((a, b) => a.path.localeCompare(b.path));
1704
1715
  return items;
1716
+ },
1717
+
1718
+ _listOpenFds() {
1719
+ return Array.from(fdTable.keys());
1705
1720
  }
1706
1721
  };
1707
1722
 
@@ -1856,6 +1871,13 @@ function __initVirtualRuntime(rootScope) {
1856
1871
  };
1857
1872
 
1858
1873
  fsShim.promises = fsPromises;
1874
+ fsShim._exportRawState = () => {
1875
+ const clonedFiles = new Map();
1876
+ for (const [k, v] of files.entries()) {
1877
+ clonedFiles.set(k, v.data instanceof Uint8Array ? v.data.slice() : new Uint8Array(v.data || 0));
1878
+ }
1879
+ return { files: clonedFiles, dirs: new Set(dirs) };
1880
+ };
1859
1881
 
1860
1882
  return fsShim;
1861
1883
  }
@@ -4586,13 +4608,17 @@ function __initVirtualRuntime(rootScope) {
4586
4608
  function transpileTS(source, filename = 'module.ts', opts = {}) {
4587
4609
  // `keepEsm` leaves `import`/`export` statements intact so the output can run
4588
4610
  // natively in a browser as an ES module (used by the built-in preview server).
4589
- const keepEsm = Boolean(opts && opts.keepEsm);
4590
- const isTS = /\.(ts|tsx|mts|cts)$/i.test(filename)
4611
+ const keepEsm = Boolean(opts && (opts.keepEsm || opts.expressionOnly));
4612
+ const expressionOnly = Boolean(opts && opts.expressionOnly);
4613
+ const isTS = expressionOnly
4614
+ || /\.(ts|tsx|mts|cts)$/i.test(filename)
4591
4615
  || /^[ \t]*(?:export\s+)?(?:abstract\s+class\s+[A-Za-z_$]|declare\s+(?:const|let|var|function|class|namespace|module|global)\b|interface\s+[A-Za-z_$][A-Za-z0-9_$]*|type\s+[A-Za-z_$][A-Za-z0-9_$]*\s*(?:<[^>]*>)?\s*=|enum\s+[A-Za-z_$][A-Za-z0-9_$]*\s*\{|namespace\s+[A-Za-z_$][A-Za-z0-9_$]*\s*\{)/m.test(source);
4592
- const hasESM = /^\s*(?:import|export)\b/m.test(source)
4616
+ const hasESM = !expressionOnly && (
4617
+ /^\s*(?:import|export)\b/m.test(source)
4593
4618
  || /\bexport\s*\{/.test(source)
4594
4619
  || /\bimport\s*\{/.test(source)
4595
- || /\bexport\s+default\b/.test(source);
4620
+ || /\bexport\s+default\b/.test(source)
4621
+ );
4596
4622
  const hasJsx = detectJsxSyntax(source, filename);
4597
4623
  if (!isTS && !hasESM && !hasJsx) return source;
4598
4624
 
@@ -4600,7 +4626,7 @@ function __initVirtualRuntime(rootScope) {
4600
4626
  if (hasJsx) {
4601
4627
  const { pragma, frag } = readJsxPragma(source);
4602
4628
  const hasReactBinding = /\bimport\s+(?!type\b)(?:\*\s+as\s+React\b|React\b)|(?:\bconst|\blet|\bvar|\bfunction|\bclass)\s+React\b|\bReact\s*=/.test(source);
4603
- const needsReact = pragma === 'React.createElement' && (keepEsm ? !hasReactBinding : !/\bReact\b/.test(source));
4629
+ const needsReact = !expressionOnly && pragma === 'React.createElement' && (keepEsm ? !hasReactBinding : !/\bReact\b/.test(source));
4604
4630
  const transformed = jsxTransform(source, { pragma, frag });
4605
4631
  if (transformed !== source) {
4606
4632
  source = transformed;
@@ -4688,18 +4714,80 @@ function __initVirtualRuntime(rootScope) {
4688
4714
  i = j;
4689
4715
  continue;
4690
4716
  }
4691
- // Template literal
4717
+ // Template literal (recursively transpile TypeScript inside ${...} expressions)
4692
4718
  if (ch === '`') {
4693
4719
  let j = i + 1;
4694
- let depth = 0;
4720
+ let rebuilt = '`';
4695
4721
  while (j < len) {
4696
- if (source[j] === '\\') { j += 2; continue; }
4697
- if (source[j] === '$' && source[j + 1] === '{') { depth++; j += 2; continue; }
4698
- if (source[j] === '}' && depth > 0) { depth--; j++; continue; }
4699
- if (source[j] === '`' && depth === 0) { j++; break; }
4722
+ if (source[j] === '\\') {
4723
+ rebuilt += source.slice(j, j + 2);
4724
+ j += 2;
4725
+ continue;
4726
+ }
4727
+ if (source[j] === '`' ) {
4728
+ rebuilt += '`';
4729
+ j++;
4730
+ break;
4731
+ }
4732
+ if (source[j] === '$' && source[j + 1] === '{') {
4733
+ j += 2;
4734
+ const exprStart = j;
4735
+ let braceDepth = 1;
4736
+ while (j < len && braceDepth > 0) {
4737
+ const ec = source[j];
4738
+ const en = source[j + 1];
4739
+ if (ec === '/' && en === '/') {
4740
+ j += 2;
4741
+ while (j < len && source[j] !== '\n') j++;
4742
+ continue;
4743
+ }
4744
+ if (ec === '/' && en === '*') {
4745
+ j += 2;
4746
+ while (j < len && !(source[j] === '*' && source[j + 1] === '/')) j++;
4747
+ j += 2;
4748
+ continue;
4749
+ }
4750
+ if (ec === "'" || ec === '"') {
4751
+ const q = ec;
4752
+ j++;
4753
+ while (j < len && source[j] !== q && source[j] !== '\n') {
4754
+ if (source[j] === '\\') j += 2;
4755
+ else j++;
4756
+ }
4757
+ if (j < len && source[j] === q) j++;
4758
+ continue;
4759
+ }
4760
+ if (ec === '`') {
4761
+ j++;
4762
+ let nestedDepth = 0;
4763
+ while (j < len) {
4764
+ if (source[j] === '\\') { j += 2; continue; }
4765
+ if (source[j] === '$' && source[j + 1] === '{') { nestedDepth++; j += 2; continue; }
4766
+ if (source[j] === '}' && nestedDepth > 0) { nestedDepth--; j++; continue; }
4767
+ if (source[j] === '`' && nestedDepth === 0) { j++; break; }
4768
+ j++;
4769
+ }
4770
+ continue;
4771
+ }
4772
+ if (ec === '{') braceDepth++;
4773
+ else if (ec === '}') {
4774
+ braceDepth--;
4775
+ if (braceDepth === 0) break;
4776
+ }
4777
+ j++;
4778
+ }
4779
+ const rawExpr = source.slice(exprStart, j);
4780
+ const transpiledExpr = isTS
4781
+ ? transpileTS(rawExpr, filename, { expressionOnly: true })
4782
+ : rawExpr;
4783
+ rebuilt += '${' + transpiledExpr + '}';
4784
+ if (j < len && source[j] === '}') j++;
4785
+ continue;
4786
+ }
4787
+ rebuilt += source[j];
4700
4788
  j++;
4701
4789
  }
4702
- code += mask(source.slice(i, j));
4790
+ code += mask(rebuilt);
4703
4791
  i = j;
4704
4792
  continue;
4705
4793
  }
@@ -5073,8 +5161,8 @@ function __initVirtualRuntime(rootScope) {
5073
5161
  };
5074
5162
  code = stripReturnTypes(code);
5075
5163
 
5076
- // Strip parameter type annotations inside `(...)` (supports multi-line parameter lists and default value `()` calls)
5077
- code = code.replace(/\(((?:[^()]|\([^()]*\))*)\)/g, (full, inner) => {
5164
+ // Strip parameter type annotations inside `(...)` from innermost parens outward so nested callbacks work
5165
+ const stripParensParamTypes = (full, inner) => {
5078
5166
  if (!inner.includes(':')) return full;
5079
5167
  if (inner.includes('?') && !/[A-Za-z0-9_$}\]]\s*\?\s*:/.test(inner)) return full;
5080
5168
  if (/[{}]/.test(inner) && !/\}\s*\??\s*:/.test(inner) && !/:\s*[A-Za-z_$][A-Za-z0-9_$.<>[\]|&\s]*\{/.test(inner)) {
@@ -5088,7 +5176,12 @@ function __initVirtualRuntime(rootScope) {
5088
5176
  const parts = splitTopLevel(inner, ',');
5089
5177
  const cleaned = parts.map((part) => cleanSingleParam(part));
5090
5178
  return `(${cleaned.join(',')})`;
5091
- });
5179
+ };
5180
+ do {
5181
+ prevCode = code;
5182
+ code = code.replace(/\(([^()]*)\)/g, stripParensParamTypes);
5183
+ } while (code !== prevCode);
5184
+ code = code.replace(/\(((?:[^()]|\([^()]*\))*)\)/g, stripParensParamTypes);
5092
5185
 
5093
5186
  // Strip variable type annotations: `const x: Type =`, `let y: Type =`
5094
5187
  code = code.replace(/\b(const|let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*:\s*[^=;\n]+(?<![=!<>])=(?![=>])/g, '$1 $2 =');
@@ -5219,7 +5312,31 @@ function __initVirtualRuntime(rootScope) {
5219
5312
  hasEsmExport = true;
5220
5313
  return `Object.assign(exports, require(${mod.trim()}));`;
5221
5314
  });
5222
- code = code.replace(/\bexport\s+default\s+(async\s+function|function|class)\s+([A-Za-z_$][A-Za-z0-9_$]*)/gm, (_, kw, name) => {
5315
+ const collectBindingIds = (pattern) => {
5316
+ const ids = [];
5317
+ const inner = pattern.trim().replace(/^[\[{]|[\]}]$/g, '');
5318
+ const isObj = pattern.trim().startsWith('{');
5319
+ for (const rawPart of splitTopLevel(inner, ',')) {
5320
+ let part = rawPart.trim();
5321
+ if (!part) continue;
5322
+ if (part.startsWith('...')) {
5323
+ part = part.slice(3).trim();
5324
+ } else if (isObj && part.includes(':')) {
5325
+ const colonIdx = part.indexOf(':');
5326
+ part = part.slice(colonIdx + 1).trim();
5327
+ }
5328
+ const eqIdx = part.indexOf('=');
5329
+ if (eqIdx !== -1) part = part.slice(0, eqIdx).trim();
5330
+ if ((part.startsWith('{') && part.endsWith('}')) || (part.startsWith('[') && part.endsWith(']'))) {
5331
+ ids.push(...collectBindingIds(part));
5332
+ } else if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(part)) {
5333
+ ids.push(part);
5334
+ }
5335
+ }
5336
+ return ids;
5337
+ };
5338
+
5339
+ code = code.replace(/\bexport\s+default\s+(async\s+function\s*\*|function\s*\*|async\s+function|function|class)\s+([A-Za-z_$][A-Za-z0-9_$]*)/gm, (_, kw, name) => {
5223
5340
  hasEsmExport = true;
5224
5341
  defaultExportName = name;
5225
5342
  return `${kw} ${name}`;
@@ -5228,11 +5345,16 @@ function __initVirtualRuntime(rootScope) {
5228
5345
  hasEsmExport = true;
5229
5346
  return 'exports.default = ';
5230
5347
  });
5231
- code = code.replace(/\bexport\s+(async\s+function|function|class)\s+([A-Za-z_$][A-Za-z0-9_$]*)/gm, (_, kw, name) => {
5348
+ code = code.replace(/\bexport\s+(async\s+function\s*\*|function\s*\*|async\s+function|function|class)\s+([A-Za-z_$][A-Za-z0-9_$]*)/gm, (_, kw, name) => {
5232
5349
  hasEsmExport = true;
5233
5350
  exportedNames.push(name);
5234
5351
  return `${kw} ${name}`;
5235
5352
  });
5353
+ code = code.replace(/\bexport\s+(const|let|var)\s+(\{[^;=\n]+\}|\[[^;=\n]+\])\s*=/gm, (_, kw, pat) => {
5354
+ hasEsmExport = true;
5355
+ exportedNames.push(...collectBindingIds(pat));
5356
+ return `${kw} ${pat} =`;
5357
+ });
5236
5358
  code = code.replace(/\bexport\s+(const|let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)/gm, (_, kw, name) => {
5237
5359
  hasEsmExport = true;
5238
5360
  exportedNames.push(name);
@@ -6364,10 +6486,16 @@ function __initVirtualRuntime(rootScope) {
6364
6486
  const activePortTable = optPortTable || portTable || _defaultPortTable;
6365
6487
  resourceTracker.pid = pid;
6366
6488
 
6367
- let currentCwd = '/workspace';
6489
+ const prevCwdGetter = _activeCwdGetter;
6490
+ let currentCwd = (typeof options.cwd === 'string' && options.cwd.trim())
6491
+ ? VirtualPath.resolve('/workspace', options.cwd.trim())
6492
+ : '/workspace';
6368
6493
  _activeCwdGetter = () => currentCwd;
6369
6494
 
6370
6495
  const vfs = optVfs || createVirtualFs(files, { cwdGetter: () => currentCwd });
6496
+ const initialOpenFds = typeof vfs._listOpenFds === 'function'
6497
+ ? new Set(vfs._listOpenFds())
6498
+ : null;
6371
6499
  if (optVfs && files && typeof files === 'object') {
6372
6500
  for (const [fPath, content] of Object.entries(files)) {
6373
6501
  const abs = fPath.startsWith('/') ? fPath : '/workspace/' + fPath;
@@ -6380,6 +6508,9 @@ function __initVirtualRuntime(rootScope) {
6380
6508
  }
6381
6509
  }
6382
6510
  }
6511
+ if (typeof vfs._setActiveStdin === 'function') {
6512
+ vfs._setActiveStdin(options && options.stdin ? String(options.stdin) : '');
6513
+ }
6383
6514
  const vhttp = createVirtualHttp(resourceTracker, activePortTable);
6384
6515
  const vnet = createVirtualNet(resourceTracker, vhttp.getTrace());
6385
6516
 
@@ -6402,6 +6533,10 @@ function __initVirtualRuntime(rootScope) {
6402
6533
  }
6403
6534
  }
6404
6535
 
6536
+ const initialVfsState = (options && options._captureVfsDiff && typeof vfs._exportRawState === 'function')
6537
+ ? vfs._exportRawState()
6538
+ : null;
6539
+
6405
6540
  // Custom timer wrappers supporting .unref() / .ref() and active handle tracking
6406
6541
  function makeTimerHandle(rawId, isInterval) {
6407
6542
  const handle = {
@@ -6763,7 +6898,7 @@ function __initVirtualRuntime(rootScope) {
6763
6898
  let syncExecDepth = 0;
6764
6899
 
6765
6900
  const sandboxProcess = Object.assign(new EventEmitter(), {
6766
- env: { NODE_ENV: 'development', PATH: '/usr/local/bin:/usr/bin:/bin', HOME: '/home/user' },
6901
+ env: Object.assign({ NODE_ENV: 'development', PATH: '/usr/local/bin:/usr/bin:/bin', HOME: '/home/user' }, options.env || {}),
6767
6902
  argv: argv || ['node', entry.startsWith('/') ? entry : `/workspace/${entry}`],
6768
6903
  argv0: 'node',
6769
6904
  execArgv: [],
@@ -6843,6 +6978,9 @@ function __initVirtualRuntime(rootScope) {
6843
6978
  }
6844
6979
 
6845
6980
  // Immediately cancel all active timers and immediates
6981
+ if (typeof vfs._setActiveStdin === 'function') {
6982
+ vfs._setActiveStdin('');
6983
+ }
6846
6984
  for (const rawId of resourceTracker.allTimers) {
6847
6985
  clearTimeout(rawId);
6848
6986
  clearInterval(rawId);
@@ -8758,6 +8896,9 @@ function __initVirtualRuntime(rootScope) {
8758
8896
  hasExited = true;
8759
8897
  try { sandboxProcess.emit('exit', exitCode); } catch (err) { _runtimeLogger.debug('executeInVirtualRuntime exit listener failed', err); }
8760
8898
  }
8899
+ if (typeof vfs._setActiveStdin === 'function') {
8900
+ vfs._setActiveStdin('');
8901
+ }
8761
8902
  for (const rawId of resourceTracker.allTimers) {
8762
8903
  clearTimeout(rawId);
8763
8904
  clearInterval(rawId);
@@ -8774,12 +8915,56 @@ function __initVirtualRuntime(rootScope) {
8774
8915
  if (!isBackground) {
8775
8916
  vhttp.closeAllServers();
8776
8917
  vnet.closeAllServers();
8918
+ if (initialOpenFds && typeof vfs._listOpenFds === 'function' && typeof vfs.closeSync === 'function') {
8919
+ for (const fd of vfs._listOpenFds()) {
8920
+ if (!initialOpenFds.has(fd)) {
8921
+ try { vfs.closeSync(fd); } catch (err) { _runtimeLogger.debug('executeInVirtualRuntime closeSync leak cleanup failed', { fd, err }); }
8922
+ }
8923
+ }
8924
+ }
8777
8925
  }
8926
+ _activeCwdGetter = prevCwdGetter;
8778
8927
  }
8779
8928
 
8780
8929
  const failedTests = testResults.filter((t) => !t.passed).length;
8781
8930
  if (failedTests > 0 && exitCode === 0) exitCode = 1;
8782
8931
 
8932
+ let vfsChanges = undefined;
8933
+ if (initialVfsState && typeof vfs._exportRawState === 'function') {
8934
+ const finalVfsState = vfs._exportRawState();
8935
+ const modifiedFiles = {};
8936
+ const deletedFiles = [];
8937
+ const createdDirs = [];
8938
+ const isNodeModulesPath = (p) => p === '/workspace/node_modules' || p.startsWith('/workspace/node_modules/');
8939
+ const bytesEqual = (a, b) => {
8940
+ if (!a || !b || a.byteLength !== b.byteLength) return false;
8941
+ for (let i = 0; i < a.byteLength; i++) {
8942
+ if (a[i] !== b[i]) return false;
8943
+ }
8944
+ return true;
8945
+ };
8946
+
8947
+ for (const d of finalVfsState.dirs) {
8948
+ if (!initialVfsState.dirs.has(d) && !isNodeModulesPath(d)) {
8949
+ createdDirs.push(d);
8950
+ }
8951
+ }
8952
+ for (const [fPath, data] of finalVfsState.files.entries()) {
8953
+ if (isNodeModulesPath(fPath)) continue;
8954
+ const prev = initialVfsState.files.get(fPath);
8955
+ if (!prev || !bytesEqual(prev, data)) {
8956
+ modifiedFiles[fPath] = data;
8957
+ }
8958
+ }
8959
+ for (const fPath of initialVfsState.files.keys()) {
8960
+ if (isNodeModulesPath(fPath)) continue;
8961
+ if (!finalVfsState.files.has(fPath)) {
8962
+ deletedFiles.push(fPath);
8963
+ }
8964
+ }
8965
+ vfsChanges = { modifiedFiles, deletedFiles, createdDirs };
8966
+ }
8967
+
8783
8968
  return {
8784
8969
  ok: exitCode === 0,
8785
8970
  exitCode,
@@ -8795,6 +8980,7 @@ function __initVirtualRuntime(rootScope) {
8795
8980
  failed: failedTests
8796
8981
  },
8797
8982
  fsSnapshot: typeof vfs.getSnapshot === 'function' ? vfs.getSnapshot() : [],
8983
+ ...(vfsChanges ? { vfsChanges } : {}),
8798
8984
  httpTrace: [...vhttp.getTrace(), ...vnet.getTrace()],
8799
8985
  replValue: replValue !== undefined ? formatConsoleArg(replValue) : undefined
8800
8986
  };
@@ -9183,14 +9369,70 @@ function __initVirtualRuntime(rootScope) {
9183
9369
 
9184
9370
  exec(sql) {
9185
9371
  const cleaned = stripSqlComments(sql);
9186
- const statements = cleaned.split(';').map((s) => s.trim()).filter(Boolean);
9372
+ const statements = [];
9373
+ let cur = '';
9374
+ let i = 0;
9375
+ while (i < cleaned.length) {
9376
+ const ch = cleaned[i];
9377
+ if (ch === "'" || ch === '"') {
9378
+ const quote = ch;
9379
+ cur += ch;
9380
+ i++;
9381
+ while (i < cleaned.length) {
9382
+ if (cleaned[i] === quote && cleaned[i + 1] === quote) {
9383
+ cur += quote + quote;
9384
+ i += 2;
9385
+ continue;
9386
+ }
9387
+ if (cleaned[i] === '\\' && quote === '"') {
9388
+ cur += cleaned.slice(i, i + 2);
9389
+ i += 2;
9390
+ continue;
9391
+ }
9392
+ cur += cleaned[i];
9393
+ if (cleaned[i] === quote) {
9394
+ i++;
9395
+ break;
9396
+ }
9397
+ i++;
9398
+ }
9399
+ continue;
9400
+ }
9401
+ if (ch === ';') {
9402
+ const trimmed = cur.trim();
9403
+ if (trimmed) statements.push(trimmed);
9404
+ cur = '';
9405
+ i++;
9406
+ continue;
9407
+ }
9408
+ cur += ch;
9409
+ i++;
9410
+ }
9411
+ if (cur.trim()) statements.push(cur.trim());
9187
9412
  for (const s of statements) {
9188
9413
  this.run(s);
9189
9414
  }
9190
9415
  }
9191
9416
 
9192
9417
  transaction(fn) {
9193
- return (...args) => fn(...args);
9418
+ const db = this;
9419
+ return (...args) => {
9420
+ const snapshot = new Map();
9421
+ for (const [tblName, tbl] of db.tables.entries()) {
9422
+ snapshot.set(tblName, {
9423
+ columns: tbl.columns.map((c) => Object.assign({}, c)),
9424
+ rows: tbl.rows.map((r) => Object.assign({}, r)),
9425
+ autoInc: tbl.autoInc
9426
+ });
9427
+ }
9428
+ try {
9429
+ return fn(...args);
9430
+ } catch (err) {
9431
+ db.tables = snapshot;
9432
+ db._persistToVfs();
9433
+ throw err;
9434
+ }
9435
+ };
9194
9436
  }
9195
9437
 
9196
9438
  close() {
@@ -9479,9 +9721,11 @@ function __workerMessageLoop(workerScope) {
9479
9721
  const msg = event.data || {};
9480
9722
  const { requestId, type, payload = {} } = msg;
9481
9723
  if (type !== 'execute') return;
9724
+ workerScope.postMessage({ requestId, type: 'started' });
9482
9725
  try {
9483
9726
  const result = await runtime.executeInVirtualRuntime({
9484
9727
  ...payload,
9728
+ _captureVfsDiff: true,
9485
9729
  onStdout(text) {
9486
9730
  workerScope.postMessage({ requestId, type: 'stdout', text });
9487
9731
  },
@@ -9533,7 +9777,10 @@ function _ensureWorkerUrl() {
9533
9777
  }
9534
9778
 
9535
9779
  function _ensureWarmWorker() {
9536
- if (_warmWorker) return _warmWorker;
9780
+ if (_warmWorker && typeof Worker === 'function' && _warmWorker instanceof Worker) {
9781
+ return _warmWorker;
9782
+ }
9783
+ if (_warmWorker) _destroyWarmWorker();
9537
9784
  _warmWorker = new Worker(_ensureWorkerUrl());
9538
9785
  return _warmWorker;
9539
9786
  }
@@ -9546,6 +9793,14 @@ function _destroyWarmWorker() {
9546
9793
  _warmWorkerBusy = false;
9547
9794
  }
9548
9795
 
9796
+ _hostRuntime.destroyWorkerPool = function destroyWorkerPool() {
9797
+ _destroyWarmWorker();
9798
+ if (_cachedWorkerUrl && typeof URL !== 'undefined' && typeof URL.revokeObjectURL === 'function') {
9799
+ try { URL.revokeObjectURL(_cachedWorkerUrl); } catch (err) { _hostLogger.debug('revokeObjectURL failed', err); }
9800
+ }
9801
+ _cachedWorkerUrl = null;
9802
+ };
9803
+
9549
9804
  _hostRuntime.cancelWorkerExecution = function cancelWorkerExecution(reason = 'Execution cancelled', instanceId) {
9550
9805
  let cancelledAny = false;
9551
9806
  for (const [jobId, job] of Array.from(_activeWorkerJobs.entries())) {
@@ -9558,11 +9813,118 @@ _hostRuntime.cancelWorkerExecution = function cancelWorkerExecution(reason = 'Ex
9558
9813
  return cancelledAny;
9559
9814
  };
9560
9815
 
9816
+ function _extractWorkerFilesFromVfs(vfs) {
9817
+ const extracted = {};
9818
+ if (!vfs || typeof vfs !== 'object') return extracted;
9819
+ try {
9820
+ if (typeof vfs._exportRawState === 'function') {
9821
+ const st = vfs._exportRawState();
9822
+ for (const [absPath, bytes] of st.files.entries()) {
9823
+ extracted[absPath] = bytes;
9824
+ }
9825
+ return extracted;
9826
+ }
9827
+ if (vfs.files instanceof Map) {
9828
+ for (const [absPath, entry] of vfs.files.entries()) {
9829
+ if (!entry) continue;
9830
+ const data = entry.data !== undefined ? entry.data : entry;
9831
+ if (typeof data === 'string') {
9832
+ extracted[absPath] = data;
9833
+ } else if (data instanceof Uint8Array) {
9834
+ extracted[absPath] = data.slice();
9835
+ } else if (ArrayBuffer.isView(data)) {
9836
+ extracted[absPath] = new Uint8Array(data.buffer, data.byteOffset, data.byteLength).slice();
9837
+ }
9838
+ }
9839
+ return extracted;
9840
+ }
9841
+ if (typeof vfs.readdirSync === 'function' && typeof vfs.readFileSync === 'function') {
9842
+ const walk = (dir) => {
9843
+ let entries = [];
9844
+ try { entries = vfs.readdirSync(dir); } catch (_) { return; }
9845
+ for (const name of entries) {
9846
+ const full = dir === '/' ? '/' + name : dir + '/' + name;
9847
+ let isDir = false;
9848
+ try { isDir = vfs.statSync(full).isDirectory(); } catch (_) { isDir = false; }
9849
+ if (isDir) walk(full);
9850
+ else {
9851
+ try {
9852
+ const raw = vfs.readFileSync(full);
9853
+ extracted[full] = raw instanceof Uint8Array
9854
+ ? raw.slice()
9855
+ : (typeof raw === 'string' ? raw : String(raw ?? ''));
9856
+ } catch (err) {
9857
+ _hostLogger.debug('_extractWorkerFilesFromVfs: skip unreadable entry', full, err);
9858
+ }
9859
+ }
9860
+ }
9861
+ };
9862
+ walk('/workspace');
9863
+ walk('/tmp');
9864
+ }
9865
+ } catch (err) {
9866
+ _hostLogger.debug('_extractWorkerFilesFromVfs failed', err);
9867
+ }
9868
+ return extracted;
9869
+ }
9870
+
9871
+ function _applyWorkerVfsChanges(vfs, vfsChanges) {
9872
+ if (!vfs || !vfsChanges || typeof vfsChanges !== 'object') return;
9873
+ const { createdDirs = [], modifiedFiles = {}, deletedFiles = [] } = vfsChanges;
9874
+ try {
9875
+ if (Array.isArray(createdDirs) && typeof vfs.mkdirSync === 'function') {
9876
+ for (const dir of createdDirs) {
9877
+ try {
9878
+ vfs.mkdirSync(dir, { recursive: true });
9879
+ } catch (err) {
9880
+ _hostLogger.debug('_applyWorkerVfsChanges: mkdirSync failed', dir, err);
9881
+ }
9882
+ }
9883
+ }
9884
+ if (modifiedFiles && typeof modifiedFiles === 'object') {
9885
+ for (const [absPath, rawBytes] of Object.entries(modifiedFiles)) {
9886
+ const slashIdx = absPath.lastIndexOf('/');
9887
+ if (slashIdx > 0 && typeof vfs.mkdirSync === 'function') {
9888
+ try {
9889
+ vfs.mkdirSync(absPath.slice(0, slashIdx), { recursive: true });
9890
+ } catch (err) {
9891
+ _hostLogger.debug('_applyWorkerVfsChanges: parent mkdirSync failed', absPath, err);
9892
+ }
9893
+ }
9894
+ const payload = rawBytes instanceof Uint8Array
9895
+ ? rawBytes
9896
+ : (ArrayBuffer.isView(rawBytes)
9897
+ ? new Uint8Array(rawBytes.buffer, rawBytes.byteOffset, rawBytes.byteLength)
9898
+ : rawBytes);
9899
+ if (typeof vfs.writeFileSync === 'function') {
9900
+ vfs.writeFileSync(absPath, payload);
9901
+ } else if (typeof vfs.writeFile === 'function') {
9902
+ vfs.writeFile(absPath, payload);
9903
+ }
9904
+ }
9905
+ }
9906
+ if (Array.isArray(deletedFiles)) {
9907
+ for (const absPath of deletedFiles) {
9908
+ try {
9909
+ if (typeof vfs.unlinkSync === 'function') vfs.unlinkSync(absPath);
9910
+ else if (typeof vfs.rmSync === 'function') vfs.rmSync(absPath, { force: true });
9911
+ } catch (err) {
9912
+ _hostLogger.debug('_applyWorkerVfsChanges: delete failed', absPath, err);
9913
+ }
9914
+ }
9915
+ }
9916
+ } catch (err) {
9917
+ _hostLogger.debug('_applyWorkerVfsChanges failed', err);
9918
+ }
9919
+ }
9920
+
9561
9921
  _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
9562
9922
  const isNonJs =
9563
9923
  Boolean(options.wasmBinary) ||
9564
9924
  Boolean(options.cppCompiler) ||
9565
9925
  Boolean(options.pythonCompiler) ||
9926
+ Boolean(options.activePortTable) ||
9927
+ Boolean(options.portTable) ||
9566
9928
  (typeof options.entry === 'string' && /\.(cpp|cc|cxx|wasm|py)$/i.test(options.entry));
9567
9929
  if (
9568
9930
  isNonJs ||
@@ -9582,6 +9944,10 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
9582
9944
  _hostRuntime.cancelWorkerExecution('Execution cancelled by new run', instanceId);
9583
9945
  }
9584
9946
 
9947
+ const mergedFiles = options.vfs
9948
+ ? Object.assign(_extractWorkerFilesFromVfs(options.vfs), options.files || {})
9949
+ : options.files;
9950
+
9585
9951
  return new Promise((resolve) => {
9586
9952
  let worker;
9587
9953
  let isWarmWorker = false;
@@ -9600,9 +9966,23 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
9600
9966
  return;
9601
9967
  }
9602
9968
 
9969
+ const startTime = typeof performance !== 'undefined' ? performance.now() : Date.now();
9603
9970
  const timeoutMs = options.timeoutMs || 15000;
9604
9971
  let settled = false;
9972
+ let userCodeStarted = false;
9605
9973
  let abortListener = null;
9974
+ const streamedStdoutChunks = [];
9975
+ const streamedStderrChunks = [];
9976
+ const streamedTestResults = [];
9977
+
9978
+ const buildTestSummary = () => {
9979
+ const failed = streamedTestResults.filter((t) => !t.passed).length;
9980
+ return {
9981
+ total: streamedTestResults.length,
9982
+ passed: streamedTestResults.length - failed,
9983
+ failed
9984
+ };
9985
+ };
9606
9986
 
9607
9987
  function releaseWorker(terminateWorker) {
9608
9988
  if (options.signal && abortListener) {
@@ -9629,14 +10009,16 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
9629
10009
  if (settled) return;
9630
10010
  settled = true;
9631
10011
  releaseWorker(true);
10012
+ const timeoutMsg = `Execution timed out after ${timeoutMs}ms (infinite loop or hung timer terminated).\n`;
9632
10013
  resolve({
9633
10014
  ok: false,
9634
10015
  timedOut: true,
9635
10016
  exitCode: 124,
9636
10017
  durationMs: timeoutMs,
9637
- stdout: '',
9638
- stderr: `Execution timed out after ${timeoutMs}ms (infinite loop or hung timer terminated).\n`,
9639
- testResults: [],
10018
+ stdout: streamedStdoutChunks.join(''),
10019
+ stderr: streamedStderrChunks.join('') + timeoutMsg,
10020
+ testResults: streamedTestResults.slice(),
10021
+ testSummary: buildTestSummary(),
9640
10022
  fsSnapshot: [],
9641
10023
  httpTrace: [],
9642
10024
  error: { message: `Execution timed out after ${timeoutMs}ms` }
@@ -9651,14 +10033,16 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
9651
10033
  settled = true;
9652
10034
  clearTimeout(timer);
9653
10035
  releaseWorker(true);
10036
+ const elapsed = Math.max(0, (typeof performance !== 'undefined' ? performance.now() : Date.now()) - startTime);
9654
10037
  resolve({
9655
10038
  ok: false,
9656
10039
  cancelled: true,
9657
10040
  exitCode: 130,
9658
- durationMs: 0,
9659
- stdout: '',
9660
- stderr: `${reason}\n`,
9661
- testResults: [],
10041
+ durationMs: elapsed,
10042
+ stdout: streamedStdoutChunks.join(''),
10043
+ stderr: streamedStderrChunks.join('') + `${reason}\n`,
10044
+ testResults: streamedTestResults.slice(),
10045
+ testSummary: buildTestSummary(),
9662
10046
  fsSnapshot: [],
9663
10047
  httpTrace: [],
9664
10048
  error: { message: reason }
@@ -9682,16 +10066,27 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
9682
10066
  worker.onmessage = (event) => {
9683
10067
  const msg = event.data || {};
9684
10068
  if (msg.requestId !== requestId) return;
9685
- if (msg.type === 'stdout' && typeof options.onStdout === 'function') {
9686
- options.onStdout(msg.text);
9687
- } else if (msg.type === 'stderr' && typeof options.onStderr === 'function') {
9688
- options.onStderr(msg.text);
9689
- } else if (msg.type === 'test-result' && typeof options.onTestResult === 'function') {
9690
- options.onTestResult(msg.testResult);
10069
+ if (msg.type === 'started') {
10070
+ userCodeStarted = true;
10071
+ } else if (msg.type === 'stdout') {
10072
+ userCodeStarted = true;
10073
+ if (typeof msg.text === 'string') streamedStdoutChunks.push(msg.text);
10074
+ if (typeof options.onStdout === 'function') options.onStdout(msg.text);
10075
+ } else if (msg.type === 'stderr') {
10076
+ userCodeStarted = true;
10077
+ if (typeof msg.text === 'string') streamedStderrChunks.push(msg.text);
10078
+ if (typeof options.onStderr === 'function') options.onStderr(msg.text);
10079
+ } else if (msg.type === 'test-result') {
10080
+ userCodeStarted = true;
10081
+ if (msg.testResult) streamedTestResults.push(msg.testResult);
10082
+ if (typeof options.onTestResult === 'function') options.onTestResult(msg.testResult);
9691
10083
  } else if (msg.type === 'complete') {
9692
10084
  if (settled) return;
9693
10085
  settled = true;
9694
10086
  clearTimeout(timer);
10087
+ if (options.vfs && msg.result && msg.result.vfsChanges) {
10088
+ _applyWorkerVfsChanges(options.vfs, msg.result.vfsChanges);
10089
+ }
9695
10090
  // Release `_warmWorker` for instant reuse, or terminate ephemeral concurrent worker
9696
10091
  releaseWorker(false);
9697
10092
  resolve(msg.result);
@@ -9700,13 +10095,16 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
9700
10095
  settled = true;
9701
10096
  clearTimeout(timer);
9702
10097
  releaseWorker(false);
10098
+ const elapsed = Math.max(0, (typeof performance !== 'undefined' ? performance.now() : Date.now()) - startTime);
10099
+ const errLine = (msg.error?.stack || msg.error?.message || 'Worker execution error') + '\n';
9703
10100
  resolve({
9704
10101
  ok: false,
9705
10102
  exitCode: 1,
9706
- durationMs: 0,
9707
- stdout: '',
9708
- stderr: (msg.error?.stack || msg.error?.message || 'Worker execution error') + '\n',
9709
- testResults: [],
10103
+ durationMs: elapsed,
10104
+ stdout: streamedStdoutChunks.join(''),
10105
+ stderr: streamedStderrChunks.join('') + errLine,
10106
+ testResults: streamedTestResults.slice(),
10107
+ testSummary: buildTestSummary(),
9710
10108
  fsSnapshot: [],
9711
10109
  httpTrace: [],
9712
10110
  error: { message: msg.error?.message || 'Worker execution error', stack: msg.error?.stack }
@@ -9714,19 +10112,40 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
9714
10112
  }
9715
10113
  };
9716
10114
 
9717
- worker.onerror = () => {
10115
+ worker.onerror = (errEvent) => {
9718
10116
  if (settled) return;
9719
10117
  settled = true;
9720
10118
  clearTimeout(timer);
9721
10119
  releaseWorker(true);
9722
- resolve(_hostRuntime.executeInVirtualRuntime(options));
10120
+ // Only fall back to in-process execution if the host blocked Blob Worker startup
10121
+ // BEFORE user code ever started. Never re-run crashed user code on the main thread.
10122
+ if (!userCodeStarted && options.allowMainThreadFallback !== false) {
10123
+ resolve(_hostRuntime.executeInVirtualRuntime(options));
10124
+ return;
10125
+ }
10126
+ const elapsed = Math.max(0, (typeof performance !== 'undefined' ? performance.now() : Date.now()) - startTime);
10127
+ const errMsg = (errEvent && errEvent.message)
10128
+ ? String(errEvent.message)
10129
+ : 'Uncaught fatal error in Web Worker execution';
10130
+ resolve({
10131
+ ok: false,
10132
+ exitCode: 1,
10133
+ durationMs: elapsed,
10134
+ stdout: streamedStdoutChunks.join(''),
10135
+ stderr: streamedStderrChunks.join('') + errMsg + '\n',
10136
+ testResults: streamedTestResults.slice(),
10137
+ testSummary: buildTestSummary(),
10138
+ fsSnapshot: [],
10139
+ httpTrace: [],
10140
+ error: { message: errMsg }
10141
+ });
9723
10142
  };
9724
10143
 
9725
10144
  worker.postMessage({
9726
10145
  requestId,
9727
10146
  type: 'execute',
9728
10147
  payload: {
9729
- files: options.files,
10148
+ files: mergedFiles,
9730
10149
  entry: options.entry,
9731
10150
  mode: options.mode,
9732
10151
  replCode: options.replCode,
@@ -9742,7 +10161,8 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
9742
10161
  printReplResult: options.printReplResult,
9743
10162
  stdin: options.stdin,
9744
10163
  wasmBinary: options.wasmBinary,
9745
- env: options.env
10164
+ env: options.env,
10165
+ cwd: options.cwd
9746
10166
  }
9747
10167
  });
9748
10168
  });
@@ -9782,9 +10202,9 @@ export const VirtualStream: any = _runtimeApi.VirtualStream;
9782
10202
  export const VirtualStreamPromises: any = _runtimeApi.VirtualStreamPromises;
9783
10203
  export const VirtualStringDecoder: any = _runtimeApi.VirtualStringDecoder;
9784
10204
  export const VirtualDns: any = _runtimeApi.VirtualDns;
9785
- export const createVirtualFs: (options?: any) => any = _runtimeApi.createVirtualFs;
9786
- export const createVirtualHttp: (portTable?: any, vfs?: any) => any = _runtimeApi.createVirtualHttp;
9787
- export const createVirtualNet: (portTable?: any) => any = _runtimeApi.createVirtualNet;
10205
+ export const createVirtualFs: (files?: any, options?: any) => any = _runtimeApi.createVirtualFs;
10206
+ export const createVirtualHttp: (resourceTracker?: any, portTable?: any) => any = _runtimeApi.createVirtualHttp;
10207
+ export const createVirtualNet: (resourceTracker?: any, httpTrace?: any) => any = _runtimeApi.createVirtualNet;
9788
10208
  export const createSqliteDatabase: (vfs?: any, getCwd?: () => string) => any = _runtimeApi.createSqliteDatabase;
9789
10209
  export const transpileTS: (code: string, filename?: string) => string = _runtimeApi.transpileTS;
9790
10210
  export const transpileForBrowser: (source: string, filename?: string) => string = _runtimeApi.transpileForBrowser;