a6132835399954a1d5db3857b7d63fb9f58b5cf6
Poiesis
A Go tool that transpiles TypeScript to JavaScript using esbuild and executes it with goja, with an extensible builtin system.
Project Structure
reichard.io/poiesis/
├── cmd/
│ └── poiesis/ # CLI application entry point
│ └── main.go
├── internal/
│ └── runtime/
│ ├── pkg/
│ │ └── builtin/ # Builtin framework (framework only)
│ │ └── builtin.go # Registration system & type conversion
│ ├── standard/ # Standard builtin implementations
│ │ ├── fetch.go # HTTP fetch builtin
│ │ └── fetch_test.go # Tests for fetch
│ ├── runtime.go # Transpilation & execution
│ └── runtime_test.go # Runtime tests
Architecture
The project is cleanly separated into three packages:
-
internal/runtime/pkg/builtin- The framework for registering builtins and type conversion- Generic registration with automatic type inference
- Bidirectional Go ↔ JavaScript type conversion
- No builtin implementations (pure framework)
-
internal/runtime/standard- Standard builtin implementationsfetch,add,greet- Custom type converters for complex types
- Independent and easily extensible
-
internal/runtime- Runtime management- TypeScript transpilation with esbuild
- JavaScript execution with goja
- Automatically imports and registers standard builtins
Installation & Build
go build ./cmd/poiesis
Testing
go test ./...
golangci-lint run
Usage
poiesis <typescript-file>
Builtin System
The builtin system allows you to easily expose Go functions to TypeScript/JavaScript.
Adding a Builtin
Just write a Go function and register it:
// Your function
func add(a, b int) int {
return a + b
}
// Register it
func init() {
builtin.RegisterBuiltin("add", add)
}
That's it! The framework automatically:
- Converts TypeScript values to Go types
- Handles errors (panics as JS errors)
- Generates TypeScript definitions
- Manages the goja integration
Example
// TypeScript code
console.log("5 + 10 =", add(5, 10));
const response = fetch("https://httpbin.org/get");
console.log("OK:", response.ok);
console.log("Status:", response.status);
console.log("Body:", response.text());
Built-in Functions
fetch(url, options?)- HTTP requestsadd(a, b)- Simple arithmetic examplegreet(name)- String manipulation example
Dependencies
github.com/evanw/esbuild/pkg/api- TypeScript transpilationgithub.com/dop251/goja- JavaScript executiongithub.com/stretchr/testify/assert- Test assertions
Description
Languages
Go
98.6%
Nix
1.4%