mirror of
https://github.com/hanzoai/pack.git
synced 2026-09-30 23:43:13 +00:00
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:
+10
-19
@@ -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]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user