Skip to content

Commit

Permalink
link to global synthetics pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshshanmugam committed May 9, 2022
1 parent 82724e8 commit a54114f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions x-pack/heartbeat/monitors/browser/source/pushed.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import (
"os/exec"
"path/filepath"
"regexp"
"strings"

"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/elastic-agent-libs/mapstr"
)

type PushedSource struct {
Expand Down Expand Up @@ -70,23 +71,28 @@ func (p *PushedSource) Fetch() error {
}

type PackageJSON struct {
Name string `json:"name"`
Private bool `json:"private"`
Dependencies common.MapStr `json:"dependencies"`
Name string `json:"name"`
Private bool `json:"private"`
Dependencies mapstr.M `json:"dependencies"`
}

// setupProjectDir sets ups the required package.json file and
// links the synthetics dependency to the globally installed one that is
// baked in to the HB to maintain compatability and allows us to control the
// agent version
func setupProjectDir(workdir string) error {
// TODO: Link to the globally installed synthetics version
fname, err := exec.LookPath("elastic-synthetics")
if err == nil {
fname, err = filepath.Abs(fname)
}

globalPath := strings.Replace(fname, "bin/elastic-synthetics", "lib/node_modules/@elastic/synthetics", 1)
symlinkPath := fmt.Sprintf("file:%s", globalPath)
pkgJson := PackageJSON{
Name: "pushed-journey",
Private: true,
Dependencies: common.MapStr{
"@elastic/synthetics": "",
Dependencies: mapstr.M{
"@elastic/synthetics": symlinkPath,
},
}
pkgJsonContent, err := json.MarshalIndent(pkgJson, "", " ")
Expand Down

0 comments on commit a54114f

Please sign in to comment.