Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 78a15cc
Showing
12 changed files
with
638 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# lockstat | ||
|
||
and did you know there's only one company in the world that produces wooden | ||
barrels? | ||
|
||
## whümf | ||
|
||
some statistics about your package-lock.json | ||
|
||
## wetch | ||
|
||
```shell | ||
$ npm install -g lockstat | ||
``` | ||
|
||
## commands | ||
|
||
### depcount | ||
|
||
print the number of version of each dependency in the tree | ||
|
||
#### usage | ||
|
||
```sh | ||
$ lockstat depcount < package.json | ||
``` | ||
|
||
#### options | ||
|
||
##### --file=\<path> | ||
the package-lock.json to operate on. | ||
you can use `-` or leave this blank to accept input on STDIN | ||
|
||
#### --min=\<int> | ||
only print dependencies that have more than this number of versions. | ||
|
||
#### --sort=\<dont|count|name> | ||
how to sort the dependencies. `dont` is the default. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import {EOL} from "os" | ||
import getLockfile from "../util/get-lockfile" | ||
import recurseDependencies from "../util/recurse-dependencies" | ||
|
||
export let command = "depcount" | ||
export let describe = "the number of versions of each dependency" | ||
export let aliases = [ | ||
"dependency-counts", | ||
"dc" | ||
] | ||
export let builder = yargs => { | ||
yargs | ||
.option("min", { | ||
describe: "show only dependencies that have more than 'min' numbers", | ||
default: 0 | ||
}) | ||
.options("sort", { | ||
default: "dont", | ||
choices: ["dont", "count", "name"], | ||
describe: "how to sort the dependencies" | ||
}) | ||
.options("show") | ||
.check(argv => { | ||
if (!(Number.isInteger(argv.min) && argv.min >= 0)) { | ||
throw new Error("Error: `min` must be a non-negative integer") | ||
} | ||
|
||
return true | ||
}) | ||
} | ||
|
||
let sorts = { | ||
count: ([, a], [, b]) => b - a, | ||
name: ([a, ], [b, ]) => a.localeCompare(b) | ||
} | ||
|
||
export async function handler (argv) { | ||
let lockfile = await getLockfile(argv) | ||
|
||
let counts = {} | ||
let maxNameLength = 0 | ||
|
||
await recurseDependencies(async (name, info) => { | ||
maxNameLength = name.length > maxNameLength | ||
? name.length | ||
: maxNameLength | ||
|
||
counts[name] = (counts[name] || 0) + 1 | ||
|
||
}, lockfile.dependencies) | ||
|
||
Object.entries(counts) | ||
.sort(sorts[argv.sort]) | ||
.filter(([, count]) => count >= argv.min) | ||
.forEach(([name, count]) => { | ||
process.stdout.write( | ||
name.padEnd(maxNameLength, " ") + "\t" + count + EOL | ||
) | ||
}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env node | ||
require = require("esm")(module) | ||
module.exports = require("./index.js") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env node | ||
let path = require("path") | ||
|
||
let commandDir = path.resolve(__dirname, "commands") | ||
|
||
let {argv} = require("yargs") | ||
.option("file", { | ||
describe: "the package-lock.json to operate on, use - or nothing for stdin" | ||
}) | ||
.commandDir(commandDir) | ||
.demandCommand() | ||
.epilogue("💖 🐕") |
Oops, something went wrong.