From 8fc5db6e7a9ae36e12cc6fdef78985761ee10831 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Sat, 12 Jun 2021 10:30:01 +0300 Subject: [PATCH] feat: handle --dry-run option in --flow=patch mode --- README.md | 2 +- src/main/ts/flows.ts | 1 - src/main/ts/stages.ts | 10 +++++++++- src/test/ts/runner.ts | 8 +++++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 977a2742..a0905ed7 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ Default fix strategy [has been changed](https://github.com/antongolub/yarn-audit |---|---|---|---| |`--flow` | Define how `yarn.lock` is modified. `convert` — to compose `npm audit fix` with two-way lockfile conversion (legacy flow). `patch` — to directly inject audit json data | `patch` |`--audit-level` | Include a vulnerability with a level as defined or higher. Supported values: low, moderate, high, critical | `low` -|`--dry-run` | Get an idea of what audit fix will do | | ✔ | +|`--dry-run` | Get an idea of what audit fix will do |`--force` | Have audit fix install semver-major updates to toplevel dependencies, not just semver-compatible ones | `false` |`--help/-h`| Print help message | |`--legacy-peer-deps` | Accept an incorrect (potentially broken) deps resolution | | ✔ diff --git a/src/main/ts/flows.ts b/src/main/ts/flows.ts index 751edcdd..922d8f14 100644 --- a/src/main/ts/flows.ts +++ b/src/main/ts/flows.ts @@ -37,7 +37,6 @@ export const patch: TFlow = { main: [ ['Runtime digest', printRuntimeDigest], ['Preparing temp assets...', clear, createTempAssets, createSymlinks], - ['Generating package-lock.json from yarn.lock...', yarnLockToPkgLock], [ 'Patching yarn.lock with audit data...', patchLockfile, diff --git a/src/main/ts/stages.ts b/src/main/ts/stages.ts index 220b0d59..8284f519 100644 --- a/src/main/ts/stages.ts +++ b/src/main/ts/stages.ts @@ -163,7 +163,11 @@ export const yarnImport: TCallback = ({ temp }) => { fs.writeFileSync(join(temp, 'yarn.lock'), yarnLockData) } -export const syncLockfile: TCallback = ({ temp }) => { +export const syncLockfile: TCallback = ({ temp, flags }) => { + if (flags.dryRun) { + return + } + fs.copyFileSync(join(temp, 'yarn.lock'), 'yarn.lock') } @@ -173,6 +177,10 @@ export const syncLockfile: TCallback = ({ temp }) => { * @return {void} */ export const yarnInstall: TCallback = ({ cwd, flags }) => { + if (flags.dryRun) { + return + } + invoke( getYarn(), [ diff --git a/src/test/ts/runner.ts b/src/test/ts/runner.ts index 05df637e..529df293 100644 --- a/src/test/ts/runner.ts +++ b/src/test/ts/runner.ts @@ -175,7 +175,13 @@ describe('yarn-audit-fix', () => { ) expect(cp.spawnSync).toHaveBeenCalledWith( getYarn(), - ['install', '--update-checksums', '--verbose', '--registry', registryUrl], + [ + 'install', + '--update-checksums', + '--verbose', + '--registry', + registryUrl, + ], { cwd, stdio }, ) expect(fs.emptyDirSync).toHaveBeenCalledWith(expect.stringMatching(temp))