Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Vindeep07/nodemon into V…
Browse files Browse the repository at this point in the history
…indeep07-develop

* 'develop' of https://github.com/Vindeep07/nodemon:
  Added fix for giving preference to package.main for script
  • Loading branch information
remy committed Jul 7, 2023
2 parents c13dbbb + 729ca73 commit 64c426a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/config/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ var existsSync = fs.existsSync || path.existsSync;
function findAppScript() {
// nodemon has been run alone, so try to read the package file
// or try to read the index.js file
if (existsSync('./index.js')) {

var pkg = existsSync(path.join(process.cwd(), 'package.json')) && require(path.join(process.cwd(), 'package.json'));
if ((!pkg || pkg.main == undefined) && existsSync('./index.js')) {
return 'index.js';
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/config/load.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,5 +320,17 @@ describe('config load', function () {
})
});

it('should give package.main preference for script over index.js', function (done) {
var dir = path.resolve(pwd, 'test/fixtures/packages/main-and-index');
process.chdir(dir);

var config = {},
settings = {},
options = {};

load(settings, options, config, function (config) {
assert.deepEqual(config.execOptions.script, 'server.js');
done();
});
});
});
Empty file.
3 changes: 3 additions & 0 deletions test/fixtures/packages/main-and-index/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"main": "server.js"
}
Empty file.

0 comments on commit 64c426a

Please sign in to comment.