Skip to content

Commit

Permalink
Warn users on importing dependencies as absolute paths (#2078)
Browse files Browse the repository at this point in the history
part of #1089

Co-authored-by: na-- <[email protected]>
  • Loading branch information
mstoykov and na-- committed Jul 8, 2021
1 parent aa1fd6a commit c2e19d9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions js/initcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"fmt"
"net/url"
"path/filepath"
"runtime"
"strings"

"github.com/dop251/goja"
Expand Down Expand Up @@ -161,6 +162,12 @@ func (i *InitContext) requireFile(name string) (goja.Value, error) {
// First, check if we have a cached program already.
pgm, ok := i.programs[fileURL.String()]
if !ok || pgm.module == nil {
if filepath.IsAbs(name) && runtime.GOOS == "windows" {
i.logger.Warnf("'%s' was imported with an absolute path - this won't be cross-platform and won't work if"+
" you move the script between machines or run it with `k6 cloud`; if absolute paths are required,"+
" import them with the `file://` schema for slightly better compatibility",
name)
}
i.pwd = loader.Dir(fileURL)
defer func() { i.pwd = pwd }()
exports := i.runtime.NewObject()
Expand Down

0 comments on commit c2e19d9

Please sign in to comment.