diff --git a/pkg/runtime/node.go b/pkg/runtime/node.go index 2251b8c23..f7da70b6a 100644 --- a/pkg/runtime/node.go +++ b/pkg/runtime/node.go @@ -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 @@ -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"), } diff --git a/pkg/runtime/runtime.go b/pkg/runtime/runtime.go index 819f57459..c72a1f9ca 100644 --- a/pkg/runtime/runtime.go +++ b/pkg/runtime/runtime.go @@ -2,6 +2,7 @@ package runtime import ( "context" + "encoding/json" "fmt" "io" "log/slog" @@ -26,7 +27,6 @@ type Worker interface { type BuildInput struct { Warp project.Warp Project *project.Project - Links project.Links Dev bool } @@ -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 @@ -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 @@ -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") } diff --git a/pkg/server/dev/aws/aws.go b/pkg/server/dev/aws/aws.go index 7ffcc86f5..a9570a8bf 100644 --- a/pkg/server/dev/aws/aws.go +++ b/pkg/server/dev/aws/aws.go @@ -241,7 +241,6 @@ func Start( Warp: warp, Project: p, Dev: true, - Links: complete.Links, }) if err == nil { bus.Publish(&FunctionBuildEvent{ @@ -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, diff --git a/pkg/server/dev/cloudflare/cloudflare.go b/pkg/server/dev/cloudflare/cloudflare.go index cae0fc151..558d1ebc6 100644 --- a/pkg/server/dev/cloudflare/cloudflare.go +++ b/pkg/server/dev/cloudflare/cloudflare.go @@ -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, }) @@ -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, })