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

feat!: make naming around package filters more consistent #462

Merged
merged 2 commits into from
Feb 4, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Install Tools
run: ./.github/workflows/scripts/install-tools.sh
- name: Check formatting
run: melos format-check
run: melos format:check

test_linux:
runs-on: ubuntu-latest
Expand Down
9 changes: 6 additions & 3 deletions docs/commands/run.mdx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
---
title: Run Command
description: "Learn more about the `run` command in Melos."
description: 'Learn more about the `run` command in Melos.'
---

# Run Command

Run a [script](/configuration/scripts) by name defined in the workspace `melos.yaml` config file.
Run a [script](/configuration/scripts) by name defined in the workspace
`melos.yaml` config file.

```bash
melos run <name>
```

## --no-select

Skips the prompt to select a package (if defined in the script configuration). Filters defined in the scripts "select-package" options will however still be applied.
Skips the prompt to select a package (if defined in the script configuration).
Filters defined in the script's "packageFilters" options will however still be
applied.

```bash
melos run <name> --no-select
Expand Down
5 changes: 5 additions & 0 deletions docs/configuration/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ Package filters to match packages that should be included in the changelog.

See [Filtering Packages](/filters) for all available filters.

<Warning>
The filter names in `packageFilters` are camel cased. For example, for the
equivalent of the command line option `--file-exists` use `fileExists`.
</Warning>

### `command/version/changelogs/description`

> optional
Expand Down
15 changes: 10 additions & 5 deletions docs/configuration/scripts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ scripts:
concurrency: 1
```

See the [`select-package`](/configuration/scripts#scriptsselect-package) option
See the [`packageFilters`](/configuration/scripts#scriptspackagefilters) option
for filtering the packages to execute the command in.

## `scripts/*/exec/concurrency`
Expand All @@ -104,25 +104,30 @@ depend on each other. Defaults to `false`.

A map of environment variables that will be passed to the executed command.

## `scripts/*/select-package`
## `scripts/*/packageFilters`

The [`melos exec`](/commands/exec) command allows you to execute a command for
multiple packages. When used in a script, you can declare filter options in the
`select-packages` section.
`packageFilters` section.

The `hello_flutter` script below is only executed in Flutter packages:

```yaml
scripts:
hello_flutter:
exec: echo 'Hello $(dirname $PWD)'
select-package:
packageFilters:
flutter: true
```

See the [global options](/filters) for a list of supported filters.

When running a script that uses `select-package`, you will be prompted to select
<Warning>
The filter names in `packageFilters` are camel cased. For example, for the
equivalent of the command line option `--file-exists` use `fileExists`.
</Warning>

When running a script that uses `packageFilters`, you will be prompted to select
the package to execute the script in. If you want to skip this prompt and run
the script in all packages, use the `--no-select` option.

Expand Down
28 changes: 28 additions & 0 deletions docs/guides/migrations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,31 @@ command, like for all other commands.

The new `preVersionCommmit` hook is executed before the version commit is
created and is the equivalent of the previous `version` hook.

### Package filters

The `select-package` option for scripts has been renamed to `packageFilters`.
This brings it in line with `command/version/changelogs/packageFilters`.

The names of filters specified in `packageFilters` are now camel cased instead
of kebab cased.

For example, take the following `test` script configuration:

```yaml
scripts:
test:
exec: dart test
packageFilters:
dirExists: test
```

This would previously have been written as:

```yaml
scripts:
test:
exec: dart test
select-package:
dir-exists: test
```
6 changes: 3 additions & 3 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ scripts:
description: Format Dart code.
run: dart format .

format-check:
format:check:
description: Check formatting of Dart code.
run: dart format --output none --set-exit-if-changed .

Expand All @@ -34,8 +34,8 @@ scripts:
run: dart test
exec:
concurrency: 1
select-package:
dir-exists:
packageFilters:
dirExists:
- 'test/'
# This tells Melos tests to ignore env variables passed to tests from `melos run test`
# as they could change the behaviour of how tests filter packages.
Expand Down
4 changes: 2 additions & 2 deletions packages/melos/lib/melos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export 'src/global_options.dart' show GlobalOptions;
export 'src/logging.dart' show MelosLogger, ToMelosLoggerExtension;
export 'src/package.dart'
show
InvalidPackageFilterException,
InvalidPackageFiltersException,
Package,
PackageFilter,
PackageFilters,
PackageMap,
PackageType;
export 'src/workspace.dart' show IdeWorkspace, MelosWorkspace;
Expand Down
4 changes: 2 additions & 2 deletions packages/melos/lib/src/command_runner/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ abstract class MelosCommand extends Command<void> {
);
}

PackageFilter parsePackageFilter(
PackageFilters parsePackageFilters(
String workingDirPath, {
bool diffEnabled = true,
}) {
Expand All @@ -153,7 +153,7 @@ abstract class MelosCommand extends Command<void> {
final scope = argResults![filterOptionScope] as List<String>? ?? [];
final ignore = argResults![filterOptionIgnore] as List<String>? ?? [];

return PackageFilter(
return PackageFilters(
scope: scope
.map((e) => createGlob(e, currentDirectoryPath: workingDirPath))
.toList(),
Expand Down
2 changes: 1 addition & 1 deletion packages/melos/lib/src/command_runner/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BootstrapCommand extends MelosCommand {

return melos.bootstrap(
global: global,
filter: parsePackageFilter(config.path),
packageFilters: parsePackageFilters(config.path),
);
}
}
2 changes: 1 addition & 1 deletion packages/melos/lib/src/command_runner/clean.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CleanCommand extends MelosCommand {

await melos.clean(
global: global,
filter: parsePackageFilter(config.path),
packageFilters: parsePackageFilters(config.path),
);
}
}
4 changes: 2 additions & 2 deletions packages/melos/lib/src/command_runner/exec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ExecCommand extends MelosCommand {

final melos = Melos(logger: logger, config: config);

final packageFilter = parsePackageFilter(config.path);
final packageFilters = parsePackageFilters(config.path);
final concurrency = int.parse(argResults!['concurrency'] as String);
final failFast = argResults!['fail-fast'] as bool;
final orderDependents = argResults!['order-dependents'] as bool;
Expand All @@ -77,7 +77,7 @@ class ExecCommand extends MelosCommand {
failFast: failFast,
orderDependents: orderDependents,
global: global,
filter: packageFilter,
packageFilters: packageFilters,
);
}
}
2 changes: 1 addition & 1 deletion packages/melos/lib/src/command_runner/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class ListCommand extends MelosCommand {
return melos.list(
long: long,
global: global,
filter: parsePackageFilter(config.path),
packageFilters: parsePackageFilters(config.path),
relativePaths: relative,
kind: kind,
);
Expand Down
4 changes: 2 additions & 2 deletions packages/melos/lib/src/command_runner/publish.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ class PublishCommand extends MelosCommand {
final yes = argResults!['yes'] as bool || false;

final melos = Melos(logger: logger, config: config);
final filter = parsePackageFilter(config.path);
final packageFilters = parsePackageFilters(config.path);

return melos.publish(
global: global,
filter: filter,
packageFilters: packageFilters,
dryRun: dryRun,
force: yes,
gitTagVersion: gitTagVersion,
Expand Down
2 changes: 1 addition & 1 deletion packages/melos/lib/src/command_runner/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RunCommand extends MelosCommand {
'no-select',
negatable: false,
help: 'Skips the prompt to select a package (if defined in the script '
'configuration). Filters defined in the scripts "select-package" '
"""configuration). Filters defined in the script's "packageFilters" """
'options will however still be applied.',
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/melos/lib/src/command_runner/script.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ScriptCommand extends MelosCommand {
'no-select',
negatable: false,
help: 'Skips the prompt to select a package (if defined in the script '
'configuration). Filters defined in the scripts "select-package" '
"""configuration). Filters defined in the script's "packageFilters" """
'options will however still be applied.',
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/melos/lib/src/command_runner/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class VersionCommand extends MelosCommand {
return melos.version(
// We only want to version the specified package and not all packages
// that could be versioned.
filter: PackageFilter(scope: [Glob(packageName)]),
packageFilters: PackageFilters(scope: [Glob(packageName)]),
manualVersions: {packageName: versionChange},
force: force,
gitTag: tag,
Expand Down Expand Up @@ -235,7 +235,7 @@ class VersionCommand extends MelosCommand {

await melos.version(
global: global,
filter: parsePackageFilter(config.path),
packageFilters: parsePackageFilters(config.path),
force: force,
gitTag: tag,
releaseUrl: releaseUrl,
Expand Down
8 changes: 6 additions & 2 deletions packages/melos/lib/src/commands/bootstrap.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
part of 'runner.dart';

mixin _BootstrapMixin on _CleanMixin {
Future<void> bootstrap({GlobalOptions? global, PackageFilter? filter}) async {
final workspace = await createWorkspace(global: global, filter: filter);
Future<void> bootstrap({
GlobalOptions? global,
PackageFilters? packageFilters,
}) async {
final workspace =
await createWorkspace(global: global, packageFilters: packageFilters);

return _runLifecycle(
workspace,
Expand Down
8 changes: 6 additions & 2 deletions packages/melos/lib/src/commands/clean.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
part of 'runner.dart';

mixin _CleanMixin on _Melos {
Future<void> clean({GlobalOptions? global, PackageFilter? filter}) async {
final workspace = await createWorkspace(global: global, filter: filter);
Future<void> clean({
GlobalOptions? global,
PackageFilters? packageFilters,
}) async {
final workspace =
await createWorkspace(global: global, packageFilters: packageFilters);

return _runLifecycle(
workspace,
Expand Down
5 changes: 3 additions & 2 deletions packages/melos/lib/src/commands/exec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ mixin _ExecMixin on _Melos {
Future<void> exec(
List<String> execArgs, {
GlobalOptions? global,
PackageFilter? filter,
PackageFilters? packageFilters,
int concurrency = 5,
bool failFast = false,
bool orderDependents = false,
}) async {
final workspace = await createWorkspace(global: global, filter: filter);
final workspace =
await createWorkspace(global: global, packageFilters: packageFilters);
final packages = workspace.filteredPackages.values;

await _execForAllPackages(
Expand Down
5 changes: 3 additions & 2 deletions packages/melos/lib/src/commands/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ mixin _ListMixin on _Melos {
GlobalOptions? global,
bool long = false,
bool relativePaths = false,
PackageFilter? filter,
PackageFilters? packageFilters,
ListOutputKind kind = ListOutputKind.column,
}) async {
final workspace = await createWorkspace(global: global, filter: filter);
final workspace =
await createWorkspace(global: global, packageFilters: packageFilters);

switch (kind) {
case ListOutputKind.graph:
Expand Down
5 changes: 3 additions & 2 deletions packages/melos/lib/src/commands/publish.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ part of 'runner.dart';
mixin _PublishMixin on _ExecMixin {
Future<void> publish({
GlobalOptions? global,
PackageFilter? filter,
PackageFilters? packageFilters,
bool dryRun = true,
bool gitTagVersion = true,
// yes
bool force = false,
}) async {
final workspace = await createWorkspace(global: global, filter: filter);
final workspace =
await createWorkspace(global: global, packageFilters: packageFilters);

logger.command('melos publish${dryRun ? " --dry-run" : ''}');
logger.child(targetStyle(workspace.path)).newLine();
Expand Down
12 changes: 6 additions & 6 deletions packages/melos/lib/src/commands/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ mixin _RunMixin on _Melos {
final workspace = await MelosWorkspace.fromConfig(
config,
global: global,
filter: script.filter?.copyWithUpdatedIgnore([
...script.filter!.ignore,
packageFilters: script.packageFilters?.copyWithUpdatedIgnore([
...script.packageFilters!.ignore,
...config.ignore,
]),
logger: logger,
Expand All @@ -94,14 +94,14 @@ mixin _RunMixin on _Melos {
...script.env,
};

if (script.filter != null) {
if (script.packageFilters != null) {
final packages = workspace.filteredPackages.values.toList();

var choices = packages.map((e) => AnsiStyles.cyan(e.name)).toList();

if (choices.isEmpty) {
throw NoPackageFoundScriptException._(
script.filter,
script.packageFilters,
script.name,
);
}
Expand Down Expand Up @@ -167,9 +167,9 @@ mixin _RunMixin on _Melos {
}

class NoPackageFoundScriptException implements MelosException {
NoPackageFoundScriptException._(this.filter, this.scriptName);
NoPackageFoundScriptException._(this.filters, this.scriptName);

final PackageFilter? filter;
final PackageFilters? filters;
final String? scriptName;

@override
Expand Down
Loading