Skip to content

Commit

Permalink
feat: handle --dry-run option in --flow=patch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Jun 12, 2021
1 parent 4a431f4 commit 8fc5db6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | | ✔
Expand Down
1 change: 0 additions & 1 deletion src/main/ts/flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion src/main/ts/stages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}

Expand All @@ -173,6 +177,10 @@ export const syncLockfile: TCallback = ({ temp }) => {
* @return {void}
*/
export const yarnInstall: TCallback = ({ cwd, flags }) => {
if (flags.dryRun) {
return
}

invoke(
getYarn(),
[
Expand Down
8 changes: 7 additions & 1 deletion src/test/ts/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 8fc5db6

Please sign in to comment.