jenius/roots — pull request #482 by declandewet (2014-06-01 02:05:19+00:00)
Title: Begin work on fixing windows issues

This pull request is a start at an attempt to fix the "`Cannot find module './new'`" error in V3. The error was being caused by a malformed path being passed to `require`, due to there being a `path.sep` instance in the passed argument. `require` supposedly handles these cross platform inconsistencies itself, and I can confirm from months of experience that a simple forward slash (`/`) in `require` calls is a sufficient path separator on Windows.

This change gets rid of the error, and executes code. Unfortunately, the `new` command now throws an error with a very unhelpful stacktrace:

```bash
$ roots new test
✘ TypeError: undefined is not a function
Potentially unhandled rejection TypeError: undefined is not a function
at PromptUI.onEachPrompt (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\sprout\node_modules\inquirer\lib\ui\prompt.js:82:16)
at c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\sprout\node_modules\inquirer\node_modules\async\lib\async.js:227:13
at iterate (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\sprout\node_modules\inquirer\node_modules\async\lib\async.js:134:13)
at async.eachSeries (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\sprout\node_modules\inquirer\node_modules\async\lib\async.js:150:9)
at _asyncMap (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\sprout\node_modules\inquirer\node_modules\async\lib\async.js:226:9)
at Object.mapSeries (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\sprout\node_modules\inquirer\node_modules\async\lib\async.js:216:23)
at new PromptUI (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\sprout\node_modules\inquirer\lib\ui\prompt.js:38:9)
at Object.inquirer.prompt (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\sprout\node_modules\inquirer\lib\inquirer.js:39:10)
at c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\when\callbacks.js:70:18
at tryCatchReject (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\when\lib\makePromise.js:790:14)
at FulfilledHandler.when (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\when\lib\makePromise.js:621:9)
at ContinuationTask.run (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\when\lib\makePromise.js:741:24)
at Scheduler._drain (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\when\lib\scheduler.js:56:14)
at Scheduler.drain (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\when\lib\scheduler.js:21:9)
at process._tickCallback (node.js:415:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:902:3
```

The second change enables `when/monitor/console`, which makes unhandled rejection errors a little bit more informative to the user:

```bash
$ roots new test
✘ TypeError: undefined is not a function
[promises] Unhandled rejections: 1
TypeError: undefined is not a function
at PromptUI.onEachPrompt (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\sprout\node_modules\inquirer\lib\ui\prompt.js:82:16)
at c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\sprout\node_modules\inquirer\node_modules\async\lib\async.js:227:13
at iterate (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\sprout\node_modules\inquirer\node_modules\async\lib\async.js:134:13)
at async.eachSeries (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\sprout\node_modules\inquirer\node_modules\async\lib\async.js:150:9)
at _asyncMap (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\sprout\node_modules\inquirer\node_modules\async\lib\async.js:226:9)
at Object.mapSeries (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\sprout\node_modules\inquirer\node_modules\async\lib\async.js:216:23)
at new PromptUI (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\sprout\node_modules\inquirer\lib\ui\prompt.js:38:9)
at Object.inquirer.prompt (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\sprout\node_modules\inquirer\lib\inquirer.js:39:10)
at c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\when\callbacks.js:70:18
from execution context:
at _apply (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\when\callbacks.js:66:18)
at Object.call (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\when\callbacks.js:97:10)
at Init.prompt_user_for_answers (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\node_modules\sprout\lib\api\init.js:129:21)
from execution context:
at module.exports (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\lib\cli\new.js:23:16)
from execution context:
at module.exports (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\lib\cli\new.js:19:8)
from execution context:
at module.exports (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\lib\cli\new.js:17:31)
from execution context:
at New.exec (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\lib\api\new.js:58:13)
at Function.Roots.new (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\lib\index.js:64:30)
at module.exports (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\lib\cli\new.js:17:24)
at CLI.run (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\lib\cli\index.js:74:13)
at Object. (c:\Users\decla_000\AppData\Roaming\npm\node_modules\roots\bin\roots:21:5)
```

I've tried debugging/inspecting the lines/files specified in the stack trace, trying to find which `undefined` is not a `function`, but all of the referred lines all `console.log` as `[function]` (and also `typeof` `'function'`, for consistency). I've also tried to see if any of the method calls in those areas are losing context, but that does not seem to be the case (unless I'm missing something obvious). I think the error may be coming from `sprout`.

I might need help on this one, it's not as easy as I thought it would be.

Also, it's worth mentioning that when this error throws, the process does not exit - I know why it does this (`cli.emit('err'...)` instead of `cli.emit('err_exit'...)`) - is this by design? 'coz it seems like exiting the process makes a lot more sense here