invertase / melos

🌋 A tool for managing Dart projects with multiple packages. With IntelliJ and Vscode IDE support. Supports automated versioning, changelogs & publishing via Conventional Commits.
https://melos.invertase.dev/~melos-latest
Apache License 2.0
1.19k stars 207 forks source link

Formatting of pubspec.lock breaks compatibility with pub #36

Closed blaugold closed 4 years ago

blaugold commented 4 years ago

I'm trying to run flutter pub run build_runner build in one of the packages, but get this error:

Cannot parse an empty string.
package:pub_semver/src/version_constraint.dart 159:7                                new VersionConstraint.parse
package:pub/src/entrypoint.dart 518:48                                              Entrypoint.assertUpToDate
package:pub/src/entrypoint.dart 111:5                                               Entrypoint.packageGraph
package:pub/src/executable.dart 87:19                                               runExecutable
package:pub/src/command/run.dart 92:26                                              RunCommand.runProtected
dart:async                                                                          new Future.sync
package:pub/src/utils.dart 113:12                                                   captureErrors.wrappedCallback
dart:async                                                                          runZonedGuarded
package:pub/src/utils.dart 130:5                                                    captureErrors
package:pub/src/command.dart 146:13                                                 PubCommand.run
package:args/command_runner.dart 197:27                                             CommandRunner.runCommand
package:pub/src/command_runner.dart 147:24                                          PubCommandRunner.runCommand
package:pub/src/command_runner.dart 136:18                                          PubCommandRunner.run
/b/s/w/ir/cache/builder/src/third_party/dart/third_party/pkg/pub/bin/pub.dart 9:48  main
This is an unexpected error. Please run

    pub --trace pub run build_runner build --delete-conflicting-outputs

and include the logs in an issue on https://github.com/dart-lang/pub/issues/new
pub finished with exit code 65

Investigating this issue, I found that pub does not fully parse the lock file as a yaml file. Instead, it uses a regex to find sdk constraints for frameworks, such as dart and flutter. This regex also matches part of the package declaration for the flutter package, after pubspec.lock has been written by melos:

  flutter: 
    dependency: "transitive"
    description: "flutter"
    source: "sdk"
    version: "0.0.0"

When the lock file is written by pub, the line with the package name terminates right after :, whereas when written by melos there is a space after :, which allows the regex to match, but with an empty version string.

To solve this issue, either the regex needs to be more strict (don't mach an empty version) or the code which prints the yaml doc needs to stop writing out the extra white space.

Salakar commented 4 years ago

Oh wow that is a weird one given that it is valid yaml to have a space there, the yaml writer lib I'm using is doing that extra space.

I do have a fix I can do to remove that extra space anyway, so will push that shortly.

Thanks for the report!

blaugold commented 4 years ago

Thanks for the quick fix.

Salakar commented 4 years ago

No worries, published version is now up. Thanks