cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rob Paveza (JIRA)" <>
Subject [jira] [Commented] (CB-8763) Unable to use console logging with hooks when using exports
Date Wed, 06 May 2015 21:10:00 GMT


Rob Paveza commented on CB-8763:

I've spent some time trying to get this issue to reproduce and I can't.  However, what I have
observed is that if you drop .js files into a named hooks directory, the .js file executes
incorrectly with the child_process.spawn function.

If you dig up a little bit earlier in HooksRunner, you see that if there isn't an explicit
choice to use the module loader or not, we choose to do so if the file ends in .js:

That all having been said, here's what I did to investigate:
 - Created a new Cordova project with Windows and Android
 - Added hooks/before_compile_custom_action.js and set it to output something via console.log,
both synchronously (log then throw) and asynchronously (returning a Q promise)
 - Added that to config.xml
  - That ran fine, both output my console message before "ERROR building one of the platforms:..."
 - Added hooks/before_compile_custom_action.bat and set it to output something via echo and
 - Replaced previous config.xml thing with the .bat file
  - That ran fine, it printed my message before "Hook failed with exit code 1"

The specific error I see is if I add hooks/before_build/test.js which is identical to the
previous .js file (and take the <hook /> element out of config.xml), I get the following
output instead:

C:\Users\me\test>cordova build windows
Running command: C:\Users\me\test\hooks\before_build\test.js C:\Users\me\test
Error: spawn UNKNOWN

This seems instead to point that, when .js files are discovered via just the directory structure,
they don't get loaded via the module loader.  So keying off of that question, I looked for
where that might get populated, and found this comment:

So there ya go.  If you want to use module-syntax, you need to load the script via a <hook>

> Unable to use console logging with hooks when using exports
> -----------------------------------------------------------
>                 Key: CB-8763
>                 URL:
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: CLI
>            Reporter: Raymond Camden
>            Assignee: Rob Paveza
>            Priority: Minor
> I was testing Holly's after_platform_add hook and decided to rewrite it inside a module.exports
format. This is what the hook's guide recommends. When I did that, I noticed that
my console.log messages stopped working. I posted this on the dev group and Shazron noted:
> "It's using child_process.spawn (if you dig down) and is probably
> ignoring all stdio when running the script.
> actually it has stdio:inherit, and does capture the output and pushes
> it back up the chain, so somewhere up the chain no one does anything
> with it"
> Apparently there is no workaround for this currently.

This message was sent by Atlassian JIRA

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message