Skip to content

Instantly share code, notes, and snippets.

@micalevisk
Last active July 23, 2023 23:12
Show Gist options
  • Save micalevisk/5276391d4e7b5c4b0c12fc98d5610245 to your computer and use it in GitHub Desktop.
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)
#!/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
@micalevisk
Copy link
Author

@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