Skip to content

Commit

Permalink
ZEA-4341: Fix Svelte containerized start command (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuaanlin authored Nov 30, 2024
2 parents 097df78 + 658380e commit cc96ee4
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/nodejs/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,12 @@ func GetStartCmd(ctx *nodePlanContext) string {
} else {
startCmd = "node " + entry
}
case framework == types.NodeProjectFrameworkSvelte:
if ctx.Bun {
startCmd = "bun build/index.js"
} else {
startCmd = "node build/index.js"
}
case types.IsNitroBasedFramework(string(framework)):
if ctx.Bun {
startCmd = "HOST=0.0.0.0 bun .output/server/index.mjs"
Expand Down
43 changes: 43 additions & 0 deletions internal/nodejs/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,49 @@ func TestGetStartCommand_Entry(t *testing.T) {
assert.Equal(t, "", startCmd)
})

t.Run("containerized svelte", func(t *testing.T) {
t.Parallel()

fs := afero.NewMemMapFs()
_ = afero.WriteFile(fs, "package.json", []byte(`{
"devDependencies": {
"svelte": "*"
}
}`), 0o644)

ctx := &nodePlanContext{
Src: fs,
Config: plan.NewProjectConfigurationFromFs(fs, ""),
Framework: optional.Some(types.NodeProjectFrameworkSvelte),
Serverless: optional.Some(false),
}

startCmd := GetStartCmd(ctx)
assert.Equal(t, "node build/index.js", startCmd)
})

t.Run("containerized svelte with bun", func(t *testing.T) {
t.Parallel()

fs := afero.NewMemMapFs()
_ = afero.WriteFile(fs, "package.json", []byte(`{
"devDependencies": {
"svelte": "*"
}
}`), 0o644)

ctx := &nodePlanContext{
Src: fs,
Config: plan.NewProjectConfigurationFromFs(fs, ""),
Framework: optional.Some(types.NodeProjectFrameworkSvelte),
Serverless: optional.Some(false),
Bun: true,
}

startCmd := GetStartCmd(ctx)
assert.Equal(t, "bun build/index.js", startCmd)
})

for _, framework := range types.NitroBasedFrameworks {
t.Run("nitro-"+string(framework), func(t *testing.T) {
t.Run("nodejs", func(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions tests/real_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ var projects = []struct {
owner: "zeabur",
repo: "vite-vanilla-template",
},
{
name: "nodejs-sveltekit-v2",
owner: "zeabur",
repo: "sveltekit-v2-template",
},
{
name: "nodejs-a-lot-of-dependencies",
dir: "nodejs-a-lot-of-dependencies",
Expand Down
12 changes: 12 additions & 0 deletions tests/snapshots/nodejs-sveltekit-v2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
PlanType: nodejs

Meta:
appDir: ""
buildCmd: "npm run build"
bun: "false"
bunVersion: "latest"
framework: "svelte"
installCmd: "COPY . .\nRUN npm install"
nodeVersion: "20"
packageManager: "npm"
startCmd: "node build/index.js"

0 comments on commit cc96ee4

Please sign in to comment.