From a54114f9b0d62d8275f7f01f6d0abe26d416f200 Mon Sep 17 00:00:00 2001 From: vigneshshanmugam Date: Mon, 9 May 2022 16:09:12 -0700 Subject: [PATCH] link to global synthetics pkg --- .../monitors/browser/source/pushed.go | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/x-pack/heartbeat/monitors/browser/source/pushed.go b/x-pack/heartbeat/monitors/browser/source/pushed.go index fd3e2f6ba33..f9b1d53edd9 100644 --- a/x-pack/heartbeat/monitors/browser/source/pushed.go +++ b/x-pack/heartbeat/monitors/browser/source/pushed.go @@ -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 { @@ -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, "", " ")