Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Modularize Laravel Package

internachi/modularize

Adds internachi/modular support to Laravel package commands via traits. Provides a --module option for console and generator commands, returning module config and generating files into the module directory with correct paths and namespaces.

View on GitHub
Deep Wiki
Context7

internachi/modularize helps Laravel package authors add seamless internachi/modular support to their Artisan commands. By mixing in lightweight traits, your commands gain a --module option and can automatically resolve the target ModuleConfig for module-aware behavior.

Use Modularize for standard commands, or ModularizeGeneratorCommand for file generators so created classes land in the correct module directory with proper namespaces.

  • Adds a --module option to Artisan commands
  • Resolves the selected module as a ModuleConfig instance
  • Module-aware paths and namespacing for generators
  • Drop-in traits for Command and GeneratorCommand
  • Designed for package authors integrating with internachi/modular
Frequently asked questions about Modularize
How do I add the --module option to an existing Laravel Artisan command?
Use the `Modularize` trait in your command class. This automatically adds the `--module` flag and injects a `module()` method that returns the resolved `ModuleConfig` instance. No additional configuration is needed beyond including the trait.
Can I use internachi/modularize with Laravel versions older than 13?
No, this package is designed for Laravel 13+ due to its reliance on Symfony 7.x components. If you’re using an older Laravel version, you’ll need to find an alternative or manually implement modular support.
What happens if I don’t specify a module when running a command with Modularize?
The `--module` flag is optional. If omitted, the `module()` method returns `null`, allowing you to handle non-module-specific logic in your command. This makes the package flexible for both module-aware and global commands.
How does ModularizeGeneratorCommand handle file generation paths and namespaces?
The `ModularizeGeneratorCommand` trait automatically places generated files in the correct module directory and applies the module’s namespace. It overrides the default `getPath()` and `getDefaultNamespace()` methods to ensure consistency with the module structure.
Is internachi/modularize compatible with custom module configurations or non-PSR-4 paths?
The package relies on `internachi/modular`'s `ModuleConfig` for path and namespace resolution. If your modules use non-standard configurations, you may need to extend or override the `ModuleConfig` class to ensure compatibility with the traits.
Can I use this package without internachi/modular installed?
No, `internachi/modularize` depends on `internachi/modular` for module resolution. If you’re not already using `internachi/modular`, this package won’t work without significant refactoring to adapt to its expected `ModuleConfig` structure.
How do I test commands that use Modularize or ModularizeGeneratorCommand?
Mock the `ModuleConfig` instance returned by the `module()` method in your tests. For generators, verify that the generated files are placed in the correct module directory and use the expected namespace. Use Laravel’s `Artisan::call()` for integration testing.
Are there any performance concerns with using Modularize in production?
The package adds minimal overhead, primarily during command initialization when resolving the module. Since it leverages Laravel’s service container and traits, there’s no significant impact on runtime performance in production environments.
What are the alternatives to internachi/modularize for Laravel modular commands?
Alternatives include `spatie/laravel-modules`, which provides a broader modular system with its own command helpers, or manually implementing module-aware logic using Laravel’s service container and traits. However, these may not offer the same seamless integration with `internachi/modular`.
How do I customize the module resolution logic in Modularize?
Extend the `Modularize` trait or override the `module()` method in your command class. You can also customize how the module is resolved by modifying the `ModuleConfig` class or injecting your own resolution logic via Laravel’s service container.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport