-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix: Rewrite getExampleFilename logic to make it case insensitive (#423) #440
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
Conversation
sapegin
left a comment
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.
Thanks, this is very cool feature!
scripts/schemas/config.js
Outdated
| // Search is case-insensitive, so `README.md` or `BUTTON.md` is also | ||
| // valid. | ||
| const readmeIndex = lowerFiles.indexOf('readme.md'); | ||
| const componentIndex = lowerFiles.indexOf(`${componentName.toLowerCase()}.md`); |
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’d move this line after the first condition; and you don't need an else because you have return.
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.
Done. I think we still need else branch because it can be that neither a readme.md nor a mycomponent.md file is available. In this case readmeIndex and componentIndex have both the value -1 and both conditions are wrong. In this case false is returned as in the previous implementation. Please have a look in the updated code.
scripts/schemas/config.js
Outdated
| if (fs.existsSync(file)) { | ||
| return file; | ||
| } | ||
| const files = fs.readdirSync(dirname); |
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.
Should we cache it somehow? Imagine a project with all components in a single folder.
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've had a look, but I'm not sure where caching could be done. getExampleFilename is called in loaders/props-loader.js and processComponent.js. The first one is already cached via webpack as it's a cachable loader (please correct me if I'm wrong). The second one is called to process a component in case it has changed, so I think in this case we should update anyway. Where in the application logic would you see the caching layer?
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 mean to cache readdirSync because it will be called for each component possible with the same results if all of them are in the same folder.
|
@sapegin Thanks for the feedback. I'll have a look hopefully somewhen later this weekend. I'll see if I can implement cache and see what I can do about failing tests (somehow they worked locally ... ??). I'll come back to you when I'm done. |
…es named after component)
…uidist into case-insensitive-readme-matching
Codecov Report
@@ Coverage Diff @@
## master #440 +/- ##
==========================================
+ Coverage 94.32% 94.38% +0.05%
==========================================
Files 82 82
Lines 1146 1158 +12
Branches 254 258 +4
==========================================
+ Hits 1081 1093 +12
Misses 61 61
Partials 4 4
Continue to review full report at Codecov.
|
|
@sapegin Sorry for the long delay. I've been quite busy within the last two weeks. I've implemented a cache layer into the The idea goes like this: What this PR misses is documentation of the cache as the second param of the Side note: I had to fix some lint issues (see commit dcf17a9) because code from master was invalid...?! |
Looks like you need to |
| getExampleFilename: { | ||
| type: 'function', | ||
| default: componentPath => { | ||
| default: (componentPath, cache) => { |
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.
Could you please explain benefits of your implementation over _.memoize?
I’d make a cached case-insensitive version of fs.existsSync and pass it to to getExampleFilename. Passing just an object doesn’t look useful and will be hard to explain in the docs.
## New features ### Copy pathline to clipboard button  (#485, #471 by @SaraVieira) ### Easier way to override style guide React components New config option `styleguideComponents` to override React components used to render a style guide. ```javascript module.exports = { styleguideComponents: { Logo: path.join(__dirname, 'styleguide/components/Logo'), StyleGuideRenderer: path.join(__dirname, 'styleguide/components/StyleGuide'), }, }; ``` (#504) ### Customizable logging New `logger` option: ```javascript module.exports = { logger: { // One of: info, debug, warn // Suppress messages info: () => {}, // Override display function warn: message => console.warn(`NOOOOOO: ${message}`), }, }; ``` (#472, #510) ## Bug fixes * Allow `devServer.watchConfig` to be configured, this also means Vagrant is now supported (#515, #516 by @esphen) * Default `getExampleFilename` should be case-insensitive (#423, #460, #440, #482) * Allow dynamic JSS styles * Isolate search placeholder styles (#509, #491 by @n1313)
This PR fixes the
getExampleFilenamemethod and re-implements the logic such that the filename can be case-insensitive as requested here: #423 (comment).