Skip to content

Support the Nuxt 4 app directory and custom Storyblok plugins - #152

Merged
marcospassos merged 1 commit into
masterfrom
fix/nuxt-source-directory
Sep 11, 2026
Merged

marcospassos merged 1 commit into
masterfrom
fix/nuxt-source-directory

Conversation

@marcospassos

Copy link
Copy Markdown
Member

The CLI treated the project root as the Nuxt source directory. Nuxt 4 uses app/, and so does Nuxt 3 with future.compatibilityVersion: 4. So croct init wrote plugins/croct-storyblok.ts where Nuxt ignores it, silently disabling the Storyblok integration. It also recorded components and examples paths in croct.json that point at root directories Nuxt never loads, so croct add slot would scaffold files that are never picked up.

Separately, apps that set usePlugin: false and install Storyblok from their own plugin, like Storyblok's demo frontend, crashed on startup on both Nuxt 3 and 4. Nuxt runs application plugins in filename order, so croct-storyblok.ts ran before storyblok.ts and useStoryblokApi() threw.

Changes:

  • PlugNuxtSdk.getPaths() resolves source with Nuxt's own srcDir rules. An explicit srcDir wins. Otherwise Nuxt 4, and Nuxt 3 on compatibility version 4, use app/, unless app/ only holds files Nuxt 3 already kept there and the root still follows the previous layout. Components, utilities and examples derive from it.
  • NuxtConfigParser statically reads srcDir and future.compatibilityVersion from nuxt.config, evaluating constants and template literals. It reuses the config lookup of NuxtConfigModuleCodemod.
  • SDK plugins receive the resolved paths, and NuxtStoryblokPlugin scaffolds the plugin under the source directory.
  • The scaffolded plugin declares name: 'croct-storyblok' and enforce: 'post', so it runs after every regular plugin, whatever that plugin is named. dependsOn can't do this because the @storyblok/nuxt plugin is unnamed.
  • The codemod now leaves files with any default export untouched. Before, it appended a second default export.

croct.json stays at the project root; only the paths it records change.

Both the parser and the codemod are covered at 100% by fixtures.

Validated by running croct init with this build on four fresh apps, then loading each in a headless browser and building for production:

App paths.source Plugin Page renders, Croct requests Build
Nuxt 3, root layout, app-installed Storyblok . plugins/
Nuxt 3, compatibility version 4 app app/plugins/
Nuxt 4 app app/plugins/
Nuxt 4, app-installed Storyblok app app/plugins/

Known limits: a config passed as a variable (defineNuxtConfig(options)) isn't resolved, same as in the module codemod, and a custom dir.plugins isn't honored.

@github-actions

Copy link
Copy Markdown

👋 @marcospassos
Thanks for your contribution!
The approval and merge process is almost fully automated 🧙
Here's how it works:

  1. You open a new pull request
  2. Automated tests check the code
  3. Maintainers review the code
  4. Once approved, the PR is ready to merge.

👉 Omit the extended description
Please remove the commit body before merging the pull request.
Instead, include the pull request number in the title to provide the full context
about the change.

☝️ Lastly, the title for the commit will come from the pull request title. So please provide a descriptive title that summarizes the changes in 50 characters or less using the imperative mood.
Happy coding! 🎉

@marcospassos marcospassos added the bug Something isn't working label Sep 11, 2026
@pkg-pr-new

pkg-pr-new Bot commented Sep 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/croct@152

commit: 9cbea0f

@marcospassos
marcospassos merged commit 4b85528 into master Sep 11, 2026
7 of 9 checks passed
@marcospassos
marcospassos deleted the fix/nuxt-source-directory branch September 11, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant