Skip to content

Fix plugin directory structure inconsistency in PluginCreateCommand#86

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

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

Conversation

@wilsonatb
Copy link
Copy Markdown

@wilsonatb wilsonatb commented Apr 7, 2026

Problem Description

There is an inconsistency between the native:plugin:create command and the native:plugin:validate command in NativePHP Mobile:

  • PluginCreateCommand creates plugins with a flat directory structure (resources/android/{Namespace}Functions.kt, resources/ios/{Namespace}Functions.swift).
  • PluginValidateCommand expects third-party plugins to use a nested directory structure (resources/android/src/, resources/ios/Sources/).

This causes validation warnings for newly created plugins, even though they are functionally correct. The system's Plugin class actually supports both structures, but the validator only checks the nested structure for third-party plugins.

Root Cause

The PluginCreateCommand.php file creates directories and files using the flat structure, while the documented plugin structure shows nested directories. Third-party plugins fail validation with warnings about missing native code.

Solution

Updated PluginCreateCommand.php to create the nested directory structure by default, aligning it with the validator's expectations and best practices.

Required Changes:

  1. Changed directory creation paths to include src/ and Sources/.
  2. Updated Kotlin and Swift file generation paths.
  3. Updated next-steps user instructions output.
  4. Updated expected paths in PluginCommandsTest.php to ensure the test suite passes.

Testing

  • Tested locally by generating a fresh plugin and running native:plugin:validate (passed with 0 warnings).
  • Updated and passed all Pest tests for PluginCommandsTest.

Visual Proof (Before & After)

Before (Current Main):
Generating a plugin and validating it results in false warnings due to the flat structure.

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

After (This PR):
Generating a new plugin creates the nested directories, and validation passes cleanly.

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

Updates PluginCreateCommand to generate nested directories (resources/android/src and resources/ios/Sources). Updates corresponding tests to reflect the new paths. This aligns the creation command with the expectations of PluginValidateCommand.
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.

1 participant