Last active
November 10, 2016 05:12
-
-
Save MarcoPolo/db5ffb4ca5f14d42d5f242a6af0b2524 to your computer and use it in GitHub Desktop.
Traverse inverse dependency react native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
counts = {} | |
a = {} // your inverse dep map | |
// helper to return a string of n spaces... omg this is left pad | |
function s (n) { let k = ''; for (i = 0; i<n; i++) {k = k + ' '}; return k} | |
function f (k, ttl, indent, seen) { | |
if (seen[k]) { console.warn('circular dep found', k, seen) } | |
let kl = (''+k).length; counts[k] = (counts[k] || 0) + 1 ;return (ttl > 0 && a[k] && a[k].length ? k + ' -> ' + a[k].map(i => f(i, ttl - 1, indent + s(4+kl), Object.assign(seen, {[k]: true}))).join('\n' + s(kl + 4) + indent) : k) | |
} | |
// Figure out most used deps | |
Object.keys(counts).map(i => [counts[i], i]).sort(([a, _a], [b, _b]) => b - a).slice(0,10) | |
// call like so | |
'\n'+Object.keys(a).map(i => f(i, 2, '', {})) && true // (remove the && true to see the string printout) |
If you turn those into a names Obj. you can then do:
function f (k, ttl, indent, seen) {
let name = names[k] || k
if (seen[k]) { console.warn('circular dep found', k, seen) }
let kl = (''+name).length; counts[k] = (counts[k] || 0) + 1 ;return (ttl > 0 && a[k] && a[k].length ? name + ' -> ' + a[k].map(i => f(i, ttl - 1, indent + s(4+kl), Object.assign(seen, {[k]: true}))).join('\n' + s(kl + 4) + indent) : name)
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for parsing what the module names are from the bundle:
wget http://localhost:8081/index.android.bundle\?platform\=android\&dev\=true\&hot\=true\&minify\=false
cat index.android.bundle\?platform=android\&dev=true\&hot=true\&minify=false | grep -o 'require([0-9]*\ \/\*\([^;]*\) \*\/);' | sed 's/.*require(\([0-9]*\)\ \/\* \(.*\) \*\/).*;/\1: "\2",/' > parsed-output