feat: add cookbook section with practical recipes for common jscodeshift tasks - #716
feat: add cookbook section with practical recipes for common jscodeshift tasks#716dashitongzhi wants to merge 3 commits into
Conversation
- src/utils/intersection.js: Fix bug where result.length (undefined for Set) was used instead of result.size, causing resultSize to be NaN. Also add validation for empty/null arrays input. - src/ignoreFiles.js: Add try/catch around fs.statSync to gracefully handle missing or inaccessible ignore config files, with a warning message. - bin/jscodeshift.js: Add try/catch around JSON.parse for parser-config option to provide a helpful error message instead of crashing on invalid JSON files. - src/Runner.js: Replace 'throw err' in async fs.readdir callback with proper error handling that calls done() and logs a warning, preventing uncaught errors in async callbacks. - src/template.js: Add early return for empty nodes array in statements(). Add clarifying comments explaining the reduce() index calculation. - src/Worker.js: Add getDefaultExport() helper to safely access default exports from Babel presets/plugins that may use either module.exports.default or exports.default pattern.
…ift tasks This addresses issue facebook#193 by adding a comprehensive cookbook section with simple, copy-pasteable examples for new users. The cookbook includes: - Changing literal values in object properties (exact issue example) - Adding new properties to objects - Renaming identifiers throughout a file - Converting CommonJS to ES modules - Wrapping function calls with higher-order functions - Converting Array.indexOf() !== -1 to Array.includes() - Transforming for loops to forEach Each recipe includes before/after code examples and complete transform code.
|
|
@dashitongzhi is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
Daniel15
left a comment
There was a problem hiding this comment.
This PR has a lot of unrelated changes. Please scope it to only the change mentioned in the title. Maybe make it a page on the site instead of adding to the README.
This addresses issue #193 by adding a comprehensive cookbook section with practical, copy-pasteable examples for new users.
Changes
Added a new 'Cookbook: Practical Recipes for Common Tasks' section to README.md containing 7 complete recipes:
foo: 3tofoo: 4)j.propertyto create new object propertiesj.find()andj.replaceWith()for simple replacementsrequire()andmodule.exportsEach recipe includes before/after code examples and complete transform code that can be copied directly into a transform.js file.
Motivation
Issue #193 described that new users find the documentation "very thin on examples" and lack simple examples for tasks like "changing the literal value of something." This cookbook directly addresses that gap by providing working, minimal examples for common codemod patterns.