From c2e19d92616dd0e9ad4158cf45dc7c90422842d8 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Thu, 8 Jul 2021 09:53:48 +0300 Subject: [PATCH] Warn users on importing dependencies as absolute paths (#2078) part of #1089 Co-authored-by: na-- --- js/initcontext.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/js/initcontext.go b/js/initcontext.go index a24fb64616a..ca443566468 100644 --- a/js/initcontext.go +++ b/js/initcontext.go @@ -26,6 +26,7 @@ import ( "fmt" "net/url" "path/filepath" + "runtime" "strings" "github.com/dop251/goja" @@ -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()