Skip to content

Add modules:remove command - #147

Open
Amad3eu wants to merge 2 commits into
InterNACHI:mainfrom
Amad3eu:feat/modules-remove
Open

Amad3eu wants to merge 2 commits into
InterNACHI:mainfrom
Amad3eu:feat/modules-remove

Conversation

@Amad3eu

@Amad3eu Amad3eu commented Sep 30, 2026

Copy link
Copy Markdown

Closes #71

What it does

php artisan modules:remove {name} reverses what make:module sets up:

  • Deletes the module directory
  • Removes the module's package (read from its own composer.json name) from require / require-dev in the application composer.json
  • Clears the module cache and reloads the registry
  • Prints the composer update <package> command to run afterwards

It asks for confirmation before deleting anything (--force skips it; declining or running non-interactively without --force aborts with exit code 1). Unknown module names fail with exit code 1.

The app-modules/* path repository is left alone, since it's shared by every module.

Tests

Added ModulesRemoveTest (removal, other modules untouched, confirmation accepted/declined, unknown module). Full suite passes (136 tests).

Thanks @adam-dziuk for letting me pick this up.

@doraemonxxx

Copy link
Copy Markdown

Thanks for implementing this! Having a modules:remove command is a great addition and a natural counterpart to make:module.

I reviewed the implementation and have a few suggestions before merging:

  1. Consider using try/finally when changing the working directory to ensure the original directory is always restored, even if Composer file operations fail.
  2. Add graceful handling for invalid or malformed module composer.json files.
  3. Add tests for modules listed under require-dev and modules without a composer.json file.
  4. Consider testing Composer file write failures to ensure the command doesn't leave the application in an inconsistent state.

The existing tests are a good starting point, particularly the confirmation and other-module preservation tests.

I support the feature, but I think these edge cases should be addressed before merging.

Thanks!

@doraemonxxx

Copy link
Copy Markdown

One additional consideration: I think we should prevent removing a module if another installed module depends on it.

For example, if the comments module requires the blog module, running modules:remove blog should fail rather than deleting it and potentially breaking the dependent module at runtime.

Expected behavior

Given the following modules:

text

app-modules/
├── blog/
├── comments/
└── users/

Where:

  • comments depends on blog.
  • users is independent.

The expected behavior should be:

  • modules:remove blog → Fail because comments depends on it.
  • modules:remove comments → Allow.
  • modules:remove users → Allow.

Suggested implementation

Before removing a module, could we:

  1. Read the target module's Composer package name.
  2. Inspect the require and require-dev dependencies declared in the other installed modules' composer.json files.
  3. Identify any modules that directly depend on the target module.
  4. If dependencies exist, abort the removal and display the dependent module names.
  5. Only proceed with deletion if no dependent modules are found.

For example:

text

Cannot remove module [blog].

The following modules depend on it:

- comments

Remove or update these dependencies before removing blog.

Additional consideration

I'd also recommend checking transitive dependencies.

For example:

text

dashboard → reports → blog

Removing blog should be blocked because dashboard indirectly depends on it through reports.

The dependency check should rely on the declared Composer dependencies rather than runtime module discovery alone. This ensures that even modules that aren't currently loaded are still considered.

I think this safeguard is important to prevent accidentally breaking other modules and to make modules:remove safer to use.

My recommendation is to make dependency checking mandatory rather than an optional flag. A module manager should protect the integrity of the application's dependency graph by default.

Thanks!

@Amad3eu

Amad3eu commented Nov 4, 2026 via email

Copy link
Copy Markdown
Author

…:remove

The working directory is now restored even when the application composer.json cannot be read or written.

Removing the last package of a section used to leave an empty JSON list behind ("require-dev": []), which Composer rejects. The section now goes away with its last package.

Adds tests for a module listed in require-dev, and for modules whose composer.json is missing or invalid.
@doraemonxxx

Copy link
Copy Markdown

Thanks for the detailed review. The edge cases and dependency safeguard are clear. Before changing the scope, should the transitive dependency check and simulated Composer write failures be included in this PR, or would you prefer the broader dependency-graph validation to be handled separately?

I'd prefer to keep this PR focused on the core modules:remove functionality and the safeguards directly required for safe removal.

The transitive dependency check is worth addressing, but I think broader dependency-graph validation deserves its own scope and dedicated tests. The same goes for simulated Composer write failures — they're useful for validating failure handling, but I'd rather avoid expanding this PR unless they're necessary to guarantee the current implementation is safe.

Let's get the essential removal flow merged first, then tackle the broader dependency handling separately.

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.

Remove or delete module feature

2 participants