update node v18.12.0 by using volta
voltaマジで便利
team開発では、現在使用しているversionがlock fileに記録されているし、そのversionをkeepしたまま開発できるからlock fileを大切にしよう package-lock.jsonとかyarn.lockとかは、いじっちゃだめ。
dependencies と devDependencies の違いであるが、意味としては前者は実行に必要なパッケージ、後者は開発やテストにのみ必要なパッケージである
dependencies または devDependencies でバージョンを指定する時、キャレット^ をつけると「Major は一致し Minor と Patch は指定されたもの以上」という意味になり、チルダ~ をつけると「Major と Minor は一致し Patch は指定されたもの以上」という意味になる。
yarn.lockをdeleteしてprojectごと消滅してた時期が懐かしいぜ
➜ ~ git:(main) ✗ volta install node@18.12.0
success: installed and set node@18.12.0 (with npm@8.19.2) as default
note: you are using node@16.16.0 in the current project
➜ ~ git:(main) ✗ volta pin node@18.12.0
success: pinned node@18.12.0 (with npm@8.19.2) in package.json
➜ ~ git:(main) ✗ volta list
⚡️ Currently active tools:
Node: v18.12.0 (current @ /Users/$HOME/package.json)
Yarn: v1.22.18 (default)
Tool binaries available:
gatsby (default)
npm-check-updates, ncu (default)
solcjs (current @ /Users/$HOME/package.json)
truffle (default)
tsc, tsserver (default)
See options for more detailed reports by running `volta list --help`.
nodeのglobalとlocal listも確認
➜ ~ git:(main) ✗ npm list
$HOME@ /Users/$HOME
├── @openzeppelin/contracts@4.7.3
├── @parcel/transformer-sass@2.7.0
├── aos@2.3.4
├── parcel@2.7.0
├── solc@0.8.17
├── tachyons@4.12.0
└── web3@1.8.0
➜ ~ git:(main) ✗ npm list -g --depth=0
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
/Users/$HOME/.volta/tools/image/node/16.16.0/lib
├── corepack@0.10.0
└── npm@8.11.0
➜ ~ git:(main) ✗ npm root -g
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
/Users/$HOME/.volta/tools/image/node/16.16.0/lib/node_modules
➜ ~ git:(main) ✗ npm root
/Users/$HOME/node_modules
➜ ~ git:(main) ✗ npm config --global list
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
; "user" config from /Users/$HOME/.npmrc
//registry.npmjs.org/:_authToken = (protected)
; "cli" config from command line options
global = true
; node bin location = /Users/$HOME/.volta/tools/image/node/16.16.0/bin/node
; node version = v16.16.0
; npm local prefix = /Users/$HOME
; npm version = 8.11.0
; cwd = /Users/$HOME
; HOME = /Users/$HOME
; Run `npm config ls -l` to show all defaults.
➜ ~ git:(main) ✗ npm config ls -l
; "default" config from default values
_auth = (protected)
access = null
all = false
allow-same-version = false
also = null
audit = true
audit-level = null
auth-type = "legacy"
before = null
bin-links = true
browser = null
ca = null
cache = "/Users/$HOME/.npm"
cache-max = null
cache-min = 0
cafile = null
call = ""
cert = null
ci-name = null
cidr = null
color = true
commit-hooks = true
depth = null
description = true
dev = false
diff = []
diff-dst-prefix = "b/"
diff-ignore-all-space = false
diff-name-only = false
diff-no-prefix = false
diff-src-prefix = "a/"
diff-text = false
diff-unified = 3
dry-run = false
editor = "vim"
engine-strict = false
fetch-retries = 2
fetch-retry-factor = 10
fetch-retry-maxtimeout = 60000
fetch-retry-mintimeout = 10000
fetch-timeout = 300000
force = false
foreground-scripts = false
format-package-lock = true
fund = true
git = "git"
git-tag-version = true
global = false
global-style = false
globalconfig = "/Users/$HOME/.volta/tools/image/node/16.16.0/etc/npmrc"
heading = "npm"
https-proxy = null
if-present = false
ignore-scripts = false
include = []
include-staged = false
include-workspace-root = false
init-author-email = ""
init-author-name = ""
init-author-url = ""
init-license = "ISC"
init-module = "/Users/$HOME/.npm-init.js"
init-version = "1.0.0"
init.author.email = ""
init.author.name = ""
init.author.url = ""
init.license = "ISC"
init.module = "/Users/$HOME/.npm-init.js"
init.version = "1.0.0"
install-links = false
json = false
key = null
legacy-bundling = false
legacy-peer-deps = false
link = false
local-address = null
location = "user"
lockfile-version = null
loglevel = "notice"
logs-dir = null
logs-max = 10
; long = false ; overridden by cli
maxsockets = 15
message = "%s"
metrics-registry = "https://registry.npmjs.org/"
node-options = null
node-version = "v16.16.0"
noproxy = [""]
npm-version = "8.11.0"
offline = false
omit = []
omit-lockfile-registry-resolved = false
only = null
optional = null
otp = null
pack-destination = "."
package = []
package-lock = true
package-lock-only = false
parseable = false
prefer-offline = false
prefer-online = false
prefix = "/Users/$HOME/.volta/tools/image/node/16.16.0"
preid = ""
production = null
progress = true
proxy = null
read-only = false
rebuild-bundle = true
registry = "https://registry.npmjs.org/"
save = true
save-bundle = false
save-dev = false
save-exact = false
save-optional = false
save-peer = false
save-prefix = "^"
save-prod = false
scope = ""
script-shell = null
searchexclude = ""
searchlimit = 20
searchopts = ""
searchstaleness = 900
shell = "/bin/zsh"
shrinkwrap = true
sign-git-commit = false
sign-git-tag = false
sso-poll-frequency = 500
sso-type = "oauth"
strict-peer-deps = false
strict-ssl = true
tag = "latest"
tag-version-prefix = "v"
timing = false
tmp = "/var/folders/7c/xsq3zg0d4ybdxd8qvb6wgypw0000gn/T"
umask = 0
unicode = true
update-notifier = true
usage = false
user-agent = "npm/{npm-version} node/{node-version} {platform} {arch} workspaces/{workspaces} {ci}"
userconfig = "/Users/$HOME/.npmrc"
version = false
versions = false
viewer = "man"
which = null
workspace = []
workspaces = null
workspaces-update = true
yes = null
; "user" config from /Users/$HOME/.npmrc
//registry.npmjs.org/:_authToken = (protected)
; "cli" config from command line options
long = true
➜ ~ git:(main) ✗ node
Welcome to Node.js v18.12.0.
Type ".help" for more information.
> global.module.paths
[
'/Users/$HOME/repl/node_modules',
'/Users/$HOME/node_modules',
'/Users/node_modules',
'/node_modules',
'/Users/$HOME/.node_modules',
'/Users/$HOME/.node_libraries',
'/Users/$HOME/.volta/tools/image/node/18.12.0/lib/node'
]
>
いらないglobal installをdeleteして、package.jsonを編集したのでnpm installでnode_modulesファイル更新
*すでにnpm install
ですべての dependency をインストールした状態で、dependency を追加・削除・アップデートしたいときは普通直接package.json
を編集せず、npm を通じて行う。npm コマンドで dependency を変更すると自動的にpackage.json
にも反映される。もしpackage.json
を直接編集した場合は再度npm install
を実行してnode_modules
内のファイルを更新する必要がある。
➜ ~ git:(main) ✗ npm install
removed 181 packages, and audited 384 packages in 2s
76 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
➜ ~ git:(main) ✗ npm list
$HOME@ /Users/$HOME
├── @openzeppelin/contracts@4.7.3
├── solc@0.8.17
└── web3@1.8.0