A CLI tool to automatically locate and recover code and assets from production sourcemaps
npm install snatcher-cli> I originally coded this tool after a frustrating incident where I lost my production code and realized I had sourcemaps still live. Instead of rewriting everything, I wanted an automated way to “snatch” my own code back from those .map files. Now you can, too!
A CLI tool to snatch the main sourcemap from your production React (or similar Webpack-based) app and reconstruct your actual code. No more rummaging through node\_modules or weird bundler files — just the good stuff (like your src/App.js)!
When snatcher-cli runs, it:
1. Fetches the main HTML from your site.
2. Locates the first script whose path includes "main".
3. Extracts the //# sourceMappingURL=... comment from that script.
4. Downloads the .map file and rebuilds the source files it contains — skipping anything that has node_modules/ or webpack/ in the path.
5. Creates a snatch-report.json in your output folder with metadata about what it did and a list of any node_modules packages it sees (but doesn’t download).
---
- Features
- Installation
- Usage
- Example
- JSON Report
- Skipping Node Modules
- Limitations & Warnings
- Contributing
- License
---
- Automagic Discovery: No need to guess your hashed filenames. snatcher-cli sees whatever the HTML references for your “main” script.
- Selective Recovery: It omits all the node_modules or webpack-related stuff in the sourcemap, focusing on your own code.
- Image Stub Replacement: Spots lines like __webpack_public_path__ + "static/media/Logo.123abc.png" and fetches the real image file for you.
- JSON Reporting: You get a snatch-report.json summarizing the job, listing packages that might be in your node_modules, etc.
---
``bash`
npm install -g snatcher-cli
This installs the CLI command snatcher-cli globally so you can run it anywhere.\npx
(Or use if you prefer not to install globally.)
---
Run snatcher-cli by providing the public URL of your site, followed by any options:
`bash`
snatcher-cli
- https://example.com/subfolder/$3
- -o, --output (default: recovered-files)
The folder in which to place the reconstructed files and the JSON report.
- -d, --debug
Prints extra logs for troubleshooting or curiosity.$3
`bash
snatcher-cli https://myusername.github.io/my-react-app/ -o recovered-code -d
`
This will:
1. Fetch the page at https://myusername.github.io/my-react-app/
2. Locate the first