Skip to content

Commit 40476ed

Browse files
authored
fix: Fix externally hosted versioning (#852)
<!-- 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
1 parent 60dbe1e commit 40476ed

File tree

5 files changed

+25
-56
lines changed

5 files changed

+25
-56
lines changed

CHANGELOG.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,6 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6-
## 2025-01-24
7-
8-
### Changes
9-
10-
---
11-
12-
Packages with breaking changes:
13-
14-
- There are no breaking changes in this release.
15-
16-
Packages with other changes:
17-
18-
- [`melos` - `v7.0.0-dev.5`](#melos---v700-dev5)
19-
20-
---
21-
22-
#### `melos` - `v7.0.0-dev.5`
23-
24-
- **FEAT**: Rollback on failed shared dependency resolution ([#848](https://github.com/invertase/melos/issues/848)). ([949c2f6c](https://github.com/invertase/melos/commit/949c2f6c77b6bae92e29a03fc452417b558010f0))
25-
- **DOCS**: Rearrange repos using melos ([#845](https://github.com/invertase/melos/issues/845)). ([f744da86](https://github.com/invertase/melos/commit/f744da860c5fde166f16c624f5cf5058c62d4370))
26-
27-
286
## 2025-01-19
297

308
### Changes

packages/melos/CHANGELOG.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
## 7.0.0-dev.5
2-
3-
- **FEAT**: Rollback on failed shared dependency resolution ([#848](https://github.com/invertase/melos/issues/848)). ([949c2f6c](https://github.com/invertase/melos/commit/949c2f6c77b6bae92e29a03fc452417b558010f0))
4-
- **DOCS**: Rearrange repos using melos ([#845](https://github.com/invertase/melos/issues/845)). ([f744da86](https://github.com/invertase/melos/commit/f744da860c5fde166f16c624f5cf5058c62d4370))
5-
61
## 7.0.0-dev.4
72

83
- **FIX**: Version package correctly ([#842](https://github.com/invertase/melos/issues/842)). ([a9fde62b](https://github.com/invertase/melos/commit/a9fde62bb2ae5a8599b72a7d792170995db9d64c))

packages/melos/lib/src/commands/version.dart

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,13 @@ mixin _VersionMixin on _RunMixin {
499499
VersionRange dependencyVersion,
500500
MelosWorkspace workspace,
501501
) async {
502-
final dependencyReference = package.pubspec.dependencies[dependencyName];
503-
final devDependencyReference =
504-
package.pubspec.devDependencies[dependencyName];
502+
final normalDependency = package.pubspec.dependencies[dependencyName];
503+
final devDependency = package.pubspec.devDependencies[dependencyName];
504+
final dependency = normalDependency ?? devDependency;
505505

506-
if (dependencyReference != null &&
507-
dependencyReference is! GitDependency &&
508-
dependencyReference is! HostedDependency) {
506+
if (dependency != null &&
507+
dependency is! GitDependency &&
508+
dependency is! HostedDependency) {
509509
logger.warning(
510510
'Skipping updating dependency $dependencyName for package '
511511
'${package.name} - '
@@ -514,40 +514,36 @@ mixin _VersionMixin on _RunMixin {
514514
);
515515
return;
516516
}
517-
if (devDependencyReference != null &&
518-
devDependencyReference is! GitDependency &&
519-
devDependencyReference is! HostedDependency) {
520-
logger.warning(
521-
'Skipping updating dev dependency $dependencyName for package '
522-
'${package.name} - '
523-
'the version is a Map definition and is most likely a dependency that '
524-
'is importing from a path or git remote.',
525-
);
526-
return;
527-
}
528517

529-
final pubspec = pubspecPathForDirectory(package.path);
530-
final contents = await readTextFileAsync(pubspec);
518+
final pubspecPath = pubspecPathForDirectory(package.path);
519+
final pubspecContent = await readTextFileAsync(pubspecPath);
531520

532-
final isGitReference = dependencyReference is GitDependency ||
533-
devDependencyReference is GitDependency;
521+
final isExternalHostedDependency =
522+
dependency is HostedDependency && dependency.hosted != null;
523+
final isGitDependency = dependency is GitDependency;
534524

535-
final String updatedContents;
536-
if (isGitReference && workspace.config.commands.version.updateGitTagRefs) {
537-
updatedContents = contents.replaceAllMapped(
525+
var updatedContents = pubspecContent;
526+
if (isExternalHostedDependency) {
527+
updatedContents = pubspecContent.replaceAllMapped(
528+
hostedDependencyVersionReplaceRegex(dependencyName),
529+
(match) => '${match.group(1)}$dependencyVersion',
530+
);
531+
} else if (isGitDependency &&
532+
workspace.config.commands.version.updateGitTagRefs) {
533+
updatedContents = pubspecContent.replaceAllMapped(
538534
dependencyTagReplaceRegex(dependencyName),
539535
(match) => '${match.group(1)}$dependencyName-'
540536
'v${dependencyVersion.min ?? dependencyVersion.max!}',
541537
);
542538
} else {
543-
updatedContents = contents.replaceAllMapped(
539+
updatedContents = pubspecContent.replaceAllMapped(
544540
dependencyVersionReplaceRegex(dependencyName),
545541
(match) => '${match.group(1)}$dependencyVersion',
546542
);
547543
}
548544

549545
// Sanity check that contents actually changed.
550-
if (contents == updatedContents) {
546+
if (pubspecContent == updatedContents) {
551547
logger.warning(
552548
'Failed to update dependency $dependencyName version to '
553549
'$dependencyVersion for package ${package.name}, '
@@ -557,7 +553,7 @@ mixin _VersionMixin on _RunMixin {
557553
return;
558554
}
559555

560-
await writeTextFileAsync(pubspec, updatedContents);
556+
await writeTextFileAsync(pubspecPath, updatedContents);
561557
}
562558

563559
void _logNewVersionTable(

packages/melos/lib/version.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// This file is generated. Do not manually edit.
2-
String melosVersion = '7.0.0-dev.5';
2+
String melosVersion = '7.0.0-dev.4';

packages/melos/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description:
33
A tool for managing Dart & Flutter repositories with multiple packages
44
(monorepo). Supports automated versioning via Conventional Commits. Inspired
55
by JavaScripts Lerna package.
6-
version: 7.0.0-dev.5
6+
version: 7.0.0-dev.4
77
homepage: https://melos.invertase.dev/~melos-latest
88
repository: https://github.com/invertase/melos/tree/main/packages/melos
99
issue_tracker: https://github.com/invertase/melos/issues

0 commit comments

Comments
 (0)