Skip to content

fix(generator): remove duplicate generate:after hook in handleEntrypoint (#1993)#2073

Closed
armorbreak001 wants to merge 1 commit intoasyncapi:masterfrom
armorbreak001:fix/generate-after-hook-dup
Closed

fix(generator): remove duplicate generate:after hook in handleEntrypoint (#1993)#2073
armorbreak001 wants to merge 1 commit intoasyncapi:masterfrom
armorbreak001:fix/generate-after-hook-dup

Conversation

@armorbreak001
Copy link
Copy Markdown

@armorbreak001 armorbreak001 commented Apr 22, 2026

Problem

Fixes #1993

When using Generator API with entrypoint set and output = 'fs' (default), the generate:after hook fires twice:

generate() {
  await this.handleEntrypoint();     // ← calls generate:after (line 350)
  await this.executeAfterHook();    // ← calls generate:after (line 368) AGAIN
}

Root Cause

handleEntrypoint() has an internal launchHook('generate:after') for the 'fs' output case, but generate() always calls executeAfterHook() afterward — which also launches the same hook.

Impact

  • All generate:after side effects run twice (file cleanup, notifications, etc.)
  • Only affects entrypoint + fs usage; other combinations are unaffected

Fix

1 line removal: Delete the launchHook('generate:after') call from inside handleEntrypoint().

The canonical hook execution is in executeAfterHook(), called unconditionally by generate().

Lifecycle After Fix

generate:before
[generation logic]
generate:after    ← exactly once, always

Summary by CodeRabbit

  • Refactor
    • Optimized internal generator hook invocation sequence to prevent duplicate execution while maintaining consistent behavior.

…int (asyncapi#1993)

When entrypoint is set with output='fs', the lifecycle was:
  1. handleEntrypoint() → launchHook('generate:after')  ← duplicate
  2. executeAfterHook() → launchHook('generate:after')  ← canonical

This caused generate:after to fire twice, running side effects twice.

Fix: Remove the hook call from handleEntrypoint(). The executeAfterHook()
call in generate() is the single canonical source for this hook.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 22, 2026

⚠️ No Changeset found

Latest commit: 1784a5f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@asyncapi-bot
Copy link
Copy Markdown
Contributor

What reviewer looks at during PR review

The following are ideal points maintainers look for during review. Reviewing these points yourself beforehand can help streamline the review process and reduce time to merge.

  1. PR Title: Use a concise title that follows our Conventional Commits guidelines and clearly summarizes the change using imperative mood (it means spoken or written as if giving a command or instruction, like "add new helper for listing operations")

    Note - In Generator, prepend feat: or fix: in PR title only when PATCH/MINOR release must be triggered.

  2. PR Description: Clearly explain the issue being solved, summarize the changes made, and mention the related issue.

    Note - In Generator, we use Maintainers Work board to track progress. Ensure the PR Description includes Resolves #<issue-number> or Fixes #<issue-number> this will automatically close the linked issue when the PR is merged and helps automate the maintainers workflow.

  3. Documentation: Update the relevant Generator documentation to accurately reflect the changes introduced in the PR, ensuring users and contributors have up-to-date guidance.

  4. Comments and JSDoc: Write clear and consistent JSDoc comments for functions, including parameter types, return values, and error conditions, so others can easily understand and use the code.

  5. DRY Code: Ensure the code follows the Don't Repeat Yourself principle. Look out for duplicate logic that can be reused.

  6. Test Coverage: Ensure the new code is well-tested with meaningful test cases that pass consistently and cover all relevant edge cases.

  7. Commit History: Contributors should avoid force-pushing as much as possible. It makes it harder to track incremental changes and review the latest updates.

  8. Template Design Principles Alignment: While reviewing template-related changes in the packages/ directory, ensure they align with the Assumptions and Principles. If any principle feels outdated or no longer applicable, start a discussion these principles are meant to evolve with the project.

  9. Reduce Scope When Needed: If an issue or PR feels too large or complex, consider splitting it and creating follow-up issues. Smaller, focused PRs are easier to review and merge.

  10. Bot Comments: As reviewers, check that contributors have appropriately addressed comments or suggestions made by automated bots. If there are bot comments the reviewer disagrees with, react to them or mark them as resolved, so the review history remains clear and accurate.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 22220e44-56f3-4573-8bf0-f7f9821d3207

📥 Commits

Reviewing files that changed from the base of the PR and between 5c4b597 and 1784a5f.

📒 Files selected for processing (1)
  • apps/generator/lib/generator.js
💤 Files with no reviewable changes (1)
  • apps/generator/lib/generator.js

📝 Walkthrough

Walkthrough

The fix removes a duplicate generate:after hook invocation in the Generator's entry point handler. When output === 'fs' and an entrypoint is provided, the hook is no longer called directly within handleEntrypoint(), allowing it to execute once via the standard executeAfterHook() flow later in the generation pipeline.

Changes

Cohort / File(s) Summary
Hook lifecycle fix
apps/generator/lib/generator.js
Removed duplicate generate:after hook invocation from handleEntrypoint() method when handling entrypoint with filesystem output, preventing the hook from being called twice in the generation lifecycle.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title follows Conventional Commits format with 'fix:' prefix, clearly describes the change (removing duplicate generate:after hook in handleEntrypoint), uses imperative mood, and is concise and well-structured.
Linked Issues check ✅ Passed The code changes directly address all objectives from issue #1993: removing the duplicate generate:after hook invocation from handleEntrypoint() so it executes only once via executeAfterHook() in generate().
Out of Scope Changes check ✅ Passed The changes are narrowly scoped to the stated objective: removing one redundant launchHook('generate:after') call with no other modifications or unrelated alterations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

@sonarqubecloud
Copy link
Copy Markdown

@derberg
Copy link
Copy Markdown
Member

derberg commented Apr 22, 2026

User blocked. Seems to be AI bot.

@derberg derberg closed this Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] generate:after hook is executed twice when using entrypoint with fs output

3 participants