npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

embed-typescript

v2.0.1

Published

Embed TypeScript Compiler in your NodeJS/Browser Application

Downloads

1,677

Readme

Embed-TypeScript

GitHub license NPM Version NPM Downloads Build Status Discord Badge

A powerful library that enables embedding the TypeScript compiler directly into your applications, supporting both Node.js and browser environments.

embed-typescript provides a streamlined API to compile TypeScript code on-the-fly without requiring external build tools or processes. This makes it ideal for applications that need to dynamically compile TypeScript code, such as playgrounds, code editors, or automated code generation tools.

Features

  • Compile TypeScript code programmatically in any JavaScript environment
  • Support for custom transformers during compilation
  • Detailed diagnostic information for compilation errors
  • Collection of external type definitions for dependency handling
  • Command-line tool for gathering type definitions from npm packages

Installation

npm install typescript
npm install embed-typescript

Note: TypeScript is a peer dependency that must be installed separately.

Usage Guide

Basic Compilation

The following example demonstrates how to create an embedded TypeScript compiler instance and compile some code:

import {
  EmbedTypeScript,
  IEmbedTypeScriptResult,
} from "embed-typescript";
import ts from "typescript";
import typiaTransform from "typia/lib/transform";

import external from "./external.json";

// Create a compiler instance with custom configuration
const compiler: EmbedTypeScript = new EmbedTypeScript({
  // External type definitions (collected from npm packages)
  external: external as Record<string, string>,
  
  // TypeScript compiler options
  compilerOptions: {
    target: ts.ScriptTarget.ES2015,
    module: ts.ModuleKind.CommonJS,
    downlevelIteration: true,
    esModuleInterop: true,
    skipLibCheck: true, // essential
    strict: true,
  },
  
  // Optional custom transformers (e.g., typia for runtime type validation)
  transformers: (program, diagnostics) => ({
    before: [
      typiaTransform(
        program,
        {},
        {
          addDiagnostic: (input) => diagnostics.push(input),
        }
      ),
    ],
  }),
});

// Compile TypeScript code
const result: IEmbedTypeScriptResult = compiler.compile({
  "src/index.ts": `
    import typia from "typia";
    console.log(typia.random<string>());
  `,
});

// Handle compilation result
if (result.type === "success") {
  // Access the compiled JavaScript
  console.log(result.javascript);
} else if (result.type === "failure") {
  // Handle compilation errors with detailed diagnostics
  console.error("Compilation failed:", result.diagnostics);
}

Handling External Dependencies

To include type definitions from npm packages, you can use the included CLI tool to collect them:

# 1. Create a directory for dependencies and install required packages
mkdir compiler-dependencies
cd compiler-dependencies
npm init
npm install @types/node @samchon/openapi typia

# 2. Use the CLI tool to extract type definitions into a JSON file
cd ..
npx embed-typescript external \
  --input ./compiler-dependencies \
  --output ./src/external.json

The generated external.json file contains all the TypeScript definition files (.d.ts) from the installed packages, which can then be used with the EmbedTypeScript constructor as shown in the compilation example.

Working with Compilation Results

The compile method returns an IEmbedTypeScriptResult which can be one of three types:

  1. Success - Compilation completed without errors:

    if (result.type === "success") {
      // Access the compiled JavaScript files
      const files = result.javascript; // Record<string, string>
         
      // Example: Execute the compiled code
      for (const [filename, code] of Object.entries(files)) {
        console.log(`Compiled ${filename}:`, code);
      }
    }
  2. Failure - Compilation completed but with errors or warnings:

    if (result.type === "failure") {
      // Handle compilation diagnostics
      for (const diagnostic of result.diagnostics) {
        console.error(`${diagnostic.file}: ${diagnostic.messageText}`);
      }
         
      // Note: Some JavaScript might still be generated despite errors
      console.log("Partial output:", result.javascript);
    }
  3. Exception - An unexpected error occurred during compilation:

    if (result.type === "exception") {
      console.error("Compilation process error:", result.error);
    }

Real-World Applications

Typia Playground

embed-typescript is used in several production applications:

  • typia playground - TypeScript type to runtime function
  • AutoBE - AI viral coding agent of backend server with compiler feedback
  • AutoView - AI frontend code generator with compiler feedback