-
Notifications
You must be signed in to change notification settings - Fork 0
Migrate remaining jscodeshift to jssg #4
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
base: main
Are you sure you want to change the base?
Conversation
- Add 5 codemod scripts for nuxt v3 to v4 migration - Add comprehensive test cases with input/expected outputs - Cover absolute-watch-path, data-error-value, dedupe-value, reactivity, template changes
- Add codemod-utils for common transformations - Add import-utils for import management - Add nuxt-patterns for reusable AST patterns - Add test-utils for testing helpers
- Add codemod.yaml with metadata and registry config - Add workflow.yaml with 5-step transformation pipeline - Add package.json with jssg dependencies and npm scripts - Add tsconfig.json for typescript compilation
- Add npm test command to validate all codemods - Check file structure, imports, and syntax - Provide developer-friendly test output and instructions
- Add comprehensive documentation for codemod usage - Add gitignore for node_modules and build artifacts
…ompatibility - All codemod scripts now use proper ES module imports with .js extensions - Added missing Edit type imports for better type safety - Improved type annotations and fixed TypeScript strict mode issues
- Created ast-utils.ts with core AST manipulation functions (hasContent, applyEdits, findFunctionCalls, etc.) - Completely rewrote import-utils.ts with better import analysis and management capabilities - Restructured nuxt-patterns.ts to use constants and cleaner pattern definitions - Removed unused codemod-utils.ts and test-utils.ts files - Updated index.ts to export from new focused module structure - Improved TypeScript generics and type safety throughout utils
…sformations, proper installation instructions, focused important notes about edge cases, and links to official Nuxt v4 migration resources
codemods/v4/utils/ast-utils.ts
Outdated
/** | ||
* Quick check if file contains specific content before processing | ||
*/ | ||
export function hasContent<T extends Record<string, any>>( |
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.
export function hasContent<T extends Record<string, any>>( | |
export function hasContent<T extends TypesMap>( |
if (!hasAnyContent(root, DATA_FETCH_HOOKS)) { | ||
return null; | ||
} |
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.
We shouldn't encourage string ops, and this is a bad practice imo. This is also a duplicate check. You're already performing an ast-based search later.
} | ||
|
||
// Extract data and error variable names from destructuring | ||
const dataErrorVars = new Set<string>(); |
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.
This shouldn't be file-wide.
Imagine you have:
function X() {
const { data: listData, error: listError } = useFetch(
() => client.value.v1.lists.fetch(),
{
default: () => shallowRef(),
}
);
}
function Y() {
const listData = ...
if (userData.value === null) {
}
}
listData is marked as dataErrorVar
in the entire file, while in function Y, we don't care about this var.
- Implement ensureImport() for import detection and insertion - Support both named and default imports with type/runtime distinction - Handle import deduplication, quote style detection, and alias resolution
- Fix AST parsing for import_clause and named_imports fields - Add logic to distinguish type conversion vs mixed import scenarios - Preserve existing imports when adding different import types
- Reduce string ops to proper AST node replacement as much as possible - Use ensureImport utility for cleaner import management - Fix import placement to avoid duplicate imports
- Change all import paths from .js to .ts extensions for consistency - Remove comprehensive-test-runner.ts (it was unnessary) - Update TypeScript types from Record<string, any> to proper TypesMap - Remove tsconfig exclude patterns that are no longer needed - Migrate template-compilation-changes to proper AST manipulation with ensureImport - Remove redundant content checks that were causing false negatives
…ed transformation - Replace fragile regex matching with proper AST node traversal - Use ensureImport utility for reliable import management instead of manual string manipulation
- Fix absolute-watch-path expected formatting to use consistent multi-line style - Remove duplicate imports from template-compilation-changes expected output
…_HOOKS, and rename import-utils to imports
…ties (although its functional but its WIP)
Overview
Official Nuxt codemods for migrating from v3 to v4, automating breaking change transformations through 5 specialized codemods that handle API updates and deprecated patterns.
Key Features
nuxt.hook('builder:watch')
to use absolute pathsundefined
foruseAsyncData
/useFetch
, adds{ deep: true }
optionsaddTemplate
fromsrc
property togetContents
functiondedupe
values to string format inrefresh()
callsnpx codemod@latest @nuxt-v3-to-v4
Impact
Files Modified
ast-utils.ts
,import-utils.ts
,nuxt-patterns.ts
)codemod.yaml
,workflow.yaml
,package.json
for Registry integration