Skip to content

Commit 674614b

Browse files
aduh95jasnell
authored andcommitted
module: remove module.createRequireFromPath
PR-URL: #37201 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 57e7604 commit 674614b

File tree

7 files changed

+8
-57
lines changed

7 files changed

+8
-57
lines changed

doc/api/deprecations.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -2382,6 +2382,9 @@ instead.
23822382
### DEP0130: `Module.createRequireFromPath()`
23832383
<!-- YAML
23842384
changes:
2385+
- version: REPLACEME
2386+
pr-url: https://github.com/nodejs/node/pull/37201
2387+
description: End-of-life.
23852388
- version: v13.0.0
23862389
pr-url: https://github.com/nodejs/node/pull/27951
23872390
description: Runtime deprecation.
@@ -2390,10 +2393,9 @@ changes:
23902393
description: Documentation-only.
23912394
-->
23922395

2393-
Type: Runtime
2396+
Type: End-of-Life
23942397

2395-
Module.createRequireFromPath() is deprecated. Please use
2396-
[`module.createRequire()`][] instead.
2398+
Use [`module.createRequire()`][] instead.
23972399

23982400
### DEP0131: Legacy HTTP parser
23992401
<!-- YAML

doc/api/module.md

-21
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,6 @@ const require = createRequire(import.meta.url);
5959
const siblingModule = require('./sibling-module');
6060
```
6161
62-
### `module.createRequireFromPath(filename)`
63-
<!-- YAML
64-
added: v10.12.0
65-
deprecated: v12.2.0
66-
-->
67-
68-
> Stability: 0 - Deprecated: Please use [`createRequire()`][] instead.
69-
70-
* `filename` {string} Filename to be used to construct the relative require
71-
function.
72-
* Returns: {require} Require function
73-
74-
```js
75-
const { createRequireFromPath } = require('module');
76-
const requireUtil = createRequireFromPath('../src/utils/');
77-
78-
// Require `../src/utils/some-tool`
79-
requireUtil('./some-tool');
80-
```
81-
8262
### `module.syncBuiltinESMExports()`
8363
<!-- YAML
8464
added: v12.12.0
@@ -214,7 +194,6 @@ consists of the following keys:
214194
[`--enable-source-maps`]: cli.md#cli_enable_source_maps
215195
[`NODE_V8_COVERAGE=dir`]: cli.md#cli_node_v8_coverage_dir
216196
[`SourceMap`]: #module_class_module_sourcemap
217-
[`createRequire()`]: #module_module_createrequire_filename
218197
[`module`]: modules.md#modules_the_module_object
219198
[module wrapper]: modules.md#modules_the_module_wrapper
220199
[source map include directives]: https://sourcemaps.info/spec.html#h.lmz475t4mvbx

doc/api/modules.md

-1
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,6 @@ This section was moved to
966966
<!-- Anchors to make sure old links find a target -->
967967
* <a id="modules_module_builtinmodules" href="module.html#module_module_builtinmodules">`module.builtinModules`</a>
968968
* <a id="modules_module_createrequire_filename" href="module.html#module_module_createrequire_filename">`module.createRequire(filename)`</a>
969-
* <a id="modules_module_createrequirefrompath_filename" href="module.html#module_module_createrequirefrompath_filename">`module.createRequireFromPath(filename)`</a>
970969
* <a id="modules_module_syncbuiltinesmexports" href="module.html#module_module_syncbuiltinesmexports">`module.syncBuiltinESMExports()`</a>
971970

972971
## Source map v3 support

lib/internal/modules/cjs/loader.js

-7
Original file line numberDiff line numberDiff line change
@@ -1170,13 +1170,6 @@ function createRequireFromPath(filename) {
11701170
return makeRequireFunction(m, null);
11711171
}
11721172

1173-
Module.createRequireFromPath = deprecate(
1174-
createRequireFromPath,
1175-
'Module.createRequireFromPath() is deprecated. ' +
1176-
'Use Module.createRequire() instead.',
1177-
'DEP0130'
1178-
);
1179-
11801173
const createRequireError = 'must be a file URL object, file URL string, or ' +
11811174
'absolute path string';
11821175

test/es-module/test-esm-json-cache.mjs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import '../common/index.mjs';
33

44
import { strictEqual, deepStrictEqual } from 'assert';
55

6-
import { createRequireFromPath as createRequire } from 'module';
7-
import { fileURLToPath as fromURL } from 'url';
6+
import { createRequire } from 'module';
87

98
import mod from '../fixtures/es-modules/json-cache/mod.cjs';
109
import another from '../fixtures/es-modules/json-cache/another.cjs';
1110
import test from '../fixtures/es-modules/json-cache/test.json';
1211

13-
const require = createRequire(fromURL(import.meta.url));
12+
const require = createRequire(import.meta.url);
1413

1514
const modCjs = require('../fixtures/es-modules/json-cache/mod.cjs');
1615
const anotherCjs = require('../fixtures/es-modules/json-cache/another.cjs');

test/parallel/test-module-create-require-from-directory.js

-18
This file was deleted.

test/parallel/test-module-create-require.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ require('../common');
44
const assert = require('assert');
55
const path = require('path');
66

7-
const { createRequire, createRequireFromPath } = require('module');
7+
const { createRequire } = require('module');
88

99
const p = path.resolve(__dirname, '..', 'fixtures', 'fake.js');
1010
const u = new URL(`file://${p}`);
1111

12-
const req = createRequireFromPath(p);
13-
assert.strictEqual(req('./baz'), 'perhaps I work');
14-
1512
const reqToo = createRequire(u);
1613
assert.deepStrictEqual(reqToo('./experimental'), { ofLife: 42 });
1714

0 commit comments

Comments
 (0)