Skip to main content

Deno

The Deno module gives Deno code one shared way to test, lint, format, and type-check. Each deno.json or deno.jsonc is a standalone project or a Deno workspace, and the module exposes each kind as a collection, so a check can run one project, one workspace, or everything. The same checks run locally, in CI, and in Dagger Cloud.

Add it to your workspace​

dagger module install dagger.io/js/deno

Run the checks​

CheckWhat it runs
deno/projects/test, deno/workspaces/testdeno test
deno/projects/lint, deno/workspaces/lintdeno lint
deno/projects/type-check, deno/workspaces/type-checkdeno check
deno/projects/format-check, deno/workspaces/format-checkdeno fmt --check
deno/projects/format/stale, deno/workspaces/format/staleFails when deno fmt would change a file
dagger check --deno                              # every Deno check
dagger check --deno --check=test # deno test everywhere
dagger check --deno-project=apps/api # every check for one project
dagger check --deno-workspace=. --check=lint # deno lint for one workspace

A check over several projects or workspaces reports every one that fails.

Projects and workspaces​

FlagCollectionKey
--deno-projectprojectsDirectory holding a standalone project's config, relative to the workspace root. The root is .
--deno-workspaceworkspacesDirectory holding a Deno workspace's config, relative to the workspace root

List the keys with dagger list deno-projects -a and dagger list deno-workspaces -a. Select collection items describes how to select items.

Every directory holding deno.json or deno.jsonc at or below the directory dagger runs from is found, plus the nearest one that encloses it. A config with a non-empty workspace array is a Deno workspace. Its members are checked through the workspace and are not keys of their own. Every other config is a standalone project. When dagger runs from inside a member, that member is a project, and its commands run from the workspace root, scoped to the member.

Format the source​

format-check only reports whether files are formatted; the format generator rewrites them and returns a changeset. Dagger prints the diff and asks before writing. Add -y to apply it without prompting:

dagger generate --deno                     # preview the diff
dagger generate -y --deno-project=apps/api # apply it for one project

Compile a binary​

compile builds a standalone executable from an entrypoint (default main.ts) and returns it as a file to export. It is named app unless outputName says otherwise:

dagger api call deno project --path . \
compile --entrypoint main.ts --target x86_64-unknown-linux-gnu \
export --path ./bin/app

project returns the project that contains a path, and workspace returns the Deno workspace that contains one.

Configure it​

List the current settings with dagger module settings deno, then change one with dagger module settings deno <key> <value>. They live in dagger.toml under [modules.deno.settings]:

  • version (default 2.9.3) is the Deno version of the default base image, denoland/deno:alpine-<version>. Pin this so every project is tested, linted, and formatted against the same Deno release.
  • base is the base container Deno runs in (for example docker.io/denoland/deno:debian). It must have deno on its PATH. With base set, version still decides how permissions are passed, so set it to the release base carries.
  • permissions (default config) sets the permissions test and compile run with. config uses the permission sets in deno.json (-P), all grants everything (-A), and none grants nothing. With a version before 2.5.0, config makes test use -A.
  • testArgs (default empty) are extra deno test flags, such as ["--doc", "--parallel"].
  • typeCheckArgs (default empty) are extra deno check flags, such as ["--allow-import"].
  • typeCheckTargets (default ["."]) are what type-check checks, relative to each project or workspace root, such as ["mod.ts"]. The config's exclude still applies.
# Pin the Deno version for the whole workspace
dagger module settings deno version 2.9.3
[modules.deno.settings]
version = "2.9.3"
permissions = "all"
testArgs = ["--parallel"]

Working with other modules​

Reach for this module whenever the repo contains one or more Deno projects, especially when they should share the same Deno version and CI checks. The base field and the install function expose a Deno-ready container you can hand to other modules, and version prints the configured toolchain version.

source code