A TypeScript compiler service built as a Cloudflare Worker that provides real-time TypeScript compilation and error checking for HONC applications and other TypeScript projects.
HONCpiler is a cloud-based TypeScript compilation service designed to:
- Compile TypeScript code in a sandboxed Cloudflare Worker environment
- Provide type checking with full dependency resolution
- Cache npm package types for fast compilation
- Support Hono framework and Cloudflare Workers development
- Stream type definitions from npm packages on-demand
The service creates a virtual file system with TypeScript libraries and dependency types, allowing for accurate type checking without requiring local installations.
- π Fast compilation using Cloudflare Workers edge computing
- π¦ Automatic dependency resolution from npm packages
- π― TypeScript error reporting with location information
- π Streaming type definitions with intelligent caching
- π οΈ Hono framework support with specialized type handling
- π Edge deployment for low-latency global access
- π Debug mode for detailed compilation insights
flowchart LR
A[Client Code]
A --> B{"HONCpiler <br> (CF Worker)"}
B --> C["KV Storage <br> (Package Types)"]
B --> D["TypeScript VFS <br> + Error Results"]
async compileTypeScript(
files: InputFiles[],
chatId: string,
userId: string,
debug?: boolean
): Promise<ErrorInfo[]>
Parameters:
files
: Array of TypeScript files to compilechatId
: Identifier for the compilation sessionuserId
: User identifier for trackingdebug
: Optional debug mode flag
Returns: Array of compilation errors and warnings
POST /
Headers: X-Honcpiler-Auth: meow
Body: InputFiles[]
type InputFiles = {
path: string; // File path (should start with "/")
content: string; // File content
};
type ErrorInfo = {
message: string; // Error message
severity: "error" | "warning"; // Error severity
location?: string; // Optional location info
};
const files = [
{
path: "/main.ts",
content: `
import { Hono } from "hono";
const app = new Hono();
app.get("/", (c) => {
return c.text("Hello World!");
});
export default app;
`
},
{
path: "/package.json",
content: JSON.stringify({
dependencies: {
"hono": "^4.0.0"
}
})
}
];
const errors = await honcpiler.compileTypeScript(files, "chat123", "user456");
const errors = await honcpiler.compileTypeScript(
files,
"chat123",
"user456",
true // Enable debug logging
);
- Node.js 18+
- pnpm
- Cloudflare account with Workers and KV
# Install dependencies
pnpm install
# Generate Cloudflare types
pnpm cf-typegen
# Start development server
pnpm dev
# Run unit tests
pnpm test
# Type checking
pnpm typecheck
# Build for production
pnpm build
# Deploy to Cloudflare Workers
pnpm deploy
# Deploy to preview environment
pnpm deploy:preview
The service relies on cached npm package types stored in Cloudflare KV:
# Seed KV with package types
pnpm kv:seed:prod
# Download specific package types
pnpm download-types
Configure in wrangler.toml
:
[env.production.vars]
CLOUDFLARE_ENV = "production"
[env.preview.vars]
CLOUDFLARE_ENV = "preview"
- KV: Stores npm package type definitions
- COMPILE_DB: D1 database for compilation results
The service uses these TypeScript compiler options:
{
target: "ESNext",
module: "ESNext",
moduleResolution: "Bundler",
lib: ["ESNext"],
strict: true,
types: ["@cloudflare/workers-types"],
skipLibCheck: true,
noEmit: true
}
HONCpiler automatically fetches and caches type definitions for npm packages:
- Dependency Detection: Parses
package.json
files to identify dependencies - Type Resolution: Fetches
.d.ts
files from npm packages - KV Storage: Caches types in Cloudflare KV for fast access
- Virtual FS: Creates in-memory filesystem with all type definitions
- Hono: Full framework support with routing and middleware types
- @cloudflare/workers-types: Cloudflare Workers runtime types
- drizzle-orm: Database ORM type definitions
- @fiberplane/hono: Fiberplane Hono extensions
- Most npm packages with TypeScript definitions
pnpm dev
- Start development server on port 8437pnpm build
- Build for productionpnpm test
- Run test suitepnpm format
- Format code with Biomepnpm typecheck
- Type check all filespnpm deploy
- Deploy to Cloudflare Workers
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run
pnpm format
andpnpm typecheck
- Submit a pull request