Skip to content

Commit 54bc35f

Browse files
committed
Merge tag 'v1.7.1'
2 parents 220fa7d + 579e2b1 commit 54bc35f

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

lib/sync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ module.exports = function (x, options) {
8888
} catch (jsonErr) {}
8989

9090
if (pkg && opts.packageFilter) {
91-
pkg = opts.packageFilter(pkg, pkgfile);
91+
pkg = opts.packageFilter(pkg, dir);
9292
}
9393

9494
return { pkg: pkg, dir: dir };

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "resolve",
33
"description": "resolve like require.resolve() on behalf of files asynchronously and synchronously",
4-
"version": "1.7.0",
4+
"version": "1.7.1",
55
"repository": {
66
"type": "git",
77
"url": "git://github.com/browserify/resolve.git"

readme.markdown

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ options are:
6060
* opts.isFile - function to asynchronously test whether a file exists
6161

6262
* `opts.packageFilter(pkg, pkgfile)` - transform the parsed package.json contents before looking at the "main" field
63+
* pkg - package data
64+
* pkgfile - path to package.json
6365

6466
* `opts.pathFilter(pkg, path, relativePath)` - transform a path within a package
6567
* pkg - package data
@@ -111,7 +113,9 @@ options are:
111113

112114
* opts.isFile - function to synchronously test whether a file exists
113115

114-
* `opts.packageFilter(pkg, pkgfile)` - transform the parsed package.json contents before looking at the "main" field
116+
* `opts.packageFilter(pkg, dir)` - transform the parsed package.json contents before looking at the "main" field
117+
* pkg - package data
118+
* dir - directory for package.json (Note: the second argument will change to "pkgfile" in v2)
115119

116120
* `opts.pathFilter(pkg, path, relativePath)` - transform a path within a package
117121
* pkg - package data

test/filter.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,32 @@ var test = require('tape');
33
var resolve = require('../');
44

55
test('filter', function (t) {
6-
t.plan(2);
6+
t.plan(4);
77
var dir = path.join(__dirname, 'resolver');
8+
var packageFilterArgs;
89
resolve('./baz', {
910
basedir: dir,
10-
packageFilter: function (pkg) {
11+
packageFilter: function (pkg, pkgfile) {
1112
pkg.main = 'doom';
13+
packageFilterArgs = [pkg, pkgfile];
1214
return pkg;
1315
}
1416
}, function (err, res, pkg) {
1517
if (err) t.fail(err);
16-
t.equal(res, path.join(dir, 'baz/doom.js'));
17-
t.equal(pkg.main, 'doom');
18+
19+
t.equal(res, path.join(dir, 'baz/doom.js'), 'changing the package "main" works');
20+
21+
var packageData = packageFilterArgs[0];
22+
t.equal(pkg, packageData, 'first packageFilter argument is "pkg"');
23+
t.equal(packageData.main, 'doom', 'package "main" was altered');
24+
25+
var packageFile = packageFilterArgs[1];
26+
t.equal(
27+
packageFile,
28+
path.join(dir, 'baz/package.json'),
29+
'second packageFilter argument is "pkgfile"'
30+
);
31+
32+
t.end();
1833
});
1934
});

test/filter_sync.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@ var resolve = require('../');
44

55
test('filter', function (t) {
66
var dir = path.join(__dirname, 'resolver');
7+
var packageFilterArgs;
78
var res = resolve.sync('./baz', {
89
basedir: dir,
9-
packageFilter: function (pkg) {
10+
packageFilter: function (pkg, dir) {
1011
pkg.main = 'doom';
12+
packageFilterArgs = [pkg, dir];
1113
return pkg;
1214
}
1315
});
14-
t.equal(res, path.join(dir, 'baz/doom.js'));
16+
17+
t.equal(res, path.join(dir, 'baz/doom.js'), 'changing the package "main" works');
18+
19+
var packageData = packageFilterArgs[0];
20+
t.equal(packageData.main, 'doom', 'package "main" was altered');
21+
22+
var packageFile = packageFilterArgs[1];
23+
t.equal(packageFile, path.join(dir, 'baz'), 'second packageFilter argument is "dir"');
24+
1525
t.end();
1626
});

0 commit comments

Comments
 (0)