diff --git a/lib/read-json.js b/lib/read-json.js index c55eca3..e47a1bb 100644 --- a/lib/read-json.js +++ b/lib/read-json.js @@ -218,15 +218,12 @@ function gypfile (file, data, cb) { return cb(null, data) } - glob('*.gyp', { cwd: dir }, function (er, files) { - if (er) { - return cb(er) - } - if (data.gypfile === false) { - return cb(null, data) - } - gypfile_(file, data, files, cb) - }) + if (data.gypfile === false) { + return cb(null, data) + } + glob('*.gyp', { cwd: dir }) + .then(files => gypfile_(file, data, files, cb)) + .catch(er => cb(er)) } function gypfile_ (file, data, files, cb) { @@ -246,22 +243,13 @@ function serverjs (file, data, cb) { if (s.start) { return cb(null, data) } - glob('server.js', { cwd: dir }, function (er, files) { - if (er) { - return cb(er) + fs.access(path.join(dir, 'server.js'), (err) => { + if (!err) { + s.start = 'node server.js' + data.scripts = s } - serverjs_(file, data, files, cb) - }) -} - -function serverjs_ (file, data, files, cb) { - if (!files.length) { return cb(null, data) - } - var s = data.scripts || {} - s.start = 'node server.js' - data.scripts = s - return cb(null, data) + }) } function authors (file, data, cb) { @@ -294,21 +282,20 @@ function readme (file, data, cb) { } var dir = path.dirname(file) var globOpts = { cwd: dir, nocase: true, mark: true } - glob('{README,README.*}', globOpts, function (er, files) { - if (er) { - return cb(er) - } - // don't accept directories. - files = files.filter(function (filtered) { - return !filtered.match(/\/$/) + glob('{README,README.*}', globOpts) + .then(files => { + // don't accept directories. + files = files.filter(function (filtered) { + return !filtered.match(/\/$/) + }) + if (!files.length) { + return cb() + } + var fn = preferMarkdownReadme(files) + var rm = path.resolve(dir, fn) + return readme_(file, data, rm, cb) }) - if (!files.length) { - return cb() - } - var fn = preferMarkdownReadme(files) - var rm = path.resolve(dir, fn) - readme_(file, data, rm, cb) - }) + .catch(er => cb(er)) } function preferMarkdownReadme (files) { @@ -346,15 +333,14 @@ function mans (file, data, cb) { } const dirname = path.dirname(file) cwd = path.resolve(path.dirname(file), cwd) - glob('**/*.[0-9]', { cwd }, function (er, mansGlob) { - if (er) { - return cb(er) - } - data.man = mansGlob.map(man => - path.relative(dirname, path.join(cwd, man)).split(path.sep).join('/') - ) - return cb(null, data) - }) + glob('**/*.[0-9]', { cwd }) + .then(mansGlob => { + data.man = mansGlob.map(man => + path.relative(dirname, path.join(cwd, man)).split(path.sep).join('/') + ) + return cb(null, data) + }) + .catch(er => cb(er)) } function bins (file, data, cb) { @@ -366,12 +352,9 @@ function bins (file, data, cb) { } m = path.resolve(path.dirname(file), m) - glob('**', { cwd: m }, function (er, binsGlob) { - if (er) { - return cb(er) - } - bins_(file, data, binsGlob, cb) - }) + glob('**', { cwd: m }) + .then(binsGlob => bins_(file, data, binsGlob, cb)) + .catch(er => cb(er)) } function bins_ (file, data, binsGlob, cb) { diff --git a/package.json b/package.json index 5edb104..d6a07f7 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "template-oss-apply": "template-oss-apply --force" }, "dependencies": { - "glob": "^8.0.1", + "glob": "^9.3.0", "json-parse-even-better-errors": "^3.0.0", "normalize-package-data": "^5.0.0", "npm-normalize-package-bin": "^3.0.0" @@ -43,9 +43,9 @@ }, "tap": { "branches": 68, - "functions": 83, - "lines": 76, - "statements": 77, + "functions": 74, + "lines": 74, + "statements": 74, "nyc-arg": [ "--exclude", "tap-snapshots/**" diff --git a/test/fixtures/serverjs/package.json b/test/fixtures/serverjs/package.json new file mode 100644 index 0000000..c9d9f19 --- /dev/null +++ b/test/fixtures/serverjs/package.json @@ -0,0 +1,2 @@ +{"name":"serverjs", "version":"99.999.999999999"} + diff --git a/test/fixtures/serverjs/server.js b/test/fixtures/serverjs/server.js new file mode 100644 index 0000000..3e0ae07 --- /dev/null +++ b/test/fixtures/serverjs/server.js @@ -0,0 +1,9 @@ +/**package + * { + * "name": "indexjs-test", + * "version": "1.2.3", + * "description": "Did you know npm could do this, even?", + * "main": "index.js" + * } + **/ +console.log('just a simple single-file package') diff --git a/test/serverjs.js b/test/serverjs.js new file mode 100644 index 0000000..2f76cdd --- /dev/null +++ b/test/serverjs.js @@ -0,0 +1,17 @@ +const t = require('tap') +const read = require('../') +const { resolve } = require('path') +t.test('server.js file present', t => { + const fixture = resolve(__dirname, 'fixtures/serverjs/package.json') + read(fixture, (er, data) => { + if (er) { + throw er + } + t.match(data, { + scripts: { + start: 'node server.js', + }, + }) + t.end() + }) +})