Skip to content

feat: Support platform specific scripts - #4471

Merged
nielsenko merged 10 commits into
serverpod:mainfrom
nielsenko:feat-platform-specific-scripts
Dec 21, 2025
Merged

nielsenko merged 10 commits into
serverpod:mainfrom
nielsenko:feat-platform-specific-scripts

Conversation

@nielsenko

@nielsenko nielsenko commented Dec 17, 2025 •

Copy link
Copy Markdown
Collaborator

Add platform-specific script support for serverpod run

Adds support for defining platform-specific commands in pubspec.yaml scripts, enabling cross-platform script definitions.

Changes

  • Scripts can now be defined with windows and posix keys for platform-specific commands
  • Added Script.fromYaml() factory for parsing both simple and platform-specific formats
  • Added supportsCurrentPlatform getter and UnsupportedPlatformException
  • serverpod run --list shows "(not available on $platform)" for unsupported scripts
  • Renamed ScriptsParseException to ScriptParseException
  • Updated e2e tests to run on Windows

Example

serverpod:
  scripts:
    build: dart compile exe bin/main.dart  # works on all platforms
    start:
      windows: start.bat
      posix: ./start.sh

Fixes #XXXX
Fixes #4439

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else.
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

Breaking changes

None

Summary by CodeRabbit

  • New Features

    • Scripts now support platform-specific commands for Windows and POSIX environments.
    • Script listing displays platform availability information.
  • Bug Fixes

    • Improved validation and error messaging for platform-incompatible scripts.
    • Enhanced Windows compatibility for CLI operations.

✏️ Tip: You can customize this high-level summary in your review settings.

@nielsenko nielsenko self-assigned this Dec 17, 2025
@nielsenko

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 17, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Dec 17, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes introduce platform-aware script definitions and execution to the Serverpod CLI. The Script class is refactored to support separate Windows and POSIX commands defined per-platform in YAML. The RunCommand validates platform availability at runtime and lists only compatible scripts. The exception type for script parsing is renamed, and comprehensive tests cover platform-specific parsing, validation, and execution flows.

Changes

Cohort / File(s) Summary
Platform-aware Script infrastructure
tools/serverpod_cli/lib/src/scripts/script.dart, tools/serverpod_cli/lib/src/scripts/scripts.dart
Script class refactored to support windowsCommand and posixCommand fields replacing single command. Added Script.platformSpecific constructor, Script.fromYaml and _fromPlatformMap factories to parse YAML definitions. New command getter and supportsCurrentPlatform getter. Exception type ScriptsParseException renamed to ScriptParseException and new UnsupportedPlatformException introduced.
Run command platform validation
tools/serverpod_cli/lib/src/commands/run.dart
Added runtime platform availability checks before script execution; logs error and exits if script unsupported on current platform. Updated script listing to show only platform-compatible scripts. Exception handling updated from ScriptsParseException to ScriptParseException.
Script parsing tests
tools/serverpod_cli/test/scripts/scripts_test.dart
Updated all test assertions to use ScriptParseException instead of ScriptsParseException. Added comprehensive test coverage for platform-specific script parsing, validation of platform keys/commands, empty platform maps, unknown platforms, and UnsupportedPlatformException behavior.
E2E test setup
tests/serverpod_cli_e2e_test/test/run_command_test.dart
Changed test annotations from @TestOn('!windows') to @Timeout. Made CLI executable path selection Windows-aware. Updated runServerpod default RunType from activated to compiled. Refactored test server script definitions to be OS-aware with separate Windows and POSIX entries in pubspec.yaml.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant CLI as Serverpod CLI
    participant ScriptLoader as Script Loader
    participant Platform as Platform Detection
    participant Executor as Script Executor

    User->>CLI: Run 'serverpod run <script>'
    CLI->>ScriptLoader: Load script from pubspec.yaml
    ScriptLoader->>ScriptLoader: Parse YAML (single or per-platform)
    ScriptLoader-->>CLI: Script object (with windows/posix commands)
    
    CLI->>Platform: Check current platform support
    Platform-->>CLI: Platform check result
    
    alt Platform Supported
        CLI->>Executor: Execute script command
        Executor-->>CLI: Command output
        CLI-->>User: Success
    else Platform Unsupported
        CLI->>CLI: Log error (platform not supported)
        CLI-->>User: Error & Exit
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • script.dart: Significant refactoring with new platform-aware fields, multiple new factories, getters, and exception types; requires verification of YAML parsing logic, platform detection mechanism, and exception handling paths
  • run.dart: Platform availability validation logic and updated exception handling; verify correct platform check placement and error messaging
  • scripts_test.dart: Extensive new test coverage for platform-specific scenarios; verify all platform combinations and edge cases are properly validated
  • scripts.dart: Exception renaming and export changes; ensure all usages across codebase are consistent

Possibly related issues

Possibly related PRs

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description has an incomplete issue reference with a placeholder '#XXXX' that was not replaced with an actual issue number. Replace the placeholder '#XXXX' with the actual issue number being fixed. The PR currently only references issue #4439, but the template requires explicitly listing at least one issue that this PR fixes.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: Support platform specific scripts' clearly and concisely summarizes the main feature being added, matching the primary change across all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@nielsenko
nielsenko force-pushed the feat-platform-specific-scripts branch from bc12ebd to 6528e23 Compare December 17, 2025 19:31
@nielsenko
nielsenko marked this pull request as ready for review December 17, 2025 20:04
@nielsenko
nielsenko requested review from a team and SandPod December 17, 2025 20:04
@nielsenko

Copy link
Copy Markdown
Collaborator Author

Ignoring flaky windows test

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes looks good! Have a couple of questions and suggestions.

@nielsenko
nielsenko requested a review from SandPod December 18, 2025 16:37
@nielsenko
nielsenko force-pushed the feat-platform-specific-scripts branch 2 times, most recently from 710f1e3 to 9ac3c51 Compare December 18, 2025 23:50

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice addition!

Leaving the last comment open as an optional thing to fix. I still think it might be good to address to ensure the exception and implementation stays in sync in the future.

@nielsenko
nielsenko force-pushed the feat-platform-specific-scripts branch 2 times, most recently from 706757b to be44c7d Compare December 20, 2025 11:34
@nielsenko
nielsenko force-pushed the feat-platform-specific-scripts branch from be44c7d to 903b73f Compare December 21, 2025 12:38
@nielsenko
nielsenko force-pushed the feat-platform-specific-scripts branch from 903b73f to 3ed4e55 Compare December 21, 2025 13:02
@nielsenko
nielsenko force-pushed the feat-platform-specific-scripts branch from 9316595 to 5f29b23 Compare December 21, 2025 13:39
@nielsenko

Copy link
Copy Markdown
Collaborator Author

Disregarding flaky tests

@nielsenko
nielsenko merged commit 19e6a9c into serverpod:main Dec 21, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 21, 2025
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.

Refactor RunCommand to use execute helper from cli_tools

2 participants