From abe1ad0ea742b589c964128bfcb6aef697438995 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 3 Feb 2021 12:31:38 +0100 Subject: [PATCH 1/2] module: remove module.createRequireFromPath --- doc/api/deprecations.md | 8 +++++--- doc/api/module.md | 20 -------------------- doc/api/modules.md | 1 - lib/internal/modules/cjs/loader.js | 7 ------- 4 files changed, 5 insertions(+), 31 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 92203b8112f416..908e8a3733be79 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2379,6 +2379,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 0c69d547d40b9a..166651db69c6af 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -1184,13 +1184,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'; From 887bc12a3dbb51cef663420c100280e17ffc9728 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 3 Feb 2021 12:51:18 +0100 Subject: [PATCH 2/2] fixup! module: remove module.createRequireFromPath --- doc/api/deprecations.md | 4 ++-- doc/api/module.md | 1 - test/es-module/test-esm-json-cache.mjs | 5 ++--- ...est-module-create-require-from-directory.js | 18 ------------------ test/parallel/test-module-create-require.js | 5 +---- 5 files changed, 5 insertions(+), 28 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 908e8a3733be79..7d709385d220cb 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2380,7 +2380,7 @@ instead. -Type: End-of-life +Type: End-of-Life Use [`module.createRequire()`][] instead. diff --git a/doc/api/module.md b/doc/api/module.md index 755b57a2c8caa0..e8e4a93a516071 100644 --- a/doc/api/module.md +++ b/doc/api/module.md @@ -191,7 +191,6 @@ consists of the following keys: [`--enable-source-maps`]: cli.md#cli_enable_source_maps [`NODE_V8_COVERAGE=dir`]: cli.md#cli_node_v8_coverage_dir [`SourceMap`]: #module_class_module_sourcemap -[`createRequire()`]: #module_module_createrequire_filename [`module`]: modules.md#modules_the_module_object [module wrapper]: modules.md#modules_the_module_wrapper [source map include directives]: https://sourcemaps.info/spec.html#h.lmz475t4mvbx 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 });