Skip to content

Commit

Permalink
fix: version workspace now stages all changes together
Browse files Browse the repository at this point in the history
  • Loading branch information
dereekb committed May 27, 2022
1 parent ece3c07 commit 588b028
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 46 deletions.
20 changes: 5 additions & 15 deletions packages/semver/src/executors/version/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,13 @@ export function tryPush({
);
}

export type AddToStage = {
export function addToStage({
paths,
dryRun,
}: {
paths: string[];
dryRun: boolean;
}

export function mergeAddToStage(stages: AddToStage[], dryRun: boolean): AddToStage {
const pathsSet = new Set<string>();

stages.forEach((stage) => stage.paths.forEach((path) => pathsSet.add(path)));

return {
paths: Array.from(pathsSet),
dryRun
};
}

export function addToStage({ paths, dryRun }: AddToStage): Observable<void> {
}): Observable<void> {
if (paths.length === 0) {
return EMPTY;
}
Expand Down
63 changes: 32 additions & 31 deletions packages/semver/src/executors/version/version.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { forkJoin, Observable, of } from 'rxjs';
import { concatMap } from 'rxjs/operators';
import { concatMap, map } from 'rxjs/operators';
import {
insertChangelogDependencyUpdates,
updateChangelog,
} from './utils/changelog';
import { commit } from './utils/commit';
import { addToStage, createTag, mergeAddToStage } from './utils/git';
import { addToStage, createTag } from './utils/git';
import { logStep } from './utils/logger';
import { updatePackageJson } from './utils/project';
import { getProjectRoots } from './utils/workspace';

export type Version =
| {
type: 'project';
version: string | null;
}
type: 'project';
version: string | null;
}
| {
type: 'dependency';
version: string | null;
dependencyName: string;
};
type: 'dependency';
version: string | null;
dependencyName: string;
};

export type StandardVersionPreset = 'angular' | 'conventionalcommits';

Expand Down Expand Up @@ -65,8 +65,8 @@ export function versionWorkspace({
tag,
...options,
})
),
concatMap((changelogPaths) => of({ paths: changelogPaths, dryRun }))),
)
),
getProjectRoots(options.workspaceRoot).pipe(
concatMap((projectRoots) =>
forkJoin(
Expand All @@ -80,17 +80,18 @@ export function versionWorkspace({
)
)
),
concatMap((packageFiles) => of({
paths: packageFiles.filter(
(packageFile) => packageFile !== null
) as string[],
dryRun,
}))
map(
(packageFiles) =>
packageFiles.filter((packageFile) => packageFile !== null) as string[]
)
),
]).pipe(
concatMap((changesToStage) =>
addToStage(mergeAddToStage(changesToStage, dryRun))
),
concatMap((pathsToStage) => {
return addToStage({
paths: pathsToStage.flat(),
dryRun,
});
}),
concatMap(() =>
commit({
dryRun,
Expand Down Expand Up @@ -139,15 +140,15 @@ export function versionProject({
/* If --skipProjectChangelog is passed `changelogPaths` has length 0, otherwise it has 1 single entry. */
changelogPaths.length === 1
? insertChangelogDependencyUpdates({
changelogPath: changelogPaths[0],
version: newVersion,
dryRun,
dependencyUpdates: options.dependencyUpdates,
}).pipe(
concatMap((changelogPath) =>
addToStage({ paths: [changelogPath], dryRun })
changelogPath: changelogPaths[0],
version: newVersion,
dryRun,
dependencyUpdates: options.dependencyUpdates,
}).pipe(
concatMap((changelogPath) =>
addToStage({ paths: [changelogPath], dryRun })
)
)
)
: of(undefined)
),
concatMap(() =>
Expand All @@ -160,9 +161,9 @@ export function versionProject({
concatMap((packageFile) =>
packageFile !== null
? addToStage({
paths: [packageFile],
dryRun,
})
paths: [packageFile],
dryRun,
})
: of(undefined)
)
)
Expand Down

0 comments on commit 588b028

Please sign in to comment.