Skip to content

Commit

Permalink
lib: expose primordials object
Browse files Browse the repository at this point in the history
Expose the internal `primordials` object to help with Node.js core
development.

```console
$ node --expose-internals -r internal/test/binding lib/fs.js
(node:5299) internal/test/binding: These APIs are for internal testing
only. Do not use them.
(Use `node --trace-warnings ...` to show where the warning was created)
```

PR-URL: #36872
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
aduh95 authored and targos committed Jun 11, 2021
1 parent 46c019b commit 8912cab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/internal/modules/cjs/loader.js
Expand Up @@ -233,9 +233,9 @@ ObjectDefineProperty(Module, 'wrapper', {
}
});

ObjectDefineProperty(Module.prototype, 'isPreloading', {
get() { return isPreloading; }
});
const isPreloadingDesc = { get() { return isPreloading; } };
ObjectDefineProperty(Module.prototype, 'isPreloading', isPreloadingDesc);
ObjectDefineProperty(NativeModule.prototype, 'isPreloading', isPreloadingDesc);

let debug = require('internal/util/debuglog').debuglog('module', (fn) => {
debug = fn;
Expand Down
7 changes: 6 additions & 1 deletion lib/internal/test/binding.js
Expand Up @@ -4,4 +4,9 @@ process.emitWarning(
'These APIs are for internal testing only. Do not use them.',
'internal/test/binding');

module.exports = { internalBinding };
if (module.isPreloading) {
globalThis.internalBinding = internalBinding;
globalThis.primordials = primordials;
}

module.exports = { internalBinding, primordials };

0 comments on commit 8912cab

Please sign in to comment.