pocka / storybook-addon-vue-info

Info addon for Vue components
https://storybook-addon-vue-info.netlify.com/?path=/story/examples-basic-usage--simple-example
MIT License
164 stars 28 forks source link

Loader for non-SFC's #119

Closed shilman closed 4 years ago

shilman commented 4 years ago

Hi @pocka, thank you for providing this wonderful library! As you know, storybook-addon-vue-info was an inspiration for addon-docs, and addon-docs depends on your loader for Vue support.

To test out the new props table support in 5.3, I'm trying to instrument evergarden with @Aaron-Pool, and we've discovered that the current loader only supports Vue SFC's (which are not used by Evergarden).

The problems comes down to this line: https://github.com/pocka/storybook-addon-vue-info/blob/master/loader/index.js#L23

In SFC's component.options evaluates to the component that Storybook Docs inspects for the info, and the loader assumes that this exists.

In Evergarden, which does not use SFC's, component is undefined. I was able to hack it in by, for example adding workaround code like this:

const component = { options: Box }

But it would be great if the loader supported this case natively. Do you think you might be able to add loader support for non-SFC's like the one used in Evergarden?

Aaron-Pool commented 4 years ago

Just a quick follow up here, right here in the vue-docgen-api. The api gets all exports from a file for parsing. The cleanest fix for this is to have the docgen-api maintainer expose the export name the documentation has been parsed from on the __documentation object, and the change the component.options.__docgenInfo = ${JSON.stringify(info)}\n line to be ${info.exportName}.options.__docgenInfo = ${JSON.stringify(info)}\n

shilman commented 4 years ago

@Aaron-Pool can you create a small PR for that change against the vue-docgen-api repo?

Aaron-Pool commented 4 years ago

@shilman yeah, think so. Could be a couple of days, but I'll try to do so ASAP

pocka commented 4 years ago

@shilman Yeah, the loader should support non-SFC as well. It's hard to implement this functionality in a current way. The way which @Aaron-Pool suggested is the best solution IMO 👍

pocka commented 4 years ago

Moved to https://github.com/pocka/vue-docgen-loader/issues/1.

I moved the loader out to vue-docgen-loader and deprecated this addon's loader (storybook-addon-vue-info/loader).

pocka commented 4 years ago

Done! https://github.com/pocka/vue-docgen-loader/pull/2

shilman commented 4 years ago

❤️❤️❤️

shilman commented 4 years ago

THANKS @pocka @Aaron-Pool @elevatebart

Alert_-_Defaults_⋅_Storybook