Skip to content

Instantly share code, notes, and snippets.

@arafathusayn
Created July 4, 2019 12:51
Show Gist options
  • Save arafathusayn/4aad657f181154bfb98f922e66155e50 to your computer and use it in GitHub Desktop.
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)
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