Merge pull request #17659 from storybookjs/fix/sorted-exports-bug

This commit is contained in:
Michael Shilman 2022-03-08 21:28:45 +08:00 committed by GitHub
commit 4741f54110
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View File

@ -47,13 +47,3 @@ CSF2StoryWithPlay.play = () => {
console.log('play!!');
userEvent.click(screen.getByRole('button'));
};
// eslint-disable-next-line no-underscore-dangle
export const __namedExportsOrder = [
'Basic',
'WithArgs',
'StoryObject',
'StoryNoRender',
'StoryWithPlay',
'CSF2StoryWithPlay',
];

View File

@ -388,8 +388,18 @@ export class CsfFile {
});
if (self._namedExportsOrder) {
const unsortedExports = Object.keys(self._storyExports);
self._storyExports = sortExports(self._storyExports, self._namedExportsOrder);
self._stories = sortExports(self._stories, self._namedExportsOrder);
const sortedExports = Object.keys(self._storyExports);
if (unsortedExports.length !== sortedExports.length) {
throw new Error(
`Missing exports after sort: ${unsortedExports.filter(
(key) => !sortedExports.includes(key)
)}`
);
}
}
return self;