-
Notifications
You must be signed in to change notification settings - Fork 0
How to debug Yeoman generators
ℹ️ This how-to article is for engineers who need to debug the
generator-android-lib
on their Mac workstations.
- 1. Install
node-inspector
. -
2. Find the path to Yeoman's
cli.js
. - 3. Starting inspection/debugging
- 4. Start debugging!
1. Install node-inspector
.
Open a Terminal and run:
$ npm i -g node-inspector
If you're using
nvm
, then you know that you might have Yeoman installed in multiple locations by Node.js version. Therefore it's important to keep aware of the Node.js version you're debugging on.
$ which yo
This should output something like
/Users/<user>/.nvm/versions/node/<node-version>/bin/yo
E.g.,
/Users/swindle/.nvm/versions/node/v7.7.3/bin/yo
$ ls /Users/<user>/.nvm/versions/node/<node-version>/lib/node_modules/yo/lib
E.g.,
$ ls -go /Users/swindle/.nvm/versions/node/v7.7.3/lib/node_modules/yo/lib
You should see cli.js
in the output.
- Remember the path to Yeoman's
cli.js
.- We'll refer to Yeoman's
cli.js
path as$YO_CLI
.
$ YO_CLI=/<path>/<to>/yo/lib/cli.js
Run the following command, where android-lib
is the Yeoman generator you want to debug:
$ node --inspect $YO_CLI android-lib
This should output something like:
Debugger listening on port 9229.
Warning: This is an experimental feature and could change at any time.
To start debugging, open the following URL in Chrome:
chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:9229/575645d0-012a-43af-9421-ca6e5b6d10f1
_-----_ ╭──────────────────────────╮
| | │ Welcome to the Verizon │
|--(o)--| │ Android Library │
`---------´ │ generator! │
( _´U`_ ) ╰──────────────────────────╯
/___A___\ /
| ~ |
__'.___.'__
´ ` |° ´ Y `
? What are you calling your library? (jsdoc-2-md-testbed)
If you get an "Address already in use" error, here's how you can kill the existing process:
- Run
$ lsof -i @localhost:9229
- Get the
PID
from the output.- Kill the process:
$ kill -9 <PID>
Now you can retry
node --inspect $YO_CLI android-lib
.
Launch Chrome or open a new tab if it's already running.
In step 3.1., you should have seen output similar to this:
To start debugging, open the following URL in Chrome:
chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:9229/575645d0-012a-43af-9421-ca6e5b6d10f1
Copy the entire chrome-devtools:
string and paste it into a new Google Chrome tab.
3.2.3.1. Open the "Sources" view of chrome-devtools
[]
3.2.3.2. Enable "Pause on Uncaught Exceptions".
[]
Go back to your Terminal and walk through your generator. If exceptions are thrown, you'll see them in chrome-devtools
.