Repository navigation
feat: Add serverpod run command for running scripts - #4416
Conversation
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
📝 WalkthroughWalkthroughThis pull request introduces a new Changes
Sequence DiagramsequenceDiagram
participant User
participant CLI as RunCommand
participant Finder as ServerDirectoryFinder
participant Parser as Scripts
participant Process as Child Process
participant Terminal
User->>CLI: serverpod run [--list] [script_name]
CLI->>Finder: findPubspecFile(directory)
Finder-->>CLI: pubspec.yaml File
CLI->>Parser: Scripts.fromPubspecFile(pubspecFile)
Parser-->>CLI: Scripts (parsed from YAML)
alt --list flag
CLI->>CLI: _listScripts(scripts)
CLI->>Terminal: print script names
else execute script
CLI->>CLI: locate script by name
CLI->>Process: spawn shell process
Process->>Process: execute command
Process-->>Terminal: stream stdout/stderr
Process-->>CLI: exit code
CLI->>Terminal: return exit code
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (4)
tools/serverpod_cli/lib/src/scripts/script.dart (1)
1-28: Well-structured immutable data model.The
Scriptclass is clean and follows Dart best practices withfinalfields, aconstconstructor, and proper equality/hashCode implementations.One minor optional improvement: consider using
Object.hash(name, command)instead of XOR forhashCode, as it provides better distribution and reduces collision risk:@override - int get hashCode => name.hashCode ^ command.hashCode; + int get hashCode => Object.hash(name, command);tools/serverpod_cli/lib/src/commands/run.dart (1)
1-1: Unused import.The
dart:asyncimport appears unused.FutureandStreamare available fromdart:core.-import 'dart:async';tools/serverpod_cli/lib/src/scripts/scripts.dart (2)
13-16: Redundantimplements Exception.
YamlExceptionalready implementsException, so the explicitimplements Exceptionis unnecessary.-class ScriptsParseException extends YamlException implements Exception { +class ScriptsParseException extends YamlException { ScriptsParseException(super.message, [super.span]); }
110-114: Consider usingpath.joinfor cross-platform path construction.String interpolation with
/may produce inconsistent path separators on Windows. Usingpath.joinfrompackage:pathensures consistent platform-appropriate separators.+import 'package:path/path.dart' as path; + ... static File? findPubspecFile(Directory directory) { final serverDir = ServerDirectoryFinder.search(directory); if (serverDir == null) return null; - return File('${serverDir.path}/pubspec.yaml'); + return File(path.join(serverDir.path, 'pubspec.yaml')); }#!/bin/bash # Verify if path package is already used elsewhere in the codebase for consistency rg -l "import 'package:path/path.dart'" tools/serverpod_cli/lib/
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
tools/serverpod_cli/bin/serverpod_cli.dart(2 hunks)tools/serverpod_cli/lib/src/commands/run.dart(1 hunks)tools/serverpod_cli/lib/src/scripts/script.dart(1 hunks)tools/serverpod_cli/lib/src/scripts/scripts.dart(1 hunks)tools/serverpod_cli/test/scripts/scripts_test.dart(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.dart
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.dart: Use the 'Given, When, Then' pattern for test descriptions to maintain consistency, appearing only once in the combined group and test description
Follow Dart formatting conventions usingdart format .
Remove unnecessary comments from production code
Use descriptive variable and function names following Dart naming conventions
Rundart format .before committing code to maintain consistent formatting across the repository
Run code analysis withutil/run_tests_analyzeormelos lint_strictto match CI strict mode before committing
Files:
tools/serverpod_cli/bin/serverpod_cli.darttools/serverpod_cli/lib/src/scripts/script.darttools/serverpod_cli/test/scripts/scripts_test.darttools/serverpod_cli/lib/src/scripts/scripts.darttools/serverpod_cli/lib/src/commands/run.dart
tools/serverpod_cli/**/*.dart
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Reactivate the Serverpod CLI after making changes by running
dart pub global activate --source path .from the tools/serverpod_cli directory
Files:
tools/serverpod_cli/bin/serverpod_cli.darttools/serverpod_cli/lib/src/scripts/script.darttools/serverpod_cli/test/scripts/scripts_test.darttools/serverpod_cli/lib/src/scripts/scripts.darttools/serverpod_cli/lib/src/commands/run.dart
**/*_test.dart
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Place passing/success test cases at the top of test files, followed by error test cases for the same functionality, grouping related test cases using
group()
Files:
tools/serverpod_cli/test/scripts/scripts_test.dart
🧠 Learnings (7)
📓 Common learnings
Learnt from: CR
Repo: serverpod/serverpod PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-09T11:50:11.951Z
Learning: Applies to tools/serverpod_cli/**/*.dart : Reactivate the Serverpod CLI after making changes by running `dart pub global activate --source path .` from the tools/serverpod_cli directory
📚 Learning: 2025-12-09T11:50:11.951Z
Learnt from: CR
Repo: serverpod/serverpod PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-09T11:50:11.951Z
Learning: Applies to tools/serverpod_cli/**/*.dart : Reactivate the Serverpod CLI after making changes by running `dart pub global activate --source path .` from the tools/serverpod_cli directory
Applied to files:
tools/serverpod_cli/bin/serverpod_cli.darttools/serverpod_cli/lib/src/scripts/script.darttools/serverpod_cli/test/scripts/scripts_test.darttools/serverpod_cli/lib/src/scripts/scripts.darttools/serverpod_cli/lib/src/commands/run.dart
📚 Learning: 2025-07-02T16:07:50.947Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3747
File: modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/lib/src/business/migrating_email_endpoint_base.dart:4-4
Timestamp: 2025-07-02T16:07:50.947Z
Learning: In Serverpod, tp prefers importing the full package (e.g., 'package:serverpod_auth_migration_server/serverpod_auth_migration_server.dart') as a baseline rather than using smaller local imports, even within the same package where it might be considered a "self-import".
Applied to files:
tools/serverpod_cli/bin/serverpod_cli.darttools/serverpod_cli/lib/src/scripts/scripts.dart
📚 Learning: 2025-08-25T19:46:58.073Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3917
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/analysis_options.yaml:3-6
Timestamp: 2025-08-25T19:46:58.073Z
Learning: In Serverpod, test tool paths like `test/integration/test_tools/serverpod_test_tools.dart` are configured per project in the "generator.yaml" file and managed by a generator system, so they don't need to be updated manually across all files at once.
Applied to files:
tools/serverpod_cli/bin/serverpod_cli.darttools/serverpod_cli/lib/src/scripts/script.darttools/serverpod_cli/test/scripts/scripts_test.darttools/serverpod_cli/lib/src/scripts/scripts.darttools/serverpod_cli/lib/src/commands/run.dart
📚 Learning: 2025-11-03T15:40:41.827Z
Learnt from: SandPod
Repo: serverpod/serverpod PR: 4144
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.dart:0-0
Timestamp: 2025-11-03T15:40:41.827Z
Learning: In Serverpod authentication IDP endpoint files (modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server), endpoint base classes should import `serverpod_auth_idp_server/core.dart` to access the Session type, rather than importing `package:serverpod_auth_core_server/session.dart` directly. This pattern is consistently used in Apple, Email, and Google endpoint files.
Applied to files:
tools/serverpod_cli/bin/serverpod_cli.dart
📚 Learning: 2025-06-27T08:39:36.440Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3721
File: util/pub_get_all:0-0
Timestamp: 2025-06-27T08:39:36.440Z
Learning: In the Serverpod project, `dart pub get` commands work fine on Flutter packages both locally and in CI environments, even when the package has `flutter: sdk: flutter` dependencies in pubspec.yaml. The technical constraint of Flutter SDK dependencies causing `dart pub` failures may not apply in all environments or recent Dart versions.
Applied to files:
tools/serverpod_cli/bin/serverpod_cli.dart
📚 Learning: 2025-12-09T11:50:11.951Z
Learnt from: CR
Repo: serverpod/serverpod PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-09T11:50:11.951Z
Learning: Applies to **/*_test.dart : Place passing/success test cases at the top of test files, followed by error test cases for the same functionality, grouping related test cases using `group()`
Applied to files:
tools/serverpod_cli/test/scripts/scripts_test.dart
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (42)
- GitHub Check: Unit tests IO (3.32.0, ubuntu-latest)
- GitHub Check: Unit tests IO (3.38.4, windows-latest)
- GitHub Check: Unit tests IO (3.32.0, windows-latest)
- GitHub Check: Unit tests IO (3.38.4, ubuntu-latest)
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server with Flutter 3.32.0
- GitHub Check: Module integration tests in tests/serverpod_new_auth_test/serverpod_new_auth_test_server with Flutter 3.38.4
- GitHub Check: Module integration tests in tests/serverpod_new_auth_test/serverpod_new_auth_test_server with Flutter 3.32.0
- GitHub Check: Module integration tests in tests/serverpod_test_nonvector/serverpod_test_nonvector_server with Flutter 3.38.4
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server with Flutter 3.38.4
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_core/serverpod_auth_core_server with Flutter 3.32.0
- GitHub Check: Module integration tests in tests/serverpod_test_nonvector/serverpod_test_nonvector_server with Flutter 3.32.0
- GitHub Check: Version change test
- GitHub Check: CLI e2e tests (3.38.4, ubuntu-latest, tests/serverpod_cli_e2e_test)
- GitHub Check: Bootstrap tests (3.38.4, windows-latest, tests/bootstrap_project)
- GitHub Check: Serverpod E2E web tests (3.38.4)
- GitHub Check: Flutter unit tests (3.32.0, windows-latest, packages/serverpod_flutter)
- GitHub Check: dart analyze (3.32.0, ubuntu-latest)
- GitHub Check: Serverpod E2E web tests (3.32.0)
- GitHub Check: Flutter unit tests (3.38.4, windows-latest, packages/serverpod_flutter)
- GitHub Check: Bootstrap tests (3.32.0, ubuntu-latest, tests/bootstrap_project)
- GitHub Check: Serverpod integration tests (flutter)
- GitHub Check: Bootstrap tests (3.38.4, ubuntu-latest, tests/bootstrap_project)
- GitHub Check: Unit tests Web (3.38.4, windows-latest)
- GitHub Check: Bootstrap tests (3.32.0, windows-latest, tests/bootstrap_project)
- GitHub Check: CLI e2e tests (3.32.0, ubuntu-latest, tests/serverpod_cli_e2e_test)
- GitHub Check: Migration e2e tests (3.32.0)
- GitHub Check: Serverpod concurrent integration tests (server) (3.32.0)
- GitHub Check: Serverpod E2E IO tests (3.38.4)
- GitHub Check: Serverpod concurrent integration tests (server) (3.38.4)
- GitHub Check: Serverpod E2E IO tests (3.32.0)
- GitHub Check: Serverpod integration tests (server) (3.38.4)
- GitHub Check: Serverpod integration tests (server) (3.32.0)
- GitHub Check: Migration e2e tests (3.38.4)
- GitHub Check: dart analyze latest (3.38.4, windows-latest)
- GitHub Check: serverpod generate (3.32.0)
- GitHub Check: serverpod generate (3.38.4)
- GitHub Check: dart analyze downgrade (3.38.4, ubuntu-latest)
- GitHub Check: dart analyze downgrade (3.32.0, windows-latest)
- GitHub Check: dart analyze downgrade (3.38.4, windows-latest)
- GitHub Check: dart analyze (3.32.0, windows-latest)
- GitHub Check: dart analyze downgrade (3.32.0, ubuntu-latest)
- GitHub Check: dart analyze latest (3.38.4, ubuntu-latest)
🔇 Additional comments (5)
tools/serverpod_cli/bin/serverpod_cli.dart (1)
14-14: LGTM!The
RunCommandimport and registration follow the existing patterns for other CLI commands. The command is correctly added to the command list.Also applies to: 82-82
tools/serverpod_cli/test/scripts/scripts_test.dart (1)
12-392: Comprehensive test coverage following coding guidelines.The test file:
- Uses the "Given, When, Then" pattern consistently as per coding guidelines
- Places success test cases before error test cases within each group
- Covers edge cases including null YAML, non-existent files, invalid structures, and directory traversal scenarios
- Uses appropriate matchers (
isA,having,allOf) for detailed exception verificationtools/serverpod_cli/lib/src/commands/run.dart (1)
51-103: Well-structured command flow with proper error handling.The
runWithConfigmethod handles all expected scenarios:
- Missing pubspec file
- Parse errors with informative messages
- Empty scripts section
- Unknown script names with helpful listing
- Script execution with exit code propagation
tools/serverpod_cli/lib/src/scripts/scripts.dart (2)
31-61: LGTM!The
fromYamlfactory properly:
- Handles null input gracefully
- Uses
yaml.nodes.entriesto preserve source spans for detailed error messages- Validates both keys and values with informative error messages
116-120: LGTM!The
UnmodifiableMapBaseimplementation correctly provides read-only map semantics by only implementing the requiredoperator[]andkeysaccessors.
3d81379 to
52621b8
Compare
52621b8 to
c66bb56
Compare
SandPod
left a comment
There was a problem hiding this comment.
Nice quick work!
A couple of comments and suggestions.
Two additional things:
- Can we add an e2e test that validates this works as expected? We have our e2e cli tests we can use.
- Is it a big addition to allow additional arguments to be passed down to the script? This is scope creep and could be added later on upon request.
Due to some conflict between args and cli_tools (or my lagging knowledge) I'm having trouble getting rest args (those after --) to work with the @coderabbitai Will you create a follow-up issue for this? |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 50 @nielsenko I've created a follow-up issue for supporting additional arguments to be passed to scripts: #4421 The issue captures the context about the conflicts between |
…serverpod tag in pubspec.yaml
32525c1 to
32e60a8
Compare
b2f1192 to
70f6c61
Compare
Added (/moved) in 80beac5 |
|
@coderabbitai Create issue for using the |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 5557 🏁 Script executed: Length of output: 186 🏁 Script executed: Length of output: 2942 🏁 Script executed: Length of output: 88 🏁 Script executed: Length of output: 50 @nielsenko I've created a follow-up issue for refactoring the e2e tests to use the The issue documents the benefits of using the centralized
🧠 Learnings used |
|
@coderabbitai Create issue to use |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 4832 🏁 Script executed: Length of output: 1095 🏁 Script executed: Length of output: 88 🏁 Script executed: Length of output: 50 @nielsenko I've created a follow-up issue for refactoring The issue documents the current implementation (shell invocation, signal forwarding, stdin/stdout/stderr streaming), explains the benefits of using the shared 🧠 Learnings used |
80beac5 to
7d4d97c
Compare
- Add `RunType` enum (`dartRun`,`compiled`,`activated`,`installed`). - `runServerpod` now takes a `RunType` to determine how to run.
7d4d97c to
3f42313
Compare
SandPod
left a comment
There was a problem hiding this comment.
Last couple of comments then we are good to go! 👍
Description
Adds
serverpod runcommand to execute scripts defined inserverpod_scriptssection of pubspec.yaml.RunCommandwith--listflag to show available scriptsScriptsclass parsesserverpod_scriptsfrom pubspec.yaml with source span error messagesServerDirectoryFinderto locate the server project's pubspecUnmodifiableMapBasefor readonly map semanticsFixes #4402
Pre-launch Checklist
///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.If you need help, consider asking for advice on the discussion board.
Breaking changes
None.
Summary by CodeRabbit
runcommand to the CLI for executing custom scripts defined in your project configuration✏️ Tip: You can customize this high-level summary in your review settings.