Sourcemapper is a bit of golang to parse a sourcemap, as generated by webpack or similar, and spit out the original JavaScript files, recreating the source tree based on the file paths in the sourcemap.
An article explaining its purpose is available here: https://pulsesecurity.co.nz/articles/javascript-from-sourcemaps
If you have a recent version of Go installed:
go install github.com/denandz/sourcemapper@latest
Otherwise you can clone and build:
git clone https://github.com/denandz/sourcemapper
cd sourcemapper
go get
go build
:~$ ./sourcemapper
Usage of ./sourcemapper:
-header value
A header to send with the request, similar to curl's -H. Can be set multiple times, EG: "./sourcemapper --header "Cookie: session=bar" --header "Authorization: blerp"
-help
Show help
-insecure
Ignore invalid TLS certificates
-output string
Source file output directory - REQUIRED
-proxy string
Proxy URL
-url string
URL or path to the Sourcemap file - REQUIRED
Sourcemapper will download or read the map file at url
, and then spit the sources out into the directory defined by output
.
The following example shows sourcemapper
reading a .map
file from Dockerhub. Note, Dockerhub have since removed this map file so the literal command below will not provide this output any more.
doi@asov:~$ ./sourcemapper -output dhubsrc -url https://hub.docker.com/public/js/client.356c14916fb23f85707f.js.map
[+] Retriving Sourcemap from https://hub.docker.com/public/js/client.356c14916fb23f85707f.js.map
[+] Read 23045027 bytes, parsing JSON
[+] Retrieved Sourcemap with version 3, containing 1828 entries
[+] Writing 9076765 bytes to dhubsrc/webpack:/js/client.356c14916fb23f85707f.js
[+] Writing 1014 bytes to dhubsrc/webpack:/webpack/bootstrap 356c14916fb23f85707f
[+] Writing 3174 bytes to dhubsrc/webpack:/app/scripts/client.js
[+] Writing 281 bytes to dhubsrc/webpack:/~/babel-runtime/helpers/interop-require-default.js
[+] Writing 151 bytes to dhubsrc/webpack:/~/babel-core/polyfill.js
{snip}
[+] Writing 271 bytes to dhubsrc/webpack:/~/rc-tooltip/~/core-js/library/fn/object/set-prototype-of.js
[+] Writing 315 bytes to dhubsrc/webpack:/~/rc-tooltip/~/core-js/library/modules/es6.object.set-prototype-of.js
[+] Writing 1044 bytes to dhubsrc/webpack:/~/rc-tooltip/~/core-js/library/modules/_set-proto.js
[+] Writing 308 bytes to dhubsrc/webpack:/~/rc-tooltip/~/core-js/library/fn/object/create.js
[+] Writing 307 bytes to dhubsrc/webpack:/~/rc-tooltip/~/core-js/library/modules/es6.object.create.js
[+] Writing 360 bytes to dhubsrc/webpack:/~/rc-animate/~/core-js/library/fn/object/define-property.js
[+] Writing 371 bytes to dhubsrc/webpack:/~/rc-animate/~/core-js/library/modules/es6.object.define-property.js
[+] Writing 1041 bytes to dhubsrc/webpack:/~/rc-animate/~/babel-runtime/helpers/createClass.js
[+] done
doi@asov:~$ cd dhubsrc/
doi@asov:~/dhubsrc$ du -hs .
20M .
doi@asov:~/dhubsrc$ cd webpack\:/
~/ app/ js/ webpack/ (webpack)/
doi@asov:~/dhubsrc$ cd webpack\:/app/scripts/
actions/ components/ middlewares/ reducers/ selectors/ stores/ vendor/
doi@asov:~/dhubsrc$ cd webpack\:/app/scripts/components/
Paths such as webpack:/~/src/whatever/omg.js
are pretty common, so this tool cleans them up on windows.