Skip to content

Commit

Permalink
fix(semver): 馃悶 fix dryRun mode
Browse files Browse the repository at this point in the history
Closes #497
  • Loading branch information
edbzn committed Apr 29, 2022
1 parent bd5b40f commit 0dd4366
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
18 changes: 18 additions & 0 deletions packages/semver/src/executors/version/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,24 @@ describe('@jscutlery/semver:version', () => {
);
});

it('should skip changelog and package.json update with --dryRun', async () => {
const { success } = await version(
{
...options,
dryRun: true,
},
context
);

expect(success).toBe(true);
expect(mockUpdatePackageJson).toBeCalledWith(
expect.objectContaining({ dryRun: true })
);
expect(mockUpdateChangelog).toBeCalledWith(
expect.objectContaining({ dryRun: true })
);
});

describe('--syncVersions=false (independent mode)', () => {
it('should run semver independently on a project', async () => {
const { success } = await version(options, context);
Expand Down
16 changes: 7 additions & 9 deletions packages/semver/src/executors/version/utils/git.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,20 +302,18 @@ describe('git', () => {
);
});

it('should pass --dryRun', async () => {
await lastValueFrom(
it('should pass --dryRun', (done) => {
commit({
dryRun: true,
noVerify: false,
commitMessage: 'chore(release): 1.0.0',
projectName: 'p',
})
);

expect(cp.exec).toBeCalledWith(
'git',
expect.arrayContaining(['--dry-run'])
);
}).subscribe({
complete: () => {
expect(cp.exec).not.toBeCalled();
done();
},
});
});

it('should pass --noVerify', async () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/semver/src/executors/version/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ export function commit({
commitMessage: string;
projectName: string;
}): Observable<void> {
if (dryRun) {
return EMPTY;
}

return exec('git', [
'commit',
...(dryRun ? ['--dry-run'] : []),
...(noVerify ? ['--no-verify'] : []),
'-m',
commitMessage,
Expand Down
6 changes: 6 additions & 0 deletions packages/semver/src/executors/version/utils/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ export function updatePackageJson({
newVersion,
projectRoot,
projectName,
dryRun,
}: {
newVersion: string;
projectRoot: string;
projectName: string;
dryRun: boolean;
}): Observable<string | null> {
if (dryRun) {
return of(null);
}

const packageJsonPath = getPackageJsonPath(projectRoot);
return readFileIfExists(packageJsonPath).pipe(
switchMap((packageJson) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/semver/src/executors/version/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export function versionWorkspace({
projectRoot,
newVersion,
projectName,
dryRun,
})
)
)
Expand Down Expand Up @@ -154,6 +155,7 @@ export function versionProject({
newVersion,
projectRoot,
projectName,
dryRun,
}).pipe(
concatMap((packageFile) =>
packageFile !== null
Expand Down

0 comments on commit 0dd4366

Please sign in to comment.