Refactoring code often causes components to become obsolete or irrelevant. This is where removing and deprecating components becomes useful and necessary.
When you deprecate a component you update it. This requires the component to be authored in your workspace or imported into it.
Run the following to deprecate a component:
The output should display the following:
The component has been modified. Snap it and export it to its remote scope.
The component's deprecated
status can be seen in the UI (scope and workspace), as well as in the terminal, when running bit show
, bit status
, bit install
, etc.
Local components should be removed with caution
Learn more in the Effects of deleting components from a workspace section.
foo/bar
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
--force
flag. - 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.
Removing components from their remote scope is highly inadvisable!
Deprecate components instead to avoid possible damage to dependent components and projects.
Learn more in the Effects of deleting components section.
To remove a component from a remote scope, specify the full component ID.
The output should display the following:
my-org.my-scope/foo/bar
To better understand how Bit handles deleted components, let's follow this example:
- The
left-pad
in theutils
scope. - A component
trim-right
depends onleft-pad
and is also inutils
scope. - A component
login
also depends onleft-pad
but is in another scope -onboarding
.
This is what happens if we remove left-pad
:
- Bit notifies that
trim-right
depends onleft-pad
. If we want to remove it, Bit asks to use the --force flag. This is because scopes don't cache their components. - The
trim-right
component has a missing dependencyleft-pad
. A refactor fortrim-right
is critical for it to work. login
that also depends onleft-pad
is not affected by the removal ofleft-pad
. This is because scopes keep a cache of external dependencies.- It is still possible to source
login
to another consumer project, as the cache works for Bit. - Installing
login
using npm fails because npm tries to installleft-pad
from its original scope.