Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/+component-cli-shim.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`reflex component` and its old subcommands now exit with a pointer to the wrapping React docs and the [component template](https://github.com/reflex-dev/component-template) instead of "No such command".
31 changes: 31 additions & 0 deletions reflex/reflex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,37 @@ def rename(new_name: str):
rename_app(new_name, get_config().loglevel)


_COMPONENT_REMOVED = (
"`reflex component` was removed in Reflex 0.10. Wrap React components "
"directly in your app (https://reflex.dev/docs/wrapping-react/overview/) "
"and start reusable component packages from the component template: "
"https://github.com/reflex-dev/component-template"
)


@cli.command(
name="component",
hidden=True,
help=_COMPONENT_REMOVED,
context_settings={"ignore_unknown_options": True},
)
@click.argument("args", nargs=-1, type=click.UNPROCESSED)
def component(args: tuple[str, ...]):
"""Point users of the removed component CLI at its replacement.

Accepts any subcommand and flags so `reflex component init`, `build`,
`share`, and `install` all land here instead of a "No such command" error.

Args:
args: The removed subcommand and its flags, ignored.

Raises:
Exit: Always, after reporting where the component workflow moved.
"""
logger.error(_COMPONENT_REMOVED)
raise click.exceptions.Exit(1)


cli.add_command(
_LazyCommand(
"deploy",
Expand Down
88 changes: 85 additions & 3 deletions tests/units/test_reflex.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def _run_cli_probe(probe: str) -> dict[str, object]:
(["--help"], _CLI_STARTUP_DENIED_MODULES),
(["--version"], _CLI_STARTUP_DENIED_MODULES),
(["run", "--help"], _CLI_STARTUP_DENIED_MODULES),
(["component", "--help"], _CLI_STARTUP_DENIED_MODULES),
(
["deploy", "--help"],
_CLI_STARTUP_DENIED_MODULES - {"reflex_cli.v2.deploy"},
Expand All @@ -87,6 +88,7 @@ def _run_cli_probe(probe: str) -> dict[str, object]:
"help",
"version",
"run-help",
"component-help",
"deploy-help",
"cloud-help",
],
Expand Down Expand Up @@ -227,9 +229,89 @@ def test_cloud_commands_registered():
}


def test_component_command_is_not_registered():
"""The custom components CLI has been removed."""
assert "component" not in reflex.cli.commands
_COMPONENT_TEMPLATE_URL = "https://github.com/reflex-dev/component-template"


def test_component_command_is_hidden():
"""The removed component CLI keeps a shim that stays out of the listing."""
assert reflex.cli.commands["component"].hidden

result = click.testing.CliRunner().invoke(reflex.cli, ["--help"])

assert result.exit_code == 0
listed = [line.split()[0] for line in result.output.splitlines() if line.strip()]
assert "component" not in listed


@pytest.mark.parametrize(
"args",
[
[],
["init"],
["build"],
["install", "reflex-example"],
["share", "--no-interactive"],
["--library-name", "reflex-example"],
],
)
def test_component_command_points_to_template(
caplog: pytest.LogCaptureFixture, args: list[str]
):
"""Every removed component subcommand reports where the workflow moved.

Args:
caplog: The pytest log capture fixture.
args: The arguments a user of the old workflow passes.
"""
result = click.testing.CliRunner().invoke(reflex.cli.commands["component"], args)

assert result.exit_code == 1
assert _COMPONENT_TEMPLATE_URL in caplog.text
assert "No such option" not in result.output
assert "No such command" not in result.output


@pytest.mark.parametrize("args", [["--help"], ["init", "--help"]])
def test_component_help_points_to_template(
monkeypatch: pytest.MonkeyPatch, args: list[str]
):
"""Asking the removed component CLI for help prints the pointer.

Args:
monkeypatch: The pytest monkeypatch fixture.
args: The help invocation after ``reflex component``.
"""
from reflex_base.utils import log

# Registered so teardown restores the variable the CLI callback sets.
monkeypatch.setenv(log._MANAGED_ENV_VAR, "true")
try:
result = click.testing.CliRunner().invoke(reflex.cli, ["component", *args])
finally:
log._reset()

assert result.exit_code == 0, result.output
assert _COMPONENT_TEMPLATE_URL in result.output


def test_component_command_dispatches_from_cli():
"""``reflex component init`` reaches the shim instead of a usage error."""
completed = subprocess.run(
[sys.executable, "-m", "reflex", "component", "init"],
capture_output=True,
text=True,
check=False,
timeout=30,
env={
**os.environ,
"REFLEX_CHECK_LATEST_VERSION": "false",
"REFLEX_TELEMETRY_ENABLED": "false",
},
)

assert completed.returncode == 1, completed.stderr
assert _COMPONENT_TEMPLATE_URL in completed.stderr
assert "No such command" not in completed.stderr


def test_lazy_command_delegates_click_introspection(monkeypatch: pytest.MonkeyPatch):
Expand Down
Loading