From 674614b3f5245f1b5cae974af1365fd632190b41 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 3 Feb 2021 12:31:38 +0100 Subject: [PATCH] module: remove module.createRequireFromPath MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/37201 Reviewed-By: Myles Borins Reviewed-By: Benjamin Gruenbaum Reviewed-By: Geoffrey Booth Reviewed-By: Michaƫl Zasso Reviewed-By: Rich Trott Reviewed-By: James M Snell --- doc/api/deprecations.md | 8 ++++--- doc/api/module.md | 21 ------------------- doc/api/modules.md | 1 - lib/internal/modules/cjs/loader.js | 7 ------- test/es-module/test-esm-json-cache.mjs | 5 ++--- ...st-module-create-require-from-directory.js | 18 ---------------- test/parallel/test-module-create-require.js | 5 +---- 7 files changed, 8 insertions(+), 57 deletions(-) delete mode 100644 test/parallel/test-module-create-require-from-directory.js diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 30f17db15de3e3..09f05df5b44906 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2382,6 +2382,9 @@ instead. ### DEP0130: `Module.createRequireFromPath()` -Type: Runtime +Type: End-of-Life -Module.createRequireFromPath() is deprecated. Please use -[`module.createRequire()`][] instead. +Use [`module.createRequire()`][] instead. ### DEP0131: Legacy HTTP parser - -> Stability: 0 - Deprecated: Please use [`createRequire()`][] instead. - -* `filename` {string} Filename to be used to construct the relative require - function. -* Returns: {require} Require function - -```js -const { createRequireFromPath } = require('module'); -const requireUtil = createRequireFromPath('../src/utils/'); - -// Require `../src/utils/some-tool` -requireUtil('./some-tool'); -``` - ### `module.syncBuiltinESMExports()` * `module.builtinModules` * `module.createRequire(filename)` -* `module.createRequireFromPath(filename)` * `module.syncBuiltinESMExports()` ## Source map v3 support diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 7696a3e1907460..6b18338e347464 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -1170,13 +1170,6 @@ function createRequireFromPath(filename) { return makeRequireFunction(m, null); } -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/es-module/test-esm-json-cache.mjs b/test/es-module/test-esm-json-cache.mjs index d08f852e255a78..68ea832ab69585 100644 --- a/test/es-module/test-esm-json-cache.mjs +++ b/test/es-module/test-esm-json-cache.mjs @@ -3,14 +3,13 @@ import '../common/index.mjs'; import { strictEqual, deepStrictEqual } from 'assert'; -import { createRequireFromPath as createRequire } from 'module'; -import { fileURLToPath as fromURL } from 'url'; +import { createRequire } from 'module'; import mod from '../fixtures/es-modules/json-cache/mod.cjs'; import another from '../fixtures/es-modules/json-cache/another.cjs'; import test from '../fixtures/es-modules/json-cache/test.json'; -const require = createRequire(fromURL(import.meta.url)); +const require = createRequire(import.meta.url); const modCjs = require('../fixtures/es-modules/json-cache/mod.cjs'); const anotherCjs = require('../fixtures/es-modules/json-cache/another.cjs'); diff --git a/test/parallel/test-module-create-require-from-directory.js b/test/parallel/test-module-create-require-from-directory.js deleted file mode 100644 index f043adacf994d8..00000000000000 --- a/test/parallel/test-module-create-require-from-directory.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; - -require('../common'); -const assert = require('assert'); -const path = require('path'); - -const { createRequireFromPath } = require('module'); - -const fixPath = path.resolve(__dirname, '..', 'fixtures'); -const p = path.join(fixPath, path.sep); - -const req = createRequireFromPath(p); -const reqFromNotDir = createRequireFromPath(fixPath); - -assert.strictEqual(req('./baz'), 'perhaps I work'); -assert.throws(() => { - reqFromNotDir('./baz'); -}, { code: 'MODULE_NOT_FOUND' }); diff --git a/test/parallel/test-module-create-require.js b/test/parallel/test-module-create-require.js index fc7c8b3fc697ea..e0e34e9f127bd3 100644 --- a/test/parallel/test-module-create-require.js +++ b/test/parallel/test-module-create-require.js @@ -4,14 +4,11 @@ require('../common'); const assert = require('assert'); const path = require('path'); -const { createRequire, createRequireFromPath } = require('module'); +const { createRequire } = require('module'); const p = path.resolve(__dirname, '..', 'fixtures', 'fake.js'); const u = new URL(`file://${p}`); -const req = createRequireFromPath(p); -assert.strictEqual(req('./baz'), 'perhaps I work'); - const reqToo = createRequire(u); assert.deepStrictEqual(reqToo('./experimental'), { ofLife: 42 });