Skip to content

fix: Limit how many projects are considered for version check validation on generate - #3273

Merged
nielsenko merged 24 commits into
serverpod:mainfrom
nielsenko:fix-2762-symlink-windows-when-serverpod-generate
Mar 12, 2025
Merged

nielsenko merged 24 commits into
serverpod:mainfrom
nielsenko:fix-2762-symlink-windows-when-serverpod-generate

Conversation

@nielsenko

@nielsenko nielsenko commented Feb 28, 2025 •

Copy link
Copy Markdown
Collaborator

This PR changes how serverpod_cli validates versions during serverpod generate.

Previously it would consider all pubspec.yaml files below the parent of the generated server project. This could potentially include a lot of projects, and is not needed.

It is important (for now) that the serverpod dependencies used between the generated server and client library match the version of serverpod_cli exactly. We ensure that by pining the version, and have serverpod generate check that the versions matches its own, and are still pinned. This guarantees that the generated code, and protocol matches.

However we don't need to run this check on any other projects. If any other project (fx. the flutter project setup during serverpod create) depends on the generated client, then normal package resolution will ensure that the project uses the same version, as it is pinned.

This change came about while investigating #2762 . There is a known issue with Directory.listSync and friends on windows, when traversing directories containing symlinks.

PathNotFoundException: Directory listing failed, path =                                                                                                                                                          
'C:\Users\chris\src\talking_noticeboard\talking_noticeboard_flutter\linux\flutter\ephemeral\.plugin_symlinks\flutter_soloud\android\.cxx\Debug\3j3u5064\arm64-v8a\CMakeFiles\flutter_soloud_plugin.dir\33da5992842d4b024c1554ca2f93d5a0\src\soloud\src\audiosource\ay\*'                                                                                                                                                          
(OS Error: The system cannot find the path specified.                                                                                                                                                            
, errno = 3)                                                                                                                                                                                                     
                                                                                                                                                                                                                 
#0      _Directory._fillWithDirectoryListing (dart:io-patch/directory_patch.dart:42:24)                                                                                                                          
#1      _Directory.listSync (dart:io/directory_impl.dart:228:5)                                                                                                                                                  
#2      findPubspecsFiles (package:serverpod_cli/src/util/pubspec_helpers.dart:20:24)    
...

Flutter uses symlinks (..\ephemeral.plugin_symlinks..) in platforms projects, if an app uses native plugins. Since we no longer invoke Directory.listSync we implicitly sidestep this issue.

fix: #2762

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. (If you are submitting multiple fixes, please make multiple PRs.)
  • 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 ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

If you need help, consider asking for advice on the discussion board.

Breaking changes

None, this will produce less warnings than before.

@nielsenko nielsenko changed the title Fix 2762 symlink windows when serverpod generate fix: Limit how many projects are considered for version check validation on generate Feb 28, 2025
@nielsenko
nielsenko force-pushed the fix-2762-symlink-windows-when-serverpod-generate branch 6 times, most recently from 559546f to 8240191 Compare March 6, 2025 07:46
@nielsenko
nielsenko requested a review from SandPod March 6, 2025 08:02
@nielsenko
nielsenko force-pushed the fix-2762-symlink-windows-when-serverpod-generate branch 2 times, most recently from eb62291 to d155091 Compare March 6, 2025 08:06

@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.

Really neat cleanup and improvements of that part of the system!

It really feels like there were a couple of hot patches in that code that could be removed.

I have a couple of questions and comments, main focus is ensuring that we don't introduce unhandled crashes that we did not have before.

@nielsenko
nielsenko force-pushed the fix-2762-symlink-windows-when-serverpod-generate branch 2 times, most recently from e0ea6c5 to 064eb9c Compare March 10, 2025 12:17
- Refactored the version check logic to use a new `PubspecPlus` class for better encapsulation and handling of pubspec files.
- Updated the `validateServerpodPackagesVersion` function to work with the new `PubspecPlus` class.
- Only check the generated server and client packages (this implicitly fix: 2762).
- Removed outdated and redundant test assets.
- Moved the `PubspecPlus` class and related code from `serverpod_packages_version_check.dart` to a new file `pubspec_plus.dart`.
- Updated imports in `serverpod_packages_version_check.dart` to reference the new `pubspec_plus.dart` file.
- Introduce loadYamlMap function in `yaml_util.dart`. This will correctly parse an empty string as a map, when a map expected (defaults to YamlScalar).
This commit removes redundant tests from the serverpod_packages_version_check_test.dart file.
The removed tests were checking all pubspec.yaml files below the test_assets directory, but
version check no longer traverses the parent of the generated serverpod directory recursively,
so the tests were redundant.
@nielsenko
nielsenko force-pushed the fix-2762-symlink-windows-when-serverpod-generate branch from bb92ea8 to 51cd174 Compare March 10, 2025 14:38
@nielsenko
nielsenko force-pushed the fix-2762-symlink-windows-when-serverpod-generate branch from 2977438 to 96152fd Compare March 11, 2025 13:56

@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 cleanup of the code!

A couple of comments and suggestions.

@nielsenko
nielsenko force-pushed the fix-2762-symlink-windows-when-serverpod-generate branch from c46c216 to 2e0290a Compare March 12, 2025 14:36
@nielsenko
nielsenko requested a review from SandPod March 12, 2025 15:21

@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.

LGTM! 🚀

@nielsenko
nielsenko merged commit 85f0a60 into serverpod:main Mar 12, 2025
@nielsenko
nielsenko deleted the fix-2762-symlink-windows-when-serverpod-generate branch March 12, 2025 15:33
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 12, 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.

Error when running serverpod generate

2 participants