From 0f9e334a19e7224ee08b611107029b4cd86c0267 Mon Sep 17 00:00:00 2001 From: Philipp Tanlak Date: Mon, 4 Dec 2023 18:30:19 +0100 Subject: Support file imports for .txt and .json (#25) --- js.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'js.go') 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) { -- cgit v1.2.3