Skip to content

Commit

Permalink
refactor: use semver for npm version parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Mar 24, 2021
1 parent 2adb481 commit d4dcb12
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion src/main/ts/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions src/main/ts/stages.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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",
)
}

Expand All @@ -52,7 +53,7 @@ export const printRuntimeDigest: TCallback = ({
yarnAuditFixVersion,
temp,
cwd,
flags
flags,
},
undefined,
2,
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d4dcb12

Please sign in to comment.