Embed TypeScript and ESLint compilers in your NodeJS/Browser Application.
This monorepo contains two packages that work together to provide embedded TypeScript compilation with optional ESLint integration:
Package | NPM | Description |
---|---|---|
embed-typescript | Core TypeScript compiler embedding | |
embed-eslint | ESLint integration for embedded TypeScript |
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
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
}
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);
}
- 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
- Node.js 18.x or higher
- pnpm 8.x or higher
# Clone the repository
git clone https://github.com/samchon/embed-typescript.git
cd embed-typescript
# Install dependencies
pnpm install
# Build all packages
pnpm build
# Run tests
cd test
npm test
# Publish with latest tag
pnpm package:latest
# Publish with next tag
pnpm package:next
embed-typescript powers several production applications:
- typia playground - Interactive TypeScript validation playground
- AutoBE - AI-powered backend code generator
- AutoView - AI-powered frontend code generator
For detailed documentation and advanced usage:
Contributions are welcome! Please:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Please make sure to update tests as appropriate and follow the existing code style.
This project is licensed under the MIT License - see the LICENSE file for details.
Jeongho Nam
- GitHub: @samchon
- Discord: Join our community
If you have any questions or need help, please:
- Open an issue
- Join our Discord community
- Check the documentation