Wire Nuxt init logging#726
Conversation
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
📝 WalkthroughWalkthroughThe changes implement Nuxt-specific logging wiring by adding optional Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 | 🔵 TrivialUpdate 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
initializerand 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
📒 Files selected for processing (6)
packages/init/src/action/configs.test.tspackages/init/src/action/templates.tspackages/init/src/templates/nuxt/server/logging.ts.tplpackages/init/src/templates/nuxt/server/plugins/logging.ts.tplpackages/init/src/types.tspackages/init/src/webframeworks/nuxt.ts
| 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; | ||
| } |
There was a problem hiding this comment.
🧹 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 Report✅ All modified and coverable lines are covered by tests.
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
2chanhaeng
left a comment
There was a problem hiding this comment.
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.
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
Summary
This fixes #724 by wiring the logging configuration generated by
fedify init -w nuxtinto 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
configure(...)promise instead of using top-levelawait.await configure(...).Verification
deno test -A packages/init/src/action/configs.test.tsdeno task -f @fedify/init checkmise run test:init -- -w nuxt -p npm -k in-memory -m in-process --no-dry-run