-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Codemods: add support for codemod debugging #19703
Conversation
Awesome! Looking forward to use this. :-) I tested this with Node.js 6.1.5 and Node 8.7.0 (because #19317). Works great on Node 6, just like you described. Also remains working without the debug param. On Node 8 this works fine too, I just get a deprecation warning: $ node --version
v8.7.0
$ npm run codemod -- --debugger single-tree-rendering ./client
> wp-calypso@0.17.0 codemod /####/wp-calypso
> node bin/codemods/run "--debugger" "single-tree-rendering" "./client"
Running single-tree-rendering on ./client
Debugger listening on ws://127.0.0.1:9229/cabe5ade-e762-4944-a41f-96de1cefbd5e
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
(node:19971) [DEP0062] DeprecationWarning: `node --inspect --debug-brk` is deprecated. Please use `node --inspect-brk` instead. |
As a sidenote, I looked into adding support for jscodeshift's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, and thanks for the documentation 😀
I left a few documentation suggestions mostly for simplicity and brevity. It's to you whether you want to make any of the changes.
bin/codemods/README.md
Outdated
If you are a codemod author, you may want to debug your codemod using the Chrome debugger. Then | ||
run the codemod script with a `--debugger` parameter: | ||
```bash | ||
./bin/codemods/run.js --debugger my-transform client/target.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for the docs we can omit this and just include a canonical npm run codemod …
. The savvy can figure out the direct invocation if they're interested.
bin/codemods/README.md
Outdated
``` | ||
This will run `jscodeshift` in a Node process that has command line arguments `--inspect` and | ||
`--debug-brk`. That means that a debugger will be attached to the Node process and will break on | ||
the first statement. That allows you to connect with Chrome and run the codemod script. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds like we may be changing the node args soon. How about leaving off the specifics:
This will run
jscodeshift
in a Node process with the appropriate flags for debugging. The process will break on the firstdebugger
statement, allowing inspection with Chrome.
bin/codemods/README.md
Outdated
the first statement. That allows you to connect with Chrome and run the codemod script. | ||
|
||
`jscodeshift` will also be run with a `--run-in-band` option, telling `jscodeshift` not to spawn | ||
worker processes and run the transformation inside one Node process -- the one being debugged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we decide to update the other parts, we might go for a higher level description here as well:
The codemod will be run in a single process to ensure that the debugger is captured, as opposed to normal invocation which spawns worker processes.
25c285f
to
41eb147
Compare
Hello @sirreal! i updated the documentation according to your suggestions. I keep mentioning the low-level command line args, but deemphasized into a parenthesized remark. I also updated the cmdline args to Node 8. Please have one last look at the changes before I merge them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I just tested on with node 8.
I wanted to debug a codemod script today and found it's not easy. Node needs to be run with
--inspect
and--debug-brk
parameters. That spawns a debugger server and breaks on first statement.jscodeshift
must be prevented from spawning worker processes by running it with--run-in-band
option. Otherwise, the transform will run in a process different from the one we are debugging.This PR adds a
--debugger
option to therun
script.How to test:
npm run codemod -- --debugger transform-name target-name
chrome-devtools://
link you see in terminal in Chromedebugger
statements in your code... and run.I don't know how Node debugging works in editors like VS Code. Maybe @blowery could help with making the debugging work in these?
Some links where I found valuable advice: