Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update default extensions to match node #145

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = function resolve(x, options, callback) {
var isDirectory = opts.isDirectory || defaultIsDir;
var readFile = opts.readFile || fs.readFile;

var extensions = opts.extensions || ['.js'];
var extensions = opts.extensions || ['.js', '.json', '.node'];
var basedir = opts.basedir || path.dirname(caller());
var parent = opts.filename || basedir;

Expand Down
2 changes: 1 addition & 1 deletion lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function (x, options) {
var isDirectory = opts.isDirectory || defaultIsDir;
var readFileSync = opts.readFileSync || fs.readFileSync;

var extensions = opts.extensions || ['.js'];
var extensions = opts.extensions || ['.js', '.json', '.node'];
var basedir = opts.basedir || path.dirname(caller());
var parent = opts.filename || basedir;

Expand Down
4 changes: 2 additions & 2 deletions readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ default `opts` values:
{
paths: [],
basedir: __dirname,
extensions: ['.js'],
extensions: [ '.js', '.json', '.node' ],
readFile: fs.readFile,
isFile: function isFile(file, cb) {
fs.stat(file, function (err, stat) {
Expand Down Expand Up @@ -151,7 +151,7 @@ default `opts` values:
{
paths: [],
basedir: __dirname,
extensions: ['.js'],
extensions: [ '.js', '.json', '.node' ],
readFileSync: fs.readFileSync,
isFile: function isFile(file) {
try {
Expand Down
15 changes: 15 additions & 0 deletions test/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ test('async foo', function (t) {
});
});

test('non-default extensions', function (t) {
t.plan(2);
var dir = path.join(__dirname, 'resolver');

resolve('./foo-json', { basedir: dir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'foo-json.json'));
});

resolve('./foo-node', { basedir: dir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(dir, 'foo-node.node'));
});
});

test('bar', function (t) {
t.plan(6);
var dir = path.join(__dirname, 'resolver');
Expand Down
1 change: 1 addition & 0 deletions test/resolver/foo-json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
1 change: 1 addition & 0 deletions test/resolver/foo-node.node
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 1;
16 changes: 16 additions & 0 deletions test/resolver_sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ test('foo', function (t) {
t.end();
});

test('non-default extensions', function (t) {
var dir = path.join(__dirname, 'resolver');

t.equal(
resolve.sync('./foo-json', { basedir: dir }),
path.join(dir, 'foo-json.json')
);

t.equal(
resolve.sync('./foo-node', { basedir: dir }),
path.join(dir, 'foo-node.node')
);

t.end();
});

test('bar', function (t) {
var dir = path.join(__dirname, 'resolver');

Expand Down