Skip to content

Commit

Permalink
fix: Fix externally hosted versioning (#852)
Browse files Browse the repository at this point in the history
<!--
  Thanks for contributing!

Provide a description of your changes below and a general summary in the
title

Please look at the following checklist to ensure that your PR can be
accepted quickly:
-->

## Description

When we swapped to `pubspec_parse` the logic for versioning externally
hosted packages was overlooked.

Fixes: #851 

This also reverts the recent versioning of Melos so that it can be
included in the new version.

## Type of Change

<!--- Put an `x` in all the boxes that apply: -->

- [ ] ✨ `feat` -- New feature (non-breaking change which adds
functionality)
- [x] 🛠️ `fix` -- Bug fix (non-breaking change which fixes an issue)
- [ ] ❌ `!` -- Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] 🧹 `refactor` -- Code refactor
- [ ] ✅ `ci` -- Build configuration change
- [ ] 📝 `docs` -- Documentation
- [ ] 🗑️ `chore` -- Chore
  • Loading branch information
spydon authored Jan 24, 2025
1 parent 60dbe1e commit 40476ed
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 56 deletions.
22 changes: 0 additions & 22 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,6 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## 2025-01-24

### Changes

---

Packages with breaking changes:

- There are no breaking changes in this release.

Packages with other changes:

- [`melos` - `v7.0.0-dev.5`](#melos---v700-dev5)

---

#### `melos` - `v7.0.0-dev.5`

- **FEAT**: Rollback on failed shared dependency resolution ([#848](https://github.com/invertase/melos/issues/848)). ([949c2f6c](https://github.com/invertase/melos/commit/949c2f6c77b6bae92e29a03fc452417b558010f0))
- **DOCS**: Rearrange repos using melos ([#845](https://github.com/invertase/melos/issues/845)). ([f744da86](https://github.com/invertase/melos/commit/f744da860c5fde166f16c624f5cf5058c62d4370))


## 2025-01-19

### Changes
Expand Down
5 changes: 0 additions & 5 deletions packages/melos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
## 7.0.0-dev.5

- **FEAT**: Rollback on failed shared dependency resolution ([#848](https://github.com/invertase/melos/issues/848)). ([949c2f6c](https://github.com/invertase/melos/commit/949c2f6c77b6bae92e29a03fc452417b558010f0))
- **DOCS**: Rearrange repos using melos ([#845](https://github.com/invertase/melos/issues/845)). ([f744da86](https://github.com/invertase/melos/commit/f744da860c5fde166f16c624f5cf5058c62d4370))

## 7.0.0-dev.4

- **FIX**: Version package correctly ([#842](https://github.com/invertase/melos/issues/842)). ([a9fde62b](https://github.com/invertase/melos/commit/a9fde62bb2ae5a8599b72a7d792170995db9d64c))
Expand Down
50 changes: 23 additions & 27 deletions packages/melos/lib/src/commands/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,13 @@ mixin _VersionMixin on _RunMixin {
VersionRange dependencyVersion,
MelosWorkspace workspace,
) async {
final dependencyReference = package.pubspec.dependencies[dependencyName];
final devDependencyReference =
package.pubspec.devDependencies[dependencyName];
final normalDependency = package.pubspec.dependencies[dependencyName];
final devDependency = package.pubspec.devDependencies[dependencyName];
final dependency = normalDependency ?? devDependency;

if (dependencyReference != null &&
dependencyReference is! GitDependency &&
dependencyReference is! HostedDependency) {
if (dependency != null &&
dependency is! GitDependency &&
dependency is! HostedDependency) {
logger.warning(
'Skipping updating dependency $dependencyName for package '
'${package.name} - '
Expand All @@ -514,40 +514,36 @@ mixin _VersionMixin on _RunMixin {
);
return;
}
if (devDependencyReference != null &&
devDependencyReference is! GitDependency &&
devDependencyReference is! HostedDependency) {
logger.warning(
'Skipping updating dev dependency $dependencyName for package '
'${package.name} - '
'the version is a Map definition and is most likely a dependency that '
'is importing from a path or git remote.',
);
return;
}

final pubspec = pubspecPathForDirectory(package.path);
final contents = await readTextFileAsync(pubspec);
final pubspecPath = pubspecPathForDirectory(package.path);
final pubspecContent = await readTextFileAsync(pubspecPath);

final isGitReference = dependencyReference is GitDependency ||
devDependencyReference is GitDependency;
final isExternalHostedDependency =
dependency is HostedDependency && dependency.hosted != null;
final isGitDependency = dependency is GitDependency;

final String updatedContents;
if (isGitReference && workspace.config.commands.version.updateGitTagRefs) {
updatedContents = contents.replaceAllMapped(
var updatedContents = pubspecContent;
if (isExternalHostedDependency) {
updatedContents = pubspecContent.replaceAllMapped(
hostedDependencyVersionReplaceRegex(dependencyName),
(match) => '${match.group(1)}$dependencyVersion',
);
} else if (isGitDependency &&
workspace.config.commands.version.updateGitTagRefs) {
updatedContents = pubspecContent.replaceAllMapped(
dependencyTagReplaceRegex(dependencyName),
(match) => '${match.group(1)}$dependencyName-'
'v${dependencyVersion.min ?? dependencyVersion.max!}',
);
} else {
updatedContents = contents.replaceAllMapped(
updatedContents = pubspecContent.replaceAllMapped(
dependencyVersionReplaceRegex(dependencyName),
(match) => '${match.group(1)}$dependencyVersion',
);
}

// Sanity check that contents actually changed.
if (contents == updatedContents) {
if (pubspecContent == updatedContents) {
logger.warning(
'Failed to update dependency $dependencyName version to '
'$dependencyVersion for package ${package.name}, '
Expand All @@ -557,7 +553,7 @@ mixin _VersionMixin on _RunMixin {
return;
}

await writeTextFileAsync(pubspec, updatedContents);
await writeTextFileAsync(pubspecPath, updatedContents);
}

void _logNewVersionTable(
Expand Down
2 changes: 1 addition & 1 deletion packages/melos/lib/version.g.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// This file is generated. Do not manually edit.
String melosVersion = '7.0.0-dev.5';
String melosVersion = '7.0.0-dev.4';
2 changes: 1 addition & 1 deletion packages/melos/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description:
A tool for managing Dart & Flutter repositories with multiple packages
(monorepo). Supports automated versioning via Conventional Commits. Inspired
by JavaScripts Lerna package.
version: 7.0.0-dev.5
version: 7.0.0-dev.4
homepage: https://melos.invertase.dev/~melos-latest
repository: https://github.com/invertase/melos/tree/main/packages/melos
issue_tracker: https://github.com/invertase/melos/issues
Expand Down

0 comments on commit 40476ed

Please sign in to comment.