Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
sst.aws.Function: build system update. do not serialize links into co…
Browse files Browse the repository at this point in the history
…de, encrypt them into a seperate file. experimental esbuild plugins support.
  • Loading branch information
thdxr committed Oct 11, 2024
1 parent 7d50c0a commit 3cf7254
Show file tree
Hide file tree
Showing 12 changed files with 513 additions and 120 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
github.com/fsnotify/fsnotify v1.7.0
github.com/gdamore/tcell/v2 v2.7.4
github.com/gorilla/websocket v1.5.0
github.com/iancoleman/strcase v0.3.0
github.com/joho/godotenv v1.5.1
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/manifoldco/promptui v0.9.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT
github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/hashicorp/hcl/v2 v2.20.1 h1:M6hgdyz7HYt1UN9e61j+qKJBqR3orTWbI1HKBJEdxtc=
github.com/hashicorp/hcl/v2 v2.20.1/go.mod h1:TZDqQ4kNKCbh1iJp99FdPiUaVDDUPivbqxZulxDYqL4=
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
Expand Down
16 changes: 7 additions & 9 deletions pkg/runtime/node/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ func (r *Runtime) Build(ctx context.Context, input *runtime.BuildInput) (*runtim
}

plugins := []esbuild.Plugin{}
if properties.Plugins != "" {
plugins = append(plugins, plugin(properties.Plugins))
}
external := append(forceExternal, properties.Install...)
external = append(external, properties.ESBuild.External...)
serializedLinks, err := json.Marshal(input.Links)
if err != nil {
return nil, err
}
slog.Info("serialized links", "links", string(serializedLinks))
options := esbuild.BuildOptions{
EntryPoints: []string{file},
Platform: esbuild.PlatformNode,
Expand All @@ -87,7 +88,6 @@ func (r *Runtime) Build(ctx context.Context, input *runtime.BuildInput) (*runtim
`import { fileURLToPath as topLevelFileUrlToPath, URL as topLevelURL } from "url"`,
`const __filename = topLevelFileUrlToPath(import.meta.url)`,
`const __dirname = topLevelFileUrlToPath(new topLevelURL(".", import.meta.url))`,
`globalThis.$SST_LINKS = ` + string(serializedLinks) + `;`,
properties.Banner,
}, "\n"),
},
Expand All @@ -97,12 +97,10 @@ func (r *Runtime) Build(ctx context.Context, input *runtime.BuildInput) (*runtim
options.Format = esbuild.FormatCommonJS
options.Target = esbuild.ESNext
options.MainFields = []string{"main"}
options.Banner = map[string]string{
"js": strings.Join([]string{
`globalThis.$SST_LINKS = ` + string(serializedLinks) + `;`,
properties.Banner,
}, "\n"),
}
}

if properties.ESBuild.Target != 0 {
options.Target = properties.ESBuild.Target
}

if properties.Splitting {
Expand Down
22 changes: 22 additions & 0 deletions pkg/runtime/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ var loaderMap = map[string]api.Loader{
"binary": api.LoaderBinary,
}

var LoaderToString = []string{
"none",
"base64",
"binary",
"copy",
"css",
"dataurl",
"default",
"empty",
"file",
"global-css",
"js",
"json",
"json",
"jsx",
"local-css",
"text",
"ts",
"ts",
"tsx",
}

type Runtime struct {
cfgPath string
contexts map[string]esbuild.BuildContext
Expand Down
Loading

0 comments on commit 3cf7254

Please sign in to comment.