From 28cbacf97cce3ee1fa56ba665c6dfcfd82d4dd0f Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Wed, 24 Mar 2021 22:24:48 +0300 Subject: [PATCH] feat: warn if yaf is out of date closes #82 --- src/main/ts/stages.ts | 15 +++++++++++---- src/test/ts/index.ts | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/ts/stages.ts b/src/main/ts/stages.ts index c99635ee..60b214c2 100644 --- a/src/main/ts/stages.ts +++ b/src/main/ts/stages.ts @@ -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`, ) } @@ -50,7 +57,7 @@ export const printRuntimeDigest: TCallback = ({ npmPath, npmVersion, nodeVersion, - yarnAuditFixVersion, + yafVersion, temp, cwd, flags, diff --git a/src/test/ts/index.ts b/src/test/ts/index.ts index fe570e61..029be0b7 100644 --- a/src/test/ts/index.ts +++ b/src/test/ts/index.ts @@ -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 */ @@ -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)