Repository navigation
feat: derive a module's sources from what its code imports - #106
Conversation
a384a5f to
8b61543
Compare
3485dc0 to
fb5f541
Compare
An experiment on top of #86: instead of asking for a list in `dagger.include`, read the module's imports — which already say what it needs. ```typescript import { greeting } from "../shared/greet.js" ``` is enough. Generation derives `["../shared"]` and writes it into the module's `resources`, with nothing declared anywhere. Three sources, all of them the user's own code or config: - a relative specifier that resolves outside the module directory, - a `file:` or `link:` dependency in package.json, - a tsconfig `paths` target outside the module directory. A bare specifier with none of those is deliberately left alone. It resolves inside node_modules, which in a monorepo sits at the repository root — outside the module and gitignored, so chasing it would name a path the engine drops from the context anyway. `ts.preProcessFile` does the extraction: a lexical scan that needs no program, no checker, and none of the files being imported. That last part is what breaks the circularity, since the files outside the module are exactly what this is trying to discover. It also sees type-only imports, `export * from` and dynamic `import()`, and ignores a commented-out import or a lookalike string literal. Directories, not files: a specifier names `./greet.js` where the file is `greet.ts`, so the resolved path often does not exist as written. The directory covers both spellings, and whatever that file reads from beside it — which is how the runtimes fixture's `readFileSync("../shared/greeting.txt")` resolves with nothing importing it. That fixture's `dagger.include` is removed here, and `runtimes:include-runs` and `runtimes:include-cache-key` pass without it. `dagger.include` stays, unioned in, because static analysis cannot see a read from a directory nothing imports. The premise that it could be dropped entirely does not hold: a module cannot reach the workspace API either (`dag.currentWorkspace is not a function` — the engine hides `Query.currentWorkspace` from the module-facing schema), so resources are the only way such a file arrives. Signed-off-by: Tom Chauveau <[email protected]>
Correcting the premise this experiment was written against. A module *can* reach any workspace file — not through `dag.currentWorkspace`, which the engine hides from the module-facing schema, but by taking a `Workspace` argument, which the caller passes: ```typescript @func() async extra(ws: Workspace): Promise<string> { return await ws.directory("/").file("data/extra.txt").contents() } ``` Verified against a module with no resources at all: that returns the file, where `readFileSync("../data/extra.txt")` on the same path fails. So reading a file was never what resources are for, and `readFileSync` on an outside path is the wrong shape — it only works where derivation happened to include the directory anyway. That leaves resources for build-time paths alone, which is exactly what deriving from imports targets. Two more such paths, both missed before: - `tsconfig.json` `extends` pointing outside the module. Not a quiet loss: tsx reads the chain at call time and dies with `File '../tsconfig.base.json' not found.` The file is derived, not its directory — `../tsconfig.base.json` sits in the module's parent, and including that whole directory would pull in the repository. - `/// <reference path="../x.d.ts" />`, which the same scan already hands back as `referencedFiles`. With those, nothing in this repository needs `dagger.include`: the runtimes fixture's declaration is already gone, and the playground case now generates `["../shared", "../tsconfig.base.json"]` from an empty package.json and answers every function. The field stays as a fallback for what static analysis cannot see — a Deno import map, a `workspace:` dependency, a path computed at run time. Signed-off-by: Tom Chauveau <[email protected]>
Deno is where derivation has the least to go on. A Deno module has no
package.json and no tsconfig, so `deno.json`'s `imports` is its only alias
mechanism — and a module importing through one names no path outside itself:
```typescript
import { greet } from "@shared/greet"
```
Before this, nothing was derived for that and the call died with
`Module not found "file:///workspace/shared/greet.ts"`. The map entry is now
read like a tsconfig `paths` target.
A relative import already worked, since `preProcessFile` is a lexical scan and
knows nothing about runtimes — verified separately with a Deno module importing
`../../shared/greet.ts`, which derives `../shared` and runs.
Granularity follows the config rather than being imposed: `"@shared/greet":
"../shared/greet.ts"` derives the file, `"@shared/": "../shared/"` derives the
directory. An import still contributes its target's directory, because there
the extension gets rewritten and the resolved path often does not exist as
written. `npm:`, `jsr:` and `https:` targets are specifiers, not paths, and are
left alone.
Covered by `runtimes:include-deno-runs`, whose fixture imports only through the
map and asserts both the derived member and a real call, and by a unit fixture
pinning what is and is not read from a map.
Signed-off-by: Tom Chauveau <[email protected]>
Follow-on from the rebase: the derived paths now feed `sources` (dagger/dagger#14693) rather than the `resources` list it replaced, so the checks assert the read the member makes and the docs stop naming a member the engine no longer has. Nothing about derivation itself changes — it produced workspace-relative patterns before and still does, and codegen is what turns them into the reads `sources` performs. Signed-off-by: Tom Chauveau <[email protected]>
A file target groups under its own parent with the file as the include, not under the module's parent with a path as the include — that is what the parent read with an include filter means, and the renamed assertion guessed the wrong one. Behaviour was right throughout; `runtimes:include-deno-runs` now pins it. Signed-off-by: Tom Chauveau <[email protected]>
8b61543 to
2e3f4c6
Compare
We should drop dagger.include since it's no longer used.
Implicitness is the whole point of this feature, we rely on what's in the code so the user don't bother maintaining multiple source of truth.
This needs to be handled, otherwise it greatly limits the usage for that feature.
We can support that in a follow up.
We shouldn't ignore it if it's set.
We can support that in a follow up, since all our deno module rely on deno.json and not deno.jsonc for now. |
Acting on the review of #106. **Transitive imports.** Stopping at the first hop only worked by accident: a sibling directory importing from a third one scanned fine and failed to compile in the container. The scanner now resolves each specifier to a real file and follows it, breadth-first, until nothing new turns up — so `../shared/greet.ts` importing `../deeper/punctuate.js` contributes `../deeper` too, attributed to the import that reached it rather than to the module's own source. Following needs the files, so the scanner reads the workspace instead of the module alone. Narrowed to what an import can resolve to and the configs an alias can come from, not the whole tree: this runs on every generate, and a monorepo's assets have no bearing on what the module imports. It stays the cheap half — a lexical scan per file, no TypeScript program — and the expensive typedef scan downstream is still keyed on the module and the derived paths. A config target is followed the same way, which caught a bug of mine on the first real run: a Deno import map naming a file marked that file seen before enumerating it, so the one file the alias pointed at was never followed. `runtimes:include-deno-runs` pins it now. **`dagger.include` is gone.** Nothing needed it: every case is either derived or better written as a `Workspace` argument. That removes the field, `ModConfig`'s reader, `module-config`'s `get-include` resolver and its tests, the two e2e checks that exercised the field, and `docs/include.md` — which becomes `docs/module-sources.md`, since it no longer documents a field. **tsconfig `baseUrl`** is honoured: `paths` resolve against it when set. Without that, `["x/*"]` under `baseUrl: ".."` resolved inside the module and was dropped as already-part-of-the-source, which is the opposite of what setting it means. **Implicitness** stays — it is the point — but each derived path is now written to stderr with the import behind it, so `dagger generate` shows in its trace what the code asked for. Implicit is not the same as invisible. `workspace:` dependencies (#108) and `deno.jsonc` (#109) stay unsupported, as agreed, and now have issues. Signed-off-by: Tom Chauveau <[email protected]>
|
All five answered — pushed in 47e5a4b. Suite is 106 passed, 0 failed on beta.18. Transitive imports — done, and you were right that it was limiting. Stopping at the first hop only ever worked by accident: Following needs the files, so the scanner reads the workspace rather than the module alone — narrowed to what an import can resolve to plus the configs an alias can come from, not the whole tree. It stays the cheap half (lexical scan per file, no TS program), and the expensive typedef scan is still keyed on the module and the derived paths. Config targets are followed the same way, which caught a bug of mine on the first live run: a Deno import map naming a file marked that file seen before enumerating it, so the one file the alias pointed at was never followed. Both fixtures now have a second hop and Dropping tsconfig Implicitness — kept, and I agree it is the point. To your question about the log: each derived path now goes to stderr as so
One thing for you to weigh before merge: the scanner now reads the workspace on every generate, where before it read only the module. It is bounded to |
Merge debris from #106, which deleted `dagger.include`: eight places still named it, in text the merge never touched. The one that mattered is user-facing — the raise when the derived paths match nothing in the workspace told people to look at a field that is not there. The rest are docstrings, including one in the generated entrypoint itself, which told a reader its `sources` member returns "whatever its `dagger.include` declares". Also the two manifest docstrings describing what a module loses when it moves between a `[runtime]` and an entrypoint: an `include` no longer becomes a package.json field, it becomes nothing to declare. Signed-off-by: Tom Chauveau <[email protected]>
…s workspace (#86) * feat: mount only the module, and dagger.include for files outside it A generated entrypoint's call() mounted `workspace.directory("/")` — the caller's whole workspace. Every unrelated file in the repository went into the module's container (.git, build output, a root .env) and keyed it, so an edit anywhere in the repository rebuilt it. It now mounts the module's own directory and nothing else. A module that needs more declares it with `dagger.include` in its package.json, or its deno.json under Deno — the nested `dagger` object `baseImage` already lives in. Entries are paths relative to the module directory, `!`-prefixed to exclude, globs allowed, resolved at generation by module-config and baked into the recipe. One list reaches three places, which is the point: the scan runs against those paths, so an import leaving the module directory resolves to what it will resolve to at run time; the recipe mounts them beside the module; and the install reads them, so a file: dependency outside the module directory resolves. .gitignore applies to them and not to the module's own directory, which may ignore the generated clients/ it cannot run without. Refused rather than silently ignored: an absolute path, one that climbs past the workspace root, one inside the module directory, one matching nothing, a module at the workspace root, and a [runtime] module — whose manifest has an `include` field for this. A module at the workspace root generates byte-identical output; for a nested one the mount narrows and the install moves to the module's path under /deps, so the relative symlink npm leaves for a file: dependency resolves the same way under both. Signed-off-by: Tom Chauveau <[email protected]> * refactor: build a call from currentModule, and declare includes as resources The recipe read the caller's workspace. It now reads the module context the engine assembles, and declares what belongs in it. dagger/dagger#14639 gives a Dang entrypoint a `resources` member. The engine reads it while it loads the module source and adds the listed paths to the module context *and the module digest*, before anything reads that digest. So: - A call mounts `currentModule.contextDirectory` and works from `currentModule.sourceSubpath`. The engine decides what is in it — the module directory, the manifest, and whatever resources lists — so the narrowing is the engine's rather than a filter of ours. - A change to an included file gives a call a new cache key. Read from the workspace, those files sat outside everything the key covers, and a function with the default policy kept returning its first answer. This is the reason for the refactor. - The context comes from the module's own source, not the caller's, so the recipe no longer depends on running from the module's own checkout. - sourceSubpath replaces the baked module path: it is the module's path inside its context, which is not the workspace-relative one when the context root is not the workspace root. `dagger.include` is unchanged for users. Generation still resolves it from the workspace for its own scan — the member it would otherwise read is the one it is about to write — and the patterns are rebased to the module-relative form the engine resolves for the member itself. Single patterns now: a directory pattern covers the directory in that grammar, so nothing is expanded. runtime, dependencies and requireGenerated lose their workspace parameter; call() keeps its own, which the interface mandates, and no longer uses it. All three fields need beta.17, which #96 already pairs this SDK with, so the only engine-related change here is the floor the targetEngineVersion docstring records. The new include fixture's manifest names that release like every other managed one. Tests: the four Go suites; `runtimes:include-cache-key`, which rewrites the included file between two loads and fails if the stale result comes back; `runtimes:include-runs`, whose fixture imports a function and a type from the included directory and reads a file there at call time; and the full check suite on beta.17. Signed-off-by: Tom Chauveau <[email protected]> * feat: return a sources directory instead of listing resource patterns dagger/dagger#14693 replaces the `resources` member this PR was built on. The entrypoint now returns the data the module builds from rather than a list of paths for the engine to interpret: ```dang pub sources(workspace: Workspace!): Directory! { directory .withDirectory(workspace.cwd + "/..", workspace.directory("..", include: ["shared"], ...)) .withDirectory(workspace.cwd, workspace.directory(".", exclude: ["**/.git", "**/node_modules"])) } ``` The engine merges that into the module context before anything reads the module digest, so the files reach every call's cache key as they did under `resources`. What changes is everything around it: - `types` and `call` take no workspace. Declaring `sources` is what selects that interface. Under `resources` both still received one, and that workspace sat outside every cache key — a read through it could be served stale, which is the hole the replacement closes. - `sources` runs with API access and receives a workspace, so it returns a directory instead of static text. The workspace is the module's own — a local checkout, the workspace it was loaded from, or a Git commit — never the caller's. - `call` gains `callDigest`, passed to the dispatcher as DAGGER_MODULE_CALL_DIGEST, matching the Go SDK's generated entrypoint. The member is emitted for every module, not only one with outside paths: one shape for every module is the engine's choice, and it is what the interface keys on. A module declaring nothing returns its own directory alone. Declared paths are read through their parent directory with an include filter rather than named directly, because a pattern can be a directory, a file (`../tsconfig.base.json`) or a glob (`../shared/*.ts`) and the parent read spells all three the same way. Patterns are grouped by that parent, and an exclude is rebased onto the read it applies to. The module's own directory comes last so it wins a collision, and is read without .gitignore since a module may ignore the generated clients/ it cannot run without. The floor moves to beta.18, with every managed fixture. There is no compatible shape: an engine without `sources` requires the workspace argument `types` no longer takes, so the module does not load. The nullable-workspace escape the engine PR allows is deliberately not taken — it cannot be tested against a beta.18 engine from here, and a form that misfires on a new engine is worse than one that fails loudly on an old one. The Go SDK made the same choice. Signed-off-by: Tom Chauveau <[email protected]> * chore: pair with the released v1.0.0-beta.18 beta.18 ships the `sources` contract (dagger/dagger#14693) and the explicit-TTL call-digest fix (dagger/dagger#14694), so the floor this branch already declared is now a release that exists. What moves with it, the way #96 moved the last one: `engine-e2e`'s `engine-dev` pin to beta.18's commit, and the committed bindings and bundle regenerated against that schema — `packager:library-bindings/stale` regenerates from whatever engine runs the checks, so the two cannot be bumped apart. The delta is six lines, a `readOnly` option on a file mount, plus its five rolled-up declarations. #14694 is the reason `call` declares `callDigest` and sets it as DAGGER_MODULE_CALL_DIGEST on the container before the exec: the engine passes it only to an entrypoint that declares it, and an entrypoint that declares it has to key its module process exec on it, or an explicit `+cache` TTL expires while the exec still answers from cache. That PR notes the TypeScript entrypoint did not declare it yet. The whole suite now runs: 98 checks pass on beta.18, including the five that execute a generated entrypoint and could not load one before — `include-runs`, `include-cache-key`, `entrypoint-error-text`, `secondary-constructor-runs` and the generation checks that load a staged module. Signed-off-by: Tom Chauveau <[email protected]> * feat: derive a module's sources from what its code imports (#106) * feat: derive a module's resources from what its source imports An experiment on top of #86: instead of asking for a list in `dagger.include`, read the module's imports — which already say what it needs. ```typescript import { greeting } from "../shared/greet.js" ``` is enough. Generation derives `["../shared"]` and writes it into the module's `resources`, with nothing declared anywhere. Three sources, all of them the user's own code or config: - a relative specifier that resolves outside the module directory, - a `file:` or `link:` dependency in package.json, - a tsconfig `paths` target outside the module directory. A bare specifier with none of those is deliberately left alone. It resolves inside node_modules, which in a monorepo sits at the repository root — outside the module and gitignored, so chasing it would name a path the engine drops from the context anyway. `ts.preProcessFile` does the extraction: a lexical scan that needs no program, no checker, and none of the files being imported. That last part is what breaks the circularity, since the files outside the module are exactly what this is trying to discover. It also sees type-only imports, `export * from` and dynamic `import()`, and ignores a commented-out import or a lookalike string literal. Directories, not files: a specifier names `./greet.js` where the file is `greet.ts`, so the resolved path often does not exist as written. The directory covers both spellings, and whatever that file reads from beside it — which is how the runtimes fixture's `readFileSync("../shared/greeting.txt")` resolves with nothing importing it. That fixture's `dagger.include` is removed here, and `runtimes:include-runs` and `runtimes:include-cache-key` pass without it. `dagger.include` stays, unioned in, because static analysis cannot see a read from a directory nothing imports. The premise that it could be dropped entirely does not hold: a module cannot reach the workspace API either (`dag.currentWorkspace is not a function` — the engine hides `Query.currentWorkspace` from the module-facing schema), so resources are the only way such a file arrives. Signed-off-by: Tom Chauveau <[email protected]> * feat: derive tsconfig extends and triple-slash references too Correcting the premise this experiment was written against. A module *can* reach any workspace file — not through `dag.currentWorkspace`, which the engine hides from the module-facing schema, but by taking a `Workspace` argument, which the caller passes: ```typescript @func() async extra(ws: Workspace): Promise<string> { return await ws.directory("/").file("data/extra.txt").contents() } ``` Verified against a module with no resources at all: that returns the file, where `readFileSync("../data/extra.txt")` on the same path fails. So reading a file was never what resources are for, and `readFileSync` on an outside path is the wrong shape — it only works where derivation happened to include the directory anyway. That leaves resources for build-time paths alone, which is exactly what deriving from imports targets. Two more such paths, both missed before: - `tsconfig.json` `extends` pointing outside the module. Not a quiet loss: tsx reads the chain at call time and dies with `File '../tsconfig.base.json' not found.` The file is derived, not its directory — `../tsconfig.base.json` sits in the module's parent, and including that whole directory would pull in the repository. - `/// <reference path="../x.d.ts" />`, which the same scan already hands back as `referencedFiles`. With those, nothing in this repository needs `dagger.include`: the runtimes fixture's declaration is already gone, and the playground case now generates `["../shared", "../tsconfig.base.json"]` from an empty package.json and answers every function. The field stays as a fallback for what static analysis cannot see — a Deno import map, a `workspace:` dependency, a path computed at run time. Signed-off-by: Tom Chauveau <[email protected]> * feat: derive a Deno module's resources from its import map Deno is where derivation has the least to go on. A Deno module has no package.json and no tsconfig, so `deno.json`'s `imports` is its only alias mechanism — and a module importing through one names no path outside itself: ```typescript import { greet } from "@shared/greet" ``` Before this, nothing was derived for that and the call died with `Module not found "file:///workspace/shared/greet.ts"`. The map entry is now read like a tsconfig `paths` target. A relative import already worked, since `preProcessFile` is a lexical scan and knows nothing about runtimes — verified separately with a Deno module importing `../../shared/greet.ts`, which derives `../shared` and runs. Granularity follows the config rather than being imposed: `"@shared/greet": "../shared/greet.ts"` derives the file, `"@shared/": "../shared/"` derives the directory. An import still contributes its target's directory, because there the extension gets rewritten and the resolved path often does not exist as written. `npm:`, `jsr:` and `https:` targets are specifiers, not paths, and are left alone. Covered by `runtimes:include-deno-runs`, whose fixture imports only through the map and asserts both the derived member and a real call, and by a unit fixture pinning what is and is not read from a map. Signed-off-by: Tom Chauveau <[email protected]> * fix: name the sources member, not the resources it replaced Follow-on from the rebase: the derived paths now feed `sources` (dagger/dagger#14693) rather than the `resources` list it replaced, so the checks assert the read the member makes and the docs stop naming a member the engine no longer has. Nothing about derivation itself changes — it produced workspace-relative patterns before and still does, and codegen is what turns them into the reads `sources` performs. Signed-off-by: Tom Chauveau <[email protected]> * fix: assert the read the Deno import map's file target actually produces A file target groups under its own parent with the file as the include, not under the module's parent with a path as the include — that is what the parent read with an include filter means, and the renamed assertion guessed the wrong one. Behaviour was right throughout; `runtimes:include-deno-runs` now pins it. Signed-off-by: Tom Chauveau <[email protected]> * feat: follow imports transitively, and drop dagger.include Acting on the review of #106. **Transitive imports.** Stopping at the first hop only worked by accident: a sibling directory importing from a third one scanned fine and failed to compile in the container. The scanner now resolves each specifier to a real file and follows it, breadth-first, until nothing new turns up — so `../shared/greet.ts` importing `../deeper/punctuate.js` contributes `../deeper` too, attributed to the import that reached it rather than to the module's own source. Following needs the files, so the scanner reads the workspace instead of the module alone. Narrowed to what an import can resolve to and the configs an alias can come from, not the whole tree: this runs on every generate, and a monorepo's assets have no bearing on what the module imports. It stays the cheap half — a lexical scan per file, no TypeScript program — and the expensive typedef scan downstream is still keyed on the module and the derived paths. A config target is followed the same way, which caught a bug of mine on the first real run: a Deno import map naming a file marked that file seen before enumerating it, so the one file the alias pointed at was never followed. `runtimes:include-deno-runs` pins it now. **`dagger.include` is gone.** Nothing needed it: every case is either derived or better written as a `Workspace` argument. That removes the field, `ModConfig`'s reader, `module-config`'s `get-include` resolver and its tests, the two e2e checks that exercised the field, and `docs/include.md` — which becomes `docs/module-sources.md`, since it no longer documents a field. **tsconfig `baseUrl`** is honoured: `paths` resolve against it when set. Without that, `["x/*"]` under `baseUrl: ".."` resolved inside the module and was dropped as already-part-of-the-source, which is the opposite of what setting it means. **Implicitness** stays — it is the point — but each derived path is now written to stderr with the import behind it, so `dagger generate` shows in its trace what the code asked for. Implicit is not the same as invisible. `workspace:` dependencies (#108) and `deno.jsonc` (#109) stay unsupported, as agreed, and now have issues. Signed-off-by: Tom Chauveau <[email protected]> --------- Signed-off-by: Tom Chauveau <[email protected]> * fix: stop naming a field that no longer exists Merge debris from #106, which deleted `dagger.include`: eight places still named it, in text the merge never touched. The one that mattered is user-facing — the raise when the derived paths match nothing in the workspace told people to look at a field that is not there. The rest are docstrings, including one in the generated entrypoint itself, which told a reader its `sources` member returns "whatever its `dagger.include` declares". Also the two manifest docstrings describing what a module loses when it moves between a `[runtime]` and an entrypoint: an `include` no longer becomes a package.json field, it becomes nothing to declare. Signed-off-by: Tom Chauveau <[email protected]> --------- Signed-off-by: Tom Chauveau <[email protected]>
Instead of asking for a list someone has to keep in step with their own imports, read the imports. They already say what the module needs.
That is the whole input. Generation derives
../shared, follows what that file imports, and returns the lot from the module'ssourcesmember — with nothing declared anywhere.The field is gone
dagger.includewas kept through the first three commits as a fallback for what static analysis could not see. The review settled that it has no such case left, so the last commit removes it: the field,ModConfig's reader,module-config'sget-includeresolver and its tests, the two e2e checks that exercised it, anddocs/include.md— nowdocs/module-sources.md, since it no longer documents a field.What made that possible is that reading a file was never what resources are for. A module takes a
Workspaceargument and the caller passes one, which is how every check in this repo works. Verified against a module with nothing declared:async extra(ws: Workspace)→ws.directory("/").file("data/extra.txt")readFileSync("../data/extra.txt")ENOENTSo
readFileSyncon an outside path is the wrong shape — it only works where derivation happened to include the directory anyway, which is why../shared/version.txtresolves without anything importing it. That leaves resources for build-time paths, which is exactly what deriving from imports targets.What is read
All of it the user's own code or config — nothing written for Dagger's benefit:
file:orlink:dependency inpackage.json;pathstarget intsconfig.jsonpointing outside, resolved againstbaseUrlwhen set;extendsintsconfig.jsonpointing outside — no quiet loss, tsx reads the chain at call time and dies withFile '../tsconfig.base.json' not found.;/// <reference path="../x.d.ts" />;importsentry indeno.jsonpointing outside.A bare specifier with none of those is deliberately left alone. It resolves inside
node_modules, and in a monorepo that directory sits at the repository root — outside the module and gitignored, so naming it would name a path the engine drops anyway. That is also whyfile:/paths/importshave to be read instead: they are how a bare specifier legitimately points outside, through a symlink static analysis cannot follow.Transitive
Stopping at the first hop only ever worked by accident.
../shared/greet.tsimporting../deeper/punctuate.jsscanned clean and then failed to compile in the container, because nothing put../deeperin the module context.Each specifier now resolves to a real file — swapping
./x.jsback tox.ts, finding an index file for a directory import — and that file is followed, breadth-first, until nothing new turns up. A path is attributed to the import that reached it, which is the one a user can act on:Config targets are followed the same way. That caught a bug of mine on the first live run: a Deno import map naming a file marked that file seen before enumerating it, so the one file the alias pointed at was never followed. Unit tests missed it because no fixture had a second hop; the real call said
Module not found "file:///workspace/deeper/punctuate.js". Both fixtures now carry one.Following needs the files, so the scanner reads the workspace rather than the module alone — bounded to
**/*.ts*pluspackage.json,tsconfig.jsonanddeno.json, skippingnode_modules. This is the one cost worth your eye: it is strictly more I/O per generate than before. It stays the cheap half — a lexical scan per file, no TypeScript program — and the expensive typedef scan downstream is still keyed on the module and the derived paths, not on all of it.Implicitness is the design
The set is derived, not declared, so there is one source of truth and nothing to keep in step. Implicit is not the same as invisible, though: every derived path goes to stderr with the import behind it, so
dagger generateshows in its trace what the code asked for. A surprise entry is then placeable without reading the generated file.Why
preProcessFileThe obvious approach — resolve the module's imports with a TS program — is circular for the first pass: resolution needs the files, and the files outside the module are exactly what you are trying to discover.
ts.preProcessFileis a lexical scan that needs no program and no checker, only the one file's text:Type-only imports and dynamic
import()in, commented-out import and lookalike string literal out. Resolution against the filesystem happens after that, to decide what to follow.Deno
Deno is where derivation has the least to go on: no package.json, no tsconfig, so the import map is a module's only alias mechanism — and a module importing through one names no path outside itself.
import … from "../../shared/greet.ts"../shared, runsimport … from "@shared/greet"(map →../shared/greet.ts)Module not found../shared/greet.tsplus what it imports, runsA relative import needed no Deno-specific code at all, since
preProcessFileknows nothing about runtimes.npm:,jsr:andhttps:targets are specifiers, not paths, and are left alone.runtimes:include-deno-runscovers it: the fixture imports only through the map, and the check asserts the derived reads and a real call.Granularity is per source
An import contributes the directory holding its target: a specifier names
./greet.jswhere the file on disk isgreet.ts, so the resolved path often does not exist as written. The directory covers both spellings and whatever that file reads from beside it. A tsconfigpathstarget is truncated at its glob for the same reason — a nested@alias/deep/thingneeds the directory, not one level of it.A config entry contributes exactly what it names, since its path is exact with no extension rewriting to absorb:
"@shared/greet": "../shared/greet.ts"derives the file,"@shared/": "../shared/"derives the directory. That matters most forextends—../tsconfig.base.jsonsits in the module's parent, and including that directory would pull in the repository root for a module one level down.Where it runs
A second bundle entry,
library/bundle/imports.js, in the introspector container before the typedef scan — it has to run first, since its output decides what the scan's tree holds.Derived paths come out workspace-relative, which is the form this SDK's own reads take; codegen rebases them into the reads the
sourcesmember performs. A path climbing past the workspace root fails generation, naming the import behind it: the SDK cannot read above that root to scan the module, so nothing would make the build work.Tests
imports.spec.tscovers what is derived (including the second hop, and that it is attributed to the import that reached it), what is correctly ignored (./helper.js, an inside tsconfig alias, the SDK's ownfile:./clients/dagger, a registry dependency,node:fs),baseUrl, a Deno import map and its transitive hop, and — pinned deliberately — that areadFileSyncwith no import is not found, which is the boundary aWorkspaceargument is for.Also driven by hand against the
typescript/include-resourcesplayground case with nothing declared:greetreturnshello world from ../shared!!— the!!coming from a second-hop directory nothing in the module names — and the Deno module answers the same through its import map alone.Not covered
workspace:dependencies name a member, not a path, so they are skipped rather than guessed at → Derive resources from aworkspace:dependency #108. A pnpm monorepo is where this bites first.deno.jsoncis not read, onlydeno.json→ Read deno.jsonc, not only deno.json #109. That one has a second half:ModConfigdetects the runtime fromdeno.jsonalone, so adeno.jsonc-only module is currently detected as Node.package.jsonimports(#foosubpath patterns) are not read.