Skip to content

Wire Nuxt init logging#726

Merged
dahlia merged 1 commit intofedify-dev:mainfrom
dahlia:bugfix/fedify-init-nuxt
Apr 25, 2026
Merged

Wire Nuxt init logging#726
dahlia merged 1 commit intofedify-dev:mainfrom
dahlia:bugfix/fedify-init-nuxt

Conversation

@dahlia
Copy link
Copy Markdown
Member

@dahlia dahlia commented Apr 25, 2026

Summary

This fixes #724 by wiring the logging configuration generated by fedify init -w nuxt into the generated Nuxt/Nitro runtime.

Previously, server/logging.ts was generated but never imported, so LogTape configuration did not run and Fedify logs stayed silent in generated Nuxt apps. The Nuxt template now generates a Nitro server plugin at server/plugins/logging.ts that imports and awaits the logging setup during Nitro startup.

Changes

  • Added a Nuxt-specific logging template at packages/init/src/templates/nuxt/server/logging.ts.tpl.
  • Changed that template to default-export the configure(...) promise instead of using top-level await.
  • Added packages/init/src/templates/nuxt/server/plugins/logging.ts.tpl to await the logging setup from a Nitro plugin.
  • Allowed framework initializers to override the default logging template.
  • Added a regression test that verifies generated Nuxt projects include the logging plugin and avoid top-level await configure(...).

Verification

  • deno test -A packages/init/src/action/configs.test.ts
  • deno task -f @fedify/init check
  • mise run test:init -- -w nuxt -p npm -k in-memory -m in-process --no-dry-run

Generate a Nuxt-specific logging template that exports the LogTape
configuration promise without top-level await.  Add a Nitro server plugin
to await that promise during startup so generated Nuxt apps actually enable
Fedify logging.

Allow framework initializers to override the default logging template and
cover the Nuxt wiring with a generated-file regression test.

Fixes fedify-dev#724

Assisted-by: Codex:gpt-5.5
@dahlia dahlia added this to the Fedify 2.2 milestone Apr 25, 2026
@dahlia dahlia requested a review from 2chanhaeng April 25, 2026 06:44
@dahlia dahlia self-assigned this Apr 25, 2026
@dahlia dahlia added component/cli CLI tools related component/build Build system and packaging integration/nuxt Nuxt integration (@fedify/nuxt) labels Apr 25, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 25, 2026

📝 Walkthrough

Walkthrough

The changes implement Nuxt-specific logging wiring by adding optional loggingTemplate support to framework initializers, creating Nuxt logging configuration and Nitro plugin templates that initialize Logtape without top-level await, and updating the Nuxt scaffolding to generate and wire these templates into the runtime.

Changes

Cohort / File(s) Summary
Test Infrastructure
packages/init/src/action/configs.test.ts
Adds a new async test that generates a Nuxt init project and validates logging wiring: verifies server/logging.ts exports configure( without await configure(, and server/plugins/logging.ts imports and awaits loggingConfigured. Includes createNuxtNpmInitData helper to construct test initialization data.
Core Infrastructure
packages/init/src/types.ts, packages/init/src/action/templates.ts
Extends WebFrameworkInitializer interface with optional loggingTemplate?: string property. Updates loadLogging function to accept initializer parameter and use initializer.loggingTemplate with fallback to default path.
Nuxt Logging Templates
packages/init/src/templates/nuxt/server/logging.ts.tpl, packages/init/src/templates/nuxt/server/plugins/logging.ts.tpl
Adds Logtape configuration template that exports a Promise<void> (avoiding top-level await for Nitro ES2019 compatibility), and a Nitro plugin template that imports and awaits the logging configuration at server startup.
Nuxt Scaffolding
packages/init/src/webframeworks/nuxt.ts
Specifies loggingTemplate path in Nuxt scaffolding configuration and adds rendering of the new Nitro logging plugin file at server/plugins/logging.ts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

  • Add Nuxt as a web framework option in fedify init #675: This PR extends the Nuxt scaffolding foundation added in PR #675 by introducing framework-specific template selection, Nuxt logging templates, and plugin generation that ensure logging configuration is properly initialized at runtime.

Suggested labels

type/bug

Suggested reviewers

  • 2chanhaeng
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Wire Nuxt init logging' clearly and specifically describes the main objective of the PR: adding logging wiring to Nuxt initialization.
Description check ✅ Passed The description is directly related to the changeset, detailing how logging configuration is wired into generated Nuxt projects through new templates and plugin setup.
Linked Issues check ✅ Passed The PR fully addresses issue #724 by implementing all required coding changes: adding Nuxt-specific logging templates, enabling template override, and wiring the plugin during startup.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing issue #724: new templates, template override support, Nuxt scaffolding updates, and regression tests for the logging wire-up.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@issues-auto-labeler issues-auto-labeler Bot added the component/integration Web framework integration label Apr 25, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for custom logging templates in the project initializer, specifically implementing it for the Nuxt framework. It adds a new loggingTemplate field to the WebFrameworkInitializer interface, updates the loadLogging function to utilize this template, and provides the necessary templates and Nitro plugin for Nuxt logging. Additionally, a new test case has been added to verify the correct wiring of Nuxt logging. I have no feedback to provide.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/init/src/action/templates.ts (1)

34-47: 🧹 Nitpick | 🔵 Trivial

Update stale JSDoc for loadLogging.

The doc still says "Reads the default logging template" and "Destructured object containing the project name", but the function now also accepts initializer and selects between framework-specific and default templates.

📝 Proposed JSDoc update
 /**
  * Loads the logging configuration file content from template.
- * Reads the default logging template and replaces the project name placeholder.
+ * Reads the logging template specified by `initializer.loggingTemplate`
+ * (falling back to `defaults/logging.ts`) and replaces the project name
+ * placeholder.
  *
- * `@param` param0 - Destructured object containing the project name
+ * `@param` param0 - InitCommandData containing the project name and initializer
  * `@returns` The complete logging configuration file content as a string
  */
 export const loadLogging = async (
   { projectName, initializer }: InitCommandData,
 ) =>

As per coding guidelines: "Include JSDoc comments for public APIs in all code".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/init/src/action/templates.ts` around lines 34 - 47, The JSDoc for
loadLogging is outdated: update the comment to reflect that the function accepts
an InitCommandData containing projectName and initializer, and that it reads a
framework-specific template when initializer.loggingTemplate is provided
(falling back to "defaults/logging.ts"), then replaces the project name
placeholder; reference the function name loadLogging, param type
InitCommandData, and helper readTemplate/loggingTemplate in the description and
param explanation so the public API docs accurately describe behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/init/src/action/configs.test.ts`:
- Around line 192-223: createNuxtNpmInitData and createNpmInitData are
duplicated; refactor by introducing a parameterized helper (eg.
createInitDataFor) that accepts a WebFrameworkDescription (description), a
WebFramework (webFramework) and dir, builds the shared base init args, calls
description.init(base) to get initializer, and returns the combined object
satisfying InitCommandData (including kv: kvStores["in-memory"], mq:
messageQueues["in-process"], env: {}). Replace createNuxtNpmInitData and
createNpmInitData to call this helper with the appropriate description and
webFramework values.

---

Outside diff comments:
In `@packages/init/src/action/templates.ts`:
- Around line 34-47: The JSDoc for loadLogging is outdated: update the comment
to reflect that the function accepts an InitCommandData containing projectName
and initializer, and that it reads a framework-specific template when
initializer.loggingTemplate is provided (falling back to "defaults/logging.ts"),
then replaces the project name placeholder; reference the function name
loadLogging, param type InitCommandData, and helper readTemplate/loggingTemplate
in the description and param explanation so the public API docs accurately
describe behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7d89ee85-9071-439e-98b6-574f246ce81f

📥 Commits

Reviewing files that changed from the base of the PR and between 1764300 and 1692097.

📒 Files selected for processing (6)
  • packages/init/src/action/configs.test.ts
  • packages/init/src/action/templates.ts
  • packages/init/src/templates/nuxt/server/logging.ts.tpl
  • packages/init/src/templates/nuxt/server/plugins/logging.ts.tpl
  • packages/init/src/types.ts
  • packages/init/src/webframeworks/nuxt.ts

Comment on lines +192 to +223
async function createNuxtNpmInitData(dir: string): Promise<InitCommandData> {
const initializer = await nuxtDescription.init({
command: "init",
projectName: "example",
packageManager: "npm",
webFramework: "nuxt",
kvStore: "in-memory",
messageQueue: "in-process",
dryRun: false,
allowNonEmpty: false,
testMode: false,
dir,
});

const data = {
command: "init",
projectName: "example",
packageManager: "npm",
webFramework: "nuxt",
kvStore: "in-memory",
messageQueue: "in-process",
dryRun: false,
allowNonEmpty: false,
testMode: false,
dir,
initializer,
kv: kvStores["in-memory"],
mq: messageQueues["in-process"],
env: {},
} satisfies InitCommandData;
return data;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Optional: factor out shared init-data construction.

createNuxtNpmInitData and createNpmInitData differ only in webFramework and the initializer source. Consider parameterizing a single helper to reduce duplication as more framework-specific tests are added.

♻️ Sketch of a parameterized helper
async function createInitDataFor(
  description: WebFrameworkDescription,
  webFramework: WebFramework,
  dir: string,
): Promise<InitCommandData> {
  const base = {
    command: "init" as const,
    projectName: "example",
    packageManager: "npm" as const,
    webFramework,
    kvStore: "in-memory" as const,
    messageQueue: "in-process" as const,
    dryRun: false,
    allowNonEmpty: false,
    testMode: false,
    dir,
  };
  const initializer = await description.init(base);
  return {
    ...base,
    initializer,
    kv: kvStores["in-memory"],
    mq: messageQueues["in-process"],
    env: {},
  } satisfies InitCommandData;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/init/src/action/configs.test.ts` around lines 192 - 223,
createNuxtNpmInitData and createNpmInitData are duplicated; refactor by
introducing a parameterized helper (eg. createInitDataFor) that accepts a
WebFrameworkDescription (description), a WebFramework (webFramework) and dir,
builds the shared base init args, calls description.init(base) to get
initializer, and returns the combined object satisfying InitCommandData
(including kv: kvStores["in-memory"], mq: messageQueues["in-process"], env: {}).
Replace createNuxtNpmInitData and createNpmInitData to call this helper with the
appropriate description and webFramework values.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

Files with missing lines Coverage Δ
packages/init/src/action/templates.ts 94.11% <100.00%> (+0.11%) ⬆️
packages/init/src/webframeworks/nuxt.ts 78.87% <100.00%> (+62.69%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@2chanhaeng 2chanhaeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! However, I'm wondering if "nuxt/server/logging.ts" is the right approach. It might be worth exploring a more versatile method in case we encounter other frameworks where top-level await isn't possible – I hope NOT, but who knows? 😂 Since it's not an urgent requirement, we can discuss this later.

@dahlia dahlia merged commit 0d42b18 into fedify-dev:main Apr 25, 2026
17 checks passed
@dahlia dahlia deleted the bugfix/fedify-init-nuxt branch April 25, 2026 07:39
dahlia added a commit to dahlia/fedify-fork that referenced this pull request Apr 27, 2026
Two follow-ups for the upstream init template change in
fedify-dev#726:

 -  Chapter 2 now lists *server/plugins/logging.ts* alongside
    *server/logging.ts*, with a one-line explanation of how the
    Nitro plugin awaits the configuration promise.
 -  Chapter 10's *Follow* listener now sets an explicit `id` on
    the outbound `Accept`, matching the example repository.  A new
    bullet in the walkthrough calls out why the explicit id matters
    for Pixelfed compatibility, even though Fedify can auto-generate
    one.

Assisted-by: Claude Code:claude-opus-4-7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/build Build system and packaging component/cli CLI tools related component/integration Web framework integration integration/nuxt Nuxt integration (@fedify/nuxt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fedify init -w nuxt scaffolds server/logging.ts but never imports it, leaving Fedify silent

2 participants