Skip to content

Commit fc69c58

Browse files
authored
ZEA-4609: Merge Bun/Hono logic to Node.js planner (#438)
#### Description (required) - **chore: Update gomod2nix lockfile** - **refactor(planner/bun): Merge Bun/hono logic to Node.js** - **fix(planner/nodejs): Improve Hono support for Node.js** - **test: Update snapshot** #### Related issues & labels (optional) - Closes ZEA-4609 - Suggested label: bug
2 parents 217daf3 + e574295 commit fc69c58

File tree

6 files changed

+30
-51
lines changed

6 files changed

+30
-51
lines changed

gomod2nix.toml

+8-8
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ schema = 3
3535
version = "v1.3.2"
3636
hash = "sha256-Qh2lAShlRm571xMxhAOfRoaFYzrfHmmk7RQmSiJxPbo="
3737
[mod."github.com/gkampitakis/go-snaps"]
38-
version = "v0.5.10"
39-
hash = "sha256-8lN/5584doDamZNiYe8UWIh2aMc8lJ0NH7JXJMaV0K8="
38+
version = "v0.5.11"
39+
hash = "sha256-ZSAqsHVVcrbu4BWgIoFigF8yOeI2w1lIdxgxMWrcwZo="
4040
[mod."github.com/goccy/go-yaml"]
41-
version = "v1.15.19"
42-
hash = "sha256-aDncy+24f167yD3q8aRBuwLufU4V+8cl3I9cGo4l24A="
41+
version = "v1.15.23"
42+
hash = "sha256-11AoZgodw3M2FSyu1UYL/RiGt2CfqHxX9JsRMmlDjXA="
4343
[mod."github.com/gogo/protobuf"]
4444
version = "v1.3.2"
4545
hash = "sha256-pogILFrrk+cAtb0ulqn9+gRZJ7sGnnLLdtqITvxvG6c="
@@ -143,11 +143,11 @@ schema = 3
143143
version = "v1.7.1"
144144
hash = "sha256-BjX0aY/PC37gIdMc7JhMgvhWFsksGdAcp2FgzpuvkPo="
145145
[mod."github.com/spf13/cobra"]
146-
version = "v1.8.1"
147-
hash = "sha256-yDF6yAHycV1IZOrt3/hofR+QINe+B2yqkcIaVov3Ky8="
146+
version = "v1.9.1"
147+
hash = "sha256-dzEqquABE3UqZmJuj99244QjvfojS8cFlsPr/MXQGj0="
148148
[mod."github.com/spf13/pflag"]
149-
version = "v1.0.5"
150-
hash = "sha256-w9LLYzxxP74WHT4ouBspH/iQZXjuAh2WQCHsuvyEjAw="
149+
version = "v1.0.6"
150+
hash = "sha256-NjrK0FZPIfO/p2xtL1J7fOBQNTZAPZOC6Cb4aMMvhxI="
151151
[mod."github.com/spf13/viper"]
152152
version = "v1.19.0"
153153
hash = "sha256-MZ8EAvdgpGbw6kmUz8UOaAAAMdPPGd14TrCBAY+A1T4="

internal/bun/bun.go

-9
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@ import (
1010

1111
// GenerateDockerfile generates the Dockerfile for Bun projects.
1212
func GenerateDockerfile(meta types.PlanMeta) (string, error) {
13-
if meta["framework"] == string(types.BunFrameworkHono) {
14-
return `FROM oven/bun:` + meta["bunVersion"] + ` AS base
15-
WORKDIR /src
16-
COPY package.json bun.lock* ./
17-
RUN bun install
18-
COPY . .
19-
ENTRYPOINT [ "bun", "run", "` + meta["entry"] + `" ]`, nil
20-
}
21-
2213
return nodejs.GenerateDockerfile(meta)
2314
}
2415

internal/bun/plan.go

-31
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package bun
22

33
import (
44
"log"
5-
"strings"
65

76
"github.com/moznion/go-optional"
87
"github.com/spf13/afero"
@@ -37,15 +36,6 @@ func GetMeta(opt GetMetaOptions) types.PlanMeta {
3736
bunVersion := DetermineVersion(ctx)
3837
meta["bunVersion"] = bunVersion
3938

40-
if framework == types.BunFrameworkHono {
41-
entry := determineEntry(ctx)
42-
if entry != "" {
43-
meta["entry"] = entry
44-
}
45-
46-
return meta
47-
}
48-
4939
if framework != types.BunFrameworkNone {
5040
opt.BunFramework = optional.Some(framework)
5141
}
@@ -99,31 +89,10 @@ func DetermineFramework(ctx *PlanContext) types.BunFramework {
9989
return fw.Unwrap()
10090
}
10191

102-
if _, isHono := packageJSON.Dependencies["hono"]; isHono {
103-
*fw = optional.Some(types.BunFrameworkHono)
104-
return fw.Unwrap()
105-
}
106-
10792
*fw = optional.Some(types.BunFrameworkNone)
10893
return fw.Unwrap()
10994
}
11095

111-
func determineEntry(ctx *PlanContext) string {
112-
if strings.HasPrefix(ctx.PackageJSON.Scripts["dev"], "bun run --hot") {
113-
return strings.TrimPrefix(ctx.PackageJSON.Scripts["dev"], "bun run --hot ")
114-
}
115-
116-
possibleEntries := []string{"index.ts", "index.js", "src/index.ts", "src/index.js"}
117-
118-
for _, entry := range possibleEntries {
119-
if utils.HasFile(ctx.Src, entry) {
120-
return entry
121-
}
122-
}
123-
124-
return ""
125-
}
126-
12796
// DetermineVersion determines the Bun version to use.
12897
func DetermineVersion(ctx *PlanContext) string {
12998
return utils.ConstraintToVersion(ctx.PackageJSON.Engines.Bun, "latest")

internal/nodejs/plan.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,11 @@ func DetermineAppFramework(ctx *nodePlanContext) types.NodeProjectFramework {
357357
return fw.Unwrap()
358358
}
359359

360+
if _, isHono := packageJSON.Dependencies["hono"]; isHono {
361+
*fw = optional.Some(types.NodeProjectFrameworkHono)
362+
return fw.Unwrap()
363+
}
364+
360365
if _, isVitepress := packageJSON.FindDependency("vitepress"); isVitepress {
361366
*fw = optional.Some(types.NodeProjectFrameworkVitepress)
362367
return fw.Unwrap()
@@ -825,6 +830,7 @@ func GetStartCmd(ctx *nodePlanContext) string {
825830

826831
predeployScript := GetPredeployScript(ctx)
827832

833+
packageJSON := ctx.GetAppPackageJSON()
828834
startScript := GetStartScript(ctx)
829835
entry := GetEntry(ctx)
830836
framework := DetermineAppFramework(ctx)
@@ -855,7 +861,13 @@ func GetStartCmd(ctx *nodePlanContext) string {
855861
case types.IsNitroBasedFramework(string(framework)):
856862
startCmd = "HOST=0.0.0.0 " + runtime + " .output/server/index.mjs"
857863
default:
858-
startCmd = runtime + " index.js"
864+
if devScript := packageJSON.Scripts["dev"]; devScript != "" && framework == types.NodeProjectFrameworkHono {
865+
// create-hono-app does not have "start" script by default.
866+
startCmd = devScript
867+
} else {
868+
// fallback
869+
startCmd = runtime + " index.js"
870+
}
859871
}
860872
}
861873

pkg/types/plan.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const (
9292
NodeProjectFrameworkGrammY NodeProjectFramework = "grammy"
9393
NodeProjectFrameworkNitropack NodeProjectFramework = "nitropack"
9494
NodeProjectFrameworkMedusa NodeProjectFramework = "medusa"
95+
NodeProjectFrameworkHono NodeProjectFramework = "hono"
9596
)
9697

9798
var NitroBasedFrameworks = []NodeProjectFramework{
@@ -244,6 +245,5 @@ const (
244245
BunFrameworkElysia BunFramework = "elysia"
245246
BunFrameworkBaojs BunFramework = "baojs"
246247
BunFrameworkBagel BunFramework = "bagel"
247-
BunFrameworkHono BunFramework = "hono"
248248
BunFrameworkNone BunFramework = "none"
249249
)

tests/snapshots/bun-hono.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
PlanType: bun
22

33
Meta:
4+
appDir: ""
5+
buildCmd: ""
6+
bun: "true"
47
bunVersion: "latest"
5-
entry: "src/index.ts"
68
framework: "hono"
9+
initCmd: "RUN npm install -g bun@latest"
10+
installCmd: "RUN bun install"
11+
nodeVersion: "20"
12+
packageManager: "bun"
13+
startCmd: "bun run --hot src/index.ts"

0 commit comments

Comments
 (0)