feat: add cookbook section with practical recipes for common jscodeshift tasks#716
Open
dashitongzhi wants to merge 3 commits into
Open
feat: add cookbook section with practical recipes for common jscodeshift tasks#716dashitongzhi wants to merge 3 commits into
dashitongzhi 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. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.