From d4dcb1274869983e5af88611808d8d45d03dfc66 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Wed, 24 Mar 2021 16:28:21 +0300 Subject: [PATCH] refactor: use semver for npm version parsing --- package.json | 4 +++- src/main/ts/cli.ts | 6 +++++- src/main/ts/stages.ts | 7 ++++--- yarn.lock | 5 +++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index eac1736c..5025fdbd 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "dependencies": { "@types/find-cache-dir": "^3.2.0", "@types/fs-extra": "^9.0.8", + "@types/semver": "^7.3.4", "globby": "^11.0.3", "chalk": "^4.1.0", "find-cache-dir": "^3.3.1", @@ -68,7 +69,8 @@ "npm": "^7.7.0", "pkg-dir": "^5.0.0", "synp": "^1.9.7", - "tslib": "^2.1.0" + "tslib": "^2.1.0", + "semver": "^7.3.5" }, "devDependencies": { "@qiwi/libdefkit": "^2.1.8", diff --git a/src/main/ts/cli.ts b/src/main/ts/cli.ts index d8e86002..78454b50 100644 --- a/src/main/ts/cli.ts +++ b/src/main/ts/cli.ts @@ -52,7 +52,11 @@ const flags = new Command() .option('--registry [registry]', 'Custom registry url', env.YAF_REGISTRY) .option('--silent [bool]', 'Disable log output', env.YAF_SILENT) .option('--temp [dir]', 'Directory for temporary assets') - .option('--verbose [bool]', 'Switch log level to verbose/debug', env.YAF_VERBOSE) + .option( + '--verbose [bool]', + 'Switch log level to verbose/debug', + env.YAF_VERBOSE, + ) .allowUnknownOption() .parse(process.argv) .opts() diff --git a/src/main/ts/stages.ts b/src/main/ts/stages.ts index 0979f6cc..c99635ee 100644 --- a/src/main/ts/stages.ts +++ b/src/main/ts/stages.ts @@ -1,6 +1,7 @@ import fs from 'fs-extra' import { dirname, join, relative } from 'path' import { sync as pkgDir } from 'pkg-dir' +import semver from 'semver' import synp from 'synp' import { TCallback } from './ifaces' @@ -36,9 +37,9 @@ export const printRuntimeDigest: TCallback = ({ ).version // NOTE npm > 7.0.0 provides monorepo support - if (isMonorepo && +(npmVersion + '').charAt(0) < 7) { + if (isMonorepo && (semver.parse(npmVersion + '')?.major as number) < 7) { console.warn( - "The project looks like monorepo, so it's recommended to use `npm v7` at least to process workspaces", + "This project looks like monorepo, so it's recommended to use `npm v7` at least to process workspaces", ) } @@ -52,7 +53,7 @@ export const printRuntimeDigest: TCallback = ({ yarnAuditFixVersion, temp, cwd, - flags + flags, }, undefined, 2, diff --git a/yarn.lock b/yarn.lock index b8f506c6..c8aa35e9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1064,6 +1064,11 @@ resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.2.0.tgz#a4e8205a4955690eef712a6d0394a1d2e121e721" integrity sha512-O3SQC6+6AySHwrspYn2UvC6tjo6jCTMMmylxZUFhE1CulVu5l3AxU6ca9lrJDTQDVllF62LIxVSx5fuYL6LiZg== +"@types/semver@^7.3.4": + version "7.3.4" + resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.4.tgz#43d7168fec6fa0988bb1a513a697b29296721afb" + integrity sha512-+nVsLKlcUCeMzD2ufHEYuJ9a2ovstb6Dp52A5VsoKxDXgvE051XgHI/33I1EymwkRGQkwnA0LkhnUzituGs4EQ== + "@types/stack-utils@^2.0.0": version "2.0.0" resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.0.tgz#7036640b4e21cc2f259ae826ce843d277dad8cff"