Skip to content

Fix fedify init crash on JSR/Deno distribution#633

Merged
dahlia merged 1 commit intofedify-dev:2.0-maintenancefrom
dahlia:fix/fedify-init-jsr-crash
Mar 18, 2026
Merged

Fix fedify init crash on JSR/Deno distribution#633
dahlia merged 1 commit intofedify-dev:2.0-maintenancefrom
dahlia:fix/fedify-init-jsr-crash

Conversation

@dahlia
Copy link
Member

@dahlia dahlia commented Mar 18, 2026

Summary

  • Fixed fedify init crashing when @fedify/cli or @fedify/init is executed through the JSR/Deno distribution (e.g., deno run -A jsr:@fedify/cli init).
  • import.meta.dirname is undefined for remote JSR modules, so the template loading and repository-relative path logic has been made safe for published JSR execution.

Changes

  • Made PACKAGES_PATH lazy by converting it to a getPackagesPath() function. This constant was eagerly computed at module top-level using import.meta.dirname!, causing an immediate crash on import. Since it is only used in test mode (which always runs locally), deferring the computation is safe.
  • Made readTemplate() async with a URL-based fallback. When import.meta.dirname is available (Node.js, local Deno, deno compile), the existing readFileSync path is used. When it is not (JSR remote execution), import.meta.url + fetch() is used to load template files from the JSR CDN.

Test plan

  • deno check passes for all files in the init package
  • deno task check passes (fmt, lint, type check) in the init package
  • deno run -A packages/cli/src/mod.ts init --help works without crashing
  • Dry-run tested with all five web frameworks (Hono, ElysiaJS, Express, Nitro, Next.js) across various package manager combinations
  • tsdown build succeeds and produces correct output (templates copied to dist/, import.meta.dirname guard present in built JS)
  • Manual verification that fetch() path works with file:// URLs (for the JSR fallback path)
  • End-to-end verification after JSR publish

Closes #624

@issues-auto-labeler issues-auto-labeler bot added breaking change Breaking change component/build Build system and packaging component/cli CLI tools related labels Mar 18, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical issue where the fedify init command would crash when run through JSR/Deno distributions. The changes ensure that the CLI tool can correctly locate and load necessary files, such as templates and package paths, regardless of whether it's executed locally or as a remote JSR module. This significantly improves the reliability and portability of the Fedify initialization process across different Deno environments.

Highlights

  • JSR/Deno Distribution Crash Fix: Fixed fedify init crashing when executed through JSR/Deno distribution by addressing import.meta.dirname being undefined for remote JSR modules.
  • Lazy Package Path Resolution: Converted the PACKAGES_PATH constant to a lazy-evaluated getPackagesPath() function to prevent eager computation crashes.
  • Asynchronous Template Loading with Fallback: Refactored readTemplate() to be asynchronous and include a URL-based fetch() fallback for template loading when import.meta.dirname is unavailable.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dahlia
Copy link
Member Author

dahlia commented Mar 18, 2026

@codex review

Copy link
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 effectively fixes a crash in fedify init when run from a JSR/Deno distribution by making template loading compatible with remote module execution. The changes are well-implemented, using lazy initialization for repository-relative paths and adding an async, fetch-based fallback for readTemplate. The related type and function signature updates across the init package are consistent and correct. I have one suggestion to improve documentation in line with the project's standards, as detailed in the comment.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6a97f15ba5

ℹ️ 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".

@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.
see 1 file 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.

`@fedify/init` crashed when executed through the JSR/Deno distribution
(e.g., `deno run -A jsr:@fedify/cli init`) because `import.meta.dirname`
is `undefined` for remote JSR modules.

Two fixes applied:

 -  Made `PACKAGES_PATH` lazy by converting it to a `getPackagesPath()`
    function.  This constant was eagerly computed at module top-level
    using `import.meta.dirname!`, causing an immediate crash on import.
    Since it is only used in test mode (which always runs locally),
    deferring the computation is safe.

 -  Made `readTemplate()` async with a URL-based fallback.  When
    `import.meta.dirname` is available (Node.js, local Deno, deno
    compile), the existing `readFileSync` path is used.  When it is
    not (JSR remote execution), `import.meta.url` + `fetch()` is used
    to load template files from the JSR CDN.

Fixes fedify-dev#624

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dahlia dahlia force-pushed the fix/fedify-init-jsr-crash branch from 6a97f15 to 12093e7 Compare March 18, 2026 12:46
@github-actions
Copy link
Contributor

Pre-release has been published for this pull request:

Packages

Package Version JSR npm
@fedify/fedify 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/cli 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/amqp 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/cfworkers 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/create 2.0.6-pr.633.9+12093e72 npm
@fedify/debugger 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/denokv 2.0.6-pr.633.9+12093e72 JSR
@fedify/elysia 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/express 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/fastify 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/fixture 2.0.6-pr.633.9+12093e72 JSR
@fedify/fresh 2.0.6-pr.633.9+12093e72 JSR
@fedify/h3 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/hono 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/init 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/koa 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/lint 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/nestjs 2.0.6-pr.633.9+12093e72 npm
@fedify/next 2.0.6-pr.633.9+12093e72 npm
@fedify/postgres 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/redis 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/relay 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/sqlite 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/sveltekit 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/testing 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/vocab 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/vocab-runtime 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/vocab-tools 2.0.6-pr.633.9+12093e72 JSR npm
@fedify/webfinger 2.0.6-pr.633.9+12093e72 JSR npm

@dahlia
Copy link
Member Author

dahlia commented Mar 18, 2026

Verified with the JSR pre-release. The original crash from #624 is fixed:

$ deno run -A jsr:@fedify/cli@2.0.6-pr.633.9+12093e72 init --help
Initialize a new Fedify project directory.
Usage: fedify init [-w/--web-framework WEB_FRAMEWORK] [-p/--package-manager PACKAGE_MANAGER] [-k/--kv-store KV_STORE] [-m/--message-queue MESSAGE_QUEUE] [--dry-run] [[-d/--debug]] [(--ignore-config | --config PATH)] [DIR]
...

No crash — help output is displayed as expected.

@dahlia dahlia merged commit ae0a7bc into fedify-dev:2.0-maintenance Mar 18, 2026
16 checks passed
@dahlia dahlia deleted the fix/fedify-init-jsr-crash branch March 18, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Breaking change component/build Build system and packaging component/cli CLI tools related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@fedify/init crashes on JSR and Deno because it assumes import.meta.dirname is available

1 participant