-
Notifications
You must be signed in to change notification settings - Fork 11
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
import.meta.runtime #19
Comments
I like this. But not |
The nice thing about the |
I assume this would expand the definition of "runtime keys" which currently is only a subset of "conditions"? |
Good point - perhaps this is wider in scope than runtime keys then. The question then would be where to specify this in WinterTC though... |
Other runtimes being able to tell they are "like" Node.js, can be both beneficial (in a way libraries can then depend on Node.js APIs) but also very confusing in other use cases when actually libraries need to check "real" Node.js (to depend on native bindings for example). unjs/std-env#100 for reference, we used to have flags like May I suggest that we split this into two proposals:
|
@pi0 how would the described split you mention handle |
Conditions like |
I'm very confused why we'd want to effectively replicate the useragent nightmare of the web, on the server. A world in which "node" is true, but it's not node, does not sound like a good one - nor does a world where people are explicitly writing code intended for node, but it still runs on "not node", potentially doing the wrong thing. (replace "node" with any other runtime, same applies) What are the concrete use cases here that can't be solved by actual feature detection? |
I have seen an unfortunate number of packages/guides using conditions "wrong", e.g. doing {node, default} instead of {browser, default} which is more likely to work. So now deno/bun need to work around those packages somehow. |
There are two separate use cases here:
(1) is the primary use case I am personally seeking to solve here right now - so we could separately specify a universal |
If you go down that road then it expands the concept of import conditions rather broadly, from something specific to changing module resolution, to a hard-to-define concept of ambient static flags about the build/runtime environment |
@jkrems and i'd have hoped that the lesson we learned from the web is, you shouldn't work around them, you should evangelize them to do things properly instead, before the problem gets too widespread. |
some kind of flags about the runtime or build-time environment seem necessary but it doesn't seem quite right for them to live under |
I agree! Although I'll also add that "working by default" beats "evangelizing and making everybody pick correctly". Which is why I would strongly recommend not having both production and development if such an API is added but only a development condition. (Longer reasoning in https://github.com/jkrems/md/blob/main/import-meta-debug.md) |
I feel like there are two major paths forward here at this current point in time:
I still think there is merit in tackling (1) because it provides a flexible more general mechanic that only needs to be implemented once in build tools as an addition to exsiting conditions handling, and this bag of bools effectively already exists ambiently at linking time to be able to inline. Are there strong arguments against this direction? |
@guybedford what are the concrete use cases that path 1 solves? It's hard to understand what a general solution would entail without a full grasp of the specific ones. |
So long as there are strict rules for not posing as other platforms, otherwise it's as useless as runtime-keys themselves for module authors, see #18 |
This is a pattern which has caused many hours of wasted time due to confusion, poor hygiene by library authors, and poor guidance on it's use. The work done with this flag is nearly always able to be done without a global switch, especially one implemented as an environment variable, and is better off with fine grained control. It should be deprecated and removed, not replaced with something to spread this pain around further. I don't have a horse in this race beyond that, but when I saw that was part of the driver for this I wanted to share in case it helped avoid another mistake like |
The runtime keys gives useful information about the environment to the resolver, but there is currently no way to inspect this information from within the runtime environment.
I understand this proposal is moving to a more general package.json spec, but before we do that, I wanted to discuss the possibility of an
import.meta.runtime
object which would expose a frozen bag of booleans corresponding to the runtime key environment.Would be useful for platform checks:
As well as dev / production checks:
Having a standard like this would get support between Node.js and tools - of course we can't get support in browsers, but that might be acceptable having this as a build time inlining. And perhaps the browser does even define
import.meta.runtime = { browser: true }
one day.The text was updated successfully, but these errors were encountered: