2
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 5 years have passed since last update.

npmで、package.jsonにあるパッケージの、tarボールのURLの一覧が欲しい

Last updated at Posted at 2018-06-20

接続ドメインが制限された環境下で、「接続予定のドメインを教えてくれ」と言われた。
ので、ドメインの一覧が欲しい。

cat package.json | \
jq -r '(.dependencies + .devDependencies) | keys | .[]' | \
xargs -I{} npm view {} dist.tarball

解説

  • catコマンドで、依存関係をpackage.jsonから読み出す
  • jqコマンドで依存関係部分のみを取得する
    • .フィールド名フィルタで、当該部分のみ選択する
    • keysフィルタで、ハッシュのキーのみ配列で取得する。(パッケージ名が取れる。)
    • .[]で、配列を分解して出力する
    • -rで、引用符を出力しないようにする
  • xargsコマンドで、それぞれの要素を1個ずつ処理する
    • -I{}でplaceholderを明示できる
  • npm view コマンドで、tarボールのURLを取得する
    • npm view helpには、npm view [パッケージ名] フィールド名.サブフィールド名...という使い方が書いてある
    • 例えば、npm view jqueryを試してみると、付表のような感じになる。
    • dist, keywords, maintainers dist-tagがフィールド名の様子。
    • tarのURLはdist.tarballで取れる。
jquery@3.3.1 | MIT | deps: none | versions: 48
JavaScript library for DOM operations
https://jquery.com

keywords: jquery, javascript, browser, library

dist
.tarball https://registry.npmjs.org/jquery/-/jquery-3.3.1.tgz
.shasum: 958ce29e81c9790f31be7792df5d4d95fc57fbca
.integrity: sha512-Ubldcmxp5np52/ENotGxlLe6aGMvmF4R8S6tZjsP6Knsaxd/xp3Zrh50cG93lR6nPXyUFwzN3ZSOQI0wRJNdGg==

maintainers:
- dmethvin <dave.methvin@gmail.com>
- mgol <m.goleb@gmail.com>
- scott.gonzalez <scott.gonzalez@gmail.com>
- timmywil <4timmywil@gmail.com>


dist-tags:
beta: 3.3.1    latest: 3.3.1

published 5 months ago by timmywil <4timmywil@gmail.com>
2
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
2
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?