Skip to content

Commit

Permalink
Merge branch 'main' into bump-pub-updater
Browse files Browse the repository at this point in the history
  • Loading branch information
Salakar authored Nov 6, 2023
2 parents 73217de + 6a64b05 commit 03f41b6
Show file tree
Hide file tree
Showing 22 changed files with 511 additions and 33 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## 2023-10-24

### Changes

---

Packages with breaking changes:

- There are no breaking changes in this release.

Packages with other changes:

- [`melos` - `v3.2.0`](#melos---v320)

---

#### `melos` - `v3.2.0`

- **REFACTOR**: fix analyzer issues ([#590](https://github.com/invertase/melos/issues/590)). ([2f19770e](https://github.com/invertase/melos/commit/2f19770eee9deff097d26202bece72bd6b2127a1))
- **FEAT**: support syncing common dependency versions ([#526](https://github.com/invertase/melos/issues/526)). ([39e5e499](https://github.com/invertase/melos/commit/39e5e499d71e95cf7794ae724ab2ccd3bb4e9fd5))
- **FEAT**: Expose `Changelog` and `ManualVersionChange` ([#538](https://github.com/invertase/melos/issues/538)). ([b049ed89](https://github.com/invertase/melos/commit/b049ed897402921a5b0f3b818e49b47e3b3bf4cf))
- **DOCS**: added link to `atproto.dart` ([#544](https://github.com/invertase/melos/issues/544)). ([aa891d82](https://github.com/invertase/melos/commit/aa891d8268f0aba7335ca274af747a15c9e72848))
- **DOCS**: growerp also use melos ([#551](https://github.com/invertase/melos/issues/551)). ([c679622f](https://github.com/invertase/melos/commit/c679622f1279107e31ec1d10d2b21c18877f7771))


## 2023-07-14

### Changes
Expand Down
37 changes: 37 additions & 0 deletions docs/commands/bootstrap.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,43 @@ example:
melos bootstrap --diff="main"
```

## Bootstrap flags

Melos bootstrap command supports a few different flags that can be defined in
your `melos.yaml`.


### Shared dependencies

If you want to share dependency versions between your packages in your Melos
project, just add the dependencies you wish to share between the packages to
your bootstrap config in your `melos.yaml` file.

If a dependency from `environment`, `dependencies` or `dev_dependencies` in
your `melos.yaml` exists in a package, the dependency version in this
package will be updated to match the version defined in your
bootstrap config every time `melos bootstrap` is run.

```yaml
# melos.yaml
# ...
command:
environment:
sdk: ">=3.0.0 <4.0.0"
flutter: ">=3.0.0 <4.0.0"
bootstrap:
dependencies:
collection: ^1.18.0
integral_isolates: any
uni_links2:
uni_links_macos:
git: https://github.com/SamJakob/uni_links_macos.git

dev_dependencies:
build_runner: ^2.3.3
# ...
```

## Adding a post bootstrap lifecycle script

Melos supports various command [lifecycle hooks](/configuration/scripts#hooks)
Expand Down
1 change: 1 addition & 0 deletions docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ The following projects are using Melos:
- [NetGlade/auto_mappr](https://github.com/netglade/auto_mappr)
- [myConsciousness/atproto.dart](https://github.com/myConsciousness/atproto.dart)
- [GrowERP Flutter ERP](https://github.com/growerp/growerp)
- [mrverdant13/coverde](https://github.com/mrverdant13/coverde)

<Info>

Expand Down
32 changes: 32 additions & 0 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,38 @@ ignore:
- packages/melos_flutter_deps_check

command:
bootstrap:
environment:
sdk: '>=2.18.0 <3.0.0'
dependencies:
ansi_styles: ^0.3.1
args: ^2.0.0
cli_launcher: ^0.3.0
cli_util: '>=0.3.0 <0.5.0'
collection: ^1.14.12
conventional_commit: ^0.6.0+1
file: ^6.1.0
glob: ^2.1.0
graphs: ^2.1.0
http: ">=0.13.1 <2.0.0"
meta: ^1.1.8
mustache_template: ^2.0.0
path: ^1.7.0
platform: ^3.1.0
pool: ^1.4.0
prompts: ^2.0.0
pub_semver: ^2.0.0
pub_updater: ^0.3.0
pubspec: ^2.1.0
string_scanner: ^1.0.5
yaml: ^3.1.0
yaml_edit: ^2.0.2
dev_dependencies:
collection: ^1.15.0
mockito: ^5.1.0
test: ^1.17.5
path: ^1.7.0
yaml: ^3.1.0
version:
# Generate commit links in package changelogs.
linkToCommits: true
Expand Down
8 changes: 8 additions & 0 deletions packages/melos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 3.2.0

- **REFACTOR**: fix analyzer issues ([#590](https://github.com/invertase/melos/issues/590)). ([2f19770e](https://github.com/invertase/melos/commit/2f19770eee9deff097d26202bece72bd6b2127a1))
- **FEAT**: support syncing common dependency versions ([#526](https://github.com/invertase/melos/issues/526)). ([39e5e499](https://github.com/invertase/melos/commit/39e5e499d71e95cf7794ae724ab2ccd3bb4e9fd5))
- **FEAT**: Expose `Changelog` and `ManualVersionChange` ([#538](https://github.com/invertase/melos/issues/538)). ([b049ed89](https://github.com/invertase/melos/commit/b049ed897402921a5b0f3b818e49b47e3b3bf4cf))
- **DOCS**: added link to `atproto.dart` ([#544](https://github.com/invertase/melos/issues/544)). ([aa891d82](https://github.com/invertase/melos/commit/aa891d8268f0aba7335ca274af747a15c9e72848))
- **DOCS**: growerp also use melos ([#551](https://github.com/invertase/melos/issues/551)). ([c679622f](https://github.com/invertase/melos/commit/c679622f1279107e31ec1d10d2b21c18877f7771))

## 3.1.1

- **FIX**: pass extra args to exec scripts ([#540](https://github.com/invertase/melos/issues/540)). ([27b2275d](https://github.com/invertase/melos/commit/27b2275d5f44cbc3b93e780c88618363afca0b55))
Expand Down
1 change: 1 addition & 0 deletions packages/melos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ The following projects are using Melos:
- [NetGlade/auto_mappr](https://github.com/netglade/auto_mappr)
- [myConsciousness/atproto.dart](https://github.com/myConsciousness/atproto.dart)
- [GrowERP Flutter ERP](https://github.com/growerp/growerp)
- [mrverdant13/coverde](https://github.com/mrverdant13/coverde)

> Submit a PR if you'd like to add your project to the list. Update the
> [README.md](https://github.com/invertase/melos/edit/main/packages/melos/README.md)
Expand Down
142 changes: 140 additions & 2 deletions packages/melos/lib/src/commands/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ mixin _BootstrapMixin on _CleanMixin {
workspace,
_CommandWithLifecycle.bootstrap,
() async {
final bootstrapCommandConfig = workspace.config.commands.bootstrap;
final pubCommandForLogging = [
...pubCommandExecArgs(
useFlutter: workspace.isFlutterWorkspace,
workspace: workspace,
),
'get',
if (workspace.config.commands.bootstrap.runPubGetOffline) '--offline'
if (bootstrapCommandConfig.runPubGetOffline) '--offline',
].join(' ');

logger
Expand All @@ -35,6 +36,20 @@ mixin _BootstrapMixin on _CleanMixin {
}

try {
if (bootstrapCommandConfig.environment != null ||
bootstrapCommandConfig.dependencies != null ||
bootstrapCommandConfig.devDependencies != null) {
final filteredPackages = workspace.filteredPackages.values;
await Stream.fromIterable(filteredPackages).parallel((package) {
return _setSharedDependenciesForPackage(
package,
environment: bootstrapCommandConfig.environment,
dependencies: bootstrapCommandConfig.dependencies,
devDependencies: bootstrapCommandConfig.devDependencies,
);
}).drain<void>();
}

await _linkPackagesWithPubspecOverrides(workspace);
} on BootstrapException catch (exception) {
_logBootstrapException(exception, workspace);
Expand Down Expand Up @@ -163,7 +178,7 @@ mixin _BootstrapMixin on _CleanMixin {
workspace: workspace,
),
'get',
if (workspace.config.commands.bootstrap.runPubGetOffline) '--offline'
if (workspace.config.commands.bootstrap.runPubGetOffline) '--offline',
];

final process = await startCommandRaw(
Expand Down Expand Up @@ -199,6 +214,129 @@ mixin _BootstrapMixin on _CleanMixin {
}
}

Future<void> _setSharedDependenciesForPackage(
Package package, {
required Environment? environment,
required Map<String, DependencyReference>? dependencies,
required Map<String, DependencyReference>? devDependencies,
}) async {
final packagePubspecFile = utils.pubspecPathForDirectory(package.path);
final packagePubspecContents = await readTextFileAsync(packagePubspecFile);
final pubspecEditor = YamlEditor(packagePubspecContents);

final updatedEnvironment = _updateEnvironment(
pubspecEditor: pubspecEditor,
workspaceEnvironment: environment,
packageEnvironment: package.pubSpec.environment,
);

final updatedDependenciesCount = _updateDependencies(
pubspecEditor: pubspecEditor,
workspaceDependencies: dependencies,
packageDependencies: package.pubSpec.dependencies,
pubspecKey: 'dependencies',
);

final updatedDevDependenciesCount = _updateDependencies(
pubspecEditor: pubspecEditor,
workspaceDependencies: devDependencies,
packageDependencies: package.pubSpec.devDependencies,
pubspecKey: 'dev_dependencies',
);

if (pubspecEditor.edits.isNotEmpty) {
await writeTextFileAsync(
packagePubspecFile,
pubspecEditor.toString(),
);

final message = <String>[
if (updatedEnvironment) 'Updated environment',
if (updatedDependenciesCount > 0)
'Updated $updatedDependenciesCount dependencies',
if (updatedDevDependenciesCount > 0)
'Updated $updatedDevDependenciesCount dev_dependencies',
];
if (message.isNotEmpty) {
logger
.child(packageNameStyle(package.name), prefix: '')
.child(message.join('\n'));
}
}
}

bool _updateEnvironment({
required YamlEditor pubspecEditor,
required Environment? workspaceEnvironment,
required Environment? packageEnvironment,
}) {
if (workspaceEnvironment == null || packageEnvironment == null) {
return false;
}

var didUpdate = false;

if (workspaceEnvironment.sdkConstraint !=
packageEnvironment.sdkConstraint) {
pubspecEditor.update(
['environment', 'sdk'],
wrapAsYamlNode(
workspaceEnvironment.sdkConstraint.toString(),
collectionStyle: CollectionStyle.BLOCK,
),
);
didUpdate = true;
}

final workspaceUnParsedYaml = workspaceEnvironment.unParsedYaml;
final packageUnParsedYaml = packageEnvironment.unParsedYaml;
if (workspaceUnParsedYaml != null && packageUnParsedYaml != null) {
for (final entry in workspaceUnParsedYaml.entries) {
if (!packageUnParsedYaml.containsKey(entry.key)) continue;
if (packageUnParsedYaml[entry.key] == entry.value) continue;

pubspecEditor.update(
['environment', entry.key],
wrapAsYamlNode(
entry.value.toString(),
collectionStyle: CollectionStyle.BLOCK,
),
);
didUpdate = true;
}
}

return didUpdate;
}

int _updateDependencies({
required YamlEditor pubspecEditor,
required Map<String, DependencyReference>? workspaceDependencies,
required Map<String, DependencyReference> packageDependencies,
required String pubspecKey,
}) {
if (workspaceDependencies == null) return 0;
// Filter out the packages that do not exist in package and only the
// dependencies that have a different version specified in the workspace.
final dependenciesToUpdate = workspaceDependencies.entries.where((entry) {
if (!packageDependencies.containsKey(entry.key)) return false;
if (packageDependencies[entry.key] == entry.value) return false;
return true;
});

for (final entry in dependenciesToUpdate) {
pubspecEditor.update(
[pubspecKey, entry.key],
wrapAsYamlNode(
entry.value.toJson(),
collectionStyle: CollectionStyle.BLOCK,
),
);
}

return dependenciesToUpdate.length;
}

void _logBootstrapSuccess(Package package) {
logger.child(packageNameStyle(package.name), prefix: '$checkLabel ').child(
packagePathStyle(printablePath(package.pathRelativeToWorkspace)),
Expand Down
4 changes: 2 additions & 2 deletions packages/melos/lib/src/commands/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ mixin _ListMixin on _Melos {
package.name,
AnsiStyles.green((package.version).toString()),
AnsiStyles.gray(printablePath(package.pathRelativeToWorkspace)),
if (package.isPrivate) AnsiStyles.red('PRIVATE')
if (package.isPrivate) AnsiStyles.red('PRIVATE'),
],
)
.cast<List<String>>()
Expand Down Expand Up @@ -132,7 +132,7 @@ mixin _ListMixin on _Melos {
'version': package.version.toString(),
'private': package.isPrivate,
'location': packagePath,
'type': package.type.index
'type': package.type.index,
};

if (long) {
Expand Down
2 changes: 1 addition & 1 deletion packages/melos/lib/src/commands/publish.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ mixin _PublishMixin on _ExecMixin {
AnsiStyles.dim(latestPublishedVersionForPackages[package.name]),
AnsiStyles.green(package.version.toString()),
];
})
}),
],
paddingSize: 4,
),
Expand Down
6 changes: 3 additions & 3 deletions packages/melos/lib/src/commands/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ mixin _VersionMixin on _RunMixin {
for (final package in workspace.filteredPackages.values)
if (!packagesToManuallyVersion.contains(package))
if (packagesWithVersionableCommits.contains(package.name))
if (!asStableRelease || !package.version.isPreRelease) package
if (!asStableRelease || !package.version.isPreRelease) package,
};
final packagesToVersion = {
...packagesToManuallyVersion,
Expand Down Expand Up @@ -662,7 +662,7 @@ mixin _VersionMixin on _RunMixin {
if (updateDependentsConstraints) {
await Future.forEach([
...pendingPackageUpdate.package.dependentsInWorkspace.values,
...pendingPackageUpdate.package.devDependentsInWorkspace.values
...pendingPackageUpdate.package.devDependentsInWorkspace.values,
], (package) {
return _setDependencyVersionForDependentPackage(
package,
Expand Down Expand Up @@ -710,7 +710,7 @@ mixin _VersionMixin on _RunMixin {
final dateSlug = [
today.year.toString(),
today.month.toString().padLeft(2, '0'),
today.day.toString().padLeft(2, '0')
today.day.toString().padLeft(2, '0'),
].join('-');

final packages =
Expand Down
4 changes: 2 additions & 2 deletions packages/melos/lib/src/common/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,10 @@ bool isPubSubcommand({required MelosWorkspace workspace}) {
void sortPackagesForPublishing(List<Package> packages) {
final packageNames = packages.map((package) => package.name).toList();
final graph = <String, Iterable<String>>{
for (var package in packages)
for (final package in packages)
package.name: [
...package.dependencies.where(packageNames.contains),
...package.devDependencies.where(packageNames.contains)
...package.devDependencies.where(packageNames.contains),
],
};
final ordered =
Expand Down
2 changes: 1 addition & 1 deletion packages/melos/lib/src/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ class PackageMap {
ignore: [
...ignore,
for (final pattern in _commonIgnorePatterns)
createGlob(pattern, currentDirectoryPath: workspacePath)
createGlob(pattern, currentDirectoryPath: workspacePath),
],
);

Expand Down
Loading

0 comments on commit 03f41b6

Please sign in to comment.