Distlang CLI: How It Compiles & Packages Worker Apps (2026)
Understanding how the Distlang CLI compiles and packages worker apps for providers is essential if you’re evaluating the tool or just getting started. This guide breaks down each stage of the build pipeline, defines every key term, and explains how a single JavaScript source file becomes a deployable worker artifact on Cloudflare or a managed Distlang subdomain.
If you’re brand new to the project, the Introducing Distlang post covers the broader vision.
What Is the Distlang CLI?
The Distlang CLI is the single command-line tool for building, running, and deploying JavaScript worker applications. It handles three jobs:
- Compile your source code into backend-ready V8 worker code.
- Run the compiled app locally using the workerd runtime for testing.
- Package and deploy the app to a supported provider (Cloudflare Workers or Distlang-hosted).
Think of it as a compiler, local dev server, and deployment tool rolled into one binary. If you’ve used Cloudflare’s Wrangler CLI, the scope is similar, but the Distlang CLI adds multi-provider packaging and automatic helper module generation on top of compilation.
→ Get the getting started checklist to set up the CLI from scratch.
Compilation: What Happens When You Build
Compilation is the first phase. When you run a build command, the CLI takes your JavaScript source and transforms it into V8 worker code, meaning code that’s ready to execute inside a V8 isolate.
What “V8 Worker Code” Actually Means
The Workers runtime uses the V8 JavaScript engine, the same engine that powers Chromium and Node.js. V8 isolates are lightweight execution contexts that provide your code with its own variables and a safe sandbox. A single runtime instance can run hundreds or thousands of isolates, switching between them seamlessly. Each isolate’s memory is completely isolated from every other isolate.
This matters because isolates start much faster than virtual machines. There’s no cold boot of an entire OS. The Distlang CLI compiles your application so it’s compatible with this isolate-based execution model, whether the target runtime is Cloudflare’s global network or a local workerd process on your laptop.
Helper Module Auto-Generation
Here’s where the Distlang build step does something distinct. During compilation, the CLI scans your import statements. When it detects Distlang-specific import paths, it auto-generates helper modules that wire up the corresponding capabilities.
For example, if your code includes:
import { metrics } from "distlang/core";
The compiler doesn’t just resolve that import. It generates a helper module that connects your app to the metrics capability, handling the plumbing that would otherwise require manual setup per provider. The same pattern applies to paths like distlang/app and other module specifiers.
This auto-generation is the mechanism behind what Distlang calls its “layers model,” which we’ll cover next.
Helper Modules and the Layers Model
A helper module in Distlang is a generated code module that connects your application to a specific platform capability (metrics ingestion, ObjectDB storage, and so on) without you writing provider-specific glue code.
A layer is the broader concept: a reusable app capability that you compose into your application through imports. Instead of manually configuring a metrics pipeline or wiring up storage bindings differently for each provider, you import the layer and the CLI generates the right helper for your target.
For a deeper explanation, read about app layering in Distlang.
Why Layers Reduce Glue Code
Without layers, deploying the same function to multiple cloud providers means maintaining separate configuration files, bindings, and SDK integrations for each target. The layers model centralizes this. You write one import statement. The compiler generates the correct helper for Cloudflare Workers, Distlang-hosted, or whatever provider you’re targeting.
Current layer examples include:
- Metrics, the API-first serverless metrics service that lets you record counters and histograms directly from worker code. See the metrics glossary for workers developers for full definitions.
- ObjectDB storage, a built-in persistence layer accessible through the same import pattern.
As the platform matures, additional layers will follow the same compile-time generation pattern.
Packaging for Providers
Packaging is the second phase, distinct from compilation. After the CLI compiles your source and generates helpers, it bundles everything into a provider-specific artifact. This is the step that makes the compiled output actually deployable.
What “Provider” Means in Distlang
A provider is a deployment target. Today that means two options:
- Cloudflare Workers produces a bundle compatible with Cloudflare’s Workers runtime, which runs on a global network of thousands of machines across hundreds of locations.
- Distlang-hosted produces a bundle for one-command deploy that returns a managed
*.distlang.comsubdomain URL.
Multi-provider parity beyond these two is on the roadmap but not yet complete. The architecture is designed so that adding a new provider means adding a new packaging target, not rewriting application code.
Cloudflare Packaging
When targeting Cloudflare, the CLI produces a worker module bundle. Cloudflare Workers accept uploaded modules up to 10 MB in size, which are then distributed to every edge location within seconds. The Distlang CLI’s Cloudflare packaging step ensures the output conforms to this format, including any generated helper modules as part of the bundle.
For context on Cloudflare as a platform target, see the Cloudflare-first platform introduction.
Distlang-Hosted Packaging
When targeting Distlang-hosted deploys, the CLI packages the same compiled output but routes it to Distlang’s managed infrastructure. A single deploy command returns a live URL on a *.distlang.com subdomain.
This is useful for demos, staging environments, and quick tests where you don’t want to configure Cloudflare accounts or DNS. The hosted deploy URLs guide covers practical use cases.
→ For a full deploy walkthrough, see deploy a worker and get a hosted URL.
The Pipeline at a Glance
Here’s the full flow of how the Distlang CLI compiles and packages worker apps for providers:
Source JS
↓
distlang compile
↓
Helper modules auto-generated (metrics, ObjectDB, etc.)
↓
V8-ready worker code
↓
Provider packaging (Cloudflare or Distlang-hosted)
↓
Deploy → live URL
Each arrow represents a distinct step. The compile phase transforms code and generates helpers. The packaging phase adapts the output for the target runtime. The deploy phase pushes the artifact and returns a URL.
Local Development with workerd
Before deploying anywhere, you can build, run, and test your worker code locally. The Distlang CLI uses workerd, Cloudflare’s open-source Workers runtime, for this purpose.
How workerd Executes Your Code
workerd creates a process-wide V8 system. Individual worker isolates live inside that system, each with a separate JavaScript heap. An isolate cannot directly share JavaScript objects with another isolate, which mirrors the production isolation model. When workerd loads your compiled application, it takes the isolate lock, creates a V8 context, loads your ES modules, resolves imports, compiles the main module, and finds the exported handlers.
This means your local testing environment uses the same execution model as production. Bugs you catch locally are the bugs you’d hit in production, not artifacts of a different simulator.
Compatibility Dates
workerd supports compatibility dates, a mechanism where a date flag determines the API surface and behavior semantics for a given isolate. The runtime rejects dates newer than itself, which lets older workers retain their original behavior even as workerd and V8 get updated. The Distlang CLI respects these flags during local development, so you get accurate behavior parity.
For hands-on instructions, read about running Distlang locally with workerd or how to debug workers locally with the CLI.
How This Compares to Wrangler
Developers coming from Cloudflare’s native toolchain will naturally wonder how the Distlang CLI differs from Wrangler.
Wrangler is Cloudflare’s official CLI for building, managing, and deploying applications on Cloudflare’s developer platform. It’s the bridge between your local environment and Cloudflare’s network, and it’s excellent at that single-provider job.
The Distlang CLI adds three things on top of the compile-and-deploy workflow:
- Multi-provider packaging. The same source compiles to a Cloudflare bundle or a Distlang-hosted bundle. Wrangler targets Cloudflare only.
- Helper module generation. The compile step auto-generates layer helpers based on your imports. Wrangler doesn’t generate code; it bundles what you give it.
- Built-in layers. Capabilities like metrics and ObjectDB are available as imports, reducing the need to manually wire third-party services differently per environment.
Both tools use workerd for local development, so the local execution model is identical.
Key Terms Quick Reference
| Term | Definition |
|---|---|
| CLI | The Distlang command-line tool. Compiles, runs, and deploys worker apps. |
| Compile | Transform JavaScript source into V8-ready worker code. Includes helper generation. |
| Package | Bundle compiled output into a provider-specific artifact for deployment. |
| Provider | A deployment target: Cloudflare Workers or Distlang-hosted (more planned). |
| Helper module | Auto-generated code that wires your app to a platform capability (metrics, storage). |
| Layer | A reusable app capability available through an import statement. |
| workerd | Cloudflare’s open-source Workers runtime, used by the CLI for local development. |
| V8 isolate | A lightweight, memory-isolated execution context inside the V8 engine. |
| Deploy target | Synonym for provider. The destination where your packaged worker runs. |
| Hosted URL | A managed *.distlang.com subdomain returned after a Distlang-hosted deploy. |
What’s Next
Now that you understand how the Distlang CLI compiles and packages worker apps for providers, the next step is to try it.
→ Compare Distlang plan features to find the right tier for your project.
If you want to go deeper into specific parts of the pipeline, these guides pick up where this glossary leaves off:
- Instrument Cloudflare Workers with counters and histograms using the metrics layer.
- Flush metrics in short-lived handlers to understand how the serverless lifecycle interacts with the metrics helper.
FAQ
What programming languages does the Distlang CLI support?
The CLI compiles JavaScript worker applications. It’s built around the V8 engine and the Workers execution model, so JavaScript (including ES modules) is the primary language. WebAssembly support follows from V8’s native capabilities, but the helper generation system is designed around JS imports.
Does the CLI require a Cloudflare account to work?
No. You can compile and run apps locally with workerd without any external account. You can also deploy to Distlang-hosted infrastructure, which returns a *.distlang.com URL without touching Cloudflare at all. A Cloudflare account is only needed if you choose Cloudflare Workers as your deploy target.
How do helper modules get generated during compilation?
The CLI scans your import statements for Distlang-specific paths like distlang/core or distlang/app. When it finds these, it generates corresponding helper modules at compile time that handle the wiring for capabilities like metrics ingestion or ObjectDB storage. You don’t write this glue code yourself.
Can I deploy the same source code to both Cloudflare and Distlang-hosted?
Yes. The compilation step produces the same V8-ready code regardless of target. The packaging step is where the output diverges, producing either a Cloudflare-compatible bundle or a Distlang-hosted bundle. Your application source stays the same.
What is a “layer” in Distlang?
A layer is a reusable app capability that you add to your worker by importing it. Metrics and ObjectDB storage are current examples. The CLI generates the necessary helper modules for each layer during compilation, so you get the capability without writing provider-specific configuration.
How does local development with workerd relate to production?
workerd is the same runtime that powers Cloudflare Workers in production. When you run your app locally through the Distlang CLI, it executes inside a real V8 isolate with the same API surface and isolation model. Compatibility dates ensure that behavior matches your intended production semantics.
Will the CLI support providers beyond Cloudflare in the future?
Multi-provider parity is on the roadmap. The architecture separates compilation from packaging specifically to make adding new provider targets possible without requiring changes to application code. Today the two supported targets are Cloudflare Workers and Distlang-hosted.
How is this different from just using Cloudflare Wrangler?
Wrangler is a single-provider tool built specifically for Cloudflare. The Distlang CLI adds multi-provider packaging, compile-time helper generation for layers, and built-in capabilities like metrics and storage that work across targets. Both use workerd for local development, so the local experience is similar.