Skip to content

Commit

Permalink
fix: packageFilter passes expected arguments
Browse files Browse the repository at this point in the history
(see #202)
  • Loading branch information
manucorporat authored and ljharb committed Nov 19, 2019
1 parent ed46ce6 commit 9f06a8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ module.exports = function (x, options) {
} catch (jsonErr) {}

if (pkg && opts.packageFilter) {
pkg = opts.packageFilter(pkg, pkgfile);
pkg = opts.packageFilter(pkg, pkgfile, dir);
}

return { pkg: pkg, dir: dir };
Expand All @@ -133,7 +133,7 @@ module.exports = function (x, options) {
} catch (e) {}

if (pkg && opts.packageFilter) {
pkg = opts.packageFilter(pkg, x);
pkg = opts.packageFilter(pkg, pkgfile, x);
}

if (pkg && pkg.main) {
Expand Down
9 changes: 6 additions & 3 deletions test/filter_sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ test('filter', function (t) {
var packageFilterArgs;
var res = resolve.sync('./baz', {
basedir: dir,
packageFilter: function (pkg, dir) {
packageFilter: function (pkg, pkgfile, dir) {
pkg.main = 'doom'; // eslint-disable-line no-param-reassign
packageFilterArgs = [pkg, dir];
packageFilterArgs = [pkg, pkgfile, dir];
return pkg;
}
});
Expand All @@ -20,7 +20,10 @@ test('filter', function (t) {
t.equal(packageData.main, 'doom', 'package "main" was altered');

var packageFile = packageFilterArgs[1];
t.equal(packageFile, path.join(dir, 'baz'), 'second packageFilter argument is "dir"');
t.equal(packageFile, path.join(dir, 'baz', 'package.json'), 'package.json path is correct');

var packageDir = packageFilterArgs[2];
t.equal(packageDir, path.join(dir, 'baz'), 'third packageFilter argument is "dir"');

t.end();
});

0 comments on commit 9f06a8f

Please sign in to comment.