Skip to content

Commit

Permalink
fix: support external hosted dependencies (#254)
Browse files Browse the repository at this point in the history
Co-authored-by: Salakar <[email protected]>
  • Loading branch information
ekasetiawans and Salakar authored Mar 21, 2022
1 parent 289c1b2 commit 0f904f3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
15 changes: 13 additions & 2 deletions packages/melos/lib/src/commands/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)}';
Expand Down
8 changes: 8 additions & 0 deletions packages/melos/lib/src/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ RegExp dependencyVersionReplaceRegex(String dependencyName) {
);
}

// https://regex101.com/r/ob8xRv/1
RegExp hostedDependencyVersionReplaceRegex(String dependencyName) {
return RegExp(
'''(^[ \t]*?(?<dependency>$dependencyName)[ \\t]*?:[ \\t]*?[\\s\\S]*?[ \\t]*?version:[ \\t]*?)(?<version>any|["'^<>=]*\\d\\.\\d\\.\\d['"._ \\t<>=\\d-\\w+]*|\$)\$''',
multiLine: true,
);
}

RegExp dependencyTagReplaceRegex(String dependencyName) {
return RegExp(
'''(?<tag_ref>^\\s+ref\\s?:\\s?)(?<opening_quote>["']?)(?<tag>$dependencyName-v[\\d]+\\.[\\d]+\\.[\\d]+)(?<closing_quote>['"]?)\$''',
Expand Down
2 changes: 1 addition & 1 deletion packages/melos/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0f904f3

Please sign in to comment.