Skip to content

Commit

Permalink
fix: 🐞 exec Git add only once to avoid file lock
Browse files Browse the repository at this point in the history
  • Loading branch information
Katona authored and edbzn committed Mar 5, 2021
1 parent 7007f5c commit 4dfce73
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 1 addition & 5 deletions packages/semver/src/builders/version/utils/changelog.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { execFile } from 'child_process';
import { resolve } from 'path';
import { defer } from 'rxjs';
import { promisify } from 'util';
import * as changelog from 'standard-version/lib/lifecycles/changelog';
import * as standardVersionDefaults from 'standard-version/defaults';

Expand Down Expand Up @@ -38,8 +36,6 @@ export function updateChangelog({
},
newVersion
);
if (!dryRun) {
await promisify(execFile)('git', ['add', changelogPath]);
}
return changelogPath;
});
}
10 changes: 10 additions & 0 deletions packages/semver/src/builders/version/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,13 @@ export function tryPushToGitRemote({
);
});
}

export function gitAdd(
paths: string[],
dryRun = false
): Observable<{ stderr: string; stdout: string }> {
return defer(() => {
const gitAddOptions = [...(dryRun ? ['--dry-run'] : []), ...paths];
return execAsync('git', ['add', ...gitAddOptions]);
});
}
4 changes: 3 additions & 1 deletion packages/semver/src/builders/version/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getChangelogPath,
updateChangelog,
} from './utils/changelog';
import { gitAdd } from './utils/git';
import { getPackageFiles, getProjectRoots } from './utils/workspace';

export interface CommonVersionOptions {
Expand Down Expand Up @@ -44,7 +45,8 @@ export function versionWorkspace({
})
)
)
)
),
switchMap((changelogPaths) => gitAdd(changelogPaths))
),
getPackageFiles(workspaceRoot).pipe(
switchMap((packageFiles) =>
Expand Down

0 comments on commit 4dfce73

Please sign in to comment.