mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
module: remove module.createRequireFromPath
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
1 parent
57e76040f5
commit
674614b3f5
7 files changed
+8
-57
No files matched your search
@@ -2382,6 +2382,9 @@ instead.
|
||||
### DEP0130: `Module.createRequireFromPath()`
|
||||
<!-- YAML
|
||||
changes:
|
||||
- version: REPLACEME
|
||||
pr-url: https://github.com/nodejs/node/pull/37201
|
||||
description: End-of-life.
|
||||
- version: v13.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/27951
|
||||
description: Runtime deprecation.
|
||||
@@ -2390,10 +2393,9 @@ changes:
|
||||
description: Documentation-only.
|
||||
-->
|
||||
|
||||
Type: Runtime
|
||||
Type: End-of-Life
|
||||
|
||||
Module.createRequireFromPath() is deprecated. Please use
|
||||
[`module.createRequire()`][] instead.
|
||||
Use [`module.createRequire()`][] instead.
|
||||
|
||||
### DEP0131: Legacy HTTP parser
|
||||
<!-- YAML
|
||||
|
||||
@@ -59,26 +59,6 @@ const require = createRequire(import.meta.url);
|
||||
const siblingModule = require('./sibling-module');
|
||||
```
|
||||
|
||||
### `module.createRequireFromPath(filename)`
|
||||
<!-- YAML
|
||||
added: v10.12.0
|
||||
deprecated: v12.2.0
|
||||
-->
|
||||
|
||||
> 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()`
|
||||
<!-- YAML
|
||||
added: v12.12.0
|
||||
@@ -214,7 +194,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
|
||||
@@ -966,7 +966,6 @@ This section was moved to
|
||||
<!-- Anchors to make sure old links find a target -->
|
||||
* <a id="modules_module_builtinmodules" href="module.html#module_module_builtinmodules">`module.builtinModules`</a>
|
||||
* <a id="modules_module_createrequire_filename" href="module.html#module_module_createrequire_filename">`module.createRequire(filename)`</a>
|
||||
* <a id="modules_module_createrequirefrompath_filename" href="module.html#module_module_createrequirefrompath_filename">`module.createRequireFromPath(filename)`</a>
|
||||
* <a id="modules_module_syncbuiltinesmexports" href="module.html#module_module_syncbuiltinesmexports">`module.syncBuiltinESMExports()`</a>
|
||||
|
||||
## Source map v3 support
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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' });
|
||||
@@ -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 });
|
||||
|
||||
|
||||
Reference in new issue
Block a user