Arguments aren't passed to executable in the same order #54

Closed
Hubro opened this Issue Jan 15, 2012 · 7 comments

3 participants

@Hubro

I'm trying to pass the arguments --nodejs --debug to coffee-script through nodemon. This is what I write:

nodemon --nodejs --debug -w src -x coffee src/server.coffee

It should work, but unfortunately nodemon is passing the arguments to coffee in the wrong order, giving me this error:

$ nodemon --nodejs --debug -w src -x coffee src/server.coffee
15 Jan 03:47:10 - [nodemon] v0.6.5
15 Jan 03:47:10 - [nodemon] watching: /root/projects/honstreams/server/src
15 Jan 03:47:10 - [nodemon] running --debug
15 Jan 03:47:10 - [nodemon] starting `coffee --debug --nodejs src/server.coffee`

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick

^

Error: unrecognized option: --debug
...

Coffee-script doesn't recognize the option --debug. The option --nodejs should come first, so coffee script knows to send the following arguments to node.

@Hubro

I forked the project to try to fix this myself, but it doesn't seem to be possible to pass ordered arguments to child_process.spawn

@loganfsmyth

I don't think the spawn function is the issue.

I think the only issue is that the arguments are sliced, but then they are shifted and unshifted onto different arrays. Any arguments in 'nodemonargs' that get unshifted into 'appargs' will have their order reversed.

See arg parsing here: https://github.com/remy/nodemon/blob/master/nodemon.js#L229

@Hubro

Well that's just silly of me, forgetting the arrays have a set order. I've fixed the problem and have issued a pull request

@remy
Owner
@Hubro

I saw that in the source and tried it, but it doesn't work.

$ nodemon --debug src/server.coffee
15 Jan 10:16:40 - [nodemon] v0.6.5
15 Jan 10:16:40 - [nodemon] watching: /root/foo/bar/server
15 Jan 10:16:40 - [nodemon] running --debug
15 Jan 10:16:40 - [nodemon] starting `node --debug src/server.coffee`
debugger listening on port 5858

/root/foo/bar/server/src/server.coffee:2

# Dependencies

^

node.js:201

        throw e; // process.nextTick error, or 'error' event on first tick
^

SyntaxError: Unexpected token ILLEGAL
    at Module._compile (module.js:427:25)
    at Object..js (module.js:450:10)
    at Module.load (module.js:351:31)
    at Function._load (module.js:310:12)
    at Array.0 (module.js:470:10)
    at EventEmitter._tickCallback (node.js:192:40)

15 Jan 10:16:40 - [nodemon] app crashed - waiting for file changes before starting...
^C15 Jan 10:16:42 - [nodemon] exiting

So it's not using the coffee executable. Specifying the executable works no better

$ nodemon --debug -x coffee src/server.coffee
15 Jan 10:20:08 - [nodemon] v0.6.5
15 Jan 10:20:08 - [nodemon] watching: /root/foo/bar/server
15 Jan 10:20:08 - [nodemon] running --debug
15 Jan 10:20:08 - [nodemon] starting `coffee --debug src/server.coffee`

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: unrecognized option: --debug
    at OptionParser.parse (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/optparse.js:40:17)
    at /usr/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:404:29
    at Object.run (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:46:5)
    at Object. (/usr/local/lib/node_modules/coffee-script/bin/coffee:7:41)
    at Module._compile (module.js:432:26)
    at Object..js (module.js:450:10)
    at Module.load (module.js:351:31)
    at Function._load (module.js:310:12)
    at Array.0 (module.js:470:10)
    at EventEmitter._tickCallback (node.js:192:40)

15 Jan 10:20:08 - [nodemon] app crashed - waiting for file changes before starting...
^C15 Jan 10:20:09 - [nodemon] exiting

No extra stuff being inserted here to help coffee-script debug.

@loganfsmyth

@remy The automatic --nodejs logic is there, but it's not quite working.

Here: https://github.com/remy/nodemon/blob/master/nodemon.js#L277

program.app is already set in getNodemonArgs, why does it need to be set again? This line break it because args in this case contains --debug first, so program.app ends up as --debug and the extension logic doesn't kick in.

Either way though, it is still a good idea to preserve argument ordering. What if someone had a custom exec that had space separated args like nodemon's -w args? They'd have to pass them in backwards.

Pull request is over here: #55

@remy
Owner

I've got a fix working - both to support:

nodemon --debug app.coffee

And

nodemon -x coffee --nodejs --debug app.coffee

I'm just running through some tests to make sure the change is good.

@remy remy added a commit that closed this issue Jan 15, 2012
@remy fixed param parsing and now reading correctly exec args - ideally quo…
…te the args, but order now counts (again!). Fixes #54
e299e56
@remy remy closed this in e299e56 Jan 15, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment