Skip to content

Commit

Permalink
Revert "add extension version"
Browse files Browse the repository at this point in the history
This reverts commit 435498c.
  • Loading branch information
Ivan Mirić authored and imiric committed Dec 20, 2022
1 parent 8d0b930 commit 7dc717b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 62 deletions.
9 changes: 1 addition & 8 deletions cmd/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

"gopkg.in/yaml.v3"

"go.k6.io/k6/js/modules"
"go.k6.io/k6/lib"
"go.k6.io/k6/lib/consts"
"go.k6.io/k6/output"
Expand Down Expand Up @@ -82,13 +81,7 @@ func getColor(noColor bool, attributes ...color.Attribute) *color.Color {

func getBanner(noColor bool) string {
c := getColor(noColor, color.FgCyan)
banner := make([]string, 0, len(modules.GetJSModuleVersions())+1)

banner = append(banner, consts.Banner())
for pkg, version := range modules.GetJSModuleVersions() {
banner = append(banner, fmt.Sprintf("extension %s %s", pkg, version))
}
return c.Sprint(strings.Join(banner, "\n"))
return c.Sprint(consts.Banner())
}

func printBanner(gs *globalState) {
Expand Down
4 changes: 0 additions & 4 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/spf13/cobra"

"go.k6.io/k6/js/modules"
"go.k6.io/k6/lib/consts"
)

Expand All @@ -17,9 +16,6 @@ func getCmdVersion(globalState *globalState) *cobra.Command {
Long: `Show the application version and exit.`,
Run: func(_ *cobra.Command, _ []string) {
printToStdout(globalState, fmt.Sprintf("k6 v%s\n", consts.FullVersion()))
for path, version := range modules.GetJSModuleVersions() {
printToStdout(globalState, fmt.Sprintf("extension %s %s\n", path, version))
}
},
}
}
52 changes: 2 additions & 50 deletions js/modules/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package modules
import (
"context"
"fmt"
"reflect"
"runtime/debug"
"strings"
"sync"

Expand All @@ -17,9 +15,8 @@ const extPrefix string = "k6/x/"

//nolint:gochecknoglobals
var (
modules = make(map[string]interface{})
moduleVersions = make(map[string]string)
mx sync.RWMutex
modules = make(map[string]interface{})
mx sync.RWMutex
)

// Register the given mod as an external JavaScript module that can be imported
Expand All @@ -37,38 +34,6 @@ func Register(name string, mod interface{}) {
panic(fmt.Sprintf("module already registered: %s", name))
}
modules[name] = mod
getPackageVersion(mod)
}

func getPackageVersion(mod interface{}) {
t := reflect.TypeOf(mod)
p := t.PkgPath()
if p == "" {
if t.Kind() != reflect.Ptr {
return
}
if t.Elem() != nil {
p = t.Elem().PkgPath()
}
}
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return
}
for _, dep := range buildInfo.Deps {
packagePath := strings.TrimSpace(dep.Path)
if strings.HasPrefix(p, packagePath) {
if _, ok := moduleVersions[packagePath]; ok {
return
}
if dep.Replace != nil {
moduleVersions[packagePath] = dep.Replace.Version
} else {
moduleVersions[packagePath] = dep.Version
}
break
}
}
}

// Module is the interface js modules should implement in order to get access to the VU
Expand All @@ -91,19 +56,6 @@ func GetJSModules() map[string]interface{} {
return result
}

// GetJSModuleVersions returns a map of all registered js modules package and their versions
func GetJSModuleVersions() map[string]string {
mx.Lock()
defer mx.Unlock()
result := make(map[string]string, len(moduleVersions))

for name, version := range moduleVersions {
result[name] = version
}

return result
}

// Instance is what a module needs to return
type Instance interface {
Exports() Exports
Expand Down

0 comments on commit 7dc717b

Please sign in to comment.