Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: package.main with -- arguments #1773

Merged
merged 3 commits into from
Oct 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/config/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ function load(settings, options, config, callback) {
}
// if the script is found as a result of not being on the command
// line, then we move any of the pre double-dash args in execArgs
const n = options.scriptPosition || options.args.length;
const n = options.scriptPosition === null ?
options.args.length : options.scriptPosition;

options.execArgs = (options.execArgs || [])
.concat(options.args.splice(0, n));
options.scriptPosition = null;
Expand Down
2 changes: 2 additions & 0 deletions lib/monitor/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ function run(options) {
utils.version.major > 4 // only fork if node version > 4

if (shouldFork) {
// this assumes the first argument is the script and slices it out, since
// we're forking
var forkArgs = cmd.args.slice(1);
var env = utils.merge(options.execOptions.env, process.env);
stdio.push('ipc');
Expand Down
2 changes: 1 addition & 1 deletion lib/monitor/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function filterAndRestart(files) {

// if there's no matches, then test to see if the changed file is the
// running script, if so, let's allow a restart
if (config.options.execOptions.script) {
if (config.options.execOptions && config.options.execOptions.script) {
const script = path.resolve(config.options.execOptions.script);
if (matched.result.length === 0 && script) {
const length = script.length;
Expand Down
23 changes: 23 additions & 0 deletions test/config/load.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,27 @@ describe('config load', function () {
done();
})
});

it('should support pkg.main and keep user args on args', done => {
process.chdir(path.resolve(pwd, 'test/fixtures/packages/main-and-start'));
const settings = { scriptPosition: 0, script: null, args: [ 'first', 'second' ] };
const options = { ignore: [], watch: [], monitor: [] };
const config = {
run: false,
system: { cwd: '/Users/remy/dev/nodemon/issues/1758' },
required: false,
dirs: [],
timeout: 1000,
options: { ignore: [], watch: [], monitor: [] },
lastStarted: 0,
loaded: []
}

load(settings, options, config, res => {
assert.deepEqual(res.execOptions.args, ['first', 'second']);
done();
})
});


});
Empty file.
6 changes: 6 additions & 0 deletions test/fixtures/packages/main-and-start/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"main": "./index.js",
"scripts": {
"start": "node index.js"
}
}