Skip to content

fix: Number as preRelease are not supported #940

@ValentinVignal

Description

@ValentinVignal

Is there an existing issue for this?

  • I have searched the existing issues.

Version

6.3.3

Description

If I have a package number 0.0.0-6 and I try to release 0.0.0-7, melos publish fails:

type 'int' is not a subtype of type 'String' in type cast
#0      _PublishMixin._getLatestPublishedVersionForPackages.<anonymous closure> (package:melos/src/commands/publish.dart:146:45)
<asynchronous suspension>
#1      Pool.forEach.run (package:pool/pool.dart:183:19)
<asynchronous suspension>
#2      Pool.withResource (package:pool/pool.dart:127:14)
<asynchronous suspension>
#3      Future.wait.<anonymous closure> (dart:async/future.dart:525:21)
<asynchronous suspension>
#4      Pool.forEach.onListen.<anonymous closure> (package:pool/pool.dart:203:23)
<asynchronous suspension>
#5      _StreamController.close (dart:async/stream_controller.dart:640:3)
<asynchronous suspension>
#6      _nullDataHandler (dart:async/stream_impl.dart:549:1)
<asynchronous suspension>

It looks like pub_semver is casting to int when possible

https://github.com/dart-lang/tools/blob/ecd7dd523c8a5761f337eedce8878b092996a75c/pkgs/pub_semver/lib/src/version.dart#L158-L167

 /// Splits a string of dot-delimited identifiers into their component parts.
 ///
 /// Identifiers that are numeric are converted to numbers.
 static List<Object> _splitParts(String text) => text
     .split('.')
     .map((part) =>
         // Return an integer part if possible, otherwise return the string
         // as-is
         int.tryParse(part) ?? part)
     .toList();

But melos casts it as a string

if (package.version.isPreRelease) {
final preid = package.version.preRelease.length == 4
? package.version.preRelease[2] as String
: package.version.preRelease[0] as String;
final versionsWithPreid = versions

Steps to reproduce

Try to publish a package from version 0.0.0-6 to 0.0.0-7

Expected behavior

Support numbers as prereleases

Screenshots

No response

Additional context and comments

No response

Other

  • I'm interested in working on a PR for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds triageThe issue needs triaging

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions