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

Fix source snippet generation #13

Merged
merged 15 commits into from
Nov 12, 2024

Conversation

JonahPlusPlus
Copy link
Collaborator

@JonahPlusPlus JonahPlusPlus commented Nov 5, 2024

This will fix:

A little bit on how code snippet generation will work after this PR:

SolidJS doesn't have a VDOM to get info on components and their children and handlers and whatnot.
So instead, I've opted for extracting the source code of stories and transforming them into JSX.
To do this, I'm using the source code taken from csf-tools and running Babel's standalone parser on it to get an AST.
The AST is then transformed, and then Babel's standalone generator turns it back into JS.
What is returned is some JSX with some basic formatting.

(I've messed around with different parsers (acorn, babel, @typescript-eslint/typescript-estree, typescript) and even formatters (prettier, biomejs), and this is what worked best while not being too expensive)

@JonahPlusPlus JonahPlusPlus marked this pull request as ready for review November 7, 2024 00:58
@JonahPlusPlus JonahPlusPlus marked this pull request as draft November 7, 2024 01:06
@JonahPlusPlus JonahPlusPlus marked this pull request as ready for review November 7, 2024 01:11
@JonahPlusPlus JonahPlusPlus marked this pull request as draft November 7, 2024 01:12
@JonahPlusPlus JonahPlusPlus marked this pull request as ready for review November 7, 2024 01:14
@JonahPlusPlus
Copy link
Collaborator Author

Okay, ready to merge (I had a brain fart remembering if I parsed the component names correctly lol)

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generally looks good to me. There are a bunch of stray console.logs that should probably be cleaned up. And stylistically I'd prefer moving the try/catch in the generateSource function up a level to the surrounding scope, but that's subjective.

Biggest thing this needs is unit tests for the new source generation, to document the current behavior and make sure it doesn't regress when the code or dependencies get updated.

@JonahPlusPlus
Copy link
Collaborator Author

@shilman Okay, I cleaned up the code and added testing. And while at it, I also refactored the CI to be cleaner and added warnings for edge cases in the parser.

@shilman shilman changed the title Update to 1.0.0-beta.4 Fix source snippetization Nov 12, 2024
@shilman shilman changed the title Fix source snippetization Fix source snippet generation Nov 12, 2024
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!!!

One small thing is are you supposed to bump the version in the PR or should you let the release script bump the versions? Asking because I'm not familiar with the release process in the repo.

@JonahPlusPlus
Copy link
Collaborator Author

@shilman Yeah, PRs handle bumping the version (easier than trusting a CD script to bump patch/minor/major correctly).

@JonahPlusPlus JonahPlusPlus merged commit 04ed357 into storybookjs:main Nov 12, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants