apache / apache/cordova-cli

Script for plugin hook "after_plugin_rm" does not work

Open
#629 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
967
Forks
344
Avg merge
8h 41m
Merged PRs (30d)
9

Description

# Bug Report

## Problem
I want to do something after plugin is removed.
I have tried to use `after_plugin_rm` hook in "plugin.xml" but it did not work.
### What is expected to happen?

Script for `after_plugin_rm` need to be executed

### What does actually happen?

No scripts found for hook `after_plugin_rm`.

## Information

Scripts for hooks(`after_plugin_add` 、 `before_plugin_rm` and `before_plugin_uninstall`) are all performed normally.
After removing the plugin, the commandline outputs 'No scripts found for hook "after_plugin_rm"'

I think It may be caused by the plugin code(include the script for "after_plugin_rm" hook) being removed before "after_plugin_rm" hook.

I built a [simple cordova plugin repository](https://github.com/trayvon2017/plugindemo.git) for test.

### Command or Code

Partial code in plugin.xml, full plugin code is [here](https://github.com/trayvon2017/plugindemo.git)
```xml

...





...
```

#### add plugin
`cordova plugin add https://github.com/trayvon2017/plugindemo.git`
outputs:
```shell
Installing "com.trayvon2017.plugindemo" for android
Installing "com.trayvon2017.plugindemo" for ios
Adding com.trayvon2017.plugindemo to package.json
after_plugin_add waited 1004 ms
```
#### remove plugin
`cordova plugin remove com.trayvon2017.plugindemo --verbose`
outputs:
```shell
Executing script found in plugin com.trayvon2017.plugindemo for hook "before_plugin_rm": plugins/com.trayvon2017.plugindemo/scripts/before_plugin_rm.js
before_plugin_rm waited 1003 ms
Calling plugman.uninstall on plugin "com.trayvon2017.plugindemo" for platform "android"
Finding scripts for "before_plugin_uninstall" hook from plugin com.trayvon2017.plugindemo on android platform only.
Executing script found in plugin com.trayvon2017.plugindemo for hook "before_plugin_uninstall": plugins/com.trayvon2017.plugindemo/scripts/before_plugin_uninstall.js
before_plugin_uninstall waited 1003 ms
Uninstalling com.trayvon2017.plugindemo from android
Loaded API for android project /Users/trayvon/code/cordova-projects/hello/platforms/android/cordova/Api.js
Beginning processing of action stack for android project...
Action stack processing complete.
Calling plugman.uninstall on plugin "com.trayvon2017.plugindemo" for platform "ios"
Finding scripts for "before_plugin_uninstall" hook from plugin com.trayvon2017.plugindemo on ios platform only.
No scripts found for hook "before_plugin_uninstall".
Uninstalling com.trayvon2017.plugindemo from ios
Loaded API for ios project /Users/trayvon/code/cordova-projects/hello/platforms/ios/cordova/Api.js
Beginning processing of action stack for ios project...
Action stack processing complete.
pods.json found in platforms/ios
Podfile found in platforms/ios
Removing "com.trayvon2017.plugindemo"
Deleted plugin "com.trayvon2017.plugindemo"
Running command: npm uninstall com.trayvon2017.plugindemo --save-dev
Command finished with error code 0: npm uninstall,com.trayvon2017.plugindemo,--save-dev
Removing com.trayvon2017.plugindemo from package.json
Removing plugin com.trayvon2017.plugindemo from fetch.json
No scripts found for hook "after_plugin_rm".
```
### Environment, Platform, Device

### Version information

Cordova CLI: 11.0.0 and 12.0.0
Cordova Platforms: android
Operating System: macos 13.5.2

## Checklist

- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with `cordova plugin remove ... --verbose` using the linked plugindemo and its `plugin.xml` entry for `scripts/after_plugin_rm.js`. Start by tracing the plugin-removal command and `plugman.uninstall` hook handling, comparing it with `before_plugin_rm` and `before_plugin_uninstall`. Done means the after-removal script is discovered and executed after plugin removal.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.