Skip to content

Commit adcb99a

Browse files
authored
fix: allow overlapping paths when splitting commits (#1733)
* test: failing test for supporting nested components * fix: allow overlapping paths when splitting commits * warning is no longer necessary
1 parent 3ca3bbc commit adcb99a

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

src/util/commit-split.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,14 @@ export class CommitSplit {
6969
newPath = newPath.replace(/^\//, '');
7070
newPath = newPath.replace(/$/, '/');
7171
newPath = newPath.replace(/^/, '/');
72-
for (let exPath of paths) {
73-
exPath = exPath.replace(/$/, '/');
74-
exPath = exPath.replace(/^/, '/');
75-
if (newPath.startsWith(exPath) || exPath.startsWith(newPath)) {
76-
throw new Error(
77-
`Path prefixes must be unique: ${newPath}, ${exPath}`
78-
);
79-
}
80-
}
8172
// store them with leading and trailing slashes removed.
8273
newPath = newPath.replace(/\/$/, '');
8374
newPath = newPath.replace(/^\//, '');
8475
paths.push(newPath);
8576
}
86-
this.packagePaths = paths;
77+
78+
// sort by longest paths first
79+
this.packagePaths = paths.sort((a, b) => b.length - a.length);
8780
}
8881
}
8982

test/util/commit-split.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,26 @@ describe('CommitSplit', () => {
5656
expect(splitCommits['pkg5']).lengthOf(1);
5757
expect(splitCommits['pkg6/pkg5']).lengthOf(1);
5858
});
59+
it('handles nested folders', () => {
60+
const commits: Commit[] = [
61+
{
62+
sha: 'abc123',
63+
message: 'commit abc123',
64+
files: ['core/foo.txt', 'pkg2/bar.txt'],
65+
},
66+
{
67+
sha: 'def234',
68+
message: 'commit def234',
69+
files: ['core/subpackage/foo2.txt', 'pkg3/asdf.txt'],
70+
},
71+
];
72+
const commitSplit = new CommitSplit({
73+
packagePaths: ['core', 'core/subpackage'],
74+
});
75+
const splitCommits = commitSplit.split(commits);
76+
expect(splitCommits['core']).lengthOf(1);
77+
expect(splitCommits['core/subpackage']).lengthOf(1);
78+
});
5979
describe('including empty commits', () => {
6080
it('should separate commits', () => {
6181
const commitSplit = new CommitSplit({

0 commit comments

Comments
 (0)