Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Remove __namedExportsOrder handling from store" #17793

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/store/src/csf/processCSFFile.test.ts
Expand Up @@ -48,7 +48,7 @@ describe('processCSFFile', () => {
});
});

it('ignores __namedExportsOrder', () => {
it('adds stories in the right order if __namedExportsOrder is supplied', () => {
const { stories } = processCSFFile(
{
default: { title: 'Component' },
Expand All @@ -63,10 +63,10 @@ describe('processCSFFile', () => {
);

expect(Object.keys(stories)).toEqual([
'component--w',
'component--x',
'component--y',
'component--z',
'component--w',
'component--y',
]);
});

Expand Down
17 changes: 15 additions & 2 deletions lib/store/src/csf/processCSFFile.ts
Expand Up @@ -39,16 +39,29 @@ export function processCSFFile<TFramework extends AnyFramework>(
title: ComponentTitle
): CSFFile<TFramework> {
const { default: defaultExport, __namedExportsOrder, ...namedExports } = moduleExports;
let exports = namedExports;

const meta: NormalizedComponentAnnotations<TFramework> =
normalizeComponentAnnotations<TFramework>(defaultExport, title, importPath);
checkDisallowedParameters(meta.parameters);

// prefer a user/loader provided `__namedExportsOrder` array if supplied
// we do this as es module exports are always ordered alphabetically
// see https://github.com/storybookjs/storybook/issues/9136
// This directly affects the order of stories in the docs view and in folders on the sidebar.
if (Array.isArray(__namedExportsOrder)) {
exports = {};
__namedExportsOrder.forEach((name) => {
const namedExport = namedExports[name];
if (namedExport) exports[name] = namedExport;
});
}

const csfFile: CSFFile<TFramework> = { meta, stories: {} };

Object.keys(namedExports).forEach((key) => {
Object.keys(exports).forEach((key) => {
if (isExportStory(key, meta)) {
const storyMeta = normalizeStory(key, namedExports[key], meta);
const storyMeta = normalizeStory(key, exports[key], meta);
checkDisallowedParameters(storyMeta.parameters);

csfFile.stories[storyMeta.id] = storyMeta;
Expand Down