Skip to content

Commit

Permalink
Revert "module: fix inconsistency between load and _findPath"
Browse files Browse the repository at this point in the history
This reverts commit 1b92214
from PR #22382.

See the discussion at
nodejs/citgm#604

PR-URL: #23228
Refs: #22382
Fixes: #4778
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
jdalton authored and jasnell committed Oct 17, 2018
1 parent 0339d3d commit 15b1241
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 70 deletions.
14 changes: 2 additions & 12 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,6 @@ function tryExtensions(p, exts, isMain) {
return false;
}

function readExtensions() {
const exts = Object.keys(Module._extensions);
for (var i = 0, j = 0; i < exts.length; ++i) {
if (path.extname(exts[i]) === '')
exts[j++] = exts[i];
}
exts.length = j;
return exts;
}

var warned = false;
Module._findPath = function(request, paths, isMain) {
if (path.isAbsolute(request)) {
Expand Down Expand Up @@ -284,15 +274,15 @@ Module._findPath = function(request, paths, isMain) {
if (!filename) {
// try it with each of the extensions
if (exts === undefined)
exts = readExtensions();
exts = Object.keys(Module._extensions);
filename = tryExtensions(basePath, exts, isMain);
}
}

if (!filename && rc === 1) { // Directory.
// try it with each of the extensions at "index"
if (exts === undefined)
exts = readExtensions();
exts = Object.keys(Module._extensions);
filename = tryPackage(basePath, exts, isMain);
if (!filename) {
filename = tryExtensions(path.resolve(basePath, 'index'), exts, isMain);
Expand Down
18 changes: 18 additions & 0 deletions test/known_issues/test-module-deleted-extensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';
// Refs: https://github.com/nodejs/node/issues/4778
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir');
const file = path.join(tmpdir.path, 'test-extensions.foo.bar');

tmpdir.refresh();
fs.writeFileSync(file, '', 'utf8');
require.extensions['.foo.bar'] = (module, path) => {};
delete require.extensions['.foo.bar'];
require.extensions['.bar'] = common.mustCall((module, path) => {
assert.strictEqual(module.id, file);
assert.strictEqual(path, file);
});
require(path.join(tmpdir.path, 'test-extensions'));
58 changes: 0 additions & 58 deletions test/parallel/test-module-deleted-extensions.js

This file was deleted.

0 comments on commit 15b1241

Please sign in to comment.