summaryrefslogtreecommitdiff
path: root/js.go
diff options
context:
space:
mode:
authorPhilipp Tanlak <philipp.tanlak@gmail.com>2023-12-04 18:30:19 +0100
committerGitHub <noreply@github.com>2023-12-04 18:30:19 +0100
commit0f9e334a19e7224ee08b611107029b4cd86c0267 (patch)
tree9740c7edc47f8e81d6a1352c94160d584bfb9f26 /js.go
parent8c68e0ed414bfb323d6e94db55c95db13797ef8e (diff)
Support file imports for .txt and .json (#25)v0.6.0
Diffstat (limited to 'js.go')
-rw-r--r--js.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/js.go b/js.go
index 0fef6dc..1f0d600 100644
--- a/js.go
+++ b/js.go
@@ -72,9 +72,19 @@ func Compile(src string, imports Imports) (Exports, error) {
}
func build(src string) (string, error) {
- res := api.Transform(src, api.TransformOptions{
+ res := api.Build(api.BuildOptions{
+ Loader: map[string]api.Loader{
+ ".txt": api.LoaderText,
+ ".json": api.LoaderJSON,
+ },
+ Bundle: true,
+ Stdin: &api.StdinOptions{
+ Contents: src,
+ ResolveDir: ".",
+ },
Platform: api.PlatformNode,
Format: api.FormatCommonJS,
+ External: []string{"flyscrape"},
})
var errs []error
@@ -89,8 +99,11 @@ func build(src string) (string, error) {
if len(res.Errors) > 0 {
return "", errors.Join(errs...)
}
+ if len(res.OutputFiles) == 0 {
+ return "", errors.New("no output generated")
+ }
- return string(res.Code), nil
+ return string(res.OutputFiles[0].Contents), nil
}
func vm(src string, imports Imports) (Exports, error) {