Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix externally hosted versioning #852

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading