Skip to content

Commit

Permalink
Add serverless field to static artifact (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuaanlin authored Oct 19, 2024
2 parents 1d5756c + 7bf1948 commit 20b34bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
4 changes: 4 additions & 0 deletions internal/dart/identify.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dart

import (
"strconv"
"strings"

"github.com/moznion/go-optional"
Expand Down Expand Up @@ -111,6 +112,9 @@ func (i *identify) PlanMeta(options plan.NewPlannerOptions) types.PlanMeta {
}

if od := determineOutputDir(ctx); od != "" {
meta["serverless"] = strconv.FormatBool(
utils.GetExplicitServerlessConfig(ctx.Config).TakeOr(false),
)
meta["outputDir"] = od
}

Expand Down
21 changes: 16 additions & 5 deletions internal/nodejs/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,11 @@ func GetStaticOutputDir(ctx *nodePlanContext) string {
return outputDir
}

if outputDir, err := plan.Cast(ctx.Config.Get(plan.ConfigOutputDir), cast.ToStringE).Take(); err == nil {
*dir = optional.Some(outputDir)
return dir.Unwrap()
}

framework := DetermineAppFramework(ctx)

// the default output directory of Angular is `dist/<project-name>/browser`
Expand Down Expand Up @@ -901,6 +906,12 @@ func getServerless(ctx *nodePlanContext) bool {
return sl.Unwrap()
}

// For projects with outputDir, it should be always serverless (if not explicitly set).
if GetStaticOutputDir(ctx) != "" {
*sl = optional.Some(true)
return sl.Unwrap()
}

// For monorepo projects, we should not deploy as serverless
// until ZEA-3469 is resolved.
if GetMonorepoAppRoot(ctx) != "" {
Expand Down Expand Up @@ -983,6 +994,11 @@ func GetMeta(opt GetMetaOptions) types.PlanMeta {
}
meta["buildCmd"] = buildCmd

serverless := getServerless(ctx)
if serverless {
meta["serverless"] = strconv.FormatBool(serverless)
}

// only set outputDir if there is no custom start command (because if there is, it shouldn't be a static project)
if opt.CustomStartCmd == nil || *opt.CustomStartCmd == "" {

Expand All @@ -1009,10 +1025,5 @@ func GetMeta(opt GetMetaOptions) types.PlanMeta {
}
meta["startCmd"] = startCmd

serverless := getServerless(ctx)
if serverless {
meta["serverless"] = strconv.FormatBool(serverless)
}

return meta
}

0 comments on commit 20b34bb

Please sign in to comment.