diff --git a/packages/melos/lib/src/commands/version.dart b/packages/melos/lib/src/commands/version.dart index fa5b4f76..947cd505 100644 --- a/packages/melos/lib/src/commands/version.dart +++ b/packages/melos/lib/src/commands/version.dart @@ -445,13 +445,24 @@ Hint: try running "melos version --all" to include private packages. final pubspec = File(pubspecPathForDirectory(Directory(package.path))); final contents = await pubspec.readAsString(); - String updatedContents; + + final isExternalHostedReference = package + .pubSpec.dependencies[dependencyName] is ExternalHostedReference || + package.pubSpec.devDependencies[dependencyName] + is ExternalHostedReference; final gitReference = package.pubSpec.dependencies[dependencyName] is GitReference || package.pubSpec.devDependencies[dependencyName] is GitReference; - if (gitReference && workspace.config.commands.version.updateGitTagRefs) { + var updatedContents = contents; + if (isExternalHostedReference) { + updatedContents = contents.replaceAllMapped( + hostedDependencyVersionReplaceRegex(dependencyName), (Match match) { + return '${match.group(1)}$dependencyVersion'; + }); + } else if (gitReference && + workspace.config.commands.version.updateGitTagRefs) { updatedContents = contents.replaceAllMapped( dependencyTagReplaceRegex(dependencyName), (Match match) { return '${match.group(1)}$dependencyName-v${dependencyVersion.toString().substring(1)}'; diff --git a/packages/melos/lib/src/package.dart b/packages/melos/lib/src/package.dart index 7427b5a8..d6ec0818 100644 --- a/packages/melos/lib/src/package.dart +++ b/packages/melos/lib/src/package.dart @@ -105,6 +105,14 @@ RegExp dependencyVersionReplaceRegex(String dependencyName) { ); } +// https://regex101.com/r/ob8xRv/1 +RegExp hostedDependencyVersionReplaceRegex(String dependencyName) { + return RegExp( + '''(^[ \t]*?(?$dependencyName)[ \\t]*?:[ \\t]*?[\\s\\S]*?[ \\t]*?version:[ \\t]*?)(?any|["'^<>=]*\\d\\.\\d\\.\\d['"._ \\t<>=\\d-\\w+]*|\$)\$''', + multiLine: true, + ); +} + RegExp dependencyTagReplaceRegex(String dependencyName) { return RegExp( '''(?^\\s+ref\\s?:\\s?)(?["']?)(?$dependencyName-v[\\d]+\\.[\\d]+\\.[\\d]+)(?['"]?)\$''', diff --git a/packages/melos/pubspec.yaml b/packages/melos/pubspec.yaml index 3348ed36..2788ae97 100644 --- a/packages/melos/pubspec.yaml +++ b/packages/melos/pubspec.yaml @@ -26,7 +26,7 @@ dependencies: platform: ^3.1.0 pool: ^1.4.0 pub_semver: ^2.0.0 - pubspec: ^2.0.1 + pubspec: ^2.1.0 string_scanner: ^1.0.5 yaml: ^3.1.0