-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(turborepo): support Bun #5934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f6aeecd
Capture incremental state.
nathanhammond 50afda0
compiles
nathanhammond af190ad
Refactor Go lockfile reading code.
31ee66b
Weak type system means runtime panics.
f8a8f4c
Disable pruning for Bun.
636b3c5
SUpport bunfig for lockfile.
1cb8710
Revert "SUpport bunfig for lockfile."
c39f452
Seamless reading of bun lockfile.
34cd7f9
Correct object name.
0bed28a
Make Go lint happy.
ed3f4ff
Make sure that tests get duplicated too.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package lockfile | ||
|
|
||
| import ( | ||
| "github.com/vercel/turbo/cli/internal/turbopath" | ||
| ) | ||
|
|
||
| // BunLockfile representation of bun lockfile | ||
| type BunLockfile struct { | ||
| contents []byte | ||
| } | ||
|
|
||
| var _ Lockfile = (*BunLockfile)(nil) | ||
|
|
||
| // ResolvePackage Given a package and version returns the key, resolved version, and if it was found | ||
| func (l *BunLockfile) ResolvePackage(_ turbopath.AnchoredUnixPath, _ string, _ string) (Package, error) { | ||
| // This is only used when doing calculating the transitive deps, but Rust | ||
| // implementations do this calculation on the Rust side. | ||
| panic("Unreachable") | ||
| } | ||
|
|
||
| // AllDependencies Given a lockfile key return all (dev/optional/peer) dependencies of that package | ||
| func (l *BunLockfile) AllDependencies(_ string) (map[string]string, bool) { | ||
| // This is only used when doing calculating the transitive deps, but Rust | ||
| // implementations do this calculation on the Rust side. | ||
| panic("Unreachable") | ||
| } | ||
|
|
||
| // DecodeBunLockfile Takes the contents of a bun lockfile and returns a struct representation | ||
| func DecodeBunLockfile(contents []byte) (*BunLockfile, error) { | ||
| return &BunLockfile{contents: contents}, nil | ||
| } | ||
|
|
||
| // GlobalChange checks if there are any differences between lockfiles that would completely invalidate | ||
| // the cache. | ||
| func (l *BunLockfile) GlobalChange(other Lockfile) bool { | ||
| _, ok := other.(*BunLockfile) | ||
| return !ok | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package packagemanager | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os/exec" | ||
|
|
||
| "github.com/vercel/turbo/cli/internal/fs" | ||
| "github.com/vercel/turbo/cli/internal/lockfile" | ||
| "github.com/vercel/turbo/cli/internal/turbopath" | ||
| ) | ||
|
|
||
| const command = "bun" | ||
| const bunLockfile = "bun.lockb" | ||
|
|
||
| func getLockfilePath(rootPath turbopath.AbsoluteSystemPath) turbopath.AbsoluteSystemPath { | ||
| return rootPath.UntypedJoin(bunLockfile) | ||
| } | ||
|
|
||
| var nodejsBun = PackageManager{ | ||
| Name: "nodejs-bun", | ||
| Slug: "bun", | ||
| Command: command, | ||
| Specfile: "package.json", | ||
| Lockfile: bunLockfile, | ||
| PackageDir: "node_modules", | ||
| ArgSeparator: func(userArgs []string) []string { | ||
| // Bun swallows a single "--" token. If the user is passing "--", we need | ||
| // to prepend our own so that the user's doesn't get swallowed. If they are not | ||
| // passing their own, we don't need the "--" token and can avoid the warning. | ||
| for _, arg := range userArgs { | ||
| if arg == "--" { | ||
| return []string{"--"} | ||
| } | ||
| } | ||
| return nil | ||
| }, | ||
|
|
||
| getWorkspaceGlobs: func(rootpath turbopath.AbsoluteSystemPath) ([]string, error) { | ||
| pkg, err := fs.ReadPackageJSON(rootpath.UntypedJoin("package.json")) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("package.json: %w", err) | ||
| } | ||
| if len(pkg.Workspaces) == 0 { | ||
| return nil, fmt.Errorf("package.json: no workspaces found. Turborepo requires Bun workspaces to be defined in the root package.json") | ||
| } | ||
| return pkg.Workspaces, nil | ||
| }, | ||
|
|
||
| getWorkspaceIgnores: func(pm PackageManager, rootpath turbopath.AbsoluteSystemPath) ([]string, error) { | ||
| // Matches upstream values: | ||
| // Key code: https://github.com/oven-sh/bun/blob/f267c1d097923a2d2992f9f60a6dd365fe706512/src/install/lockfile.zig#L3057 | ||
| return []string{ | ||
| "**/node_modules", | ||
| "**/.git", | ||
| }, nil | ||
| }, | ||
|
|
||
| canPrune: func(cwd turbopath.AbsoluteSystemPath) (bool, error) { | ||
| return false, nil | ||
| }, | ||
|
|
||
| GetLockfileName: func(rootPath turbopath.AbsoluteSystemPath) string { | ||
| return bunLockfile | ||
| }, | ||
|
|
||
| GetLockfilePath: func(rootPath turbopath.AbsoluteSystemPath) turbopath.AbsoluteSystemPath { | ||
| return getLockfilePath(rootPath) | ||
| }, | ||
|
|
||
| GetLockfileContents: func(projectDirectory turbopath.AbsoluteSystemPath) ([]byte, error) { | ||
| lockfilePath := getLockfilePath(projectDirectory) | ||
| cmd := exec.Command(command, lockfilePath.ToString()) | ||
| cmd.Dir = projectDirectory.ToString() | ||
|
|
||
| return cmd.Output() | ||
| }, | ||
|
|
||
| UnmarshalLockfile: func(_rootPackageJSON *fs.PackageJSON, contents []byte) (lockfile.Lockfile, error) { | ||
| return lockfile.DecodeBunLockfile(contents) | ||
| }, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.