Skip to content

Commit e4ade76

Browse files
authored
fix: Run examples from own directory (#834)
<!-- 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 Due to dart-lang/pub#4486 examples must run `exec` from their own directories (not sure why this wasn't the case from the beginning). ## 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 ade758c commit e4ade76

File tree

5 files changed

+19
-39
lines changed

5 files changed

+19
-39
lines changed

docs/environment-variables.mdx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ The path of the package that's currently executing a script (when using
3535

3636
### `MELOS_PARENT_PACKAGE_NAME`
3737

38-
The name of the parent package of the current package that's currently executing
39-
a script (when using `melos exec`).
38+
The name of the parent package of the example that's currently being executed
39+
in a script (when using `melos exec`).
4040

4141
### `MELOS_PARENT_PACKAGE_VERSION`
4242

43-
The version of the parent package of the current package that's currently
44-
executing a script (when using `melos exec`).
43+
The version of the parent package of the example that's currently being executed
44+
in a script (when using `melos exec`).
4545

4646
### `MELOS_PARENT_PACKAGE_PATH`
4747

48-
The path of the parent package of the current package that's currently executing
49-
a script (when using `melos exec`).
48+
The path of the parent package of the example that's currently being executed
49+
in a script (when using `melos exec`).
5050

5151
### `MELOS_PUBLISH_DRY_RUN`
5252

@@ -55,13 +55,14 @@ Whether the current publish is a dry run or not. This is `true` when running
5555

5656
#### What is a 'parent package'
5757

58-
If a package exists in a directory that is also a child of another package, then
59-
its parent is the 'parent package'. For example; the package `firebase_auth` has
60-
a `example` directory that is also a package, when running a `melos exec` script
61-
in the `example` package then the parent package would be `firebase_auth`.
58+
If an example package exists in a directory that is a child of another package,
59+
then its parent is the 'parent package'. For example; the package
60+
`firebase_auth` has an `example` directory that is also a package, when running
61+
a `melos exec` script in the `example` package then the parent package would be
62+
`firebase_auth`.
6263

6364
Note, this 'parent package' functionality only currently works when the 'child
64-
package' name ends with `example`
65+
package' name ends with `example`.
6566

6667
## User Defined
6768

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ mixin _ExecMixin on _Melos {
7878
logger: logger,
7979
environment: environment,
8080
workingDirectory: package.path,
81-
prefix: prefixLogs ? packagePrefix : null,
81+
logPrefix: prefixLogs ? packagePrefix : null,
8282
// The parent env is injected manually above
8383
includeParentEnvironment: false,
8484
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ mixin _FormatMixin on _Melos {
134134
logger: logger,
135135
environment: environment,
136136
workingDirectory: package.path,
137-
prefix: prefixLogs ? packagePrefix : null,
137+
logPrefix: prefixLogs ? packagePrefix : null,
138138
);
139139
}
140140
}

packages/melos/lib/src/common/utils.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ List<int> get runningPids => UnmodifiableListView(_runningPids);
440440

441441
Future<int> startCommand(
442442
List<String> command, {
443-
String? prefix,
443+
String? logPrefix,
444444
Map<String, String> environment = const {},
445445
String? workingDirectory,
446446
bool onlyOutputOnError = false,
@@ -466,14 +466,14 @@ Future<int> startCommand(
466466
var stdoutStream = process.stdout;
467467
var stderrStream = process.stderr;
468468

469-
if (prefix != null && prefix.isNotEmpty) {
469+
if (logPrefix != null && logPrefix.isNotEmpty) {
470470
final pluginPrefixTransformer =
471471
StreamTransformer<String, String>.fromHandlers(
472472
handleData: (data, sink) {
473473
const lineSplitter = LineSplitter();
474474
var lines = lineSplitter.convert(data);
475475
lines = lines
476-
.map((line) => '$prefix$line${line.contains('\n') ? '' : '\n'}')
476+
.map((line) => '$logPrefix$line${line.contains('\n') ? '' : '\n'}')
477477
.toList();
478478
sink.add(lines.join());
479479
},

packages/melos/lib/src/package.dart

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -987,29 +987,8 @@ class Package {
987987
return pubClient.fetchPackage(name);
988988
}
989989

990-
/// The example [Package] contained within this package, if any.
991-
///
992-
/// A package is considered to be an example if it is located in the `example`
993-
/// directory of the [enclosingPackage].
994-
late final Package? examplePackage = () {
995-
final examplePath = p.join(path, 'example');
996-
return _packageMap.values
997-
.firstWhereOrNull((package) => p.equals(package.path, examplePath));
998-
}();
999-
1000-
/// The [Package] that encloses this package, if any.
1001-
///
1002-
/// A package is considered to be the enclosing package if this package is
1003-
/// located in a direct child directory of the enclosing package.
1004-
late final Package? enclosingPackage = () {
1005-
final enclosingPackagePath = p.dirname(path);
1006-
return _packageMap.values.firstWhereOrNull(
1007-
(package) => p.equals(package.path, enclosingPackagePath),
1008-
);
1009-
}();
1010-
1011-
/// Whether this package is an example package as defined by [examplePackage].
1012-
bool get isExample => enclosingPackage?.examplePackage == this;
990+
/// Whether this package is an example package.
991+
bool get isExample => p.dirname(path).endsWith('example');
1013992

1014993
/// Returns whether this package is a Flutter app.
1015994
///

0 commit comments

Comments
 (0)