Skip to content

samchon/embed-typescript

Repository files navigation

embed-typescript

GitHub license Build Status Discord Badge

Embed TypeScript and ESLint compilers in your NodeJS/Browser Application.

Packages

This monorepo contains two packages that work together to provide embedded TypeScript compilation with optional ESLint integration:

Package NPM Description
embed-typescript NPM Version NPM Downloads Core TypeScript compiler embedding
embed-eslint NPM Version NPM Downloads ESLint integration for embedded TypeScript

Overview

The embed-typescript project enables you to compile TypeScript code directly within your application at runtime, without requiring external build tools or processes. This is particularly useful for:

  • Online code editors and playgrounds
  • Dynamic plugin systems that accept TypeScript code
  • Code generation tools that need to validate generated TypeScript
  • Educational platforms for teaching TypeScript
  • Testing environments that generate test code dynamically

Quick Start

Basic TypeScript Compilation

npm install typescript embed-typescript
import { EmbedTypeScript } from "embed-typescript";
import ts from "typescript";

const compiler = new EmbedTypeScript({
  compilerOptions: {
    target: ts.ScriptTarget.ES2015,
    module: ts.ModuleKind.CommonJS,
    strict: true,
  },
});

const result = compiler.compile({
  "src/index.ts": `
    const greeting: string = "Hello, World!";
    console.log(greeting);
  `
});

if (result.success) {
  console.log(result.value["src/index.js"]);
  // Output: compiled JavaScript code
}

With ESLint Integration

npm install typescript embed-typescript embed-eslint
import { EmbedEsLint } from "embed-eslint";

const compiler = new EmbedEsLint({
  compilerOptions: {
    target: ts.ScriptTarget.ES2015,
    module: ts.ModuleKind.CommonJS,
  },
  rules: {
    "no-floating-promises": "error",
    "@typescript-eslint/no-unused-vars": "warn",
  },
});

const result = compiler.compile({
  "src/index.ts": `
    async function fetchData() {
      return { data: "test" };
    }
    
    fetchData(); // Will trigger ESLint error
  `
});

if (!result.success) {
  console.log("ESLint violations found:", result.diagnostics);
}

Key Features

  • In-memory compilation: No filesystem access required
  • Browser compatible: Works in both NodeJS and browser environments
  • Custom transformers: Support for TypeScript transformer plugins
  • Virtual filesystem: Bundle external type definitions as JSON
  • ESLint integration: Apply linting rules during compilation
  • Detailed diagnostics: Rich error information for debugging

Development

Prerequisites

  • Node.js 18.x or higher
  • pnpm 8.x or higher

Setup

# Clone the repository
git clone https://github.com/samchon/embed-typescript.git
cd embed-typescript

# Install dependencies
pnpm install

# Build all packages
pnpm build

Testing

# Run tests
cd test
npm test

Publishing

# Publish with latest tag
pnpm package:latest

# Publish with next tag
pnpm package:next

Real-World Applications

Typia Playground

embed-typescript powers several production applications:

  • typia playground - Interactive TypeScript validation playground
  • AutoBE - AI-powered backend code generator
  • AutoView - AI-powered frontend code generator

Documentation

For detailed documentation and advanced usage:

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please make sure to update tests as appropriate and follow the existing code style.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Jeongho Nam

Support

If you have any questions or need help, please:

About

Embed TypeScript Compiler into your Browser/NodeJS Application

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •