diff --git a/README.md b/README.md index 62f2742..8f29144 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ The race detector can be enabled by setting `XK6_RACE_DETECTOR=1`. ```go builder := xk6.Builder{ k6Version: "v0.29.0", - Plugins: []xk6.Dependency{ + Extensions: []xk6.Dependency{ { ModulePath: "github.com/k6io/xk6-sql", Version: "v0.0.1", diff --git a/builder.go b/builder.go index 53a9f74..ba4a0dc 100644 --- a/builder.go +++ b/builder.go @@ -36,7 +36,7 @@ import ( type Builder struct { Compile K6Version string `json:"k6_version,omitempty"` - Plugins []Dependency `json:"plugins,omitempty"` + Extensions []Dependency `json:"extensions,omitempty"` Replacements []Replace `json:"replacements,omitempty"` TimeoutGet time.Duration `json:"timeout_get,omitempty"` TimeoutBuild time.Duration `json:"timeout_build,omitempty"` @@ -45,7 +45,7 @@ type Builder struct { } // Build builds k6 at the configured version with the -// configured plugins and plops down a binary at outputFile. +// configured extensions and writes a binary at outputFile. func (b Builder) Build(ctx context.Context, outputFile string) error { if outputFile == "" { return fmt.Errorf("output file path is required") diff --git a/cmd/xk6/main.go b/cmd/xk6/main.go index 37806c6..a0979d1 100644 --- a/cmd/xk6/main.go +++ b/cmd/xk6/main.go @@ -55,7 +55,7 @@ func main() { func runBuild(ctx context.Context, args []string) error { // parse the command line args... rather primitively var argK6Version, output string - var plugins []xk6.Dependency + var extensions []xk6.Dependency var replacements []xk6.Replace for i := 0; i < len(args); i++ { switch args[i] { @@ -69,7 +69,7 @@ func runBuild(ctx context.Context, args []string) error { return err } mod = strings.TrimSuffix(mod, "/") // easy to accidentally leave a trailing slash if pasting from a URL, but is invalid for Go modules - plugins = append(plugins, xk6.Dependency{ + extensions = append(extensions, xk6.Dependency{ PackagePath: mod, Version: ver, }) @@ -115,7 +115,7 @@ func runBuild(ctx context.Context, args []string) error { Cgo: os.Getenv("CGO_ENABLED") == "1", }, K6Version: k6Version, - Plugins: plugins, + Extensions: extensions, Replacements: replacements, RaceDetector: raceDetector, SkipCleanup: skipCleanup, @@ -214,7 +214,7 @@ func runDev(ctx context.Context, args []string) error { Cgo: os.Getenv("CGO_ENABLED") == "1", }, K6Version: k6Version, - Plugins: []xk6.Dependency{ + Extensions: []xk6.Dependency{ {PackagePath: importPath}, }, Replacements: replacements, diff --git a/environment.go b/environment.go index 182487a..d6684ce 100644 --- a/environment.go +++ b/environment.go @@ -35,8 +35,8 @@ func (b Builder) newEnvironment(ctx context.Context) (*environment, error) { } // clean up any SIV-incompatible module paths real quick - for i, p := range b.Plugins { - b.Plugins[i].PackagePath, err = versionedModulePath(p.PackagePath, p.Version) + for i, p := range b.Extensions { + b.Extensions[i].PackagePath, err = versionedModulePath(p.PackagePath, p.Version) if err != nil { return nil, err } @@ -46,8 +46,8 @@ func (b Builder) newEnvironment(ctx context.Context) (*environment, error) { tplCtx := goModTemplateContext{ K6Module: k6ModulePath, } - for _, p := range b.Plugins { - tplCtx.Plugins = append(tplCtx.Plugins, p.PackagePath) + for _, p := range b.Extensions { + tplCtx.Extensions = append(tplCtx.Extensions, p.PackagePath) } // evaluate the template for the main module @@ -86,7 +86,7 @@ func (b Builder) newEnvironment(ctx context.Context) (*environment, error) { env := &environment{ k6Version: b.K6Version, - plugins: b.Plugins, + extensions: b.Extensions, k6ModulePath: k6ModulePath, tempFolder: tempFolder, timeoutGoGet: b.TimeoutGet, @@ -121,21 +121,21 @@ func (b Builder) newEnvironment(ctx context.Context) (*environment, error) { default: } - // pin versions by populating go.mod, first for k6 itself and then plugins + // pin versions by populating go.mod, first for k6 itself and then extensions log.Println("[INFO] Pinning versions") err = env.execGoGet(ctx, k6ModulePath, env.k6Version) if err != nil { return nil, err } -nextPlugin: - for _, p := range b.Plugins { +nextExt: + for _, p := range b.Extensions { // if module is locally available, do not "go get" it; // also note that we iterate and check prefixes, because - // a plugin package may be a subfolder of a module, i.e. - // foo/a/plugin is within module foo/a. + // an extension package may be a subfolder of a module, i.e. + // foo/a/extension is within module foo/a. for repl := range replaced { if strings.HasPrefix(p.PackagePath, repl) { - continue nextPlugin + continue nextExt } } err = env.execGoGet(ctx, p.PackagePath, p.Version) @@ -157,7 +157,7 @@ nextPlugin: type environment struct { k6Version string - plugins []Dependency + extensions []Dependency k6ModulePath string tempFolder string timeoutGoGet time.Duration @@ -239,8 +239,8 @@ func (env environment) execGoGet(ctx context.Context, modulePath, moduleVersion } type goModTemplateContext struct { - K6Module string - Plugins []string + K6Module string + Extensions []string } const mainModuleTemplate = `package main @@ -251,7 +251,7 @@ import ( // plug in k6 modules here // TODO: Create /modules/standard dir structure? // _ "{{.K6Module}}/modules/standard" - {{- range .Plugins}} + {{- range .Extensions}} _ "{{.}}" {{- end}} )