Skip to content

fix: normalize oclif v2 plugin hooks for v4 compatibility#922

Merged
shazron merged 8 commits intomasterfrom
fix/oclif-v2-hook-compat
Apr 28, 2026
Merged

fix: normalize oclif v2 plugin hooks for v4 compatibility#922
shazron merged 8 commits intomasterfrom
fix/oclif-v2-hook-compat

Conversation

@shazron
Copy link
Copy Markdown
Member

@shazron shazron commented Apr 27, 2026

Fixes #921

Summary

  • When the global aio-cli (oclif v2) invokes commands from this plugin (oclif v4), v4's Config.load detects the incoming v2 Config and re-uses its Plugin objects directly
  • oclif v2 stores hooks as plain string arrays (['./src/hooks/foo.js']); oclif v4's runHook expects {identifier, target} objects — so hook.target was undefined, crashing path.extname(undefined) with ERR_INVALID_ARG_TYPE
  • Fixed by normalizing all plugin hooks to v4 {identifier, target} format once in BaseCommand.init(), covering every command that calls this.config.runHook

Test plan

  • Run aio app deploy in a project with @adobe/aio-cli-plugin-events linked — confirm the pre-deploy-event-reg hook runs without ERR_INVALID_ARG_TYPE
  • Run aio app undeploy — confirm pre-undeploy-event-reg hook works
  • Run aio app pack — confirm pre-pack hook works
  • Run existing unit tests: npm test

🤖 Generated with Claude Code

When the global aio-cli (oclif v2) runs commands from this plugin
(oclif v4), v4's Config.load re-uses the v2 Plugin objects as-is.
Those objects store hooks as plain string arrays, but v4's runHook
expects {identifier, target} objects — causing hook.target to be
undefined and crashing path.extname() with ERR_INVALID_ARG_TYPE.

Normalize all plugin hooks to v4 format once in BaseCommand.init()
so every command that calls this.config.runHook works correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

🤖 PR Reviewer

The diff adds a normalization step for oclif v2 plugin hooks in the init method. The logic is straightforward and well-commented, but there are a few concerns around safety and maintainability.

📝 2 suggestion(s) - Please review inline comments below.


💡 How to re-trigger

Comment /review or /pr-reviewer on this PR

Comment thread src/BaseCommand.js
Comment thread src/BaseCommand.js
shazron and others added 3 commits April 28, 2026 00:11
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When the global aio-cli (oclif v2) runs commands from this plugin
(oclif v4), v4's Config.load re-uses the v2 Plugin objects as-is.
Those objects store hooks as plain string arrays, but v4's runHook
expects {identifier, target} objects — causing hook.target to be
undefined and crashing path.extname() with ERR_INVALID_ARG_TYPE.

Normalize all plugin hooks to v4 format in BaseCommand.init(), but
only when string hooks are actually present to avoid unnecessary
mutation of already-normalized plugin objects.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When the global aio-cli (oclif v2) runs commands from this plugin
(oclif v4), v4's Config.load re-uses the v2 Plugin objects as-is.
Those objects store hooks as plain string arrays, but v4's runHook
expects {identifier, target} objects — causing hook.target to be
undefined and crashing path.extname() with ERR_INVALID_ARG_TYPE.

Normalize all plugin hooks to v4 format in BaseCommand.init(), but
only when string hooks are actually present to avoid unnecessary
mutation of already-normalized plugin objects. Uses getPluginsList()
if available, falling back to this.config.plugins Map.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
github-actions[bot]
github-actions Bot previously approved these changes Apr 27, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

🤖 PR Reviewer

The previous suggestions have been addressed: a guard for getPluginsList is now in place, and a check prevents unnecessary mutation when no string hooks are present. The implementation is clean and well-tested with good coverage of edge cases including fallback paths and frozen/already-normalized hooks.

LGTM! This PR looks good to merge.


💡 How to re-trigger

Comment /review or /pr-reviewer on this PR

@github-actions github-actions Bot dismissed their stale review April 27, 2026 16:27

Superseded by new review

github-actions[bot]
github-actions Bot previously approved these changes Apr 27, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

🤖 PR Reviewer

The implementation is clean and well-reasoned, correctly normalizing oclif v2 string hooks to v4 object format with appropriate guards. Tests are thorough and cover edge cases including the fallback path, frozen-object concerns, and mixed formats. One minor concern: the code silently mutates plugin objects that may be shared/frozen references, though the comment acknowledges this, and the actual freeze guard is not implemented.

LGTM! This PR looks good to merge.


💡 How to re-trigger

Comment /review or /pr-reviewer on this PR

Comment thread src/BaseCommand.js Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot dismissed their stale review April 27, 2026 16:31

Superseded by new review

shazron and others added 2 commits April 28, 2026 00:35
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

🤖 PR Reviewer

The hook normalization logic is well-structured and the tests provide good coverage. However, the previously raised concern about mutating potentially frozen/sealed plugin hooks objects remains unaddressed — the comment says 'guard against frozen plugin references' but no actual guard is implemented, which will throw a TypeError in strict mode if a plugin's hooks object is frozen or sealed.

🔄 1 re-raised suggestion(s) from previous review


💡 How to re-trigger

Comment /review or /pr-reviewer on this PR

Comment thread src/BaseCommand.js Outdated
@github-actions github-actions Bot dismissed their stale review April 27, 2026 18:06

Superseded by new review

When the global aio-cli (oclif v2) runs commands from this plugin
(oclif v4), v4's Config.load re-uses the v2 Plugin objects as-is.
Those objects store hooks as plain string arrays, but v4's runHook
expects {identifier, target} objects — causing hook.target to be
undefined and crashing path.extname() with ERR_INVALID_ARG_TYPE.

Normalize all plugin hooks to v4 format in BaseCommand.init(), but
only when string hooks are actually present to avoid unnecessary
mutation of already-normalized plugin objects. Uses getPluginsList()
if available, falling back to this.config.plugins Map. Wraps
assignment in try/catch to handle frozen plugin hook objects.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

🤖 PR Reviewer

The re-raised frozen-object concern has been addressed with a try/catch block. The implementation is clean and well-tested, covering string normalization, frozen hooks, fallback plugin iteration, and edge cases. No significant issues remain.

LGTM! This PR looks good to merge.


💡 How to re-trigger

Comment /review or /pr-reviewer on this PR

@github-actions github-actions Bot dismissed their stale review April 28, 2026 06:51

Superseded by new review

@shazron shazron merged commit 3c71159 into master Apr 28, 2026
11 checks passed
@shazron shazron deleted the fix/oclif-v2-hook-compat branch April 28, 2026 06:55
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.

hooks failure when events data is missing in config

2 participants