Removing Components
Refactoring code often causes components to become obsolete or irrelevant. This is where removing and deprecating components becomes useful and necessary.
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 ui/buttonsuccessfully removed components:ui/buttonBit triggers a warning when trying to remove modified components. Use the --force flag to force it.
tip
Use bit remove --help or bit remove -h to get a list of available options for this command.
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. Several cases 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.
Remove a component from a remote scope#
To remove a component from a remote scope, specify the full component ID.
bit remove username.your-scope/ui/button --remotesuccessfully removed components:username.your-scope/ui/buttonEffects of deleting components#
To better understand how Bit handles deleted components, let's follow this example:
- The
buttoncomponent is in theuiscope. - A
cardcomponent depends on thebuttoncomponent and is also inuiscope. - A
logincomponent also depends on thebuttoncomponent but is in another scope -admin.
This is what happens if we remove the button component:
- Bit notifies that the
cardcomponent depends on thebuttoncomponent. If we want to remove it, Bit asks to use the--forceflag. This is because scopes don't cache their components. - The
cardcomponent has a missing dependency ofbuttoncomponent. A refactor forcardis critical for it to work. - The
logincomponent that also depends on thebuttoncomponent is not affected by the removal of thebuttoncomponent. This is because scopes keep a cache of external dependencies. - It is still possible to source the
logincomponent to another consumer project, as the cache works for Bit. - Installing the
logincomponent using npm fails because npm tries to install thebuttoncomponent from its original scope.
Deprecate a component in a remote scope#
To deprecate a component in a remote Scope, specify the full component ID and use the --remote option.
bit deprecate username.your-scope/ui/button --remotedeprecated components: username.your-scope/ui/buttonDeprecating a component in a workspace#
To deprecate a component in a workspace, specify the component ID.
bit deprecate ui/buttondeprecated components: ui/buttontip
Use bit deprecate --help or bit deprecate -h to get a list of available options for this command.