Skip to content

Commit

Permalink
module: ignore package.json/ directories
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeck committed Jan 19, 2018
1 parent 1b0d979 commit fec4a5d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ function readPackage(requestPath) {
return entry;

const jsonPath = path.resolve(requestPath, 'package.json');
const rc = stat(jsonPath);
if (rc !== 0) {
return false;
}
const json = internalModuleReadJSON(path.toNamespacedPath(jsonPath));

if (json === undefined) {
Expand Down
Empty file.
13 changes: 13 additions & 0 deletions test/parallel/test-require-package-json-directory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';
require('../common');
const assert = require('assert');
const fixtures = require('../common/fixtures');

try {
require(fixtures.path('module-package-json-directory'));
process.exit(1);
} catch (err) {
assert.ok(
/Cannot find module/.test(err.message),
`require() should ignore package.json/ directories: ${err.message}`);
}

0 comments on commit fec4a5d

Please sign in to comment.