Remove & Deprecate Components
Refactoring code often causes components to become obsolete or irrelevant. This is where removing and deprecating components becomes useful and necessary.
Each collection has an internal cache for its dependencies. But this does not mean that removing components is not dangerous. Due to the fact, that package managers don’t always use cache. It may break builds that rely on deleted content. Deprecating a component means that Bit marks it as obsolete. Deprecated components are still available to consumers.
Remove a component from a remote Collection
To remove a component from a remote Collection, specify the full component ID.
$ bit remove username.your-collection/foo/bar
successfully removed components:
username.your-collection/foo/bar
Effects of deleting components
To better understand how Bit handles deleted components, let’s follow this example:
- The
left-padin theutilscollection. - A component
trim-rightdepends onleft-padand is also inutilscollection. - A component
loginalso depends onleft-padbut is in another collection -onboarding.
This is what happens if we remove left-pad:
- Bit notifies that
trim-rightdepends onleft-pad. If we want to remove it, Bit asks to use the —force flag. This is because collections don’t cache their components. - The
trim-rightcomponent has a missing dependencyleft-pad. A refactor fortrim-rightis critical for it to work. loginthat also depends onleft-padis not affected by the removal ofleft-pad. This is because collections keep a cache of external dependencies.- It is still possible to source
loginto another consumer project, as the cache works for Bit. - Installing
loginusing npm fails because npm tries to installleft-padfrom its original collection.
Remove a component from a workspace
Removing a local component has no ripple effects. This is only relevant to the consuming project. To do so specify the component ID to remove.
$ bit remove foo/bar
successfully removed components:
foo/bar
Bit triggers a warning when trying to remove modified components. Use the --force flag to force it.
Effects of deleting components from a workspace
Other components in the workspace may depend on removed components. Meaning that removing these dependencies affects dependent components. There are several cases which may occur when deleting a local component:
- A new component that depends on a removed component is not affected. This is because Bit did not isolate the component.
- A staged component that depends on a removed component causes Bit to stop the remove command. To force it, we use the
--forceflag. - An exported component that depends on a local removed component is not affected. This is because an exported component is isolated and immutable. So deleting a local dependency does not affect.
Deprecate a component in a remote collection
To deprecate a component in a remote Collection, specify the full component ID and use the --remote option.
$ bit deprecate username.your-collection/foo/bar --remote
deprecated components: username.your-collection/foo/bar
Deprecating a component in a workspace
To deprecate a component in a workspace, specify the component ID.
$ bit deprecate foo/bar
deprecated components: foo/bar