Description
Description
The dependency graph Trivy builds from bun.lock has no edges between workspaces and their direct dependencies.
Workspace packages (Relationship: workspace) and direct dependencies (Relationship: direct) are found, but workspaces have an empty DependsOn.
As a result, JSON, SBOM and the dependency tree do not show which workspace pulls in a package, or through which chain a vulnerable package gets into the project.
This describes the behavior after #11071 (the lock file is generated by bun 1.4.2).
package.json:
{
"name": "bun-ws-edges",
"workspaces": ["packages/*"],
"dependencies": {
"lodash": "4.17.21"
}
}packages/a/package.json:
{
"name": "a",
"version": "1.0.0",
"dependencies": {
"b": "workspace:*",
"ms": "2.0.0"
},
"devDependencies": {
"minimist": "1.2.8"
}
}packages/b/package.json:
{
"name": "b",
"version": "1.0.0",
"dependencies": {
"lodash": "4.17.15"
}
}bun.lock (after bun install)
{
"lockfileVersion": 2,
"configVersion": 1,
"workspaces": {
"": {
"name": "bun-ws-edges",
"dependencies": {
"lodash": "4.17.21",
},
},
"packages/a": {
"name": "a",
"version": "1.0.0",
"dependencies": {
"b": "workspace:*",
"ms": "2.0.0",
},
"devDependencies": {
"minimist": "1.2.8",
},
},
"packages/b": {
"name": "b",
"version": "1.0.0",
"dependencies": {
"lodash": "4.17.15",
},
},
},
"packages": {
"a": ["a@workspace:packages/a"],
"b": ["b@workspace:packages/b"],
"lodash": ["lodash@4.17.21", "", {}, "sha512-..."],
"minimist": ["minimist@1.2.8", "", {}, "sha512-..."],
"ms": ["ms@2.0.0", "", {}, "sha512-..."],
"b/lodash": ["lodash@4.17.15", "", {}, "sha512-..."],
}
}Packages in the output of trivy fs --include-dev-deps -f json . (fields ID, Relationship, Dev, DependsOn):
{"ID": "a@1.0.0", "Relationship": "workspace"}
{"ID": "b@1.0.0", "Relationship": "workspace"}
{"ID": "lodash@4.17.15", "Relationship": "direct"}
{"ID": "lodash@4.17.21", "Relationship": "direct"}
{"ID": "minimist@1.2.8", "Relationship": "direct", "Dev": true}
{"ID": "ms@2.0.0", "Relationship": "direct"}No package has DependsOn: there is no a → b, no a → ms, and no b → lodash@4.17.15.
For comparison, the yarn analyzer builds the workspace → dependency edges (pkg/fanal/analyzer/language/nodejs/yarn/yarn.go).
Root cause
The parser (pkg/dependency/parser/nodejs/bun/parse.go) builds edges only from the metadata of an entry in packages (dependencies in the metadata object).
Since lockfileVersion: 1, a workspace entry in packages is just an identifier ("a": ["a@workspace:packages/a"]), without metadata.
bun writes the dependencies of a workspace only to the workspaces section, and the parser uses that section only to set Relationship: direct and the Dev flag.
Implementation challenges
1. The format depends on the lock file version
In lockfileVersion: 0 (bun 1.1.x), a workspace entry in packages has metadata with its dependencies, and the workspace → dependency edges do appear today:
"a": ["a@workspace:packages/a", { "dependencies": { ... }, "devDependencies": { ... } }],A dependency on another workspace is written there as a path ("a": "packages/a") rather than "workspace:*".
Since lockfileVersion: 1, workspaces have no metadata.
As a result, the graph of the same project differs depending on the bun version that generated the lock file.
At the same time, version 0 is a legacy format: bun 1.4.2 still reads it, but rewrites the file as version 1 on the next bun install, and bun install --frozen-lockfile fails on it with lockfile had changes, but lockfile is frozen.
So it may not be worth adding dedicated handling for version 0: it may be enough that such lock files keep being parsed, while the workspace edges are built for version 1 and later.
2. Dev dependencies of workspaces
The Dev flag is computed by walking the graph from the direct prod dependencies (walkProdPackages), and workspaces are currently skipped by that walk.
Once a workspace has edges, including edges to its devDependencies, the dev dependencies of workspaces must not become prod (in the example above, minimist@1.2.8 must stay Dev: true).
3. Resolving workspace dependencies
A direct dependency of a workspace can be a nested copy (b/lodash for packages/b) or a top-level one (ms for packages/a).
The install path of a workspace comes from its <name>@workspace:<dir> entry.
A dependency on another workspace ("b": "workspace:*") points to a package with Relationship: workspace rather than a regular package.
4. Tests
The expected DependsOn in the existing parser tests (multiple workspaces, workspace with nested direct dependencies) currently has no workspace edges.
The fixtures are generated by bun 1.4.2; there is no workspace fixture for lockfileVersion: 0.
Related
- fix(nodejs): derive Bun package name and version from the identifier #11071 — resolves nested Bun dependencies and the direct dependencies of workspaces by install path.
Before implementation
Please describe the chosen approach in this issue and agree on it with the maintainers before opening a PR.
Activity
[-]fix(nodejs): Bun workspaces have no dependency edges[/-][+]Bun workspaces have no dependency edges[/+]drawliin commentedon Nov 12, 2026
hi @DmitriyLewen.. i'd like to work on this. here is the approach i have in mind.. on top of #11071 since it already resolves workspace dependencies by install path.
workspacesexcept the root, resolve itsdependencies,optionalDependencies,peerDependenciesanddevDependencieswithresolveDependency(wsPaths[wsDir], name, pkgs)and add them todeps[wsPaths[wsDir]].. deduplicated with any edges already built from metadata. the nearest copy rule gives an edge frombtob/lodash(4.17.15) and fromatoms.. and"b": "workspace:*"resolves to the workspace entryb. the root workspace has no entry inpackagesso it gets no edges.. same as today.walkProdPackageskeeps starting only from the direct prod dependencies, which skip workspaces.. so the walk never goes through a workspace. a workspace'sdevDependenciesget an edge but stayDev: trueunless a prod package also reaches them.. this matches the yarn analyzer (minimist@1.2.8in your example).lockfileVersion: 0.. no dedicated handling. workspace entries there already carry metadata so their edges keep coming from it.. the edges fromworkspacesonly merge with them.DependsOninmultiple workspacesandworkspace with nested direct dependencies.. and add the lock file from this issue (bun 1.4.2) as a case that checks the edges fromatob,msandminimistand frombtolodash@4.17.15.. plus thatminimiststays dev.i'll wait for #11071 to be merged and start from main after that.. is it suitable for you?
DmitriyLewen commentedon Nov 13, 2026
Hello @drawliin thanks, the approach looks good, assigned issue to you.
Feel free to pick it up once #11071 is merged.
A couple of notes on the tests:
bun_workspace_nested.lockhas a workspace depending on another workspace (b→a), nested copies (a/lodashetc.) and a dev dependency of a workspace (minimist@0.0.10inb), andbun_multiple_ws.lockhas a workspace dependency resolved from the top level (my-app→lodash).It's enough to update the expected
DependsOnand check thatminimist@0.0.10staysDev: true.multiple workspacescurrently doesn't checkDependsOnat all:multipleWsDepsisnil, and the test compares the dependencies only whenwantDeps != nil.Please set the expected edges there (
my-app→lodash,my-lib→chalk), otherwise the new edges aren't checked by this case.Regards, Dmitriy