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

$ ./show_last_modified_dates.sh 
2017-10-26T21:00:34.418Z	tv4
2019-01-15T20:29:21.950Z	reflect-metadata
2019-01-30T20:23:34.438Z	toml
2019-05-29T15:17:01.038Z	node-machine-id
2020-04-18T08:20:27.180Z	typeorm-seeding
2020-05-18T00:29:29.526Z	mysql-error-codes
2020-06-06T15:15:54.760Z	ssh-keygen
2021-03-30T17:02:51.646Z	@joi/date
2021-08-03T08:47:42.246Z	@nestjs/typeorm
2021-09-12T18:47:35.923Z	dockerode
2021-11-18T09:19:58.256Z	@nestjs/swagger
2021-11-29T17:04:37.699Z	glob
2021-12-01T20:14:49.984Z	simple-git
2021-12-07T20:23:03.752Z	tar
2021-12-09T09:51:16.440Z	ejs
2021-12-16T09:24:24.380Z	swagger-ui-express
2021-12-18T17:02:49.944Z	axios
2021-12-18T17:03:00.283Z	joi
2021-12-20T18:03:24.661Z	pino-http
2021-12-28T18:46:17.263Z	mysql
2022-01-01T21:33:56.063Z	nestjs-form-data
2022-01-03T09:30:14.595Z	@nestjs/config
2022-01-06T17:27:50.410Z	@vrbo/pino-rotating-file
2022-01-09T06:16:51.367Z	dayjs
2022-01-10T02:45:50.624Z	rimraf
2022-01-10T05:04:38.568Z	ssh2
2022-01-10T17:20:11.324Z	pino
2022-01-11T15:47:08.258Z	@automapper/nestjs
2022-01-11T15:47:10.763Z	@automapper/classes
2022-01-11T15:47:12.557Z	@automapper/core
2022-01-12T10:10:34.224Z	@nestjs/core
2022-01-12T10:10:35.525Z	@nestjs/platform-express
2022-01-12T10:10:35.628Z	@nestjs/common
2022-01-13T08:02:15.725Z	ms
2022-01-13T21:46:44.513Z	rxjs
2022-01-15T15:18:17.850Z	typeorm
2022-01-17T02:09:41.056Z	nestjs-pino

now you can see which packages seems to be unmaintained.

@mcmxcdev
Copy link

mcmxcdev commented Dec 1, 2022

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 me time.modified as 2022-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.

@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