diff options
| author | Philipp Tanlak <philipp.tanlak@gmail.com> | 2023-12-04 18:30:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-04 18:30:19 +0100 |
| commit | 0f9e334a19e7224ee08b611107029b4cd86c0267 (patch) | |
| tree | 9740c7edc47f8e81d6a1352c94160d584bfb9f26 /js.go | |
| parent | 8c68e0ed414bfb323d6e94db55c95db13797ef8e (diff) | |
Support file imports for .txt and .json (#25)v0.6.0
Diffstat (limited to 'js.go')
| -rw-r--r-- | js.go | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -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) { |