1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

更新するべきパッケージ一覧をCSVで出力(ruby, js)

Last updated at Posted at 2021-08-15

メモ

Ruby

$ bundle outdated --strict | sed -n "/^Gem /,\$p" | sed -e "s/  \+/,/g"

出力例

i18n-js,3.8.0,3.8.4,~> 3.8.0,default
js-routes,1.4.9,2.0.8,>= 0,default
json,2.3.1,2.5.1
jwt,2.2.2,2.2.3

JavaScript

jqを利用する

package-lock.json

$ npm outdated --json | jq -r "to_entries | .[] | [.key, .value.current, .value.wanted, .value.latest] | @csv"

出力例

"i18next","19.8.7","19.9.2","20.4.0"
"jest","26.6.3","26.6.3","27.0.6"
...

yarn.lock

$ npx yarn outdated --json | tail -n 1 | jq -r ".data.body[] | [.[0], .[1], .[2], .[3]] | @csv"

出力例

"@babel/plugin-transform-runtime","7.13.10","7.15.0","7.15.0"
"@babel/preset-typescript","7.13.0","7.15.0","7.15.0"
...

1つのプロジェクト以下に複数のpackage-lock.jsonやyarn.lockがある時

$ find . -type d -name node_modules -prune -o -type f -name 'package-lock.json' -print -o -type f -name 'yarn.lock' -print | xargs -I{} dirname {} | uniq | xargs -I{} bash -c 'echo {} && cd {} && (if [ -e ./package-lock.json ]; then (npm outdated --json | jq -r "to_entries | .[] | [.key, .value.current, .value.wanted, .value.latest] | @csv"); else (npx yarn outdated --json 2>/dev/null | tail -n 1 | jq -r ".data.body[] | [.[0], .[1], .[2], .[3]] | @csv"); fi)', .value.wanted, .value.latest] | @csv"); else (npx yarn outdated --json 2>/dev/null | tail -n 1 | jq -r ".data.body[] | [.[0], .[1], .[2], .[3]] | @csv"); fi)'

出力例

./hoge #<= ディレクトリパス
"@babel/plugin-transform-runtime","7.13.10","7.15.0","7.15.0"
"@babel/preset-typescript","7.13.0","7.15.0","7.15.0"
...
./hoge/foo
"i18next","19.8.7","19.9.2","20.4.0"
"jest","26.6.3","26.6.3","27.0.6"
...
./fuga
"jest","26.6.3","26.6.3","27.0.6"
...

参考

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?