Created
August 11, 2018 10:05
-
-
Save wkrueger/9dadb9fd8e47179214b5e38cd211f3b6 to your computer and use it in GitHub Desktop.
depcheck
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
//@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