Skip to content

Commit 4f0944d

Browse files
Claudeclaude
andcommitted
feat(turborepo-lockfiles): Update bun.lock support to match Bun's current implementation
This commit updates Turborepo's bun.lock parser to support features from Bun's latest lockfile format, addressing compatibility gaps and adding missing functionality. ## Changes ### Version Support - Added LockfileVersion enum to properly handle v0 and v1 lockfile formats - Implemented version validation that rejects unsupported versions - Fixed global_change() to detect lockfile version changes (was only checking package manager changes) - Added bun_global_change() standalone function for API consistency with other package managers ### New Lockfile Fields - trustedDependencies: Security-related trusted package list - overrides: Package version override mappings - catalog/catalogs: Reusable dependency version specifications (default and named groups) - os/cpu: Platform-specific dependency constraints (via new Negatable type) ### Feature Implementations #### 1. Catalog Resolution - Supports default catalog ("catalog:") and named groups ("catalog:group:") - Integrated into resolve_package() for transparent resolution - Properly handles missing catalogs/packages #### 2. Override Functionality - apply_overrides() method checks for package overrides - Modified resolve_package() to use overrides before normal resolution - Overrides work with patches (override version + patch = combined result) #### 3. V1 Workspace Optimizations - V1 lockfiles can resolve workspace dependencies directly from workspaces section - Eliminates redundant workspace entries in packages section - Reduces lockfile size and parsing overhead #### 4. Platform-Specific Dependencies - Implemented Negatable enum for os/cpu constraints - Supports single platform, multiple platforms, and negated platforms - Handles special "none" value for unconstrained packages #### 5. Subgraph Filtering - Filters overrides to only include packages in subgraph - Filters trusted dependencies appropriately - Preserves catalogs for potential references ## Testing - Added 43 new tests (72 total Bun tests, up from 29) - Comprehensive coverage of all new features - Integration tests combining multiple features - All existing tests continue to pass (238 total) ## Known Issues & Limitations 1. The LockfileVersion enum is defined but v1-specific behavior beyond workspace optimization may be incomplete 2. Trusted dependencies are parsed/filtered but don't affect installation behavior (may not be needed for Turborepo) 3. The libc field mentioned in Bun source is not implemented (marked TODO in Bun) 4. The Negatable::allows() method for platform matching is unused (added for completeness) 5. Some test fixtures use simplified examples that may not cover all real-world edge cases ## References - Based on Bun's src/install/lockfile/bun.lock.zig - Follows patterns from existing npm/pnpm/yarn implementations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6c0b9d5 commit 4f0944d

File tree

5 files changed

+2754
-4
lines changed

5 files changed

+2754
-4
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"lockfileVersion": 0,
3+
"workspaces": {
4+
"": {
5+
"name": "bun-catalog-test",
6+
"devDependencies": {
7+
"turbo": "^2.3.3"
8+
}
9+
},
10+
"apps/web": {
11+
"name": "web",
12+
"dependencies": {
13+
"react": "catalog:",
14+
"lodash": "catalog:"
15+
}
16+
},
17+
"apps/docs": {
18+
"name": "docs",
19+
"dependencies": {
20+
"react": "catalog:frontend",
21+
"next": "catalog:frontend"
22+
}
23+
}
24+
},
25+
"packages": {
26+
"turbo": ["turbo@2.3.3", "", {}, "sha512-example"],
27+
"react": ["react@18.2.0", "", {}, "sha512-react"],
28+
"lodash": ["lodash@4.17.21", "", {}, "sha512-lodash"],
29+
"docs/react": ["react@19.0.0", "", {}, "sha512-react19"],
30+
"docs/next": ["next@14.0.0", "", {}, "sha512-next14"]
31+
},
32+
"catalog": {
33+
"react": "^18.2.0",
34+
"lodash": "^4.17.21"
35+
},
36+
"catalogs": {
37+
"frontend": {
38+
"react": "^19.0.0",
39+
"next": "^14.0.0"
40+
}
41+
}
42+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"lockfileVersion": 1,
3+
"workspaces": {
4+
"": {
5+
"name": "bun-v1-test",
6+
"devDependencies": {
7+
"turbo": "^2.3.3"
8+
}
9+
},
10+
"apps/web": {
11+
"name": "web",
12+
"version": "1.0.0",
13+
"dependencies": {
14+
"@repo/ui": "packages/ui",
15+
"react": "^18.0.0"
16+
}
17+
},
18+
"apps/docs": {
19+
"name": "docs",
20+
"version": "1.0.0",
21+
"dependencies": {
22+
"@repo/ui": "packages/ui",
23+
"@repo/shared-utils": "packages/shared-utils"
24+
}
25+
},
26+
"packages/ui": {
27+
"name": "@repo/ui",
28+
"version": "0.1.0",
29+
"dependencies": {
30+
"react": "^18.0.0"
31+
},
32+
"devDependencies": {
33+
"@repo/shared-utils": "packages/shared-utils"
34+
}
35+
},
36+
"packages/shared-utils": {
37+
"name": "@repo/shared-utils",
38+
"version": "0.2.0",
39+
"dependencies": {
40+
"lodash": "^4.17.21"
41+
}
42+
}
43+
},
44+
"packages": {
45+
"turbo": ["turbo@2.3.3", {}, "sha512-turbo"],
46+
"react": ["react@18.0.0", {}, "sha512-react"],
47+
"lodash": ["lodash@4.17.21", {}, "sha512-lodash"]
48+
}
49+
}

0 commit comments

Comments
 (0)