From cb26bd290a2215cba7d1d1a3d8e3a42de6129cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Wed, 27 Jun 2018 13:44:44 +0200 Subject: [PATCH 1/3] Update resolve to 1.17 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 97a310c..540d324 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "author": "Roman Shtylman ", "license": "MIT", "dependencies": { - "resolve": "1.1.7" + "resolve": "^1.17.0" }, "devDependencies": { "mocha": "^2.5.3" From ed75d008ae9522e246e34e96f6c596df2144d05f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Thu, 18 Jun 2020 21:28:11 +0200 Subject: [PATCH 2/3] Fix tests Removes `package: { main: 'fixtures' }` from test cases where it was copy-pasted from earlier tests. Updates expected results since the bugfix in `resolve`. --- test/modules.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/test/modules.js b/test/modules.js index 488b6e3..a1ced3c 100644 --- a/test/modules.js +++ b/test/modules.js @@ -8,7 +8,7 @@ test('index.js of module dir', function(done) { resolve('module-a', { paths: [ fixtures_dir ], package: { main: 'fixtures' } }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-a/index')); - assert.strictEqual(pkg, undefined); + assert.strictEqual(pkg.main, 'fixtures'); done(); }); }); @@ -70,7 +70,7 @@ test('string alt browser field as main - require subfile', function(done) { // one of the keys replaces the main file // this would be done if the user needed to replace main and some other module test('object browser field as main', function(done) { - resolve('module-d', { paths: [ fixtures_dir ], package: { main: 'fixtures' } }, function(err, path, pkg) { + resolve('module-d', { paths: [ fixtures_dir ] }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-d/browser')); assert.equal(pkg.main, './browser.js'); @@ -82,7 +82,7 @@ test('object browser field as main', function(done) { // one of the keys replaces the main file // however the main has no prefix and browser uses ./ prefix for the same file test('object browser field as main', function(done) { - resolve('module-k', { paths: [ fixtures_dir ], package: { main: 'fixtures' } }, function(err, path, pkg) { + resolve('module-k', { paths: [ fixtures_dir ] }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-k/browser')); assert.equal(pkg.main, './browser.js'); @@ -91,7 +91,7 @@ test('object browser field as main', function(done) { }); test('deep module reference mapping', function(done) { - resolve('module-l/direct', { basedir: __dirname + '/fixtures', package: { main: 'fixtures' } }, function(err, path, pkg) { + resolve('module-l/direct', { basedir: __dirname + '/fixtures' }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-l/browser-direct')); assert.equal(pkg.main, './browser.js'); @@ -102,14 +102,14 @@ test('deep module reference mapping', function(done) { // package.json has browser field as object // test that file resolves even though the file extension is omitted test('deep module reference mapping without file extension - .js', function(done) { - resolve('module-n/foo', { basedir: __dirname + '/fixtures', package: { main: 'fixtures' } }, function(err, path, pkg) { + resolve('module-n/foo', { basedir: __dirname + '/fixtures' }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-n/browser-foo')); done(); }); }); test('deep module reference mapping without file extension - .json', function(done) { - resolve('module-n/bar', { basedir: __dirname + '/fixtures', package: { main: 'fixtures' } }, function(err, path, pkg) { + resolve('module-n/bar', { basedir: __dirname + '/fixtures' }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-n/browser-bar')); done(); @@ -285,7 +285,6 @@ test('alt-browser field', function(done) { test('alt-browser deep module reference mapping', function(done) { resolve('alt-browser-field/direct', { basedir: __dirname + '/fixtures', - package: { main: 'fixtures' }, browser: 'chromeapp' }, function(err, path, pkg) { assert.ifError(err); @@ -312,10 +311,9 @@ test('alt-browser fallback to "browser" on deps of deps', function(done) { }); test('not fail on accessing path name defined in Object.prototype', function (done) { - resolve('toString', { paths: [ fixtures_dir ], package: { main: 'fixtures' } }, function(err, path, pkg) { + resolve('toString', { paths: [ fixtures_dir ] }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/toString/index')); - assert.strictEqual(pkg, undefined); done(); }); }); @@ -334,10 +332,9 @@ test('respect symlinks', function (done) { // - node_modules // - symlink to x // - resolve('linked', { paths: [ fixtures_dir + '/linker/node_modules' ], package: { main: 'fixtures' } }, function(err, path, pkg) { + resolve('linked', { paths: [ fixtures_dir + '/linker/node_modules' ] }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/linked/index')); - assert.strictEqual(pkg, undefined); done(); }); -}); \ No newline at end of file +}); From 03d3067a394596b1ca6d1f5c7202516346b03d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Thu, 18 Jun 2020 21:46:27 +0200 Subject: [PATCH 3/3] Revert #92, use resolve's `preserveSymlinks` option --- index.js | 20 +------------------- test/modules.js | 2 +- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index 53334b2..8a1908a 100644 --- a/index.js +++ b/index.js @@ -206,7 +206,7 @@ function build_resolve_opts(opts, base) { return opts; } -function resolve(id, opts, callback) { +function resolve(id, opts, cb) { // opts.filename // opts.paths @@ -216,24 +216,6 @@ function resolve(id, opts, callback) { opts = opts || {}; opts.filename = opts.filename || ''; - var cb = function(err, path, pkg) { - fs.stat(path, function(notPath) { - if (notPath) { - callback(err, path, pkg); - } - else { - fs.realpath(path, function(notReal, real) { - if (notReal) { - callback(err, path, pkg); - } - else { - callback(err, real, pkg); - } - }); - } - }); - } - var base = path.dirname(opts.filename); if (opts.basedir) { diff --git a/test/modules.js b/test/modules.js index a1ced3c..ddf26d2 100644 --- a/test/modules.js +++ b/test/modules.js @@ -332,7 +332,7 @@ test('respect symlinks', function (done) { // - node_modules // - symlink to x // - resolve('linked', { paths: [ fixtures_dir + '/linker/node_modules' ] }, function(err, path, pkg) { + resolve('linked', { paths: [ fixtures_dir + '/linker/node_modules' ], preserveSymlinks: false }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/linked/index')); done();