From 14701e539c190563cc5b041d101682129f4f5770 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 29 May 2019 09:59:08 -0400 Subject: [PATCH] module: runtime deprecate createRequireFromPath() This commit moves DEP0130 to a runtime deprecation. PR-URL: https://github.com/nodejs/node/pull/27951 Reviewed-By: Luigi Pinca Reviewed-By: Trivikram Kamat Reviewed-By: Rich Trott Reviewed-By: James M Snell --- doc/api/deprecations.md | 5 ++++- lib/internal/modules/cjs/loader.js | 7 ++++++- test/message/async_error_sync_esm.out | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 9773c4069f61c6..7aeab5be7d448d 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2451,12 +2451,15 @@ instead. ### DEP0130: Module.createRequireFromPath() -Type: Documentation-only +Type: Runtime Module.createRequireFromPath() is deprecated. Please use [`module.createRequire()`][] instead. diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index e676d06fa91456..27f8c8912a9ef1 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -860,7 +860,12 @@ function createRequireFromPath(filename) { return makeRequireFunction(m); } -Module.createRequireFromPath = createRequireFromPath; +Module.createRequireFromPath = deprecate( + createRequireFromPath, + 'Module.createRequireFromPath() is deprecated. ' + + 'Use Module.createRequire() instead.', + 'DEP0130' +); const createRequireError = 'must be a file URL object, file URL string, or ' + 'absolute path string'; diff --git a/test/message/async_error_sync_esm.out b/test/message/async_error_sync_esm.out index f34628ef44e52a..544916e24866e2 100644 --- a/test/message/async_error_sync_esm.out +++ b/test/message/async_error_sync_esm.out @@ -5,3 +5,4 @@ Error: test at async three (*fixtures*async-error.js:20:3) at async four (*fixtures*async-error.js:24:3) at async main (*message*async_error_sync_esm.mjs:7:5) +(node:*) [DEP0130] DeprecationWarning: Module.createRequireFromPath() is deprecated. Use Module.createRequire() instead.