js: Add Inject config option

Fixes #8164
This commit is contained in:
Bjørn Erik Pedersen
2021-01-22 17:07:23 +01:00
parent 241b7483ea
commit 32b86076ee
4 changed files with 73 additions and 33 deletions

View File

@@ -18,6 +18,7 @@ import (
"io/ioutil"
"os"
"path"
"path/filepath"
"regexp"
"strings"
@@ -103,6 +104,28 @@ func (t *buildTransformation) Transform(ctx *resources.ResourceTransformationCtx
defer os.Remove(buildOptions.Outdir)
}
if opts.Inject != nil {
// Resolve the absolute filenames.
for i, ext := range opts.Inject {
impPath := filepath.FromSlash(ext)
if filepath.IsAbs(impPath) {
return errors.Errorf("inject: absolute paths not supported, must be relative to /assets")
}
m := resolveComponentInAssets(t.c.rs.Assets.Fs, impPath)
if m == nil {
return errors.Errorf("inject: file %q not found", ext)
}
opts.Inject[i] = m.Filename()
}
buildOptions.Inject = opts.Inject
}
result := api.Build(buildOptions)
if len(result.Errors) > 0 {