Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,38 @@ coverage/

# Temporary folders
tmp/
temp/
temp/

# Vendor files (large dependencies for demos only)
**/vendor/

# Development tools (not needed in repo)
**/.prettierrc

# Test files and demo files - prevent them from being created
**/test*.mjs
**/test*.html
**/quick-test.mjs
**/debug-*.html
**/simple-test.html
**/offline-demo.html

# Extra integration files (allow only integration-demo.html)
**/integration-*.mjs
**/integration-example.*

# Extra documentation files - keep only README.md
**/*EXAMPLES.md
**/*CHECKLIST.md
**/PROJECT_DOCUMENTATION.md
**/QUICK_REFERENCE.md
**/README-INTEGRATION.md
**/TEACHING_GUIDE.md
**/DEMO_EXAMPLES.md
**/LEARNING_CHECKLIST.md

# Extra config files
**/tsconfig-*.json

# Specific playground files that keep coming back
packages/ts-executor/test-playground.html
116 changes: 11 additions & 105 deletions packages/ts-executor/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions packages/ts-executor/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
{
"name": "@webrunnr/ts-executor",
"version": "1.0.0",
"description": "TypeScript code executor for WebRunnr",
"description": "Offline TypeScript code executor for WebRunnr",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
"clean": "rm -rf dist",
"test": "node test-executor.mjs"
},
"dependencies": {
"@babel/standalone": "^7.28.2"
"format": "prettier --write src/**/*.ts *.mjs *.html",
"format:check": "prettier --check src/**/*.ts *.mjs *.html"
},
"devDependencies": {
"prettier": "^3.6.2",
"typescript": "^5.0.0"
},
"files": [
"dist/**/*"
]
],
"dependencies": {
"@babel/standalone": "^7.28.2"
}
}
14 changes: 0 additions & 14 deletions packages/ts-executor/src/babel-standalone.d.ts

This file was deleted.

30 changes: 15 additions & 15 deletions packages/ts-executor/src/compile.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

import {
CompilerOptions,
CompilationResult,
CompilationError,
CompilationResult,
CompilerOptions,
} from './types.js';

export class TypeScriptCompiler {
Expand All @@ -15,27 +14,32 @@ export class TypeScriptCompiler {
skipLibCheck: true,
};


private async getBabel() {
// Check if we're in browser with global Babel
// Check for global Babel (from bundled file or main app)
if (typeof window !== 'undefined' && (window as any).Babel) {
return (window as any).Babel;
}

// Node.js environment - use dynamic import
const BabelModule = await import('@babel/standalone');
return BabelModule.default || BabelModule;
// In Node.js or bundled environments, try npm import
try {
// @ts-ignore - @babel/standalone doesn't have type definitions
const BabelModule = await import('@babel/standalone');
return BabelModule.default || BabelModule;
} catch (error) {
throw new Error(
'Babel not available. In browsers, ensure Babel is loaded globally. In Node.js, ensure @babel/standalone is installed.'
);
}
}


public async compile(
tsCode: string,
options?: CompilerOptions
): Promise<CompilationResult> {
try {
const mergedOptions = { ...this.defaultOptions, ...options };

// Basic TypeScript error detection
// Basic TypeScript error detection
const typeErrors = this.detectBasicTypeErrors(tsCode);
if (typeErrors.length > 0) {
return {
Expand Down Expand Up @@ -84,7 +88,7 @@ export class TypeScriptCompiler {
}

//Parses compilation errors from Babel

private parseCompilationError(error: any): CompilationError[] {
const errors: CompilationError[] = [];

Expand All @@ -103,13 +107,9 @@ export class TypeScriptCompiler {
return errors;
}


private detectBasicTypeErrors(code: string): CompilationError[] {
const errors: CompilationError[] = [];

// Very basic error detection
// For now, just return empty array (no error detection)

return errors;
}
}
Expand Down
Loading