diff --git a/lib/read-json.js b/lib/read-json.js index aaf24e9..d35f09e 100644 --- a/lib/read-json.js +++ b/lib/read-json.js @@ -352,7 +352,7 @@ function bins (file, data, cb) { return cb(null, data) } - m = path.resolve(path.dirname(file), m) + m = path.resolve(path.dirname(file), path.join('.', path.join('/', m))) glob('**', { cwd: m }) .then(binsGlob => bins_(file, data, binsGlob, cb)) .catch(er => cb(er)) diff --git a/test/bin.js b/test/bin.js index c399310..738253c 100644 --- a/test/bin.js +++ b/test/bin.js @@ -41,3 +41,25 @@ tap.test('Empty bin test', function (t) { t.end() }) }) + +tap.test('Bin dir test', function (t) { + var p = path.resolve(__dirname, 'fixtures/bindir.json') + var warn = createWarningCollector() + readJson(p, warn, function (er, data) { + t.equal(warn.warnings.length, 0) + t.equal(data.name, 'bindir-test') + t.strictSame(data.bin, { echo: 'bin/echo' }) + t.end() + }) +}) + +tap.test('Bin dir trim prefix test', function (t) { + var p = path.resolve(__dirname, 'fixtures/bindiroutofscope.json') + var warn = createWarningCollector() + readJson(p, warn, function (er, data) { + t.equal(warn.warnings.length, 0) + t.equal(data.name, 'bindiroutofscope-test') + t.strictSame(data.bin, { echo: 'bin/echo' }) + t.end() + }) +}) diff --git a/test/fixtures/bindir.json b/test/fixtures/bindir.json new file mode 100644 index 0000000..c4d0dbc --- /dev/null +++ b/test/fixtures/bindir.json @@ -0,0 +1,14 @@ +{ + "name": "bindir-test", + "description": "my desc", + "repository": { + "type": "git", + "url": "git://github.com/npm/read-package-json.git" + }, + "version": "0.0.1", + "readme": "hello world", + "directories": { + "bin": "./bin" + }, + "license": "ISC" +} diff --git a/test/fixtures/bindiroutofscope.json b/test/fixtures/bindiroutofscope.json new file mode 100644 index 0000000..5c7b033 --- /dev/null +++ b/test/fixtures/bindiroutofscope.json @@ -0,0 +1,14 @@ +{ + "name": "bindiroutofscope-test", + "description": "my desc", + "repository": { + "type": "git", + "url": "git://github.com/npm/read-package-json.git" + }, + "version": "0.0.1", + "readme": "hello world", + "directories": { + "bin": "../../../../../bin" + }, + "license": "ISC" +}