Skip to content

Commit

Permalink
feat: warn if yaf is out of date
Browse files Browse the repository at this point in the history
closes #82
  • Loading branch information
antongolub committed Mar 24, 2021
1 parent 9022960 commit 6ac2bd1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/main/ts/stages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,21 @@ export const printRuntimeDigest: TCallback = ({
const npmPath = getNpm(flags['npm-path'])
const npmVersion = invoke(npmPath, ['--version'], temp, true, false)
const nodeVersion = invoke('node', ['--version'], temp, true, false)
const yarnAuditFixVersion = readJson(
const latestYafVersion = invoke(npmPath, ['view', 'yarn-audit-fix', 'version'], temp, true, false) as string
const yafVersion = readJson(
join(pkgDir(__dirname) + '', 'package.json'), // eslint-disable-line
).version

// NOTE npm > 7.0.0 provides monorepo support
if (isMonorepo && (semver.parse(npmVersion + '')?.major as number) < 7) {
if (isMonorepo && (semver.parse(npmVersion as string)?.major as number) < 7) {
console.warn(
"This 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',
)
}

if (semver.gte(latestYafVersion, yafVersion)) {
console.warn(
`yarn-audit-fix version ${yafVersion} is out of date. Install the latest ${latestYafVersion} for better results`,
)
}

Expand All @@ -50,7 +57,7 @@ export const printRuntimeDigest: TCallback = ({
npmPath,
npmVersion,
nodeVersion,
yarnAuditFixVersion,
yafVersion,
temp,
cwd,
flags,
Expand Down
4 changes: 2 additions & 2 deletions src/test/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('yarn-audit-fix', () => {
/* noop */
})
// @ts-ignore
fs.readFileSync.mockImplementation(() => '{}')
fs.readFileSync.mockImplementation(() => '{"version": "1.0.0"}')
// @ts-ignore
fs.removeSync.mockImplementation(() => {
/* noop */
Expand All @@ -48,7 +48,7 @@ describe('yarn-audit-fix', () => {
// @ts-ignore
synp.npmToYarn.mockImplementation(() => '{}')
// @ts-ignore
cp.spawnSync.mockImplementation(() => ({ status: 0, stdout: 'foobar' }))
cp.spawnSync.mockImplementation(() => ({ status: 0, stdout: '1.0.1' }))
})
afterEach(jest.clearAllMocks)
afterAll(jest.resetAllMocks)
Expand Down

0 comments on commit 6ac2bd1

Please sign in to comment.