Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace mention of plugins with extensions #11

Merged
merged 1 commit into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions cmd/xk6/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand All @@ -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,
})
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
30 changes: 15 additions & 15 deletions environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -157,7 +157,7 @@ nextPlugin:

type environment struct {
k6Version string
plugins []Dependency
extensions []Dependency
k6ModulePath string
tempFolder string
timeoutGoGet time.Duration
Expand Down Expand Up @@ -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
Expand All @@ -251,7 +251,7 @@ import (
// plug in k6 modules here
// TODO: Create /modules/standard dir structure?
// _ "{{.K6Module}}/modules/standard"
{{- range .Plugins}}
{{- range .Extensions}}
_ "{{.}}"
{{- end}}
)
Expand Down