Skip to content

Commit

Permalink
module: remove module.createRequireFromPath
Browse files Browse the repository at this point in the history
PR-URL: #37201
Reviewed-By: Myles Borins <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
aduh95 authored and jasnell committed Feb 15, 2021
1 parent 57e7604 commit 674614b
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 57 deletions.
8 changes: 5 additions & 3 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
21 changes: 0 additions & 21 deletions doc/api/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion doc/api/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
5 changes: 2 additions & 3 deletions test/es-module/test-esm-json-cache.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
18 changes: 0 additions & 18 deletions test/parallel/test-module-create-require-from-directory.js

This file was deleted.

5 changes: 1 addition & 4 deletions test/parallel/test-module-create-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down

0 comments on commit 674614b

Please sign in to comment.