example · node · daukle/node

node-hello-dependency

A managed Node project with a dependency. The repository holds daukle.toml, src/ and the pin file daukle/npm/lock.lua, which daukle npm:resolve --resolve wrote, and nothing else: no package.json, no package-lock.json, no node_modules and no .npmrc are committed. daukle downloads a Node runtime, verifies it against a digest the plugin pins, generates a package.json into build/daukle/node/, and drives the npm that runtime bundles.

$ daukle node:run
hello from daukle: 42 is even

daukle node:install provisions node, fetches is-even and its closure against the sha256 each has in daukle/npm/lock.lua, and installs them into build/daukle/node/ with no network, and node:run does that first if needed. daukle tasks lists the two tasks and their order.

Run ls afterwards. Beside daukle.toml, src/ and build/ the root now holds a node_modules link and a package.json copy, both placed by node:install and both meant to be gitignored.

What to look at

src/main.mjs imports is-even as a bare specifier, and node_modules is three directories away in build/daukle/node/, which node's own resolution would never find. What finds it is __daukle_resolver__.mjs, generated beside those packages and handed to node with --import. It is a module.registerHooks resolve hook, it covers import and require alike, and it needs neither the root node_modules nor the root package.json, which exist for the tools that bypass it.

This example names a published coordinate, exactly as your project would, so the directory can be copied anywhere and daukle sync works. The suite runs it twice, once as committed against the published release and once with this repository's working tree staged over a copy, so a break in the plugin as it stands reddens this repository rather than waiting for a release. The two lines are a pinned resolver and a coordinate:

[resolvers.github]
url = "https://raw.githubusercontent.com/daukle/daukle/<commit>/plugins/github-releases.lua"
sha256 = "..."

[plugins]
node = { resolver = "github", coordinate = "daukle/node@^1.0.0" }

Nothing vendors a copy of the plugin either way.

version is a constraint and the plugin pins what satisfies it. ">=22.15.0" takes the newest Node this plugin carries a digest for; "22.15.0" takes that one exactly. Anything that could resolve below 22.15.0 is refused outright, because the resolver this toolchain depends on does not exist there. The npm version is not separately choosable: it is whatever the Node release bundles.

.mjs, not .js. The generated package.json sits in the derived directory, which is not an ancestor of src/, so it cannot tell node that your sources are modules. The extension can, and .cjs works the same way for CommonJS. A project that wants "type": "module" to apply to its own sources writes its own package.json at the root, which daukle neither generates nor reads.

What this example cannot show

A lockfile you can commit. npm writes package-lock.json beside the generated package.json, inside build/daukle/node/, and daukle clean deletes the whole derived tree. So the install is reproducible between runs on this machine and not between machines or across a clean. That is a deferral with the cost named rather than a claim the cost is small; the design records the two shapes that would buy the property back and why neither was taken.

Resolution that daukle can see. npm turns is-even = "1.0.0" into a url and a digest, and daukle never sees either. Every other acquisition in daukle is pinned by sha256 and this one is not, because it is npm's. A toolchain that delegated resolution has not answered the question of what daukle resolves; it has avoided needing to.

npm run, workspaces, npx, or publishing. None is modelled. A project needing one of them reaches for a project-level run task, which is the escape hatch the architecture leans on.

The first run is slow

Roughly 50 MB of Node, with no progress reported while it downloads, and then npm reaching the registry. It is cached per digest afterwards, shared by every project on the machine that pins the same release.

The one file that is a harness input rather than part of the example

needs-tools marks this example as one that downloads a runtime and reaches the registry, so a local run skips it unless DAUKLE_EXAMPLE_E2E=1 is set. CI sets it on every runner. The console block above is executed rather than decorative: its $ line is run and the line beneath it must appear in the output, so the command and its result cannot drift apart the way a separate expectation file did.

Every file in it

daukle.toml

schema = 1
project = "daukle/example-node-hello-dependency"
version = "1.0.0"

[modules]

[resolvers.github]
url = "https://raw.githubusercontent.com/daukle/daukle/1f515141e06d16eace718a45944a39933611fa39/plugins/github-releases.lua"
sha256 = "3789865c266eb53fafcf7300d77a24461170c615195d92d0ddf88078c556e23e"

[plugins]
npm = { url = "https://github.com/daukle/npm/releases/download/2.1.0/plugin.lua", sha256 = "12d18faf6b72cffc6da76afe678d231ee7820229f63fd466206021dd89a2d5f6" }
node = { resolver = "github", coordinate = "daukle/node@^4.0.0" }

[toolchains.node]
version = ">=22.15.0"
entry = "src/main.mjs"

[toolchains.npm]
version = ">=22.15.0"

[toolchains.npm.packages]
is-even = "1.0.0"

daukle/npm/lock.lua

-- Generated by npm:resolve. Do not edit: daukle.toml is yours, this is not.
-- Loaded by daukle itself: no daukle.lua line is needed.

do
  local toolchains = daukle.config.toolchains
  local own = toolchains and toolchains["npm"]
  if own ~= nil then
    own.pinnedFrom = {
      packages = { ["is-even"] = "1.0.0" },
      devPackages = {  },
    }
  end
  local target = toolchains and toolchains["node"]
  if target ~= nil then
    target.npmLock = {
      text = [[
{
  "name": "npm",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "dependencies": {
        "is-even": "1.0.0"
      },
      "devDependencies": {}
    },
    "node_modules/is-buffer": {
      "version": "1.1.6",
      "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
      "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==",
      "license": "MIT"
    },
    "node_modules/is-even": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/is-even/-/is-even-1.0.0.tgz",
      "integrity": "sha512-LEhnkAdJqic4Dbqn58A0y52IXoHWlsueqQkKfMfdEnIYG8A1sm/GHidKkS6yvXlMoRrkM34csHnXQtOqcb+Jzg==",
      "license": "MIT",
      "dependencies": {
        "is-odd": "^0.1.2"
      },
      "engines": {
        "node": ">=0.10.0"
      }
    },
    "node_modules/is-number": {
      "version": "3.0.0",
      "resolved": "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz",
      "integrity": "sha512-4cboCqIpliH+mAvFNegjZQ4kgKc3ZUhQVr3HvWbSh5q3WH2v82ct+T2Y1hdU5Gdtorx/cLifQjqCbL7bpznLTg==",
      "license": "MIT",
      "dependencies": {
        "kind-of": "^3.0.2"
      },
      "engines": {
        "node": ">=0.10.0"
      }
    },
    "node_modules/is-odd": {
      "version": "0.1.2",
      "resolved": "https://registry.npmjs.org/is-odd/-/is-odd-0.1.2.tgz",
      "integrity": "sha512-Ri7C2K7o5IrUU9UEI8losXJCCD/UtsaIrkR5sxIcFg4xQ9cRJXlWA5DQvTE0yDc0krvSNLsRGXN11UPS6KyfBw==",
      "license": "MIT",
      "dependencies": {
        "is-number": "^3.0.0"
      },
      "engines": {
        "node": ">=0.10.0"
      }
    },
    "node_modules/kind-of": {
      "version": "3.2.2",
      "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz",
      "integrity": "sha512-NOW9QQXMoZGg/oqnVNoNTTIFEIid1627WCffUBJEdMxYApq7mNE7CpzucIPc+ZQg25Phej7IJSmX3hO+oblOtQ==",
      "license": "MIT",
      "dependencies": {
        "is-buffer": "^1.1.5"
      },
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
]],
      entries = {
        { path = "node_modules/is-buffer", url = "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", sha256 = "3d1ad8c0a086873150d3dc69e6c6e628a3729e04e954f90ba6c0f7407272880e", as = "is-buffer 1.1.6" },
        { path = "node_modules/is-even", url = "https://registry.npmjs.org/is-even/-/is-even-1.0.0.tgz", sha256 = "d77c6aeabdfb84feed20106b7533975fe68d17d1fa7969672ddf8efb2c37b60c", as = "is-even 1.0.0" },
        { path = "node_modules/is-number", url = "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz", sha256 = "c4ad5fbaebeb2e367b73366a71016c31d7f0554a955f0017127e749f4b5c37a7", as = "is-number 3.0.0" },
        { path = "node_modules/is-odd", url = "https://registry.npmjs.org/is-odd/-/is-odd-0.1.2.tgz", sha256 = "24cf488e63ef149d0e2450ed083bdf33d4b01ea21557f57532f43b603ea2ddc8", as = "is-odd 0.1.2" },
        { path = "node_modules/kind-of", url = "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", sha256 = "78a42e34fb8ba2b9459207e6003bd3cb082333591b488f2071c5d93086b65d47", as = "kind-of 3.2.2" },
      },
    }
  end
end

src/main.mjs

import isEven from "is-even";

const answer = isEven(42) ? "even" : "odd";
console.log(`hello from daukle: 42 is ${answer}`);

Not shown here: needs-tools.