Skip to content

Commit

Permalink
Merge pull request #25452 from ksugawara61/case-insensitive-trailing-…
Browse files Browse the repository at this point in the history
…duplicate

AutoTitle: Fix case-insensitive trailing duplicate
  • Loading branch information
shilman authored Jan 8, 2024
2 parents 6302cc6 + d2c59b3 commit 898557a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 10 additions & 0 deletions code/lib/preview-api/src/modules/store/autoTitle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ describe('userOrAutoTitleFromSpecifier', () => {
).toMatchInlineSnapshot(`to/button`);
});

it('match with case-insensitive trailing duplicate', () => {
expect(
userOrAuto(
'./path/to/button/Button.stories.js',
normalizeStoriesEntry({ directory: './path' }, options),
undefined
)
).toMatchInlineSnapshot(`to/Button`);
});

it('match with trailing index', () => {
expect(
userOrAuto(
Expand Down
9 changes: 5 additions & 4 deletions code/lib/preview-api/src/modules/store/autoTitle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ const sanitize = (parts: string[]) => {
if (parts.length === 1) return [lastStripped];

const nextToLast = parts[parts.length - 2];
if (lastStripped && nextToLast && lastStripped.toLowerCase() === nextToLast.toLowerCase()) {
return [...parts.slice(0, -2), lastStripped];
}

return lastStripped &&
nextToLast &&
(lastStripped === nextToLast ||
/^(story|stories)([.][^.]+)$/i.test(last) ||
/^index$/i.test(lastStripped))
(/^(story|stories)([.][^.]+)$/i.test(last) || /^index$/i.test(lastStripped))
? parts.slice(0, -1)
: [...parts.slice(0, -1), lastStripped];
};
Expand Down

0 comments on commit 898557a

Please sign in to comment.