Skip to content

Commit 3933dae

Browse files
Merge pull request #97 from browserify/resolve-twelve
2 parents 10d0909 + 03d3067 commit 3933dae

File tree

3 files changed

+11
-32
lines changed

3 files changed

+11
-32
lines changed

index.js

+1-19
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ function build_resolve_opts(opts, base) {
206206
return opts;
207207
}
208208

209-
function resolve(id, opts, callback) {
209+
function resolve(id, opts, cb) {
210210

211211
// opts.filename
212212
// opts.paths
@@ -216,24 +216,6 @@ function resolve(id, opts, callback) {
216216
opts = opts || {};
217217
opts.filename = opts.filename || '';
218218

219-
var cb = function(err, path, pkg) {
220-
fs.stat(path, function(notPath) {
221-
if (notPath) {
222-
callback(err, path, pkg);
223-
}
224-
else {
225-
fs.realpath(path, function(notReal, real) {
226-
if (notReal) {
227-
callback(err, path, pkg);
228-
}
229-
else {
230-
callback(err, real, pkg);
231-
}
232-
});
233-
}
234-
});
235-
}
236-
237219
var base = path.dirname(opts.filename);
238220

239221
if (opts.basedir) {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"author": "Roman Shtylman <[email protected]>",
2222
"license": "MIT",
2323
"dependencies": {
24-
"resolve": "1.1.7"
24+
"resolve": "^1.17.0"
2525
},
2626
"devDependencies": {
2727
"mocha": "^2.5.3"

test/modules.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test('index.js of module dir', function(done) {
88
resolve('module-a', { paths: [ fixtures_dir ], package: { main: 'fixtures' } }, function(err, path, pkg) {
99
assert.ifError(err);
1010
assert.equal(path, require.resolve('./fixtures/node_modules/module-a/index'));
11-
assert.strictEqual(pkg, undefined);
11+
assert.strictEqual(pkg.main, 'fixtures');
1212
done();
1313
});
1414
});
@@ -70,7 +70,7 @@ test('string alt browser field as main - require subfile', function(done) {
7070
// one of the keys replaces the main file
7171
// this would be done if the user needed to replace main and some other module
7272
test('object browser field as main', function(done) {
73-
resolve('module-d', { paths: [ fixtures_dir ], package: { main: 'fixtures' } }, function(err, path, pkg) {
73+
resolve('module-d', { paths: [ fixtures_dir ] }, function(err, path, pkg) {
7474
assert.ifError(err);
7575
assert.equal(path, require.resolve('./fixtures/node_modules/module-d/browser'));
7676
assert.equal(pkg.main, './browser.js');
@@ -82,7 +82,7 @@ test('object browser field as main', function(done) {
8282
// one of the keys replaces the main file
8383
// however the main has no prefix and browser uses ./ prefix for the same file
8484
test('object browser field as main', function(done) {
85-
resolve('module-k', { paths: [ fixtures_dir ], package: { main: 'fixtures' } }, function(err, path, pkg) {
85+
resolve('module-k', { paths: [ fixtures_dir ] }, function(err, path, pkg) {
8686
assert.ifError(err);
8787
assert.equal(path, require.resolve('./fixtures/node_modules/module-k/browser'));
8888
assert.equal(pkg.main, './browser.js');
@@ -91,7 +91,7 @@ test('object browser field as main', function(done) {
9191
});
9292

9393
test('deep module reference mapping', function(done) {
94-
resolve('module-l/direct', { basedir: __dirname + '/fixtures', package: { main: 'fixtures' } }, function(err, path, pkg) {
94+
resolve('module-l/direct', { basedir: __dirname + '/fixtures' }, function(err, path, pkg) {
9595
assert.ifError(err);
9696
assert.equal(path, require.resolve('./fixtures/node_modules/module-l/browser-direct'));
9797
assert.equal(pkg.main, './browser.js');
@@ -102,14 +102,14 @@ test('deep module reference mapping', function(done) {
102102
// package.json has browser field as object
103103
// test that file resolves even though the file extension is omitted
104104
test('deep module reference mapping without file extension - .js', function(done) {
105-
resolve('module-n/foo', { basedir: __dirname + '/fixtures', package: { main: 'fixtures' } }, function(err, path, pkg) {
105+
resolve('module-n/foo', { basedir: __dirname + '/fixtures' }, function(err, path, pkg) {
106106
assert.ifError(err);
107107
assert.equal(path, require.resolve('./fixtures/node_modules/module-n/browser-foo'));
108108
done();
109109
});
110110
});
111111
test('deep module reference mapping without file extension - .json', function(done) {
112-
resolve('module-n/bar', { basedir: __dirname + '/fixtures', package: { main: 'fixtures' } }, function(err, path, pkg) {
112+
resolve('module-n/bar', { basedir: __dirname + '/fixtures' }, function(err, path, pkg) {
113113
assert.ifError(err);
114114
assert.equal(path, require.resolve('./fixtures/node_modules/module-n/browser-bar'));
115115
done();
@@ -285,7 +285,6 @@ test('alt-browser field', function(done) {
285285
test('alt-browser deep module reference mapping', function(done) {
286286
resolve('alt-browser-field/direct', {
287287
basedir: __dirname + '/fixtures',
288-
package: { main: 'fixtures' },
289288
browser: 'chromeapp'
290289
}, function(err, path, pkg) {
291290
assert.ifError(err);
@@ -312,10 +311,9 @@ test('alt-browser fallback to "browser" on deps of deps', function(done) {
312311
});
313312

314313
test('not fail on accessing path name defined in Object.prototype', function (done) {
315-
resolve('toString', { paths: [ fixtures_dir ], package: { main: 'fixtures' } }, function(err, path, pkg) {
314+
resolve('toString', { paths: [ fixtures_dir ] }, function(err, path, pkg) {
316315
assert.ifError(err);
317316
assert.equal(path, require.resolve('./fixtures/node_modules/toString/index'));
318-
assert.strictEqual(pkg, undefined);
319317
done();
320318
});
321319
});
@@ -334,10 +332,9 @@ test('respect symlinks', function (done) {
334332
// - node_modules
335333
// - symlink to x
336334
//
337-
resolve('linked', { paths: [ fixtures_dir + '/linker/node_modules' ], package: { main: 'fixtures' } }, function(err, path, pkg) {
335+
resolve('linked', { paths: [ fixtures_dir + '/linker/node_modules' ], preserveSymlinks: false }, function(err, path, pkg) {
338336
assert.ifError(err);
339337
assert.equal(path, require.resolve('./fixtures/linked/index'));
340-
assert.strictEqual(pkg, undefined);
341338
done();
342339
});
343-
});
340+
});

0 commit comments

Comments
 (0)