-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Allow AI setup for React Rsbuild projects #34888
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
Closed
agustiobvious
wants to merge
2
commits into
storybookjs:next
from
agustiobvious:codex/ai-setup-react-rsbuild
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { | ||
| getUnsupportedAiSetupProjectMessage, | ||
| isAiSetupSupportedProject, | ||
| } from './supported-project.ts'; | ||
|
|
||
| describe('isAiSetupSupportedProject', () => { | ||
| it('allows React projects using the Vite builder', () => { | ||
| expect( | ||
| isAiSetupSupportedProject({ | ||
| rendererPackage: '@storybook/react', | ||
| builderPackage: '@storybook/builder-vite', | ||
| }) | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('allows React projects using the Rsbuild builder', () => { | ||
| expect( | ||
| isAiSetupSupportedProject({ | ||
| rendererPackage: '@storybook/react', | ||
| builderPackage: 'storybook-builder-rsbuild', | ||
| }) | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('rejects non-React projects even when they use a supported builder', () => { | ||
| expect( | ||
| isAiSetupSupportedProject({ | ||
| rendererPackage: '@storybook/vue3', | ||
| builderPackage: 'storybook-builder-rsbuild', | ||
| }) | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects React projects using unsupported builders', () => { | ||
| expect( | ||
| isAiSetupSupportedProject({ | ||
| rendererPackage: '@storybook/react', | ||
| builderPackage: '@storybook/builder-webpack5', | ||
| }) | ||
| ).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getUnsupportedAiSetupProjectMessage', () => { | ||
| it('lists the supported builder families and detected packages', () => { | ||
| expect( | ||
| getUnsupportedAiSetupProjectMessage({ | ||
| rendererPackage: '@storybook/react', | ||
| builderPackage: '@storybook/builder-webpack5', | ||
| }) | ||
| ).toBe( | ||
| 'AI-assisted setup is currently only available for projects using the React renderer with Vite or Rsbuild builders. Detected renderer: @storybook/react, builder: @storybook/builder-webpack5' | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import type { ProjectInfo } from './types.ts'; | ||
|
|
||
| const SUPPORTED_REACT_BUILDERS = ['@storybook/builder-vite', 'storybook-builder-rsbuild'] as const; | ||
|
|
||
| type AiSetupProjectSupportInfo = Pick<ProjectInfo, 'rendererPackage' | 'builderPackage'>; | ||
|
|
||
| export function isAiSetupSupportedProject(projectInfo: AiSetupProjectSupportInfo): boolean { | ||
| return ( | ||
| projectInfo.rendererPackage === '@storybook/react' && | ||
| SUPPORTED_REACT_BUILDERS.includes(projectInfo.builderPackage as SupportedReactBuilder) | ||
| ); | ||
| } | ||
|
|
||
| export function getUnsupportedAiSetupProjectMessage( | ||
| projectInfo: AiSetupProjectSupportInfo | ||
| ): string { | ||
| return ( | ||
| 'AI-assisted setup is currently only available for projects using the React renderer with Vite or Rsbuild builders. Detected renderer: ' + | ||
| projectInfo.rendererPackage + | ||
| ', builder: ' + | ||
| projectInfo.builderPackage | ||
| ); | ||
| } | ||
|
|
||
| type SupportedReactBuilder = (typeof SUPPORTED_REACT_BUILDERS)[number]; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
🌐 Web query:
Does Node.js fs.existsSync accept afile:///...string path directly, or should file URLs be passed as URL objects / converted with fileURLToPath?💡 Result:
fs.existsSync does NOT accept a
file:///...URL string directly as a path; pass a WHATWG URL object (e.g.,new URL('file:///...')) or convert the file URL to a filesystem path withfileURLToPath(). Node’s fs API docs explicitly say thepathparameter can be a WHATWGURLobject using thefile:protocol (not a URL string) for fs functions likefs.access()[1]. An issue discussion in the Node.js repo notes that fs APIs support URL inputs only when passed as URL objects, not plain URL strings [2]. The same issue also reflects the rationale that file systems may contain characters like:that would make treatingfile://...strings as paths ambiguous, implying Node keeps string inputs as plain paths [2]. Recommended pattern: 1) If you already have a file URL string: - Convert:existsSync(fileURLToPath(urlString))2) If you already have a URL object: - Use:existsSync(urlObject)Example: const { existsSync } = require('node:fs'); const { fileURLToPath } = require('node:url'); const fileUrlString = 'file:///C:/path/to/file.txt'; const ok = existsSync(fileURLToPath(fileUrlString)); If you pass'file:///C:/path/to/file.txt'directly toexistsSyncas a string, it will be treated as a literal path string (not a URL), which won’t match real filesystem paths.Citations:
Fix
existsSyncwhenbuilderNameis afile://URLWhen
builderNameis afile://...URL string, the code ends up callingfs.existsSync()with afile://...string (not a filesystem path), which can false-negative and skip loading the builder preset. Convertfile:URLs to paths withfileURLToPath()before building thepreset.jspath / callingexistsSync.Suggested fix
🤖 Prompt for AI Agents