From 0a7045391897306e82fe60ce1da0a84c3ec85696 Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Sat, 10 Feb 2018 09:36:55 -0600 Subject: [PATCH] test: formalize exposure of internal bindings moves exposed internalBindings to a single location with short guidelines on how to expose them and a warning for users should they come across it --- lib/internal/loader/ModuleWrap.js | 5 ----- lib/internal/test/binding.js | 13 +++++++++++++ node.gyp | 2 +- test/parallel/test-internal-module-wrap.js | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) delete mode 100644 lib/internal/loader/ModuleWrap.js create mode 100644 lib/internal/test/binding.js diff --git a/lib/internal/loader/ModuleWrap.js b/lib/internal/loader/ModuleWrap.js deleted file mode 100644 index b2b11daead7dde..00000000000000 --- a/lib/internal/loader/ModuleWrap.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -// exposes ModuleWrap for testing - -module.exports = internalBinding('module_wrap').ModuleWrap; diff --git a/lib/internal/test/binding.js b/lib/internal/test/binding.js new file mode 100644 index 00000000000000..7b9e1a089d2c36 --- /dev/null +++ b/lib/internal/test/binding.js @@ -0,0 +1,13 @@ +'use strict'; + +process.emitWarning( + 'These APIs are exposed only for testing and are not ' + + 'tracked by any versioning system or deprecation process.', + 'internal/test/binding'); + +// These exports should be scoped as specifically as possible +// to avoid exposing APIs because even with that warning and +// this file being internal people will still try to abuse it. +module.exports = { + ModuleWrap: internalBinding('module_wrap').ModuleWrap, +}; diff --git a/node.gyp b/node.gyp index e2b17cd2b5fae6..0eedd9bb86c7ee 100644 --- a/node.gyp +++ b/node.gyp @@ -107,7 +107,6 @@ 'lib/internal/loader/DefaultResolve.js', 'lib/internal/loader/ModuleJob.js', 'lib/internal/loader/ModuleMap.js', - 'lib/internal/loader/ModuleWrap.js', 'lib/internal/loader/Translators.js', 'lib/internal/safe_globals.js', 'lib/internal/net.js', @@ -125,6 +124,7 @@ 'lib/internal/repl.js', 'lib/internal/repl/await.js', 'lib/internal/socket_list.js', + 'lib/internal/test/binding.js', 'lib/internal/test/unicode.js', 'lib/internal/timers.js', 'lib/internal/tls.js', diff --git a/test/parallel/test-internal-module-wrap.js b/test/parallel/test-internal-module-wrap.js index 634d1ebc6f678e..66a17a0f344701 100644 --- a/test/parallel/test-internal-module-wrap.js +++ b/test/parallel/test-internal-module-wrap.js @@ -6,7 +6,7 @@ const common = require('../common'); common.crashOnUnhandledRejection(); const assert = require('assert'); -const ModuleWrap = require('internal/loader/ModuleWrap'); +const { ModuleWrap } = require('internal/test/binding'); const { getPromiseDetails, isPromise } = process.binding('util'); const setTimeoutAsync = require('util').promisify(setTimeout);