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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@contextjs/compiler

v25.1.0

Published

ContextJS - TypeScript compiler with extension support for transformers.

Readme

@contextjs/compiler

Tests npm License: MIT

TypeScript compiler with extensibility support for internal and external transformers.

✨ Features

  • ⚙️ Drop-in replacement for tsc with support for compiler extensions
  • 🔌 Register transformers using the ICompilerExtension API
  • 🧩 Cleanly integrates into the ContextJS CLI (@contextjs/context)
  • 🧪 Full diagnostics support with clean formatting
  • ⚙️ Supports dynamic override of tsconfig.json settings via typescriptOptions
  • 📦 Designed for testability and modular build systems
  • 🛠️ No external dependencies

📦 Installation

npm i @contextjs/compiler

🚀 Usage

Basic Compile

import { Compiler } from "@contextjs/compiler";

const result = Compiler.compile("/absolute/project/path");

if (!result.success) {
    for (const message of result.diagnostics)
        console.error(message);
}

Override TypeScript Options

You can override tsconfig.json compiler settings programmatically:

Compiler.compile("/absolute/project/path", {
    typescriptOptions: {
        target: ts.ScriptTarget.ES2022,
        strict: true,
        noEmitOnError: true
    }
});

Registering Extensions

import { Compiler, ICompilerExtension } from "@contextjs/compiler";

const myExtension: ICompilerExtension = {
    name: "my-extension",
    getTransformers(program) {
        return {
            before: [
                context => sourceFile => {
                    // Transformer logic
                    return sourceFile;
                }
            ],
            after: null
        };
    }
};

Compiler.registerExtension(myExtension);

🧪 Tests

  • 100% test coverage
  • Fully validated transformer registration, diagnostic formatting, and compilation logic

📄 API Reference

Compiler

/**
 * Entry point to the ContextJS compiler system.
 * Provides methods for compiling TypeScript projects with internal and custom extensions.
 */
export declare class Compiler {
    /**
     * Compiles a TypeScript project using registered extensions and optional custom transformers.
     *
     * @param projectPath Path to the root of the project (must contain a `tsconfig.json`).
     * @param options Optional compile options including custom transformers and diagnostic hooks.
     * @returns A result object containing the success status and formatted diagnostics.
     */
    public static compile(projectPath: string, options?: ICompilerOptions): ICompilerResult;

    /**
     * Watches a TypeScript project for changes and recompiles it when files change.
     *
     * @param projectPath Path to the root of the project (must contain a `tsconfig.json`).
     * @param options Optional watch options including custom transformers and diagnostic hooks.
     * @returns A watch object that monitors the project for changes and recompiles as needed.
     */
    public static watch(projectPath: string, options?: ICompilerOptions): typescript.WatchOfConfigFile<SemanticDiagnosticsBuilderProgram>;

    /**
     * Registers a new compiler extension.
     * This must be called before `compile()` in order for the extension to participate.
     *
     * @param extension An object implementing `ICompilerExtension`.
     */
    public static registerExtension(extension: ICompilerExtension): void;
}

Interfaces

/**
 * Represents a compiler extension that can contribute custom TypeScript transformers.
 */
export declare interface ICompilerExtension {
    /**
     * The unique name of the extension (used for identification and debugging).
     */
    name: string;

    /**
     * Provides transformer functions for a given TypeScript program.
     *
     * @param program The TypeScript program instance.
     * @returns An object containing optional `before` and `after` transformer arrays.
     */
    getTransformers(program: typescript.Program): {
        before: typescript.TransformerFactory<typescript.SourceFile>[] | null;
        after: typescript.TransformerFactory<typescript.SourceFile>[] | null;
    };
}

/**
 * Optional configuration for the `Compiler.compile()` method.
 */
export declare interface ICompilerOptions {
    /**
     * Additional custom transformers provided by the caller.
     * These will be merged with all registered internal extensions.
     */
    transformers?: typescript.CustomTransformers;

    /**
     * Optional callback invoked for each diagnostic emitted during compilation.
     */
    onDiagnostic?: (diagnostic: typescript.Diagnostic) => void;

    /**
     * Optional TypeScript compiler options that override the default ones.
     * Supports all valid `tsconfig.json` settings.
     */
    typescriptOptions?: typescript.CompilerOptions;
}

/**
 * Result object returned by `Compiler.compile()`.
 */
export declare interface ICompilerResult {
    /**
     * Indicates whether the TypeScript emit phase completed without errors.
     */
    success: boolean;

    /**
     * Full list of diagnostic messages.
     */
    diagnostics: typescript.Diagnostic[];
}