-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Controls: Add Channels API to search for files in the project root #26726
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 4d055fb. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
06844d3
to
8a17339
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't judge whether this is functionally sound, but code-wise seems mostly okay. Please do consider the security implications of accepting user-input for file system operations though.
cb5ef4d
to
23fce6f
Compare
Closes #26660
What I did
Experimental Channel API
I have added a new server channel preset to
@storybook/addon-controls
to search for files in the project root.The search result will return a list of objects containing the full file path (relative to the project root) and a list of exports inside the file.
Parser
I have created a generic parser to parse files using the packages
es-module-lexer
andcjs-module-lexer
. These packages are pretty fast compared to, for example, Acorn (20x faster). We are already using these packages for theexport-order-plugin
.The generic parser is currently enough to analyze files with React components. Indeed, the parser doesn't interpret all exports separately to determine whether they are React components. This is okay for now.
The architecture of the parser is built in an easily extensible way so that we can add parsers for vue, svelte, ... very quickly in the future.
File search
The file search takes a
.gitignore
file in the project's root into account and will not search for ignored files. Thenode_modules
folder is also always ignored, even if a.gitignore
file doesn't exist. I am usingglobby
to search for files because it has a built-in.gitignore
mechanic.The file search supports two modes:
*,
+(...)
, and so on. In this particular case, the search query is transformed to two glob searches like this:[**/*${searchQuery}*, **/*${searchQuery}*/**];
. This will match folders and files, which will partially match with the search query (see unit tests).The search query is then passed to globby. The supported glob patterns are the ones from minimatch. Only files in the project root are considered.
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
yarn task --task sandbox --start-from auto --template react-vite/default-ts
src/stories/Button.stories.ts
and adjust the meta section like this:Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
Make sure this PR contains one of the labels below:
Available labels
bug
: Internal changes that fixes incorrect behavior.maintenance
: User-facing maintenance tasks.dependencies
: Upgrading (sometimes downgrading) dependencies.build
: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup
: Minor cleanup style change. Will not show up in release changelog.documentation
: Documentation only changes. Will not show up in release changelog.feature request
: Introducing a new feature.BREAKING CHANGE
: Changes that break compatibility in some way with current major version.other
: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/core
team here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>