Skip to content

Commit 64c426a

Browse files
committedJul 7, 2023
Merge branch 'develop' of https://github.com/Vindeep07/nodemon into Vindeep07-develop
* 'develop' of https://github.com/Vindeep07/nodemon: Added fix for giving preference to package.main for script
2 parents c13dbbb + 729ca73 commit 64c426a

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed
 

‎lib/config/load.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ var existsSync = fs.existsSync || path.existsSync;
1616
function findAppScript() {
1717
// nodemon has been run alone, so try to read the package file
1818
// or try to read the index.js file
19-
if (existsSync('./index.js')) {
19+
20+
var pkg = existsSync(path.join(process.cwd(), 'package.json')) && require(path.join(process.cwd(), 'package.json'));
21+
if ((!pkg || pkg.main == undefined) && existsSync('./index.js')) {
2022
return 'index.js';
2123
}
2224
}

‎test/config/load.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -320,5 +320,17 @@ describe('config load', function () {
320320
})
321321
});
322322

323+
it('should give package.main preference for script over index.js', function (done) {
324+
var dir = path.resolve(pwd, 'test/fixtures/packages/main-and-index');
325+
process.chdir(dir);
326+
327+
var config = {},
328+
settings = {},
329+
options = {};
323330

331+
load(settings, options, config, function (config) {
332+
assert.deepEqual(config.execOptions.script, 'server.js');
333+
done();
334+
});
335+
});
324336
});

‎test/fixtures/packages/main-and-index/index.js

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"main": "server.js"
3+
}

‎test/fixtures/packages/main-and-index/server.js

Whitespace-only changes.

0 commit comments

Comments
 (0)
Please sign in to comment.