hammerkit

tsc

Compile a TypeScript project with tsc.

Compile a TypeScript project with tsc. The task runs in a node container, keeps the compiler output as its result, and is skipped when the sources and tsconfig.json are unchanged.

Install first

The task runs the tool from node_modules, and a container task only sees the files it declares and the outputs of its dependencies, so the install must be a dependency. Include the entry of your package manager (npm, yarn or pnpm) and extend the task to add it, which works with any of them and keeps the entry free of a package manager:

.hammerkit.yaml
includes:
  npm:
    git: https://github.com/no0dles/hammerkit.git
    ref: v1.22.0
    path: catalog/npm
  tsc:
    git: https://github.com/no0dles/hammerkit.git
    ref: v1.22.0
    path: catalog/tsc

tasks:
  build:
    extend: tsc:build
    deps: [npm:install]

extend keeps the entry's image, sources and commands and adds the dependency (see extending).

Tasks

TaskWhat it doesReadsProduces
buildCompile the project with tsc.package.json, tsconfig.json, SOURCE_DIROUTPUT_DIR

Inputs

InputDefaultMeaning
NODE_VERSION24Tag of the node image the task runs in, e.g. 22 or 24. The image is node:<NODE_VERSION>-alpine.
SOURCE_DIRsrcFolder with the TypeScript sources, relative to the working directory.
OUTPUT_DIRdistFolder tsc writes to. It must be the outDir of your tsconfig.json.

Another layout

The entry reads tsconfig.json and the SOURCE_DIR folder. A monorepo that shares a base configuration adds it to the task's src when it extends, for example src: [../../tsconfig.base.json].

The entry

catalog/tsc/build.yaml
# Compiles a TypeScript project with tsc. The project's own dependencies must be installed
# first, see the page of this entry.
envs:
  # tag of the node image tsc runs in
  NODE_VERSION: 24
  # folder with the TypeScript sources, relative to the working directory
  SOURCE_DIR: src
  # folder tsc writes to, the outDir of the tsconfig.json
  OUTPUT_DIR: dist

tasks:
  build:
    description: compile the project with tsc
    image: node:${NODE_VERSION}-alpine
    src: [package.json, tsconfig.json, '${SOURCE_DIR}']
    generates: ['${OUTPUT_DIR}']
    cmds:
      - node_modules/.bin/tsc

On this page