hammerkit
Build file

Includes

Includes are similar to references, with one key difference: the working directory. An included build file runs in the directory of the file that includes it.

Includes are ideal for defining repetitive tasks once and reusing them in multiple places. Referenced files also split up tasks, but their working directory stays fixed to the directory they are in. For includes, the working directory is the directory of the including file.

The following example is a TypeScript monorepo with two projects, a and b. Project b depends on a, and both need up-to-date dependencies before compiling the source code.

build.npm.yaml
tasks:
  install:
    cmds:
     - npm install
    src:
      - package.json
      - package-lock.json
    generates:
      - node_modules

The npm install uses an include: each project has its own package.json, but the task definition is the same.

project/a/.hammerkit.yaml
tasks:
  build:
    deps: [npm:install]
    cmds:
      - node_modules/.bin/tsc -b

includes:
  npm: ../../build.npm.yaml

The build task depends on the included install task, which ensures that node_modules is installed first.

project/b/.hammerkit.yaml
tasks:
  build:
    deps: [npm:install, a:build]
    cmds:
      - node_modules/.bin/tsc -b

references:
  a: ../a
            
includes:
  npm: ../../build.npm.yaml

The build file of project b uses the same include for the npm install task. An additional reference to a and a task dependency on a:build ensure that project a is built before project b is compiled.

references vs. includes vs. extend — when to use which

All three reuse definitions, but they differ in what they reuse and where it runs:

What it pulls inWorking directoryUse it when
referencesA whole other build file (its tasks + services)The referenced file's own directoryThe other file is its own project (a sub-package you also want to build in place).
includesA whole other build fileThe including file's directoryYou want to reuse a task definition and run it here — the same install/build template across every package.
extendA single task, as a base templateThe current task's fileOne task is almost another, with a tweak or two.

A common monorepo setup combines them: an includes brings in a shared build.npm.yaml so each package runs install in its own directory, while references wire up cross-package build order. See the monorepo guide.

On this page