Skip to content

Commit c88cca4

Browse files
committed
Remove prending deprecation for backporting
1 parent 281c4f7 commit c88cca4

4 files changed

Lines changed: 6 additions & 33 deletions

File tree

doc/api/deprecations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2704,7 +2704,7 @@ changes:
27042704
description: Documentation-only deprecation.
27052705
-->
27062706
2707-
Type: Documentation-only (supports [`--pending-deprecation`][])
2707+
Type: Documentation-only
27082708
27092709
A CommonJS module can access the first module that required it using
27102710
`module.parent`. This feature is deprecated because it does not work

doc/api/modules.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ Module {
690690
id: '.',
691691
path: '/absolute/path/to',
692692
exports: {},
693+
parent: null,
693694
filename: '/absolute/path/to/entry.js',
694695
loaded: false,
695696
children: [],
@@ -903,7 +904,7 @@ deprecated: REPLACEME
903904

904905
The module that first required this one, or `null` if the current module is the
905906
entry point of the current process, or `undefined` if the module was loaded by
906-
something that is not a CommonJS module (E.G.: REPL or `import`). Read only.
907+
something that is not a CommonJS module (E.G.: REPL or `import`).
907908

908909
### `module.path`
909910
<!-- YAML

lib/internal/modules/cjs/loader.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const {
3939
ReflectSet,
4040
RegExpPrototypeTest,
4141
SafeMap,
42-
SafeWeakMap,
4342
String,
4443
StringPrototypeIndexOf,
4544
StringPrototypeMatch,
@@ -160,12 +159,11 @@ function updateChildren(parent, child, scan) {
160159
children.push(child);
161160
}
162161

163-
const moduleParentCache = new SafeWeakMap();
164162
function Module(id = '', parent) {
165163
this.id = id;
166164
this.path = path.dirname(id);
167165
this.exports = {};
168-
moduleParentCache.set(this, parent);
166+
this.parent = parent;
169167
updateChildren(parent, this, false);
170168
this.filename = null;
171169
this.loaded = false;
@@ -234,18 +232,6 @@ ObjectDefineProperty(Module, 'wrapper', {
234232
}
235233
});
236234

237-
function getModuleParent() {
238-
return moduleParentCache.get(this);
239-
}
240-
ObjectDefineProperty(Module.prototype, 'parent', {
241-
get: pendingDeprecation ? deprecate(
242-
getModuleParent,
243-
'module.parent is deprecated due to accuracy issues. Please use ' +
244-
'require.main to find program entry point instead.',
245-
'DEP0143'
246-
) : getModuleParent
247-
});
248-
249235
const debug = require('internal/util/debuglog').debuglog('module');
250236
Module._debug = deprecate(debug, 'Module._debug is deprecated.', 'DEP0077');
251237

@@ -1032,7 +1018,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
10321018
const requireStack = [];
10331019
for (let cursor = parent;
10341020
cursor;
1035-
cursor = moduleParentCache.get(cursor)) {
1021+
cursor = cursor.parent) {
10361022
requireStack.push(cursor.filename || cursor.id);
10371023
}
10381024
let message = `Cannot find module '${request}'`;
@@ -1225,7 +1211,7 @@ Module._extensions['.js'] = function(module, filename) {
12251211
const pkg = readPackageScope(filename);
12261212
// Function require shouldn't be used in ES modules.
12271213
if (pkg && pkg.data && pkg.data.type === 'module') {
1228-
const parent = moduleParentCache.get(module);
1214+
const { parent } = module;
12291215
const parentPath = parent && parent.filename;
12301216
const packageJsonPath = path.resolve(pkg.path, 'package.json');
12311217
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);

test/parallel/test-module-parent-deprecation.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)