Last active
July 23, 2023 23:12
-
-
Save micalevisk/5276391d4e7b5c4b0c12fc98d5610245 to your computer and use it in GitHub Desktop.
Display the last modified date of every package on package.json dependencies list using npm-view (https://docs.npmjs.com/cli/v7/commands/npm-view)
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
#!/bin/bash | |
## (c) 2022 Micael Levi L. C. | |
## This script requires: | |
## - npm (https://nodejs.org) | |
## - jq (https://stedolan.github.io/jq) | |
file="${1:-./package.json}" | |
[ -r "$file" ] || { echo "The file $file is not readable" ; exit 1 ; } | |
readarray -t pkgs < <(jq --raw-output '.dependencies | keys | .[]' "$file") | |
readarray -t modified_vals < <(printf 'npm view "%s" time.modified\n' ${pkgs[@]} | bash) | |
paste <(printf "%s\n" "${modified_vals[@]}") <(printf "%s\n" "${pkgs[@]}") | sort |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mcmxcdev thanks! good question
here you can see how NPM computes that value: https://github.com/npm/cli/blob/34db56263c0d25caf5fff46e97f391e9ff094243/lib/commands/view.js#L350-L351
tbh I didn't fully understand it lol Keep in mind that a NPM package doesn't need to have a Git repo, so I believe that they don't try to look up for the last commit made