Skip to content

Commit bc2db1a

Browse files
authored
Merge pull request #503 from facebook/ElonVolo-VSCode-Debugging-README
Adding VSCode debugging setup
2 parents 9bc2dcd + 04c35d4 commit bc2db1a

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

README.md

+83
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ $ npm install -g jscodeshift
2020

2121
This will install the runner as `jscodeshift`.
2222

23+
## VSCode Debugger
24+
25+
[Configure VSCode to debug codemods](#vscode-debugging)
26+
2327
## Usage (CLI)
2428

2529
The CLI provides the following options:
@@ -508,6 +512,85 @@ defineInlineTest(transform, /* ... */)
508512

509513
To view these docs locally, use `npx http-server ./docs`
510514

515+
## VSCode Debugging
516+
517+
It's recommended that you set up your codemod project to all debugging via the VSCode IDE. When you open your project in VSCode, add the following configuration to your launch.json debugging configuration.
518+
519+
```
520+
{
521+
// Use IntelliSense to learn about possible attributes.
522+
// Hover to view descriptions of existing attributes.
523+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
524+
"version": "0.2.0",
525+
"configurations": [
526+
{
527+
"type": "pwa-node",
528+
"request": "launch",
529+
"name": "Debug Transform",
530+
"skipFiles": [
531+
"<node_internals>/**"
532+
],
533+
"program": "${workspaceRoot}/node_modules/.bin/jscodeshift",
534+
"stopOnEntry": false,
535+
"args": ["--dry", "--print", "-t", "${input:transformFile}", "--parser", "${input:parser}", "--run-in-band", "${file}"],
536+
"preLaunchTask": null,
537+
"runtimeExecutable": null,
538+
"runtimeArgs": [
539+
"--nolazy"
540+
],
541+
"console": "internalConsole",
542+
"sourceMaps": true,
543+
"outFiles": []
544+
},
545+
{
546+
"name": "Debug All JSCodeshift Jest Tests",
547+
"type": "node",
548+
"request": "launch",
549+
"runtimeArgs": [
550+
"--inspect-brk",
551+
"${workspaceRoot}/node_modules/jest/bin/jest.js",
552+
"--runInBand",
553+
"--testPathPattern=${fileBasenameNoExtension}"
554+
],
555+
"console": "integratedTerminal",
556+
"internalConsoleOptions": "neverOpen",
557+
"port": 9229
558+
}
559+
],
560+
"inputs": [
561+
{
562+
"type": "pickString",
563+
"id": "parser",
564+
"description": "jscodeshift parser",
565+
"options": [
566+
"babel",
567+
"babylon",
568+
"flow",
569+
"ts",
570+
"tsx",
571+
],
572+
"default": "babel"
573+
},
574+
{
575+
"type": "promptString",
576+
"id": "transformFile",
577+
"description": "evcodeshift transform file",
578+
"default": "transform.js"
579+
}
580+
]
581+
}
582+
```
583+
584+
Once this has been added to the configuration
585+
586+
1. Install evcodeshift as a package if you haven't done so already by running the command **npm install --save evcodeshift**. The debug configuration will not work otherwise.
587+
2. Once the evcodeshift local package has been installed, go to the VSCode file tree and select the file on which you want to run the transform. For example, if you wanted to run codemod transforms of foo.js file, you would click on the entry for foo.js file in your project tree.
588+
3. Select "Debug Transform" from the debugging menu's options menu.
589+
4. Click the **"Start Debugging"** button on the VSCode debugger.
590+
5. You will be then prompted for the name of evcodeshift transform file. Enter in the name of the transform file to use. If no name is given it will default to **transform.js**
591+
6. Select the parser to use from the presented selection list of parsers. The transform will otherwise default to using the **babel** parser.
592+
7. The transform will then be run, stopping at any breakpoints that have been set.
593+
8. If there are no errors and the transform is complete, then the results of the transform will be printed in the VSCode debugging console. The file with the contents that have been transformed will not be changed, as the debug configuration makes use the evcodeshift **--dry** option.
511594

512595

513596
### Recipes

0 commit comments

Comments
 (0)