prantlf / storybook-multilevel-sort

Applies specific sort order to more than two levels of chapters and stories in Storybook.
https://storybook.js.org/addons/storybook-multilevel-sort/
Other
8 stars 4 forks source link

Incompatibility with `storyStoreV7` #7

Closed ptim closed 1 year ago

ptim commented 1 year ago

Hi!

Thanks for the great plugin! 🙏

FYI, I'm seeing an error when when storybook is configured to use config.options.storyStoreV7:

Are you using a V6-style sort function in V7 mode?

When I remove the storyStoreV7 storybook builds fine.

const config = {
  framework: '@storybook/react',

  core: {
    builder: 'webpack5',
  },

  features: {
    /** Configures Storybook to load stories on demand, rather than during boot up */
    storyStoreV7: true,
  },
};

export default config;
> start-storybook -p 6006 --no-open

info @storybook/react v6.5.14
info
info => Loading presets
info => Serving static files from ././.storybook/assets at /
info => Loading custom manager config
info Addon-docs: using MDX1
info => Using implicit CSS loaders
info => Using default Webpack5 setup
info => Loading custom manager config
/my-project/node_modules/@storybook/store/dist/cjs/sortStories.js:52
    throw new Error((0, _tsDedent.default)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n    Error sorting stories with sort parameter ", ":\n\n    > ", "\n    \n    Are you using a V6-style sort function in V7 mode?\n\n    More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#v7-style-story-sort\n  "])), storySortParameter, err.message));
          ^

Error: Error sorting stories with sort parameter (story1, story2) => sort(order, story1, story2):

> sort is not defined

Are you using a V6-style sort function in V7 mode?

More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#v7-style-story-sort
    at sortStoriesV7 (/my-project/node_modules/@storybook/store/dist/cjs/sortStories.js:52:11)
    at StoryIndexGenerator.sortStories (/my-project/node_modules/@storybook/core-server/dist/cjs/utils/StoryIndexGenerator.js:164:32)
    at StoryIndexGenerator.getIndex (/my-project/node_modules/@storybook/core-server/dist/cjs/utils/StoryIndexGenerator.js:178:18)
    at /my-project/node_modules/@storybook/core-server/dist/cjs/dev-server.js:117:24

Node.js v18.12.1
npm ERR! Lifecycle script `storybook` failed with error:
npm ERR! Error: command failed
npm ERR!   in workspace: @my-workspace@0.1.0
npm ERR!   at location: /my-project/apps/storybook
jrencz commented 1 year ago

With 7.0.0-beta.43, where I checked there's an improved logging:

Error: Error sorting stories with sort parameter (story1, story2) => sort(order, story1, story2);

> sort is not defined

Are you using a V6-style sort function in V7 mode?

More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#v7-style-story-sort
    at sortStoriesV7 (./node_modules/@storybook/core-server/node_modules/@storybook/preview-api/dist/index.js:36:2333)
    at StoryIndexGenerator.sortStories (./node_modules/@storybook/core-server/dist/index.js:10:15604)
    at async StoryIndexGenerator.getIndex (./node_modules/@storybook/core-server/dist/index.js:10:15834)
    at async ./node_modules/@storybook/core-server/dist/index.js:20:1513
ERROR: "storybook:dev" exited with 1.
ERROR: "storybook" exited with 1.
gatsbimantico commented 1 year ago

Anyone else having an issue forcing the sorting function to be inlined and not use anything from outside the function definition?

prantlf commented 1 year ago

Yes, the versions 1.x of this package don't work with Storybook 7. I'm working on it. Thanks for the kind words! I'm sorry for the delay.

@gatsbimantico, yes, the limitation of the code usable in preview.js is exactly what makes the migration difficult. You'd have to inline everything, function and configuration. The only ugly solution that occurred to me is to abuse another Storybook initialisation file, like main.js, for example, set the data to globalThis there and then access them from there in storySort, which is luckily executed later.

prantlf commented 1 year ago

Let's continue about this problem and the progress of the migration to the new framework API at the issue #8.

Storybook 7 will be supported by versions 2.x of this package. Versions 1.x will remain supporting Storybook 6 and older. The parameter storyStoreV7 opens the door to the new API and its enabling will need a version 2.x of this package too.

ptim commented 1 year ago

Let's continue about this problem and the progress of the migration to the new framework API at the issue https://github.com/prantlf/storybook-multilevel-sort/issues/8.

👍