Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: TypeScript Support #48

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions cmd/function/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/spf13/cobra"
"os"
"path"
"strings"
)

// BuildCmd encapsulates the commands for building Functions
Expand All @@ -43,6 +44,7 @@ func BuildCmd(hidden bool) command.SetupCommand[*config.Config] {
var directory string

var release bool
var target string

var goBin string
var tinygoBin string
Expand Down Expand Up @@ -88,6 +90,16 @@ func BuildCmd(hidden bool) command.SetupCommand[*config.Config] {
return utils.InvalidStringError("tag", sf.Tag)
}

buildTarget := build.WASITarget
switch strings.ToLower(target) {
case "wasi":
buildTarget = build.WASITarget
case "wasm":
buildTarget = build.WASMTarget
default:
return fmt.Errorf("invalid build target %s", target)
}

sourceDir := directory
if !path.IsAbs(sourceDir) {
wd, err := os.Getwd()
Expand Down Expand Up @@ -158,7 +170,7 @@ func BuildCmd(hidden bool) command.SetupCommand[*config.Config] {
SignatureSchema: signatureSchema,
Storage: stb,
Release: release,
Target: build.WASITarget,
Target: buildTarget,
GoBin: goBin,
TinyGoBin: tinygoBin,
Args: tinygoArgs,
Expand All @@ -172,7 +184,7 @@ func BuildCmd(hidden bool) command.SetupCommand[*config.Config] {
SignatureSchema: signatureSchema,
Storage: stb,
Release: release,
Target: build.WASITarget,
Target: buildTarget,
CargoBin: cargoBin,
Args: cargoArgs,
}
Expand All @@ -185,7 +197,7 @@ func BuildCmd(hidden bool) command.SetupCommand[*config.Config] {
SignatureSchema: signatureSchema,
Storage: stb,
Release: release,
Target: build.WASITarget,
Target: buildTarget,
NPMBin: npmBin,
}
scaleFunc, err = build.LocalTypescript(opts)
Expand Down Expand Up @@ -240,6 +252,7 @@ func BuildCmd(hidden bool) command.SetupCommand[*config.Config] {
buildCmd.Flags().StringVarP(&tag, "tag", "t", "", "the (optional) tag of this scale function")

buildCmd.Flags().BoolVar(&release, "release", false, "build the function in release mode")
buildCmd.Flags().StringVar(&target, "target", "wasi", "the compile target for the function")

buildCmd.Flags().StringVar(&tinygoBin, "tinygo", "", "the (optional) path to the tinygo binary")
buildCmd.Flags().StringVar(&goBin, "go", "", "the (optional) path to the go binary")
Expand Down
2 changes: 1 addition & 1 deletion cmd/function/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func NewCmd(hidden bool) command.SetupCommand[*config.Config] {
signaturePath = path.Join(signaturePath, "rust", "guest")
case scalefunc.TypeScript:
signatureVersion = ""
signaturePath = path.Join(signaturePath, "typescript", "guest")
signaturePath = path.Join(signaturePath, "typescript", "guest.tar.gz")
default:
return fmt.Errorf("language %s is not supported", language)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/signature/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func UseCmd(hidden bool) command.SetupCommand[*config.Config] {
case scalefunc.Rust:
signaturePath = path.Join(signaturePath, "rust", "guest")
case scalefunc.TypeScript:
signaturePath = path.Join(signaturePath, "typescript", "guest")
signaturePath = path.Join(signaturePath, "typescript", "guest.tar.gz")
default:
return fmt.Errorf("failed to use signature %s/%s:%s: unknown or unsupported language", parsed.Organization, parsed.Name, parsed.Tag)
}
Expand Down Expand Up @@ -220,7 +220,7 @@ func UseCmd(hidden bool) command.SetupCommand[*config.Config] {
return fmt.Errorf("failed to use signature %s/%s:%s: %w", parsed.Organization, parsed.Name, parsed.Tag, err)
}

err = p.AddDependency("signature", signaturePath)
err = p.AddDependency("signature", fmt.Sprintf("file:%s", signaturePath))
if err != nil {
return fmt.Errorf("failed to use signature %s/%s:%s: %w", parsed.Organization, parsed.Name, parsed.Tag, err)
}
Expand Down
62 changes: 33 additions & 29 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/loopholelabs/auth v0.2.47
github.com/loopholelabs/cmdutils v0.1.4
github.com/loopholelabs/releaser v0.1.1
github.com/loopholelabs/scale v0.4.3
github.com/loopholelabs/scale v0.4.5
github.com/mattn/go-isatty v0.0.19
github.com/mitchellh/go-homedir v1.1.0
github.com/natefinch/lumberjack v2.0.0+incompatible
Expand All @@ -22,7 +22,7 @@ require (
github.com/rs/zerolog v1.31.0
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.16.0
github.com/spf13/viper v1.17.0
github.com/valyala/fasthttp v1.50.0
)

Expand All @@ -31,67 +31,71 @@ require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/briandowns/spinner v1.23.0 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/evanw/esbuild v0.19.3 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/evanw/esbuild v0.19.4 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/loads v0.21.2 // indirect
github.com/go-openapi/spec v0.20.8 // indirect
github.com/go-resty/resty/v2 v2.7.0 // indirect
github.com/go-openapi/spec v0.20.9 // indirect
github.com/go-resty/resty/v2 v2.9.1 // indirect
github.com/gocarina/gocsv v0.0.0-20230616125104-99d496ca653d // indirect
github.com/gofiber/fiber/v2 v2.49.2 // indirect
github.com/gofiber/helmet/v2 v2.2.4 // indirect
github.com/gofiber/helmet/v2 v2.2.26 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-github/v40 v40.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/hcl/v2 v2.18.0 // indirect
github.com/hashicorp/hcl/v2 v2.18.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kataras/tablewriter v0.0.0-20180708051242-e063d29b7c23 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/lensesio/tableprinter v0.0.0-20201125135848-89e81fc956e7 // indirect
github.com/loopholelabs/polyglot v1.1.3 // indirect
github.com/loopholelabs/scale-signature-interfaces v0.1.7 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tetratelabs/wazero v1.5.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/zclconf/go-cty v1.13.2 // indirect
go.mongodb.org/mongo-driver v1.11.3 // indirect
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.10.0 // indirect
github.com/zclconf/go-cty v1.14.1 // indirect
go.mongodb.org/mongo-driver v1.12.1 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.16.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
Loading