Created
July 4, 2019 12:51
-
-
Save arafathusayn/4aad657f181154bfb98f922e66155e50 to your computer and use it in GitHub Desktop.
Get all node_modules/npm package names from webpage if published (eg. Trello)
This file contains hidden or 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
main = async (url) => { | |
let el = document.createElement('div') | |
el.innerHTML = await fetch(url).then(res => res.text()) | |
const scripts = el.querySelectorAll('script') | |
const scriptCodes = await Promise.all(Array.from(scripts).filter(script => script.src).map(script => script.src).map(async url => { | |
const code = await fetch(url).then(res => res.text()).catch(e => null) | |
return code | |
})) | |
const nodeModules = Array.from(new Set(scriptCodes.join('').match(/node_modules(\/(?!@).+?\/|\/(.+?\/.+?\/))/g))).map(str => str.replace('node_modules/', '').replace(/\/$/, '')) | |
return nodeModules | |
} | |
main(PASS_WEBPAGE_URL_HERE) // eg. main('https://trello.com/b/AwYSWOyt/ultimate-to-do-list') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment