-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Standartize what open
, k6/experimental/fs.open
and k6/net/grpc.Client#load
are relative to
#3857
Comments
This code is similar to the one made for `require` but for `open`. Part of #3857 Closes #3960 Co-authored-by: Joan López de la Franca Beltran <[email protected]>
I would not go the what is really missing for me is to be able to express in paths relative to current-work-dir, not the installation dir. Here's the use-case. Consider that we ship an installation of our extended compilation together with a bunch of js libs that facilitate API testing with all kinds of patterns, export pre-configured accessors to all kinds of data storages, and pre-configured clients to the SUT. We load configuration and fixture files using When Same behavior with a native installation and a docker image that packs the setup. Now, in docker env - it forces me to mount the user scripts & fixtures volume on a sub directory of the installation dir, which ...kinda limiting... 🤷 |
Thank you for input 🙇 This is exactly why this issue is open.
This is arguably what experimental There isn't really a way to get the currently working directory in k6 and it is mentioned in #2259 - arguably this is going to be a very easy addition. I would argue that this is related but not on the topic of what the functions here should be relative to. Arguably I would prefer if we have single behavior for this so that it is at least consistent if not intuitive or perfect. Looking over all other tools it does seem that while Arguably Now that k6 does have From implementation perspective (which arguably isn't the most important one, but still) this is way easier. The current working directory is readily available in the init context and is already the behavior for 2 of the 3 functions. Now of course while writing this something in the back of my head was "not exactly". So after some checking - it isn't an easy :(. Basically for old reasons around how This also means that actually experimental fs's open and grpc Client.load are relative to the main module NOT to the working directory. I have confirmed that both deno's Deno.open and node's fs.open are relative to where you execute deno or node not to the file that is on the cli. CORRECTION: Unfortunately this likely will mean that implementation wise this will be either convoluted or will need to be a breaking change on the go API as well. This means that just like with It also makes the breaking change for Now ideally we would be dropping But that still means that we have to break grpc Client.load and experimental fs.open. Which makes it a bit less nice than I first thought at first. Some of your example make a compelling argument for being relative to the current working directory, some don't or at least I am not certain that they will. Again adding a way to get the current working directory + We likely should look into this more especially before experimental fs is made not experimental. p.s. as I did go over the post after I have written most of it to correct it, there is a good chance that I have missed some place that needs a fix or rewording. So if something seems off -please ask. |
What?
Have
open
,k6/experimental/fs.open
andk6/net/grpc.Client#load
be relative to the same path for each execution.Or at least specify and stick to one new norm among them and anything else related to loading files.
Why?
Consistency, ease of reasoning, also potentially debugging and using one in place of the other.
Current situation:
k6/experimental/fs.open
andk6/net/grpc.Client#load
are relative to the entry point ofk6
- so either the folder of the argument torun
or if is-
(stdin) - the folder k6 is executed in.I am pretty sure this was a mistake in gRPC (#2781).
fs.open
was more of "let's not make this more complicated especially given this is an experimental module".open
on the other hand is relative to the currently executed file, but I would argue by design it was supposed to be relative to the file it is called in. Similar to howrequire
(previously buggy) is defined, and also howimport
s both static and dynamic usually work in ECMAScript. And how they are actually now implemented.So for me this seems like a bug all around.
Examples of the behaviour:
If we have the following structure
main.js:
A.js
B.js
In this case the
openHelper
is arguably the "good" example for the current behaviour, but if you wanted to have helper that does something completely different but as part of it it opensThat relative path will be relative to whatever calls
checkSomethingExists
as in the example above.Proposal:
Change all of them to be relative to the file being called in - how imports and require work.
Given that the three currently have 3 different behaviours and only on of them is experimental - we will need to have at least a couple of releases with warnings about this.
I recommend we do the same as with
require
- test that the new implementation will not give a different result (which is possible in some cases) and only if it isn't - then emit a warning.We can also recommend using #3856 if it is implemented at the time.
The existance of
import.meta.resolve
doesn't change the fact that the functions having different things they are relative to is a confusing behaviour.Related issues and PRs
#2674
#2782
#3534
The text was updated successfully, but these errors were encountered: