Lerna 最高!!

Lerna 便利です。

Lerna で monorepo 管理するようになって、各パッケージで使っているパッケージのバージョンを更新するのが、少し面倒に

(後述しますが、自分の無知からくる面倒さであって、Lerna のせいではありません。)


使用パッケージの更新の確認は、対象ディレクトリでncupackage.jsonの更新はncu -uで更新できます。

Lerna で複数パッケージを管理するようになって、これまで使用パッケージの更新は、各ディレクトリでncu -uを実行して更新していたのですが、管理するパッケージが増えてくると面倒になってきました。

lerna runでできそうですが、なんとなくpackage.jsonncuのコマンドを書きたくなかったので、却下

なにかいい方法ないかなと思っていたのですが、ふとncuの方にサブディレクトリもチェックする機能あるかも?と思いncu -hを実行したところ、

--deep  Run recursively in current working directory. Alias of (--packageFile '**/package.json').


ncu --deepを実行してみたところ、サブディレクトリも再帰的に更新内容が表示され、ncu --deep -uでバージョンの更新も問題なく出来ました。



--packageFile <path|glob>    Package file(s) location (default: ./package.json).


  • ncu --deepでサブディレクトリもチェック可
  • ncu --deep -uでサブディレクトリのpackage.jsonも更新可
  • --packageFileでより細かい指定もできそう(未確認)

参考情報 - ncu -h 全文

$ ncu -h
Usage: cli [options] [filter]

[filter] is a list or regex of package names to check (all others will be ignored).

  --color                      Force color in terminal
  --concurrency <n>            Max number of concurrent HTTP requests to registry. (default: 8)
  --configFileName <filename>  Config file name (default: .ncurc.{json,yml,js})
  --configFilePath <path>      Directory of .ncurc config file (default: directory of `packageFile`).
  --cwd <path>                 Working directory in which npm will be executed.
  --deep                       Run recursively in current working directory. Alias of (--packageFile '**/package.json').
  --dep <value>                Check one or more sections of dependencies only: dev, optional, peer, prod, bundle (comma-delimited).
  --deprecated                 Include deprecated packages.
  --doctor                     Iteratively installs upgrades and runs tests to identify breaking upgrades. Run "ncu --doctor" for detailed help. Add "-u" to execute.
  --enginesNode                Include only packages that satisfy engines.node as specified in the package file.
  -e, --errorLevel <n>         Set the error level. 1: exits with error code 0 if no errors occur. 2: exits with error code 0 if no packages need updating (useful for continuous integration). (default: 1)
  -f, --filter <matches>       Include only package names matching the given string, wildcard, glob, comma-or-space-delimited list, or /regex/.
  --filterVersion <matches>    Filter on package version using comma-or-space-delimited list, or /regex/.
  --format <value>             Enable additional output data, string or comma-delimited list: ownerChanged, repo. ownerChanged: shows if the package owner changed between versions. repo: infers and displays links to source code repository. (default: [])
  -g, --global                 Check global packages instead of in the current project.
  --greatest                   DEPRECATED. Renamed to "--target greatest".
  -i, --interactive            Enable interactive prompts for each dependency; implies -u unless one of the json options are set,
  -j, --jsonAll                Output new package file instead of human-readable message.
  --jsonDeps                   Like `jsonAll` but only lists `dependencies`, `devDependencies`, `optionalDependencies`, etc of the new package data.
  --jsonUpgraded               Output upgraded dependencies in json.
  -l, --loglevel <n>           Amount to log: silent, error, minimal, warn, info, verbose, silly. (default: "warn")
  --mergeConfig                Merges nested configs with the root config file for --deep or --packageFile options (default: false)').
  -m, --minimal                Do not upgrade newer versions that are already satisfied by the version range according to semver.
  -n, --newest                 DEPRECATED. Renamed to "--target newest".
  -o, --ownerChanged           DEPRECATED. Renamed to "--format ownerChanged".
  --packageData <value>        Package file data (you can also use stdin).
  --packageFile <path|glob>    Package file(s) location (default: ./package.json).
  -p, --packageManager <name>  npm, yarn (default: "npm")
  --peer                       Check peer dependencies of installed packages and filter updates to compatible versions. Run "ncu --help --peer" for details.
  --pre <n>                    Include -alpha, -beta, -rc. (default: 0; default with --newest and --greatest: 1).
  --prefix <path>              Current working directory of npm.
  -r, --registry <url>         Third-party npm registry.
  -x, --reject <matches>       Exclude packages matching the given string, wildcard, glob, comma-or-space-delimited list, or /regex/.
  --rejectVersion <matches>    Exclude package.json versions using comma-or-space-delimited list, or /regex/.
  --removeRange                Remove version ranges from the final package version.
  --semverLevel <value>        DEPRECATED. Renamed to --target.
  -s, --silent                 Don't output anything (--loglevel silent).
  -t, --target <value>         Target version to upgrade to: latest, newest, greatest, minor, patch. Run "ncu --help --target" for details.` (default: "latest")
  --timeout <ms>               Global timeout in milliseconds. (default: no global timeout and 30 seconds per npm-registery-fetch).
  -u, --upgrade                Overwrite package file with upgraded versions instead of just outputting to console.
  -V, --version                output the version number
  -h, --help                   display help for command