@innovatorved/code-lab 0.1.13 → 0.2.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.
@@ -34,7 +34,17 @@ export function guidedLabExtension(workbench: any, options: Partial<GuidedLabExt
34
34
  steps: workbench.steps
35
35
  };
36
36
 
37
+ if (!workbench.enabledLanguages || !(workbench.enabledLanguages instanceof Set)) {
38
+ workbench.enabledLanguages = new Set(['js']);
39
+ }
40
+
37
41
  if (parsed.tsStarterFiles || parsed.tsSolutionFiles || parsed.tsFiles) {
42
+ workbench.enabledLanguages.add('ts');
43
+ workbench.hasMultipleLanguages = true;
44
+ }
45
+
46
+ if (parsed.cppStarterFiles || parsed.cppSolutionFiles || parsed.cppFiles) {
47
+ workbench.enabledLanguages.add('cpp');
38
48
  workbench.hasMultipleLanguages = true;
39
49
  }
40
50
 
@@ -0,0 +1,54 @@
1
+ /**
2
+ * JavaScript Language Extension for CodeLab
3
+ *
4
+ * Enabled by default in CodeLab. Uses the browser's built-in JavaScript engine
5
+ * and CodeLab's zero-dependency virtual Node.js + Bun runtime (`node`, `bun`, `npm`).
6
+ */
7
+
8
+ export interface JavaScriptExtensionOptions {
9
+ /**
10
+ * Optional starter files to seed when JavaScript is selected.
11
+ */
12
+ files?: Record<string, string>;
13
+ /**
14
+ * Default entry file for JavaScript runs (e.g. 'src/demo.js' or 'index.js').
15
+ */
16
+ entry?: string;
17
+ }
18
+
19
+ export function javascriptExtension(workbench: any, options: JavaScriptExtensionOptions = {}) {
20
+ if (!workbench) return workbench;
21
+
22
+ if (!workbench.enabledLanguages || !(workbench.enabledLanguages instanceof Set)) {
23
+ workbench.enabledLanguages = new Set(['js']);
24
+ } else {
25
+ workbench.enabledLanguages.add('js');
26
+ }
27
+
28
+ if (options.files && typeof options.files === 'object') {
29
+ workbench.jsFiles = { ...(workbench.jsFiles || {}), ...options.files };
30
+ }
31
+ if (options.entry && !workbench.entry) {
32
+ workbench.entry = options.entry;
33
+ }
34
+
35
+ workbench.hasMultipleLanguages = workbench.enabledLanguages.size > 1;
36
+
37
+ if (typeof workbench._renderShell === 'function' && workbench.container) {
38
+ workbench._renderShell();
39
+ if (typeof workbench._bindEvents === 'function') workbench._bindEvents();
40
+ if (typeof workbench._renderFileLists === 'function') workbench._renderFileLists();
41
+ }
42
+
43
+ return workbench;
44
+ }
45
+
46
+ export function createJavaScriptExtension(options: JavaScriptExtensionOptions = {}) {
47
+ const plugin = (workbench: any) => javascriptExtension(workbench, options);
48
+ plugin.extensionName = 'javascript';
49
+ plugin.languageId = 'js' as const;
50
+ return plugin;
51
+ }
52
+
53
+ export const jsExtension = javascriptExtension;
54
+ export default javascriptExtension;
@@ -0,0 +1,85 @@
1
+ /**
2
+ * TypeScript Language Extension for CodeLab
3
+ *
4
+ * Zero-dependency browser TypeScript extension powered by CodeLab's built-in
5
+ * `transpileTS` compiler and virtual Node.js / Bun runtime.
6
+ */
7
+
8
+ export interface TypeScriptExtensionOptions {
9
+ /**
10
+ * Optional TypeScript workspace files (`tsFiles`).
11
+ */
12
+ files?: Record<string, string>;
13
+ /**
14
+ * Optional Guided Lab TypeScript starter files (`tsStarterFiles`).
15
+ */
16
+ starterFiles?: Record<string, string>;
17
+ /**
18
+ * Optional Guided Lab TypeScript reference solution files (`tsSolutionFiles`).
19
+ */
20
+ solutionFiles?: Record<string, string>;
21
+ /**
22
+ * Optional entry file when TypeScript is active (e.g. 'src/demo.ts').
23
+ */
24
+ entry?: string;
25
+ /**
26
+ * Immediately switch the active workbench language to 'ts'.
27
+ */
28
+ activate?: boolean;
29
+ }
30
+
31
+ export function typescriptExtension(workbench: any, options: TypeScriptExtensionOptions = {}) {
32
+ if (!workbench) return workbench;
33
+
34
+ if (!workbench.enabledLanguages || !(workbench.enabledLanguages instanceof Set)) {
35
+ workbench.enabledLanguages = new Set(['js', 'ts']);
36
+ } else {
37
+ workbench.enabledLanguages.add('ts');
38
+ }
39
+
40
+ if (options.files && typeof options.files === 'object') {
41
+ workbench.tsFiles = { ...(workbench.tsFiles || {}), ...options.files };
42
+ if (workbench.guidedConfig) {
43
+ workbench.guidedConfig.tsFiles = { ...(workbench.guidedConfig.tsFiles || {}), ...options.files };
44
+ }
45
+ }
46
+ if (options.starterFiles && typeof options.starterFiles === 'object') {
47
+ if (!workbench.guidedConfig) workbench.guidedConfig = {};
48
+ workbench.guidedConfig.tsStarterFiles = {
49
+ ...(workbench.guidedConfig.tsStarterFiles || {}),
50
+ ...options.starterFiles
51
+ };
52
+ }
53
+ if (options.solutionFiles && typeof options.solutionFiles === 'object') {
54
+ if (!workbench.guidedConfig) workbench.guidedConfig = {};
55
+ workbench.guidedConfig.tsSolutionFiles = {
56
+ ...(workbench.guidedConfig.tsSolutionFiles || {}),
57
+ ...options.solutionFiles
58
+ };
59
+ }
60
+ if (options.entry) {
61
+ workbench.tsEntry = options.entry;
62
+ }
63
+
64
+ workbench.hasMultipleLanguages = workbench.enabledLanguages.size > 1;
65
+
66
+ if (options.activate && typeof workbench.setLanguage === 'function') {
67
+ workbench.setLanguage('ts');
68
+ } else if (typeof workbench._renderShell === 'function' && workbench.container) {
69
+ workbench._renderShell();
70
+ if (typeof workbench._bindEvents === 'function') workbench._bindEvents();
71
+ if (typeof workbench._renderFileLists === 'function') workbench._renderFileLists();
72
+ }
73
+
74
+ return workbench;
75
+ }
76
+
77
+ export function createTypeScriptExtension(options: TypeScriptExtensionOptions = {}) {
78
+ const plugin = (workbench: any) => typescriptExtension(workbench, options);
79
+ plugin.extensionName = 'typescript';
80
+ plugin.languageId = 'ts' as const;
81
+ return plugin;
82
+ }
83
+
84
+ export const tsExtension = typescriptExtension;
85
+ export default typescriptExtension;
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * @innovatorved/code-lab v0.1.10
3
- * Browser-native IDE, POSIX Shell, Web Worker Node.js/Bun Runtime, and Git Engine.
2
+ * @innovatorved/code-lab v0.2.0
3
+ * Browser-native IDE, POSIX Shell, Web Worker Node.js/Bun Runtime, WASI C++20 Toolchain, and Git Engine.
4
4
  */
5
5
 
6
6
  export * from './schemas';
@@ -51,8 +51,36 @@ export {
51
51
  } from './shell';
52
52
  export * from './terminal';
53
53
  export { guidedLabExtension } from './extensions/guided-lab';
54
+ export {
55
+ type JavaScriptExtensionOptions,
56
+ javascriptExtension,
57
+ createJavaScriptExtension
58
+ } from './extensions/javascript';
59
+ export {
60
+ type TypeScriptExtensionOptions,
61
+ typescriptExtension,
62
+ createTypeScriptExtension
63
+ } from './extensions/typescript';
64
+ export {
65
+ type CppCompileOptions,
66
+ type CppCompileResult,
67
+ type CppCompilerAdapter,
68
+ DEFAULT_CPP_CDN_BASE_URL,
69
+ BUILTIN_CPP_HEADERS,
70
+ extractTarToVfs,
71
+ createTarArchive,
72
+ seedCppHeadersIntoVfs,
73
+ parseCppCompilerFlags,
74
+ CppToolchainManager,
75
+ registerCppCompilerOnRuntime,
76
+ cppExtension,
77
+ createCppExtension
78
+ } from './extensions/cpp';
54
79
 
55
80
  import { guidedLabExtension } from './extensions/guided-lab';
81
+ import { javascriptExtension } from './extensions/javascript';
82
+ import { typescriptExtension } from './extensions/typescript';
83
+ import { cppExtension } from './extensions/cpp';
56
84
 
57
85
  declare const globalThis: any;
58
86
  const root = typeof window !== 'undefined' ? window : (typeof globalThis !== 'undefined' ? globalThis : {});
@@ -61,6 +89,9 @@ const root = typeof window !== 'undefined' ? window : (typeof globalThis !== 'un
61
89
  if (root.CodeLab) {
62
90
  root.CodeLab.extensions = root.CodeLab.extensions || {};
63
91
  root.CodeLab.extensions.guidedLab = guidedLabExtension;
92
+ root.CodeLab.extensions.javascript = javascriptExtension;
93
+ root.CodeLab.extensions.typescript = typescriptExtension;
94
+ root.CodeLab.extensions.cpp = cppExtension;
64
95
  }
65
96
 
66
97
  export default (root.CodeLab || {});