Skip to content

Fix issues with app path and namespace #2042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

solomon-ochepa
Copy link
Contributor

@solomon-ochepa solomon-ochepa commented Mar 9, 2025

Summary
Resolve issues with the app/ path by supporting both default and custom names while ensuring proper namespace conversion.

Description
The app/ path was previously removed due to multiple issues. This task involves reintroducing support for it while ensuring:

  • It correctly supports both default (app/) and custom paths (src/, /).
  • The namespace is properly converted to StudlyCase.
  • No existing features are broken in the process.
  • Tests have been added to verify correctness and stability.

Acceptance Criteria:

  • app/ path works with both default and custom configurations.
  • Namespace is correctly converted to StudlyCase.
  • No feature breakages in this branch.
  • Tests validate the expected behavior.

Tests (PathNamespaceTest)

  • test_generates_app_path()
  • test_generates_custom_app_path()
  • test_generates_root_app_path()
  • test_removes_duplicate_app_path()
  • test_identifies_app_path()
  • test_recognizes_custom_app_path(), etc.

Let me know if you want any modifications! 🚀

@solomon-ochepa solomon-ochepa force-pushed the fix-issues-with-app-path-and-namespace branch 2 times, most recently from 7782291 to 8fe9572 Compare March 12, 2025 01:17
@solomon-ochepa
Copy link
Contributor Author

Hi, @dcblogdev. Your attention is needed here, please.

@dcblogdev
Copy link
Collaborator

this needs to work with the existing app_folder path in the config otherwise it will break for existing apps.

Confirmed app and src folder work as long as the modules composer are updated accordingly such as "Modules\\Blog\\": "app/",

@solomon-ochepa
Copy link
Contributor Author

this needs to work with the existing app_folder path in the config otherwise it will break for existing apps.

That is true. I'll immediately add a backward compatibility replacement for the old app_folder.

Confirmed app and src folder work as long as the modules composer are updated accordingly such as "Modules\\Blog\\": "app/",

Sure, they are all working, and I've written some tests for that. You can go ahead and confirm it.

Tests:

test_generates_app_path() (modules.paths.app: 'app/' or '') - default path.

public function test_generates_app_path()
    {
        $app_path = $this->path_namespace->app_path();

        $this->assertSame('app/Models/User', $this->path_namespace->app_path('Models/User'));
        $this->assertSame($app_path, $this->path_namespace->app_path(null));
    }

test_generates_custom_app_path() (modules.paths.app: 'src/') - any custom path of your choice, including src/

public function test_generates_custom_app_path()
    {
        config(['modules.paths.app' => 'src/']);

        $this->assertSame('src/Models/User', $this->path_namespace->app_path('Models/User'));
    }

test_generates_root_app_path() (modules.paths.app: '/') - can also be used without the app/ path

public function test_generates_root_app_path()
    {
        config(['modules.paths.app' => '/']);

        $this->assertSame('Models/User', $this->path_namespace->app_path('Models/User'));
    }

@solomon-ochepa solomon-ochepa force-pushed the fix-issues-with-app-path-and-namespace branch from 0e924d9 to 33aba43 Compare April 28, 2025 03:17
@solomon-ochepa solomon-ochepa force-pushed the fix-issues-with-app-path-and-namespace branch from 33aba43 to 8097896 Compare April 28, 2025 03:58
@solomon-ochepa
Copy link
Contributor Author

Sorry, your merge affected the workflow. I'll be submitting a new PR shortly.
@dcblogdev

@solomon-ochepa solomon-ochepa reopened this May 7, 2025
@solomon-ochepa
Copy link
Contributor Author

this needs to work with the existing app_folder path in the config otherwise it will break for existing apps.

Confirmed app and src folder work as long as the modules composer are updated accordingly such as "Modules\\Blog\\": "app/",

Hi, @dcblogdev.

The backward compatibility support for both modules.paths.app_folder and composer.json $APP_FOLDER_NAME$ has been added successfully. Please check it out and let me know if more changes are needed.

Thanks, and have a nice day.

@dcblogdev
Copy link
Collaborator

thanks, I'll have a look at this tonight.

@alissn
Copy link
Contributor

alissn commented May 7, 2025

After merging this PR, we’ll likely be saying hi to a lot of new issues. 🤷‍♂️

Having 230 changed files is not normal. It would be better if the author could split this into smaller, more focused PRs so the community can review the changes more effectively.

@solomon-ochepa
Copy link
Contributor Author

After merging this PR, we’ll likely be saying hi to a lot of new issues. 🤷‍♂️

Having 230 changed files is not normal. It would be better if the author could split this into smaller, more focused PRs so the community can review the changes more effectively.

Do you discover any bug you'd like the author to correct?

The CI/CD tests was created to detect early bugs. If passed, the code is believed to be okay!

Thanks and have a great day

@solomon-ochepa
Copy link
Contributor Author

After merging this PR, we’ll likely be saying hi to a lot of new issues. 🤷‍♂️

Having 230 changed files is not normal. It would be better if the author could split this into smaller, more focused PRs so the community can review the changes more effectively.

image

More than 156 files are tests and snapshots.

@alissn
Copy link
Contributor

alissn commented May 8, 2025

I don't want this to happen again.

Reference: https://x.com/taylorotwell/status/1552452998546300929
image

@solomon-ochepa
Copy link
Contributor Author

I don't want this to happen again.

Reference: https://x.com/taylorotwell/status/1552452998546300929
image

Do you realize at all that this same PR is to correct a problem you yourself introduced to this package?

Don't be too sentimental. Go through the PR and recommend changes if any.

Have you tested the PR and it's not working or do you find any bugs you'll like the author to fix?

Do you know the level of damages your changes cost us?

Let's join hands together and create solutions, not fighting each other all the time.

No one is paying us to contribute code here! Let's not feel so entitled or sentimental or judgemental please 🙏

@dcblogdev
Copy link
Collaborator

we're not looking to argue, its a massive PR, going to find some time to look over this and try out with a few apps I have.

The tests are all passing which is great 👍 with there being so many changes just want to check there's no unexpected issues that the tests don't check for.

@solomon-ochepa solomon-ochepa force-pushed the fix-issues-with-app-path-and-namespace branch 5 times, most recently from bf0dd09 to 0435c4e Compare May 9, 2025 06:02
@solomon-ochepa
Copy link
Contributor Author

After merging this PR, we’ll likely be saying hi to a lot of new issues. 🤷‍♂️

Having 230 changed files is not normal. It would be better if the author could split this into smaller, more focused PRs so the community can review the changes more effectively.

Hi, I figured out a way to extract fractions of the PR into a separate micro PR. I've created a draft PR and will mark it ready once this is reviewed and merged.

While waiting for @dcblogdev and the rest of the QA team to complete the review, I'll review the codebase again to see if there is still room for more micro PRs.

Thanks for your observation and recommendation.

@solomon-ochepa solomon-ochepa force-pushed the fix-issues-with-app-path-and-namespace branch 6 times, most recently from df4eb1b to 1206ed2 Compare May 9, 2025 08:29
@solomon-ochepa
Copy link
Contributor Author

I've squashed and optimized the commits to improve clarity. I recommend reviewing the pull request via the 14 commits rather than the 206 files changed—it’ll be much easier to follow the changes that way.

Thanks.
@dcblogdev @alissn

@DeRaja
Copy link

DeRaja commented May 19, 2025

Hello!

Thanks solomon-ochepa for showing me this solution. Can you check, if my solution is OK or easier?

I have found a totally different solution compared to what is proposed above. My solution is tiny and simple, easy to implement. Check it here:

#2073

@solomon-ochepa
Copy link
Contributor Author

Hello!

Thanks solomon-ochepa for showing me this solution. Can you check, if my solution is OK or easier?

I have found a totally different solution compared to what is proposed above. My solution is tiny and simple, easy to implement. Check it here:

#2073

Your solution is a temporary fix, yes. But this PR is a better solution to solve the entire problem once and for all.

@solomon-ochepa solomon-ochepa mentioned this pull request May 20, 2025
@dcblogdev
Copy link
Collaborator

@solomon-ochepa as soon as I pull in this PR I'm getting this error


   BadMethodCallException 

  Method Nwidart\Modules\Laravel\Module::app_path does not exist.

  at vendor/laravel/framework/src/Illuminate/Macroable/Traits/Macroable.php:115
    111▕      */
    112▕     public function __call($method, $parameters)
    113▕     {
    114▕         if (! static::hasMacro($method)) {
  ➜ 115▕             throw new BadMethodCallException(sprintf(
    116▕                 'Method %s::%s does not exist.', static::class, $method
    117▕             ));
    118▕         }
    119▕ 

  1   /Users/dave/Herd/packages/laravel-modules/src/Module.php:171
      Nwidart\Modules\Module::__call("app_path", [])
      +14 vendor frames 

  16  [internal]:0
      Illuminate\Foundation\Application::{closure:Illuminate\Foundation\Application::boot():1130}(Object(Mhmiton\LaravelModulesLivewire\LaravelModulesLivewireServiceProvider), "Mhmiton\LaravelModulesLivewire\LaravelModulesLivewireServiceProvider")

This happens when I have mhmiton/laravel-modules-livewire installed

@solomon-ochepa
Copy link
Contributor Author

@solomon-ochepa as soon as I pull in this PR I'm getting this error


   BadMethodCallException 

  Method Nwidart\Modules\Laravel\Module::app_path does not exist.

  at vendor/laravel/framework/src/Illuminate/Macroable/Traits/Macroable.php:115
    111▕      */
    112▕     public function __call($method, $parameters)
    113▕     {
    114▕         if (! static::hasMacro($method)) {
  ➜ 115▕             throw new BadMethodCallException(sprintf(
    116▕                 'Method %s::%s does not exist.', static::class, $method
    117▕             ));
    118▕         }
    119▕ 

  1   /Users/dave/Herd/packages/laravel-modules/src/Module.php:171
      Nwidart\Modules\Module::__call("app_path", [])
      +14 vendor frames 

  16  [internal]:0
      Illuminate\Foundation\Application::{closure:Illuminate\Foundation\Application::boot():1130}(Object(Mhmiton\LaravelModulesLivewire\LaravelModulesLivewireServiceProvider), "Mhmiton\LaravelModulesLivewire\LaravelModulesLivewireServiceProvider")

This happens when I have mhmiton/laravel-modules-livewire installed

Thanks for the feedback. This probably happens because of the few changes I separated into new PRs.

I'm debugging it right away!

Thanks for the review and feedback, @dcblogdev

… methods

- [test] Enhance PathNamespaceTest with additional path and namespace conversion tests
- [feat] add module_path and module_app_path methods for improved module path handling
- [refactor] fix trimming logic in clean() method for improved path handling
- [fix] trim leading and trailing slashes in app path for consistency
- [refactor] enhance path handling methods for improved clarity and consistency
…nerator for improved namespace handling and code clarity
refactor: update `default_namespace()` method to accept a default path for improved flexibility

refactor: update `default_namespace()` method to use an empty string as default value for improved clarity
…e new `path` method for improved module retrieval
…r generated files

- Updated namespaces in generated module files from 'Modules\Blog\Http\Controllers' to 'Modules\Blog\App\Http\Controllers'.
- Changed service provider namespaces from 'Modules\Blog\Providers' to 'Modules\Blog\App\Providers'.
- Adjusted repository, request, resource, and rule namespaces to follow the new structure.
- Modified test snapshots to reflect the updated namespaces.
- Cleaned up unnecessary module path variables in tests for better readability and maintainability.
@solomon-ochepa solomon-ochepa force-pushed the fix-issues-with-app-path-and-namespace branch from 506f004 to 5bcef5b Compare May 22, 2025 01:34
@solomon-ochepa
Copy link
Contributor Author

Hi, @dcblogdev.

The issue has been fixed successfully - d95887e

Nevertheless, I need to work on the laravel-modules-livewire package ASAP

@dcblogdev
Copy link
Collaborator

thanks that error is fixed now, my tests are failing because Livewire can't see my components.

If you need a project that uses Livewire you can use https://github.com/laravel-modules-com/fuse

@solomon-ochepa
Copy link
Contributor Author

thanks that error is fixed now, my tests are failing because Livewire can't see my components.

If you need a project that uses Livewire you can use https://github.com/laravel-modules-com/fuse

Can you share a screenshot or at least the error log, please?

Secondly, this PR is not about Livewire and has nothing to do with Livewire.

Livewire integration is handled completely by another package (laravel-modules-livewire).

I'm already working on a patch to fix every possible issue that may result from this PR.
image

I need some time to finish it. I'm currently in a meeting at my workplace.

Thank you, @dcblogdev

@dcblogdev
Copy link
Collaborator

I understand this is not about Livewire but my components work perfectly until I use this branch. tested on 3 different apps.

Livewire\Exceptions\ComponentNotFoundException
Unable to find component: [admin::admin.notifications-menu]

@solomon-ochepa
Copy link
Contributor Author

I understand this is not about Livewire but my components work perfectly until I use this branch. tested on 3 different apps.

Livewire\Exceptions\ComponentNotFoundException
Unable to find component: [admin::admin.notifications-menu]

I understand why, and I'm not doubting you.

Have you forgotten? When the changes were made by @alissn he also changed a few codes in the Laravel-modules-livewire repo, which I'll fix ASAP.

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.

4 participants