-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
module: add isPreloading indicator #36263
Conversation
Maybe it might be a little out of context for a single PR, but would it be possible to also add |
@ShogunPanda ... There's already require.main that can be used to easily make that determination. Not sure adding an additional property helps. |
Adds a `module.isPreloading` property that is `true` only during the preload (`-r`) phase of Node.js bootstrap. This provides modules an easy, non-hacky way of knowing if they are being loaded during preload. Signed-off-by: James M Snell <jasnell@gmail.com>
4bb59fb
to
e0a80b2
Compare
Adds a `module.isPreloading` property that is `true` only during the preload (`-r`) phase of Node.js bootstrap. This provides modules an easy, non-hacky way of knowing if they are being loaded during preload. Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #36263 Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
Landed in 8ff2501 |
@nodejs/modules-active-members If there are any concerns about this, including whether |
I've often thought we might instead want to use conditions to allow this, i don't know where to put a property like this PR does on an ESM thing (JS or WASM). |
Is this something that can be polyfilled, since it won’t be backportable earlier than node 14? |
Is this an attribute of the execution phase more so than of the current file? If so, could it be something imported, e.g. from module or process? That should work for both ESM and CJS. |
Or even simpler, a global that only exists during this phase. |
Unless we had preloads figured out for ESM, it doesn't really matter. If preloads did support it, a property in import.meta would make sense.
Why wouldn't it be backportable earlier than 14? And no, it can't be polyfilled.
It's an attribute of the execution phase that is not relevant to ESM because preloads do not support ESM. |
@jasnell i was under the impression that v12.20 was the last expected minor in v12 before it goes into maintenance. Preloads will one day support ESM, so it seems prudent to aim for a mechanism that's the same in both CJS and ESM. |
import { isPreloading } from 'module' ... Should work easily enough if preloads ever actually support ESM? There may be process reasons why it's not backported but there's no technical reason why it can't be backported. It can't be polyfilled tho. |
What's the advantage to making it importable when it's global state? Global state is usually accessed via "a global". |
I haven't made it importable. I'm just saying that it could be if necessary. The pattern I suggested is consistent with what we've done elsewhere also (see |
We're having the discussion after it landed because a modules feature landed without anyone on the modules github team being pinged, as is customary for any feature that has a stakeholder github team. I think you're right that it would work fine for ESM - I'm mainly just asking why "a global" wasn't considered, given that it's global state. |
I'm still confused. It was considered. For instance... $ node -pe "module.isPreloading" Feels pretty global. We even list We do have a tradition of treating new globals as semver-major, which I wanted to avoid here. Dropping this off the existing pseudo-global And as for pinging the modules team, I had (apparently incorrectly) assumed that the CODEOWNERS file would cover notifying the modules team of changes in the |
Thanks, that answers my question (and I'm convinced; new globals are indeed semver-major, and fwiw, i'm not implying a mistake was made or anything intentional was done or that a revert would be reasonable, it's just that the post-merge ping is the reason it's being discussed now :-) thanks for bearing with me. |
We should ideally make sure that the live binding for |
Alternatively, |
Adds a `module.isPreloading` property that is `true` only during the preload (`-r`) phase of Node.js bootstrap. This provides modules an easy, non-hacky way of knowing if they are being loaded during preload. Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #36263 Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: #36435 Notable changes: * child_processes: * add AbortSignal support (Benjamin Gruenbaum) (#36308) * deps: * update ICU to 68.1 (Michaël Zasso) (#36187) * events: * support signal in EventTarget (Benjamin Gruenbaum) (#36258) * graduate Event, EventTarget, AbortController (James M Snell) (#35949) * http: * enable call chaining with setHeader() (pooja d.p) (#35924) * module: * add isPreloading indicator (James M Snell) (#36263) * stream: * support abort signal (Benjamin Gruenbaum) (#36061) * add FileHandle support to Read/WriteStream (Momtchil Momtchev) (#35922) * worker: * add experimental BroadcastChannel (James M Snell) (#36271)
Adds a `module.isPreloading` property that is `true` only during the preload (`-r`) phase of Node.js bootstrap. This provides modules an easy, non-hacky way of knowing if they are being loaded during preload. Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: nodejs#36263 Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: #36435 Notable changes: * child_processes: * add AbortSignal support (Benjamin Gruenbaum) (#36308) * deps: * update ICU to 68.1 (Michaël Zasso) (#36187) * events: * support signal in EventTarget (Benjamin Gruenbaum) (#36258) * graduate Event, EventTarget, AbortController (James M Snell) (#35949) * http: * enable call chaining with setHeader() (pooja d.p) (#35924) * module: * add isPreloading indicator (James M Snell) (#36263) * stream: * support abort signal (Benjamin Gruenbaum) (#36061) * add FileHandle support to Read/WriteStream (Momtchil Momtchev) (#35922) * worker: * add experimental BroadcastChannel (James M Snell) (#36271)
PR-URL: #36435 Notable changes: * child_processes: * add AbortSignal support (Benjamin Gruenbaum) (#36308) * deps: * update ICU to 68.1 (Michaël Zasso) (#36187) * events: * support signal in EventTarget (Benjamin Gruenbaum) (#36258) * graduate Event, EventTarget, AbortController (James M Snell) (#35949) * http: * enable call chaining with setHeader() (pooja d.p) (#35924) * module: * add isPreloading indicator (James M Snell) (#36263) * stream: * support abort signal (Benjamin Gruenbaum) (#36061) * add FileHandle support to Read/WriteStream (Momtchil Momtchev) (#35922) * worker: * add experimental BroadcastChannel (James M Snell) (#36271)
Adds a `module.isPreloading` property that is `true` only during the preload (`-r`) phase of Node.js bootstrap. This provides modules an easy, non-hacky way of knowing if they are being loaded during preload. Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: nodejs#36263 Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
Fixes: nodejs#36775 PR-URL: nodejs#36944 Refs: nodejs#36263 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Adds a `module.isPreloading` property that is `true` only during the preload (`-r`) phase of Node.js bootstrap. This provides modules an easy, non-hacky way of knowing if they are being loaded during preload. Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #36263 Backport-PR-URL: #36988 Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
Adds a
module.isPreloading
property that istrue
only during thepreload (
-r
) phase of Node.js bootstrap. This provides modules aneasy, non-hacky way of knowing if they are being loaded during preload.
For example,
sample.js
:$ node sample.js false
Signed-off-by: James M Snell jasnell@gmail.com
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes