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

feat: add import.meta.DEBUG #18417

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

jkrems
Copy link

@jkrems jkrems commented Oct 21, 2024

Description

Adds an alternative to process.env.NODE_ENV-based guards. It's a simple boolean and doesn't require the use of node-specific APIs in non-node code.

See: https://github.com/jkrems/md/blob/main/import-meta-debug.md
Or just skip ahead to the section that defines this new property: https://github.com/jkrems/md/blob/main/import-meta-debug.md#importmetaDEBUG.

The goal is to have this property reliably available across tools. PRs across bundlers:

I wouldn't be surprised if there's some bikeshedding on the name (.DEBUG vs .DEV vs .development vs ..?). So it's likely a good idea to hold off on landing it in any of the tools before there's a broader consensus on the name. The API itself seems simple enough that I'm not expecting a lot of churn.

@jkrems jkrems force-pushed the jk-import-meta-debug branch 2 times, most recently from ca2800c to 8232f70 Compare October 21, 2024 18:21
Adds an alternative to `process.env.NODE_ENV`-based guards. It's a simple
boolean and doesn't require the use of node-specific APIs in non-node code.
@sapphi-red sapphi-red added the p2-to-be-discussed Enhancement under consideration (priority) label Oct 23, 2024
@sapphi-red
Copy link
Member

https://github.com/jkrems/md/blob/main/import-meta-debug.md#package-exports-development
How about using something like esm-env?

The downside of using import.meta is that the source code needs to be in ESM. I don't think it's that bad, but just to point it out.

I think this needs some kind of standard otherwise the whole benefit will disappear, but the discussion about that seems to be happening on the webpack PR.

(This is just my take. I'll try to talk about this in the next team meeting.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-to-be-discussed Enhancement under consideration (priority)
Projects
Status: Later
Development

Successfully merging this pull request may close these issues.

2 participants