An alternative solution might just be to manually add a check at the end of package-delete to handle the proper removal of the last package.