refactor(deno): simplify main file resolution (#624)

*   Replace manual file checking logic with App helper methods to reduce code duplication.
*   Update entrypoint resolution to prefer main files in the project root before scanning the directory tree.
*   Remove unused DenoJson struct.

Generated-by: aiautocommit
This commit is contained in:
Michael Bianco
2026-07-13 13:32:39 -06:00
committed by GitHub
parent de1a4d3a9a
commit 90b21b1dc8
+10 -19
View File
@@ -3,6 +3,7 @@ package deno
import (
"fmt"
"github.com/railwayapp/railpack/core/app"
"github.com/railwayapp/railpack/core/generate"
"github.com/railwayapp/railpack/core/plan"
)
@@ -12,10 +13,6 @@ const (
ROOT_CACHE = "/root/.cache"
)
type DenoJson struct {
Tasks map[string]string `json:"tasks"`
}
type DenoProvider struct {
mainFile string
}
@@ -30,7 +27,7 @@ func (p *DenoProvider) Detect(ctx *generate.GenerateContext) (bool, error) {
}
func (p *DenoProvider) Initialize(ctx *generate.GenerateContext) error {
p.mainFile = p.findMainFile(ctx)
p.mainFile = findMainFile(ctx.App)
return nil
}
@@ -100,22 +97,16 @@ func (p *DenoProvider) InstallMisePackages(ctx *generate.GenerateContext, miseSt
}
}
func (p *DenoProvider) findMainFile(ctx *generate.GenerateContext) string {
files := []string{"main.ts", "main.js", "main.mjs", "main.mts"}
for _, file := range files {
if ctx.App.HasFile(file) {
return file
}
// selects the entrypoint for a Deno app. It prefers an explicit main.* file in the
// project root, falling back to the first .ts/.js/.mjs/.mts file found anywhere in the tree.
func findMainFile(app *app.App) string {
if name, _, _ := app.ReadFirstFileOf("main.ts", "main.js", "main.mjs", "main.mts"); name != "" {
return name
}
files, err := ctx.App.FindFiles("**/*.{ts,js,mjs,mts}")
if err != nil {
matches, err := app.FindFiles("**/*.{ts,js,mjs,mts}")
if err != nil || len(matches) == 0 {
return ""
}
if len(files) == 0 {
return ""
}
return files[0]
return matches[0]
}