From c38b2ad4ab108f464dfc6cda63f08f8d14c60602 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Wed, 25 Nov 2020 07:54:32 -0800 Subject: [PATCH] module: add isPreloading indicator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 PR-URL: https://github.com/nodejs/node/pull/36263 Reviewed-By: Gerhard Stöbich Reviewed-By: Rich Trott --- doc/api/module.md | 8 ++++++++ lib/internal/modules/cjs/loader.js | 9 +++++++++ test/fixtures/ispreloading.js | 2 ++ test/parallel/test-preload.js | 13 +++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 test/fixtures/ispreloading.js diff --git a/doc/api/module.md b/doc/api/module.md index 2fb6ca884b4443..77d5f433b9c270 100644 --- a/doc/api/module.md +++ b/doc/api/module.md @@ -76,6 +76,14 @@ const requireUtil = createRequireFromPath('../src/utils/'); requireUtil('./some-tool'); ``` +### `module.isPreloading` + + +* Type: {boolean} `true` if the module is running during the Node.js preload + phase. + ### `module.syncBuiltinESMExports()`