Skip to content

Instantly share code, notes, and snippets.

@wkrueger
Created August 11, 2018 10:05
Show Gist options
  • Save wkrueger/9dadb9fd8e47179214b5e38cd211f3b6 to your computer and use it in GitHub Desktop.
Save wkrueger/9dadb9fd8e47179214b5e38cd211f3b6 to your computer and use it in GitHub Desktop.
depcheck
//@ts-check
const fs = require("fs")
const utl = require("util")
const path = require("path")
process.on("unhandledRejection", (...arg) => {
console.error("unhandledRejection", ...arg)
process.exit(1)
})
const checkFor = process.argv[2] || "@types/react-dom"
let found = {}
let devfound = {}
console.log("check for", checkFor)
function main(ctx = process.cwd()) {
try {
var str = String(fs.readFileSync(ctx + "/package.json"))
let package = JSON.parse(str)
if (package.dependencies && package.dependencies[checkFor]) {
found[ctx] = package.dependencies[checkFor]
}
if (package.devDependencies && package.devDependencies[checkFor]) {
devfound[ctx] = package.devDependencies[checkFor]
}
} catch (err) {}
try {
var dirs = fs.readdirSync(ctx)
} catch (err) {}
for (let x = 0; x < dirs.length; x++) {
let dir = path.resolve(ctx, dirs[x])
if (fs.statSync(dir).isDirectory()) main(dir)
}
}
main()
console.log("found", found)
console.log("dev", found)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment