VS Codeの拡張機能のNx Consoleでlint:fix
やformat:fix
のようなコロン区切りのスクリプトを実行するとコロン以降が消えたスクリプトが実行されるのでメモ。
例)lint:fix
を実行する
* 実行するタスク: yarn nx run {project}:lint:fix
yarn run v1.22.18
$ node_modules/.bin/nx run {project}:lint:fix
> nx run {project}:lint [existing outputs match the cache, left as is]
lint:fix
を実行しているにも関わらず、lint
が実行されます。
原因
Nx generally uses a colon to delimit
nx run {project}:{target}:{configuration}
, so it interprets the command as a target and configuration.
https://github.com/nrwl/nx/issues/9232#issuecomment-1067207447
つまり、今回の例で言うと:fix
に当たる部分がtargetではなく、configurationとして認識されるために起こってしまいます。
スクリプトをコマンドラインから実行する場合は、以下のようにすると動きます。
nx run {project}:\"lint:fix\"
ただ、Nx Consoleでは上記のような設定はできません。
解決策
スクリプトをコロン区切りではなく、ハイフン区切りに変更すると直ります。
* 実行するタスク: yarn nx run {project}:lint-fix
yarn run v1.22.18
$ node_modules/.bin/nx run {project}:lint-fix
> nx run {project}:lint-fix [existing outputs match the cache, left as is]
実際、Nxのpackage.jsonのスクリプトは全てハイフン区切りになっていました。
nx/package.json at master · nrwl/nx
参考
lerna run fails on colon-separated scripts with lerna+Nx
Command nx run project:command does not work if command contains a colon (:)
Make nx run more flexible when using script runner workflow