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 |
@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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Micael, thanks for this script, it works perfectly!
I was trying to figure out though what
time.modified
even means.Looking at e.g. https://github.com/shelljs/shx/commits/main I see that the last commit was on Aug 10 as of writing this. Running
npm view shx --json
shows metime.modified
as2022-06-26T19:13:27.666Z
So if it is not the latest commit on the main branch then what is it?
I would also argue that latest commit is a better indicator, since that seems to be newer than the
time.modified
, at least in this case.