Fix @fedify/nuxt runtime packaging and fedify init scaffolding edge cases#717
Fix @fedify/nuxt runtime packaging and fedify init scaffolding edge cases#717dahlia wants to merge 8 commits intofedify-dev:mainfrom
@fedify/nuxt runtime packaging and fedify init scaffolding edge cases#717Conversation
Build the Nuxt server runtime files as tsdown entry points and point the Nuxt module at the generated JavaScript under dist. This keeps installed consumers from feeding TypeScript runtime sources into Nitro's Rollup pipeline. Add a package-level self-import test so the Node test path exercises @fedify/nuxt through the package exports and catches missing built runtime files before publishing. Fixes fedify-dev#716 Assisted-by: Codex:gpt-5.4
Generated projects now use the Biome 2 configuration shape for import organization, matching the @biomejs/biome version installed by fedify init. Add a scaffold-level regression test that creates an npm project and checks the generated Biome schema version against the exact installed Biome package version. fedify-dev#716 Assisted-by: Codex:gpt-5.4
Treat a target directory that only contains a freshly initialized Git repository as empty, while still rejecting repositories whose HEAD resolves to a commit or whose .git metadata shows existing refs. Add regression coverage for unborn repositories, committed repositories, packed refs, detached HEADs, .git files, and additional project files. fedify-dev#716 Assisted-by: Codex:gpt-5.4
Allow fedify init to run in non-empty directories when explicitly requested, but check the files Fedify would generate before running any framework scaffolding command. The command now fails before making changes if a generated file already exists, so unrelated files can coexist without accidental merges or appends. Document the option and add regression coverage for the conflict checks. fedify-dev#716 Assisted-by: Codex:gpt-5.4
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds a new --allow-non-empty init option with a preflight check that errors if would-be-generated files already exist, refines empty-directory detection to treat unborn Git repos as empty, updates generated Biome config to Biome 2 layout, and switches Nuxt runtime imports to built distribution artifacts. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant CLI as "fedify init CLI"
participant fillDir as "fillDir"
participant assertConflicts as "assertNoGeneratedFileConflicts"
participant FS as "FileSystem"
participant Init as "Init Handler"
User->>CLI: run with --allow-non-empty
CLI->>fillDir: call with allowNonEmpty=true
fillDir->>CLI: return selected dir (skip prompt)
CLI->>assertConflicts: run preflight check
assertConflicts->>FS: stat/access deduped generated paths
alt conflicts found
assertConflicts-->>CLI: throw GeneratedFileConflictError (list paths)
CLI-->>User: surface error and abort
else no conflicts
assertConflicts->>Init: proceed
Init->>FS: write generated files (e.g., biome.json, package.json)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
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 |
|
@codex review |
There was a problem hiding this comment.
Code Review
This pull request introduces the --allow-non-empty option to fedify init, allowing project initialization in non-empty directories while preventing overwrites of existing files. It also refines directory checks to treat freshly initialized Git repositories as empty and updates the generated Biome configuration to version 2 syntax. Furthermore, the Nuxt integration is updated to resolve runtime modules from the compiled dist directory. Feedback was provided to optimize file conflict detection by parallelizing asynchronous checks and simplifying path handling.
There was a problem hiding this comment.
Pull request overview
This PR fixes a packaging regression in @fedify/nuxt that caused Nitro to bundle TypeScript runtime sources from node_modules, and it improves fedify init scaffolding to better handle non-empty directories, align generated Biome config with Biome 2, and support non-interactive workflows (closes #716).
Changes:
- Bundle Nuxt runtime server entrypoints into
dist/runtime/server/*and resolve Nitro middleware/plugin paths from built output. - Update
fedify initto (a) treat “.git-only unborn repos” as empty, and (b) add--allow-non-emptywith preflight conflict detection. - Update generated
biome.jsonto Biome 2 syntax and add regression tests ensuring schema/package version alignment.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/nuxt/tsdown.config.ts | Adds runtime server files as build entrypoints so compiled JS lands under dist/runtime/server/. |
| packages/nuxt/src/package.test.ts | Adds a regression test ensuring module registration references dist/runtime/... and not src/runtime. |
| packages/nuxt/src/module.ts | Resolves middleware/plugin paths via ../dist/runtime/server/*.js for Nitro integration. |
| packages/nuxt/src/module.test.ts | Adds coverage for resolveRuntimeServerPath() to ensure compiled-runtime resolution behavior. |
| packages/nuxt/package.json | Stops shipping src/runtime/ and ensures tests run against built output via pretest. |
| packages/init/src/package.test.ts | Updates init package test data to include the new allowNonEmpty flag. |
| packages/init/src/lib.ts | Enhances emptiness detection to treat only unborn .git-only repos as “empty”. |
| packages/init/src/lib.test.ts | Adds tests for the unborn Git repo detection behavior. |
| packages/init/src/json/biome.json | Updates the scaffolded Biome config to Biome 2 schema and assist.actions.source.organizeImports. |
| packages/init/src/command.ts | Adds --allow-non-empty to the fedify init CLI options. |
| packages/init/src/ask/dir.ts | Skips the non-empty directory prompt when --allow-non-empty is set. |
| packages/init/src/action/patch.ts | Adds preflight detection to fail if any would-be generated files already exist when --allow-non-empty is used. |
| packages/init/src/action/patch.test.ts | Adds tests for the generated-file conflict preflight behavior. |
| packages/init/src/action/mod.ts | Wires the conflict preflight into the hydrated (non-dry-run) init flow. |
| packages/init/src/action/configs.test.ts | Adds a regression test that schema version in biome.json matches the installed @biomejs/biome version. |
| docs/cli.md | Documents the new --allow-non-empty option and its behavior. |
| CHANGES.md | Adds changelog entries for the init behavior changes and links #716/#717. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fee5abcfbe
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Parallelize generated-file conflict checks while preserving path splitting for Windows-compatible path joins. Treat any existing Git ref as evidence that a .git-only directory is not fresh, including refs outside the current HEAD branch and any packed ref. References fedify-dev#717 (comment) References fedify-dev#717 (comment) Assisted-by: Codex:gpt-5.4
|
@codex review |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces the --allow-non-empty option to fedify init, enabling project initialization in non-empty directories while ensuring existing files that would be generated are not overwritten. It also updates the isDirectoryEmpty logic to recognize unborn Git repositories as empty and migrates the generated Biome configuration to version 2 syntax. Furthermore, the Nuxt integration is updated to resolve runtime server files from the distribution directory. Feedback was provided to ensure npm package names in the documentation follow the project's convention of using italics instead of backticks.
|
Codex Review: Didn't find any major issues. What shall we delve into next? ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Codecov Report❌ Patch coverage is
... and 8 files with indirect coverage changes 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
CHANGES.md (1)
136-147:⚠️ Potential issue | 🟡 MinorAdd the missing
@fedify/nuxtpackaging fix entry.This PR also fixes the published Nuxt package/runtime entrypoint contract, but the unreleased changelog only documents the
@fedify/initside. Please add a user-facing@fedify/nuxtentry and keep the first-use link definitions with that section.📝 Proposed changelog addition
### `@fedify/nuxt` - Added `@fedify/nuxt` package for integrating Fedify with [Nuxt]. It provides a Nuxt module that delegates non-federation requests to Nuxt, supports shared-route content negotiation, and returns deferred `406 Not Acceptable` when Fedify routes are requested without ActivityPub-compatible `Accept` headers and Nuxt has no matching page. [[`#149`], [`#674`] by ChanHaeng Lee] + - Fixed the published `@fedify/nuxt` package so its Nuxt module and Nitro + runtime middleware load compiled *dist/* JavaScript instead of TypeScript + source files. This restores imports from the built package output in + Node.js package consumers. [[`#716`], [`#717`]] + [Nuxt]: https://nuxt.com/ [`#149`]: https://github.com/fedify-dev/fedify/issues/149 [`#674`]: https://github.com/fedify-dev/fedify/pull/674 +[`#716`]: https://github.com/fedify-dev/fedify/issues/716 +[`#717`]: https://github.com/fedify-dev/fedify/pull/717 @@ -[`#716`]: https://github.com/fedify-dev/fedify/issues/716 -[`#717`]: https://github.com/fedify-dev/fedify/pull/717As per coding guidelines, “Update
CHANGES.mdwith the issue number, PR number, and your name when fixing bugs.”Also applies to: 182-183
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@CHANGES.md` around lines 136 - 147, Update CHANGES.md to add a user-facing packaging fix entry under the `@fedify/nuxt` section describing the Nuxt package/runtime entrypoint contract fix (include the related issue number, PR number, and your name as per guidelines), and ensure the first-use link definitions for [Nuxt], [`#149`], and [`#674`] are present with that section; also apply the same packaging-fix entry to the corresponding nearby lines referenced (the other occurrence around lines 182-183) so both places document the fix consistently.packages/init/src/action/patch.ts (1)
47-154: 🧹 Nitpick | 🔵 TrivialPre-flight conflict detection looks correct; minor nit on path splitting.
Logic and error reporting are solid: gated on
allowNonEmpty, de-duped viaSet, parallelized withPromise.all, and ENOENT correctly classified viathrowUnlessNotExists.Nit (non-blocking):
path.split("/")at Line 131 assumes generated paths always use forward slashes. Today that holds because initializer file keys and.env/framework files use/, but somedevToolConfigsentries are built viajoinPath(".vscode", "extensions.json"), which is OS-dependent. On the current Unix-only dev/test environment this is fine, but a future Windows-capable run would silently produce a single un-split segment. Consider usingjoinPath(data.dir, path)directly (Node'spath.joinalready normalizes forward slashes on POSIX and handles either separator on Windows), e.g.:Suggested simplification
- const exists = await pathExists(joinPath(data.dir, ...path.split("/"))); + const exists = await pathExists(joinPath(data.dir, path));🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/init/src/action/patch.ts` around lines 47 - 154, The path-splitting in getExistingGeneratedFiles uses path.split("/") which assumes forward slashes; change the existence check to call joinPath(data.dir, path) directly (instead of joinPath(data.dir, ...path.split("/"))) so OS-native separators from entries produced by joinPath (e.g., devToolConfigs) are handled correctly; update the map in getExistingGeneratedFiles to use joinPath(data.dir, path) and keep the rest of the logic (paths, Promise.all, pathExists) intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@CHANGES.md`:
- Around line 157-160: Update the CHANGES.md entry for "Fixed `fedify init`" to
explicitly mention that Git refs/packed-refs are treated as non-empty: clarify
that directories where .git contains refs (including packed-refs) are considered
non-empty even if HEAD is unborn, and only a directory with a freshly
initialized Git repo with no refs and no files outside *.git* is treated as
empty; keep the user-facing tone (what changed, why, and what users should do)
and reference the `fedify init` behavior and Git refs/packed-refs in the
description.
In `@packages/init/src/lib.ts`:
- Around line 257-262: The parseHeadRef function currently parses and returns a
ref string but callers (looksLikeUnbornGitRepository) only test for null, so the
actual branch name is unused; either make parseHeadRef a boolean predicate
(e.g., isHeadRefValid) and update callers to use the boolean, or keep
parseHeadRef returning the ref and modify looksLikeUnbornGitRepository to use
the returned ref to directly check the exact branch file (refs/heads/<branch>)
before falling back to loose-ref scanning; update calls and tests accordingly
and keep the unique symbols parseHeadRef and looksLikeUnbornGitRepository in
mind when making the change.
---
Outside diff comments:
In `@CHANGES.md`:
- Around line 136-147: Update CHANGES.md to add a user-facing packaging fix
entry under the `@fedify/nuxt` section describing the Nuxt package/runtime
entrypoint contract fix (include the related issue number, PR number, and your
name as per guidelines), and ensure the first-use link definitions for [Nuxt],
[`#149`], and [`#674`] are present with that section; also apply the same
packaging-fix entry to the corresponding nearby lines referenced (the other
occurrence around lines 182-183) so both places document the fix consistently.
In `@packages/init/src/action/patch.ts`:
- Around line 47-154: The path-splitting in getExistingGeneratedFiles uses
path.split("/") which assumes forward slashes; change the existence check to
call joinPath(data.dir, path) directly (instead of joinPath(data.dir,
...path.split("/"))) so OS-native separators from entries produced by joinPath
(e.g., devToolConfigs) are handled correctly; update the map in
getExistingGeneratedFiles to use joinPath(data.dir, path) and keep the rest of
the logic (paths, Promise.all, pathExists) intact.
🪄 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: fb2572f6-a229-45f5-8e26-6b042a93819c
📒 Files selected for processing (17)
CHANGES.mddocs/cli.mdpackages/init/src/action/configs.test.tspackages/init/src/action/mod.tspackages/init/src/action/patch.test.tspackages/init/src/action/patch.tspackages/init/src/ask/dir.tspackages/init/src/command.tspackages/init/src/json/biome.jsonpackages/init/src/lib.test.tspackages/init/src/lib.tspackages/init/src/package.test.tspackages/nuxt/package.jsonpackages/nuxt/src/module.test.tspackages/nuxt/src/module.tspackages/nuxt/src/package.test.tspackages/nuxt/tsdown.config.ts
Clarify the changelog wording for Git refs in freshly initialized repositories, simplify HEAD ref validation to a boolean predicate, and use path.join() directly when checking generated-file conflicts. References fedify-dev#717 (comment) References fedify-dev#717 (comment) References fedify-dev#717 (comment) Assisted-by: Codex:gpt-5.4
|
Regarding the CodeRabbit outside-diff suggestions in #717 (comment): I did not add an @fedify/nuxt changelog entry because @fedify/nuxt has not had a formal release yet. The path-joining nit was fixed in 53dc63c by using |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/lib.ts`:
- Around line 240-253: The function looksLikeUnbornGitRepository currently only
checks refs and HEAD but must also reject repositories with existing object DB
or state files; modify looksLikeUnbornGitRepository to return false if the
.git/objects directory contains any loose objects or packfiles, if an index file
exists (check joinPath(gitDir, "index") via isFile or equivalent), or if
reflogs/logs are present (check joinPath(gitDir, "logs") and ensure it’s empty).
Implement small helpers (e.g., hasAnyLooseObjects, hasAnyPackfiles,
hasAnyFilesInDir) or reuse/extend hasAnyLooseRef/hasAnyPackedRef to perform
these checks and call them before returning true. Ensure you reference gitDir
and use existing helpers like isDirectory/isFile/readGitFile where appropriate.
🪄 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: 01b886c3-cd07-4e3c-855f-bb7d9e2d8bff
📒 Files selected for processing (3)
CHANGES.mdpackages/init/src/action/patch.tspackages/init/src/lib.ts
Treat an unborn Git repository as empty only when it has no refs, stored objects, index, reflogs, or other common state paths. This keeps fedify init from skipping the non-empty-directory safeguard for repositories with deleted refs but remaining Git state. References fedify-dev#717 (comment) Assisted-by: Codex:gpt-5.4
Summary
Closes #716.
This PR fixes the
@fedify/nuxtpackaging issue reported in #716 and also addresses the relatedfedify initside findings from the same issue.For
@fedify/nuxt, the Nuxt module now points Nitro at compiled runtime JavaScript in dist/ instead of package TypeScript sources. The runtime server entry points are included in thetsdownbuild, and the package-level regression test imports@fedify/nuxtfrom the built package output so this class of packaging issue is covered.For
@fedify/init, generated Biome configuration now matches the Biome 2 version thatfedify initinstalls. The generatedbiome.jsonuses the Biome 2assist.actions.source.organizeImportsconfiguration, and the scaffold-level test checks that the schema version exactly matches the installed@biomejs/biomepackage version.This also improves non-empty directory handling in
fedify init. A directory that only contains a freshly initialized, unborn Git repository is now treated as empty, while repositories whoseHEADresolves to a commit or whose Git metadata contains refs are still treated as non-empty. Finally, a new--allow-non-emptyoption allows non-interactive scaffolding in directories with unrelated files, but fails before making changes if any file that Fedify would generate already exists.Changes
tsdown.@fedify/nuxtimport regression test against built output.fedify init.--allow-non-emptyfor safe non-interactive init in non-empty directories.--allow-non-emptyin docs/cli.md.@fedify/inituser-facing changes.Verification
pnpm --dir packages/init --config.enable-pre-post-scripts=false testdeno task checkinpackages/inithongdown --check CHANGES.md docs/cli.mdgit diff --check