Skip to content

Fix plugin directory structure inconsistency in PluginCreateCommand#86

Open
wilsonatb wants to merge 1 commit into
NativePHP:mainfrom
wilsonatb:fix-plugin-create-directory-structure
Open

Fix plugin directory structure inconsistency in PluginCreateCommand#86
wilsonatb wants to merge 1 commit into
NativePHP:mainfrom
wilsonatb:fix-plugin-create-directory-structure

Conversation

@wilsonatb
Copy link
Copy Markdown

@wilsonatb wilsonatb commented Apr 7, 2026

Updated PR based on simonhamp feedback to adapt the validator instead of the creator.

Problem Description

Freshly created plugins generate a flat directory structure (resources/android/ and resources/ios/), but PluginValidateCommand strictly expects a nested structure (/src/ and /Sources/), resulting in false positive warnings like No native code directories found.

Solution

Instead of forcing the creation command to use nested folders, this PR updates PluginValidateCommand to support both architectures.

What changed in PluginValidateCommand.php:

  1. The validator now checks for the nested structure first.
  2. If not found, it gracefully falls back to checking the flat structure.
  3. It only emits warnings if the implementation is missing in both locations.
    This aligns the validator with the core Plugin class which already supports both approaches seamlessly.

Testing

  • Tested locally by generating a fresh plugin with flat structure.
  • Ran native:plugin:validate (passed with a clean OK and 0 warnings).

Visual Proof (Before & After)

Before (Current Main):

$ php artisan native:plugin:validate packages/wilsonatb/plugin-test-bug
  plugin-test-bug (android: 21, ios: 15.0) ...................................................................... WARN  
  ⚠ No native code directories found (resources/android or resources/ios)
  ⚠ Android implementation not found for TestBug.Execute
  ⚠ iOS implementation not found for TestBug.Execute

After (This PR):

$ php artisan native:plugin:validate packages/wilsonatb/plugin-test-fallback
  plugin-test-fallback (android: 21, ios: 15.0) ........................................................................ OK 

@simonhamp
Copy link
Copy Markdown
Member

I think I'd probably prefer this the other way around: so the validator changes

Thoughts @shanerbaner82 ?

@wilsonatb wilsonatb marked this pull request as draft May 25, 2026 16:31
Updates PluginValidateCommand to check both nested and flat structures, gracefully falling back to flat directories (resources/android, resources/ios). This prevents false positive warnings on freshly created plugins while keeping support for the nested architecture.
@wilsonatb wilsonatb force-pushed the fix-plugin-create-directory-structure branch from 66ef072 to f7e148c Compare May 25, 2026 17:18
@wilsonatb
Copy link
Copy Markdown
Author

@simonhamp I completely agree with your approach. It makes much more sense to make the validator smarter rather than forcing a specific scaffolding structure, especially since the Plugin class already handles both gracefully.

I've updated the PR. I reverted the changes to the creator and instead updated PluginValidateCommand to fallback to the flat structure if the nested one is not found. Tested locally and works perfectly!

@wilsonatb wilsonatb marked this pull request as ready for review May 25, 2026 17:24
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.

2 participants