Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f1c3b9a
feat: add jssg codemod scripts and test cases
ShadiBitaraf Sep 30, 2025
55ca68e
feat: add shared utils to reduce code duplication
ShadiBitaraf Sep 30, 2025
19a2f8f
config: add codemod workflow and build setup
ShadiBitaraf Sep 30, 2025
aa744bb
feat: add comprehensive test runner
ShadiBitaraf Sep 30, 2025
7836638
docs: add readme and gitignore
ShadiBitaraf Sep 30, 2025
f2524b2
cleanup: remove individual codemod directories after consolidation
ShadiBitaraf Sep 30, 2025
553dfd2
fix: add .js extensions to imports and improve type safety for jssg c…
ShadiBitaraf Sep 30, 2025
08fe5e3
refactor: split utils into focused modules and improve import management
ShadiBitaraf Sep 30, 2025
3046c8d
feat: replace mock test runner with actual codemod execution testing
ShadiBitaraf Sep 30, 2025
32e2835
config: update build setup for jssg compatibility
ShadiBitaraf Sep 30, 2025
23c3e7e
fix: update expected output to reflect node:path import fix
ShadiBitaraf Sep 30, 2025
e5b3155
docs: restructure README with clear and concise bullet points of tran…
ShadiBitaraf Sep 30, 2025
3df4f78
feat: add import management utilities for AST-grep codemods
ShadiBitaraf Oct 10, 2025
5a36e31
feat: test suite for different cases the import utils functionality c…
ShadiBitaraf Oct 10, 2025
7629aba
feat: new and improved import utils source code
ShadiBitaraf Oct 10, 2025
e5b37a2
fix(import-utils): handle mixed type/runtime imports correctly
ShadiBitaraf Oct 10, 2025
8311e5b
refactor(absolute-watch-path): improved AST handling
ShadiBitaraf Oct 10, 2025
9524617
chore: standardize imports and clean up unused code
ShadiBitaraf Oct 10, 2025
4b81d7d
refactor(template-compilation-changes): migrate from regex to AST-bas…
ShadiBitaraf Oct 10, 2025
8b78270
test: update expected outputs to match JSSG codemod behavior
ShadiBitaraf Oct 10, 2025
c48b25c
refactor: convert string op to ast grep based detection
ShadiBitaraf Oct 10, 2025
7da73d8
docs: add import-utils testing commands to README
ShadiBitaraf Oct 10, 2025
d1e9894
refactor(utils): remove unused files and code, consolidate DATA_FETCH…
ShadiBitaraf Oct 13, 2025
581b15b
refactor: add Vue file support to jssg codemods
ShadiBitaraf Oct 17, 2025
4c2825a
feat: add Vue parsing to absolute-watch-path and enhance import utili…
ShadiBitaraf Oct 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added codemods/v4/.gitignore
Empty file.
57 changes: 57 additions & 0 deletions codemods/v4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Nuxt v3 to v4 Migration Codemod

This codemod migrates your project from Nuxt v3 to v4, handling the breaking changes:

- Updates `nuxt.hook('builder:watch')` calls to use absolute paths with proper path normalization
- Transforms null checks to undefined for data fetching variables (`useAsyncData`, `useFetch`)
- Converts deprecated boolean `dedupe` values to new string format in `refresh()` calls
- Adds `{ deep: true }` option to data fetching hooks that need deep reactivity
- Modernizes `addTemplate` calls from `src` property to `getContents` function pattern

## Installation

```bash
# Install and run the codemod
npx codemod@latest run @nuxt-v3-to-v4

# Or run locally
npx codemod@latest run -w workflow.yaml --target /path/to/your/project --allow-dirty
```

## Important Notes

⚠️ **Backup First**: This codemod modifies code! Run it only on Git-tracked files, and commit or stash changes first.

⚠️ **Path Normalization**: The `absolute-watch-path` transformation assumes standard Nuxt project structure. Custom watch path handling may need manual adjustment.

⚠️ **Data Fetching Variables**: If you have custom null checking logic beyond simple equality comparisons, you may need to adjust these manually.

⚠️ **Complete Migration**: This codemod performs all necessary transformations in the correct order to ensure your code properly migrates to Nuxt v4.

## Testing Import Utils

Test the `ensureImport` utility function with various scenarios. Navigate to `codemods/v4/` and run:

```bash
# Replace case-X with: case-1-add-empty-file, case-2-no-action-exists, ...

# Test basic import scenarios (cases 1-5, 8-9)
codemod jssg run --language typescript --target tests/import-utils/case-X/input.ts tests/import-utils/test-runner.ts

# Test type to runtime conversion (case 6)
codemod jssg run --language typescript --target tests/import-utils/case-6-mixed-type-to-runtime/input.ts tests/import-utils/case-6-type-to-runtime-test.ts

# Test runtime to type conversion (case 7)
codemod jssg run --language typescript --target tests/import-utils/case-7-mixed-runtime-to-type/input.ts tests/import-utils/case-7-runtime-to-type-test.ts

```

**Verify results:** Compare output with the `expected.ts` file in each test directory.

## Resources

- [Nuxt v4 Migration Guide](https://nuxt.com/docs/getting-started/upgrade#nuxt-4)

## License

MIT
19 changes: 0 additions & 19 deletions codemods/v4/absolute-watch-path/.codemodrc.json

This file was deleted.

2 changes: 0 additions & 2 deletions codemods/v4/absolute-watch-path/.gitignore

This file was deleted.

9 changes: 0 additions & 9 deletions codemods/v4/absolute-watch-path/LICENSE

This file was deleted.

28 changes: 0 additions & 28 deletions codemods/v4/absolute-watch-path/README.md

This file was deleted.

This file was deleted.

This file was deleted.

20 changes: 0 additions & 20 deletions codemods/v4/absolute-watch-path/package.json

This file was deleted.

138 changes: 0 additions & 138 deletions codemods/v4/absolute-watch-path/src/index.ts

This file was deleted.

24 changes: 0 additions & 24 deletions codemods/v4/absolute-watch-path/tsconfig.json

This file was deleted.

7 changes: 0 additions & 7 deletions codemods/v4/absolute-watch-path/vitest.config.ts

This file was deleted.

20 changes: 20 additions & 0 deletions codemods/v4/codemod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
schema_version: "1.0"

name: "@nuxt-v3-to-v4"
version: "1.0.0"
description: "Complete migration toolkit for Nuxt 3 to Nuxt 4"
author: "Shadi Bitaraf <bitarafshh@gmail.com>"
license: "MIT"
workflow: "workflow.yaml"
category: "migration"
repository: "https://github.com/codemod/nuxt-codemods"

targets:
languages: ["typescript"]

keywords: ["nuxt", "breaking-change", "migration", "nuxt-v4", "nuxt-v3-to-v4"]

registry:
access: "public"
visibility: "public"

33 changes: 0 additions & 33 deletions codemods/v4/default-data-error-value/.gitignore

This file was deleted.

Loading