Skip to content

Commit

Permalink
Bun: allow overriding Bun framework (or force using Node.js framework) (
Browse files Browse the repository at this point in the history
#393)

#### Description (required)

- **chore: Update lockfile**
- **fix(planner/bun): Allow overriding Bun framework**

#### Related issues & labels (optional)

- Suggested label: enhancement
  • Loading branch information
yuaanlin authored Dec 1, 2024
2 parents f5cf727 + b63931b commit 1a7844f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ schema = 3
version = "v1.5.0"
hash = "sha256-ztVhGQXs67MF8UadVvG72G3ly0ypQW0IRDdOOkjYwoE="
[mod."github.com/moby/buildkit"]
version = "v0.17.1"
hash = "sha256-8ko8Phv2FHUoGeEgEr1E+y+TfAZa8yoJCkLUKtIU8DQ="
version = "v0.17.2"
hash = "sha256-MTvjpKph4ykFU8umwxN2xS8k3L2CwMElHYaHTkCqIhA="
[mod."github.com/moznion/go-optional"]
version = "v0.12.0"
hash = "sha256-SCkBIo2GsDER5FnyPJknB+V5OC+Hltm9QIrfZK06vQg="
Expand Down Expand Up @@ -146,8 +146,8 @@ schema = 3
version = "v1.19.0"
hash = "sha256-MZ8EAvdgpGbw6kmUz8UOaAAAMdPPGd14TrCBAY+A1T4="
[mod."github.com/stretchr/testify"]
version = "v1.9.0"
hash = "sha256-uUp/On+1nK+lARkTVtb5RxlW15zxtw2kaAFuIASA+J0="
version = "v1.10.0"
hash = "sha256-fJ4gnPr0vnrOhjQYQwJ3ARDKPsOtA7d4olQmQWR+wpI="
[mod."github.com/subosito/gotenv"]
version = "v1.6.0"
hash = "sha256-LspbjTniiq2xAICSXmgqP7carwlNaLqnCTQfw2pa80A="
Expand Down
15 changes: 15 additions & 0 deletions internal/bun/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import (

"github.com/moznion/go-optional"
"github.com/spf13/afero"
"github.com/spf13/cast"
"github.com/zeabur/zbpack/internal/nodejs"
"github.com/zeabur/zbpack/internal/utils"
"github.com/zeabur/zbpack/pkg/plan"
"github.com/zeabur/zbpack/pkg/types"
)

// PlanContext is the context for Bun project planning.
type PlanContext struct {
PackageJSON nodejs.PackageJSON
Src afero.Fs
Config plan.ImmutableProjectConfiguration

Framework optional.Option[types.BunFramework]
}
Expand Down Expand Up @@ -62,6 +65,7 @@ func CreateBunContext(opt GetMetaOptions) *PlanContext {
return &PlanContext{
PackageJSON: packageJSON,
Src: opt.Src,
Config: opt.Config,
}
}

Expand All @@ -74,6 +78,17 @@ func DetermineFramework(ctx *PlanContext) types.BunFramework {
return framework
}

// Return None if Node.js framework is specified.
if ctx.Config.Get("node.framework").IsSome() {
*fw = optional.Some(types.BunFrameworkNone)
return fw.Unwrap()
}

if framework, err := plan.Cast(ctx.Config.Get("bun.framework"), cast.ToStringE).Take(); err == nil {
*fw = optional.Some(types.BunFramework(framework))
return fw.Unwrap()
}

if _, isBaojs := packageJSON.Dependencies["baojs"]; isBaojs {
*fw = optional.Some(types.BunFrameworkBaojs)
return fw.Unwrap()
Expand Down

0 comments on commit 1a7844f

Please sign in to comment.