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
Storybook generator creates stories for stories #10286
Comments
I don't have time to open a PR, on a tight deadline. But I did trace down the problem. Affected code:
|
visitNotIgnoredFiles(tree, projectPath, (path) => { | |
if ( | |
(path.endsWith('.tsx') && !path.endsWith('.spec.tsx')) || | |
(path.endsWith('.js') && !path.endsWith('.spec.js')) || | |
(path.endsWith('.jsx') && !path.endsWith('.spec.jsx')) | |
) { | |
const ext = path.slice(path.lastIndexOf('.')); | |
const storyPath = `${path.split(ext)[0]}.stories${ext}`; | |
// only add component if a stories file doesnt already exist | |
if (!tree.exists(storyPath)) { | |
componentPaths.push(path); | |
} | |
} | |
}); |
Suggestion for updated code
visitNotIgnoredFiles(tree, projectPath, (path) => {
if (
(path.endsWith('.tsx') && !path.endsWith('.spec.tsx')) ||
(path.endsWith('.js') && !path.endsWith('.spec.js')) ||
(path.endsWith('.jsx') && !path.endsWith('.spec.jsx'))
) {
const ext = path.slice(path.lastIndexOf('.'));
const storyPath = `${path.split(ext)[0]}.stories${ext}`;
// Use the new path using endsWith
const isStory = storyPath.endsWith(`.stories.stories${ext}`)
// Optionally use the org path as a comparison
// const isStory = path.slice(-ext.length - 7, -ext.length) === 'stories'
// Updating this line with set check
if (!isStory && !tree.exists(storyPath)) {
componentPaths.push(path);
}
}
});
Conclusion
Honestly, I think there is a deeper problem with tree.exists()
function. Apparently, that should be grabbing the fact that a file exists in that tree. In my case I am using subfolders. libs/client/components/src/lib/
so maybe that is causing issues.
Still, if we know the path of the file we are going to generate, it is easy enough to check if it exists in any number of ways.
The way I see the code currently, it will tag the .stories
extension on everything and then check to see if it exists. Which will keep causing recursive creations.
@Coly010 It looks like you fixed this before. I didn't have this issue an update or two ago (can't remember when). |
Bump, I can confirm this is occurring on my repo as well. It is generating stories for story files as well as double-generating cypress specs. |
Oops that sounds frustrating. Looking into it now, thanks @Brian-McBride @Balance8 ! |
ISSUES CLOSED: nrwl#10286
ISSUES CLOSED: nrwl#10286
ISSUES CLOSED: nrwl#10286
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
Storybook
npx nx generate @nrwl/react:stories
is creating stories for files that have.stories
in the name.Expected Behavior
Stories should only be created for actual component files.
Steps to Reproduce
`npx nx generate @nrwl/react:stories --project=
Environment
The text was updated successfully, but these errors were encountered: