LoginSignup
0
0

【yarn】Yarnのコマンドを片っ端から試して見る。

Posted at

どうも、IT系学生のあまみやです。

先日別のQiita投稿をしたばかりですが、せっかくなのでもうひと投稿しようかとおもいます。

私は普段nodejsやyarnを使ってWebアプリを開発しているのですが、 実際使うのはyarn(yarn install)yarn addくらいです。なのでこれを機にいろいろな少しコマンドを試してみます。

version, versions

yarnをインストールしたならば、きちんと動作するかを確かめるためにyarn -v コマンドを実行するかと思います。(ちなみにyarnだけだとダウンロードが勝手に始まってしまいます。💦)

version

ちなみに公式のドキュメントだと

yarn version

コマンドはこうで、

info Current version: 1.0.1
question New version: 1.0.2
info New version: 1.0.2
✨  Done in 9.42s.

このように開発しているアプリケーションのバージョン変更を行えるようです。

ちなみに自分も実際に実行してみました。

$ yarn version
yarn version v1.22.19
info Current version: 0.4.1
question New version: 0.4.2
info New version: 0.4.2
Done in 4.16s.

コマンド上で変更が完了しました。

試しにcat package.jsonでファイルを見てみると、

cat package.json

{
    "name": "vx",
    "version": "0.4.2",
    "main": "index.js",
    "license": "MIT",
    "scripts": {
        "dev": "next dev",
        "build": "next build",
        "start": "next start",
...(以下略)

ちゃんと変更されています。

versions

綴りが似ていますが、versionsだと

$ yarn versions
yarn versions v1.22.19
{
  yarn: '1.22.19',
  vx: '0.4.2',
  node: '18.18.0',
  acorn: '8.10.0',
  ada: '2.6.0',
  ares: '1.19.1',
  brotli: '1.0.9',
  cldr: '43.1',
  icu: '73.2',
  llhttp: '6.0.11',
  modules: '108',
  napi: '9',
  nghttp2: '1.55.0',
  nghttp3: '0.7.0',
  ngtcp2: '0.8.1',
  openssl: '3.0.10+quic',
  simdutf: '3.2.14',
  tz: '2023c',
  undici: '5.22.1',
  unicode: '15.0',
  uv: '1.46.0',
  uvwasi: '0.0.18',
  v8: '10.2.154.26-node.26',
  zlib: '1.2.13.1-motley'
}

と出力されnodejsやJavascriptエンジン、自分のアプリケーションのバージョンが表示されます。

why

WHY!?なコマンドですが、これは各ライブラリの使い方やフォルダ容量を表示してくれるようです。

試しにreactで実行してみます。

$ yarn why react
yarn why v1.22.19
[1/4] Why do we have the module "react"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "react@18.2.0"
info Has been hoisted to "react"
info Reasons this module exists
   - Specified in "dependencies"
   - Hoisted from "@metamask#sdk-react#@metamask#sdk#@metamask#sdk-install-modal-web#react"
info Disk size without dependencies: "376KB"
info Disk size with unique dependencies: "408KB"
info Disk size with transitive dependencies: "436KB"
info Number of shared dependencies: 2
Done in 0.54s.

こんな感じです。
nodejsはnode_modules(ライブラリファイルの格納場所)が肥大化しやすいので便利かもしれない

nextjsとreact-domも実行してみる。

nextjs

 yarn why next
yarn why v1.22.19
[1/4] Why do we have the module "next"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "next@13.4.9"
info Has been hoisted to "next"
info This module exists because it's specified in "dependencies".
info Disk size without dependencies: "63.98MB"
info Disk size with unique dependencies: "72.58MB"
info Disk size with transitive dependencies: "73.07MB"
info Number of shared dependencies: 14
=> Found "@types/next#next@14.0.3"
info This module exists because "@types#next" depends on it.
info Disk size without dependencies: "98.61MB"
info Disk size with unique dependencies: "106.5MB"
info Disk size with transitive dependencies: "107MB"
info Number of shared dependencies: 13
Done in 2.75s.

react-dom

 yarn why react-dom
yarn why v1.22.19
[1/4] Why do we have the module "react-dom"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "react-dom@18.2.0"
info Has been hoisted to "react-dom"
info Reasons this module exists
   - Specified in "dependencies"
   - Hoisted from "@metamask#sdk-react#@metamask#sdk#@metamask#sdk-install-modal-web#react-dom"
info Disk size without dependencies: "4.53MB"
info Disk size with unique dependencies: "4.71MB"
info Disk size with transitive dependencies: "4.73MB"
info Number of shared dependencies: 3
Done in 0.56s.

意外とnextjsの容量がでかいですね、100MB前後あります。

あとがき

普段はこんな感じでへんなことやったりアプリを作っています。

あとワタシのアプリもよろしく。

参考サイト

0
0
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
0
0