Skip to content

Commit

Permalink
use bun for deps
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed Feb 8, 2024
1 parent 87a0773 commit dbcee7e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
8 changes: 8 additions & 0 deletions cmd/sst/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ func main() {
}
}

if global.NeedsBun() {
spin.Start()
err := global.InstallBun()
if err != nil {
return err
}
}

if global.NeedsPlugins() {
spin.Start()
err := global.InstallPlugins()
Expand Down
19 changes: 18 additions & 1 deletion pkg/global/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ var configDir = (func() string {
if err != nil {
panic(err)
}
return filepath.Join(home, "sst")
result := filepath.Join(home, "sst")
os.Setenv("PATH", os.Getenv("PATH")+":"+result+"/bin")
return result
}())

func ConfigDir() string {
Expand Down Expand Up @@ -78,3 +80,18 @@ func InstallPulumi() error {
_, err := exec.Command("bash", "-c", cmd).CombinedOutput()
return err
}

func NeedsBun() bool {
_, err := exec.LookPath("bun")
if err != nil {
return true
}
return false
}

func InstallBun() error {
slog.Info("installing bun")
cmd := exec.Command("bash", "-c", `curl -fsSL https://bun.sh/install | bash`)
cmd.Env = append(os.Environ(), "BUN_INSTALL="+configDir)
return cmd.Run()
}
4 changes: 4 additions & 0 deletions pkg/platform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"test": "vitest run",
"dev": "tsc --watch --noEmit"
},
"trustedDependencies": [
"esbuild",
"protobufjs"
],
"dependencies": {
"@aws-sdk/client-bedrock-runtime": "3.478.0",
"@aws-sdk/client-cloudfront": "3.478.0",
Expand Down
4 changes: 1 addition & 3 deletions pkg/project/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ func InstallDeps(version, cfgPath string) error {

os.RemoveAll(filepath.Join(platformDir, "node_modules"))

cmd := exec.Command("npm", "install", "--omit=dev")
cmd := exec.Command("bun", "install")
cmd.Dir = platformDir
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout

err = cmd.Run()
if err != nil {
Expand Down

0 comments on commit dbcee7e

Please sign in to comment.