Skip to content

Commit

Permalink
do not compile links into esbuild in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed May 20, 2024
1 parent 3d4c5ee commit d354c25
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
3 changes: 0 additions & 3 deletions pkg/runtime/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ func (r *NodeRuntime) Build(ctx context.Context, input *BuildInput) (*BuildOutpu
MinifyIdentifiers: properties.Minify,
}

links, _ := json.Marshal(input.Links)

if isESM {
options.Format = esbuild.FormatESModule
options.Target = esbuild.ESNext
Expand All @@ -159,7 +157,6 @@ func (r *NodeRuntime) Build(ctx context.Context, input *BuildInput) (*BuildOutpu
`const require = topLevelCreateRequire(import.meta.url);`,
`import { fileURLToPath as topLevelFileUrlToPath, URL as topLevelURL } from "url"`,
`const __dirname = topLevelFileUrlToPath(new topLevelURL(".", import.meta.url))`,
`globalThis.$SST_LINKS = ` + string(links) + ";",
properties.Banner,
}, "\n"),
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package runtime

import (
"context"
"encoding/json"
"fmt"
"io"
"log/slog"
Expand All @@ -26,7 +27,6 @@ type Worker interface {
type BuildInput struct {
Warp project.Warp
Project *project.Project
Links project.Links
Dev bool
}

Expand All @@ -42,6 +42,8 @@ type BuildOutput struct {

type RunInput struct {
Project *project.Project
Warp project.Warp
Links project.Links
Server string
FunctionID string
WorkerID string
Expand Down Expand Up @@ -78,13 +80,6 @@ func Build(ctx context.Context, input *BuildInput) (*BuildOutput, error) {
if err := os.MkdirAll(out, 0755); err != nil {
return nil, err
}
links := project.Links{}
for _, name := range input.Warp.Links {
value := input.Links[name]
links[name] = value
}
input.Links = links

result, err := runtime.Build(ctx, input)
if err != nil {
return nil, err
Expand Down Expand Up @@ -119,6 +114,11 @@ func Run(ctx context.Context, input *RunInput) (Worker, error) {
slog.Info("running function", "runtime", input.Runtime, "functionID", input.FunctionID)
runtime, ok := GetRuntime(input.Runtime)
input.Env = append(input.Env, "SST_LIVE=true")
for _, name := range input.Warp.Links {
value := input.Links[name]
serialized, _ := json.Marshal(value)
input.Env = append(input.Env, fmt.Sprintf("SST_RESOURCE_%s=%s", name, serialized))
}
if !ok {
return nil, fmt.Errorf("runtime not found")
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/server/dev/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ func Start(
Warp: warp,
Project: p,
Dev: true,
Links: complete.Links,
})
if err == nil {
bus.Publish(&FunctionBuildEvent{
Expand Down Expand Up @@ -269,6 +268,8 @@ func Start(
}
warp := complete.Warps[functionID]
worker, _ := runtime.Run(ctx, &runtime.RunInput{
Warp: warp,
Links: complete.Links,
Server: server + workerID,
Project: p,
WorkerID: workerID,
Expand Down
2 changes: 0 additions & 2 deletions pkg/server/dev/cloudflare/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ func Start(ctx context.Context, proj *project.Project, args map[string]interface

output, err := runtime.Build(ctx, &runtime.BuildInput{
Warp: warp,
Links: complete.Links,
Dev: true,
Project: proj,
})
Expand All @@ -132,7 +131,6 @@ func Start(ctx context.Context, proj *project.Project, args map[string]interface
if runtime.ShouldRebuild(warp.Runtime, workerID, file.Path) {
output, err := runtime.Build(ctx, &runtime.BuildInput{
Warp: warp,
Links: complete.Links,
Dev: true,
Project: proj,
})
Expand Down

0 comments on commit d354c25

Please sign in to comment.