Skip to content

Commit

Permalink
Fixes of Bun planner (#392)
Browse files Browse the repository at this point in the history
#### Description (required)

- **fix(planner/bun): Add more determinations**
- **fix(planner/nodejs): Remove bunVersion fallback if bun is disabled**
- **chore: Update snapshot**

#### Related issues & labels (optional)

- Suggested label: bug
  • Loading branch information
yuaanlin authored Nov 30, 2024
2 parents cc96ee4 + a1a6c9d commit f5cf727
Show file tree
Hide file tree
Showing 27 changed files with 36 additions and 40 deletions.
42 changes: 30 additions & 12 deletions internal/bun/identify.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,40 @@ func (i *identify) PlanType() types.PlanType {
}

func (i *identify) Match(fs afero.Fs) bool {
hasPackageJSON := utils.HasFile(fs, "package.json")
hasBunLockfile := utils.HasFile(fs, "bun.lockb")
hasBunTypes := false

packageJSON, err := utils.ReadFileToUTF8(fs, "package.json")
if err == nil {
hasBunTypes = bytes.Contains(packageJSON, []byte(`"bun-types"`))
strategies := []func() bool{
// has bun lockfile
func() bool {
return utils.HasFile(fs, "bun.lockb")
},
// has .bun-version
func() bool {
return utils.HasFile(fs, ".bun-version")
},
// has bun types
func() bool {
packageJSON, err := utils.ReadFileToUTF8(fs, "package.json")
if err != nil {
return false
}
return bytes.Contains(packageJSON, []byte(`"bun-types"`))
},
// has bun@ (engine)
func() bool {
packageJSON, err := utils.ReadFileToUTF8(fs, "package.json")
if err != nil {
return false
}
return bytes.Contains(packageJSON, []byte(`bun@`))
},
}

// Some developer use bun as package manager for their Next.js project.
// In this case, we should treat it as a Node.js project.
if bytes.Contains(packageJSON, []byte(`"next"`)) {
return false
for _, strategy := range strategies {
if strategy() {
return true
}
}

return hasPackageJSON && (hasBunLockfile || hasBunTypes)
return false
}

func (i *identify) PlanMeta(options plan.NewPlannerOptions) types.PlanMeta {
Expand Down
6 changes: 4 additions & 2 deletions internal/nodejs/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -1020,8 +1020,10 @@ func GetMeta(opt GetMetaOptions) types.PlanMeta {
}

meta := types.PlanMeta{
"bun": strconv.FormatBool(opt.Bun),
"bunVersion": "latest",
"bun": strconv.FormatBool(opt.Bun),
}
if opt.Bun {
meta["bunVersion"] = "latest"
}

_, reldir := ctx.GetAppSource()
Expand Down
4 changes: 2 additions & 2 deletions tests/snapshots/bun-nextjs.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PlanType: nodejs
PlanType: bun

Meta:
appDir: ""
buildCmd: "bun run build"
bun: "false"
bun: "true"
bunVersion: "latest"
framework: "next.js"
installCmd: "COPY . .\nRUN bun install"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/node-astro.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "pnpm run build"
bun: "false"
bunVersion: "latest"
framework: "astro"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/node-sveltekit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "pnpm run build"
bun: "false"
bunVersion: "latest"
framework: "svelte"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-a-lot-of-dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: ""
bun: "false"
bunVersion: "latest"
framework: "next.js"
installCmd: "COPY . .\nRUN yarn install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-angular.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "npm run build"
bun: "false"
bunVersion: "latest"
framework: "angular"
installCmd: "COPY . .\nRUN npm install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-docusaurus.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "pnpm run build"
bun: "false"
bunVersion: "latest"
framework: "docusaurus"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "16"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-expressjs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "pnpm run build"
bun: "false"
bunVersion: "latest"
framework: "none"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-foal.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "pnpm run build"
bun: "false"
bunVersion: "latest"
framework: "none"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "18"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-nestjs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "pnpm run build"
bun: "false"
bunVersion: "latest"
framework: "nest.js"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-nextjs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "pnpm run build"
bun: "false"
bunVersion: "latest"
framework: "next.js"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-nuejs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: ""
bun: "false"
bunVersion: "latest"
framework: "nuejs"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-nuxtjs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "NITRO_PRESET=node pnpm run build"
bun: "false"
bunVersion: "latest"
framework: "nuxt.js"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-payload.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "yarn build"
bun: "false"
bunVersion: "latest"
framework: "next.js"
installCmd: "COPY . .\nRUN yarn install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-qwik-city.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "npm run build"
bun: "false"
bunVersion: "latest"
framework: "qwik"
installCmd: "COPY . .\nRUN npm install"
nodeVersion: "15"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-remix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "pnpm run build"
bun: "false"
bunVersion: "latest"
framework: "remix"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "18"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-rspress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "pnpm run build"
bun: "false"
bunVersion: "latest"
framework: "rspress"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-slidev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "pnpm run build"
bun: "false"
bunVersion: "latest"
framework: "sli.dev"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-starlight.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "pnpm run build"
bun: "false"
bunVersion: "latest"
framework: "astro-starlight"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-sveltekit-v2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "npm run build"
bun: "false"
bunVersion: "latest"
framework: "svelte"
installCmd: "COPY . .\nRUN npm install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-umi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "pnpm run build"
bun: "false"
bunVersion: "latest"
framework: "umi"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-vite-vanilla.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "yarn build"
bun: "false"
bunVersion: "latest"
framework: "vite"
installCmd: "COPY . .\nRUN yarn install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-vitepress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "pnpm run docs:build"
bun: "false"
bunVersion: "latest"
framework: "vitepress"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-vocs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "pnpm run build"
bun: "false"
bunVersion: "latest"
framework: "vocs"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/nodejs-waku.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "pnpm run build"
bun: "false"
bunVersion: "latest"
framework: "waku"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/static-hexo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Meta:
appDir: ""
buildCmd: "yarn build"
bun: "false"
bunVersion: "latest"
framework: "hexo"
installCmd: "COPY . .\nRUN yarn install"
nodeVersion: "20"
Expand Down

0 comments on commit f5cf727

Please sign in to comment.