Skip to content

Comments

feat(dev): add --remove-on-exit flag to tear down service on exit#13321

Merged
czubocha merged 7 commits intomainfrom
sc-3720
Feb 4, 2026
Merged

feat(dev): add --remove-on-exit flag to tear down service on exit#13321
czubocha merged 7 commits intomainfrom
sc-3720

Conversation

@czubocha
Copy link
Contributor

@czubocha czubocha commented Feb 4, 2026

Summary

Adds a --remove-on-exit flag to the serverless dev command that prompts users to remove the deployed service stack when exiting Dev Mode with Ctrl+C.

Changes

  • Added --remove-on-exit boolean option to the dev command schema
  • When the flag is present and user presses Ctrl+C:
    • Prompts for confirmation: Remove "service-name" from stage "stage" in "region"? (y/N)
    • If confirmed, runs serverless remove with a spinner showing progress
    • If declined, shows a warning reminding users to run serverless deploy or serverless remove

Usage

serverless dev --remove-on-exit

Why

Dev Mode deploys a modified service with instrumentation shim. After exiting, users must either:

  • Run serverless deploy to restore original code
  • Run serverless remove to tear down the stack

This flag streamlines the teardown workflow for users who want to clean up immediately after development.

Summary by CodeRabbit

  • New Features

    • Dev Mode now prompts on Ctrl+C to optionally remove the deployed service, shows removal progress, and reports success or errors; if removal is declined the original exit warning remains.
  • Documentation

    • CLI reference updated to document the new --remove-on-exit option.

@Mmarzex
Copy link
Contributor

Mmarzex commented Feb 4, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

Adds a new boolean CLI option --remove-on-exit to the dev command and implements an async Ctrl+C handler that, when enabled, prompts the user to confirm and optionally runs the service removal flow before exiting.

Changes

Cohort / File(s) Summary
Dev Command Schema
packages/serverless/lib/cli/commands-schema.js
Added new boolean option remove-on-exit with usage description to the dev command schema.
Dev Mode Exit Handler
packages/serverless/lib/plugins/aws/dev/index.js
Converted Ctrl+C handler to async; when remove-on-exit is enabled, prompt for confirmation, spawn the remove action, display progress, handle success/errors, and preserve final exit logging/behavior.
Documentation (CLI)
docs/sf/providers/aws/cli-reference/dev.md
Documented the new --remove-on-exit CLI option in the Dev command reference.
Documentation (AWS domains guide)
docs/sf/providers/aws/guide/domains.md
Reformatted and reordered the configuration reference table for custom domains (presentational changes only).

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ExitHandler as Exit Handler
    participant Prompt as Prompter
    participant RemoveAction as Remover
    participant Logger as Logger

    User->>ExitHandler: Press Ctrl+C
    ExitHandler->>Prompt: If remove-on-exit -> ask confirmation
    alt confirmed
        Prompt->>RemoveAction: spawn remove action
        RemoveAction->>Logger: emit progress updates
        RemoveAction->>Logger: emit success / completion
    else cancelled
        Prompt->>Logger: emit cancellation warning
    end
    ExitHandler->>Logger: log final blank line
    ExitHandler->>User: exit process
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped by code and left a mark,
A tiny flag to clear the park,
Ctrl+C hums a gentle test—
Confirm, then watch the stacks rest,
Soft paws tidy, then I depart.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main change: adding a --remove-on-exit flag to the dev command for service teardown. The title is concise, specific, and clearly summarizes the primary feature addition.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sc-3720

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0fb6db6783

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@czubocha czubocha requested a review from eahefnawy February 4, 2026 19:28
eahefnawy
eahefnawy previously approved these changes Feb 4, 2026
@czubocha czubocha merged commit 3a480ae into main Feb 4, 2026
12 checks passed
@czubocha czubocha deleted the sc-3720 branch February 4, 2026 20:55
@github-actions github-actions bot locked and limited conversation to collaborators Feb 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants