Skip to content

Commit

Permalink
feat(Resolver): give high priority to extension of parent file (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
aicest authored and devongovett committed Dec 11, 2017
1 parent 7c0acb3 commit 2e32662
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ class Resolver {
return {path: path.resolve(path.dirname(parent), filename)};
}

let extensions = Object.keys(this.options.extensions);
if (parent) {
const parentExt = path.extname(parent);
// parent's extension given high priority
extensions = [parentExt, ...extensions.filter(ext => ext !== parentExt)];
}

return resolver(filename, {
filename: parent,
paths: this.options.paths,
modules: builtins,
extensions: Object.keys(this.options.extensions),
extensions: extensions,
packageFilter(pkg, pkgfile) {
// Expose the path to the package.json file
pkg.pkgfile = pkgfile;
Expand Down

0 comments on commit 2e32662

Please sign in to comment.