Skip to main content

Module Structure

It's essential to understand a few key concepts about Dagger Modules created for use with the TypeScript SDK, for a better fit with your normal development workflow.

Runtime container with Node 21.3

Dagger Modules run in a container (called the "runtime container") that's bootstrapped specifically by the TypeScript SDK, with the necessary environment to run the module's code. It's currently hardcoded to run in Node.js 21.3 (although this may be configurable in future).

Bun is experimentally supported and work is in progress to support Deno.

Automatic SDK install

The TypeScript SDK is installed automatically, including dependencies, with a version that's tied to the currently running Dagger Engine container1:

# executed by the runtime container
npm install --package-lock-only ./sdk

This is why the initial package.json doesn't include any dependencies except a local link to the sdk generated directory.

{
"dependencies": {
"typescript": "^5.3.2"
},
"devDependencies": {
"@dagger.io/dagger": "./sdk"
}
}

Modules as TypeScript libraries

Dagger Modules in Typescript are built to be installed, like libraries. The runtime container installs the module code with:

# executed by the runtime container
npm install

This means that so long as the project has a package.json file, it can be used as a library and it can be managed using any Node.js package manager such as npm, pnpm or yarn.

Multiple files

Due to TypeScript limitations, it is not possible to split your main class module (index.ts) into multiple files. However, it is possible to create sub-classes in different files and access them from your main class module:

// src/index.ts
import { func, object } from "@dagger.io/dagger"

import { Test } from "./test" // in src/test.ts
import { Lint } from "./lint" // in src/lint.ts

@object()
class MyModule {
@func()
test(): Test {
return new Test()
}

@func()
lint(): Lint {
return new Lint()
}
}

src layout

The default template from dagger init creates a index.ts file inside a src/ directory. The TypeScript SDK expects to find the Dagger Module's source code inside the src/ directory.

Footnotes

  1. The SDK filesare mounted under /sdk in the Dagger Engine runtime container.