Skip to content

Commit

Permalink
fix: handle unresolvable symbolic links (#280)
Browse files Browse the repository at this point in the history
Fixes #269
  • Loading branch information
blaugold authored Apr 23, 2022
1 parent 9870270 commit 7009436
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/melos/lib/src/common/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ extension DirectoryUtils on Directory {
}
} else if (entity is Link) {
if (!followLinks ||
visitedLinks.contains(await entity.resolveSymbolicLinks())) {
visitedLinks.contains(await entity.tryResolveSymbolicLinks())) {
yield entity;
break;
}
Expand Down Expand Up @@ -440,6 +440,21 @@ extension DirectoryUtils on Directory {
}
}

extension FileSystemEntityUtils on FileSystemEntity {
/// Tries to resolve the path of this [FileSystemEntity] through
/// [resolveSymbolicLinks] and returns `null` if the path cannot be resolved.
///
/// For example, a path cannot be resolved when it is a link to a non-existing
/// file.
Future<String?> tryResolveSymbolicLinks() async {
try {
return await resolveSymbolicLinks();
} on FileSystemException {
return null;
}
}
}

extension StreamUtils<T> on Stream<T> {
/// Runs [convert] for each event in this stream and emits the result, while
/// ensuring that no more events than specified by [parallelism] are being
Expand Down
14 changes: 14 additions & 0 deletions packages/melos/test/workspace_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import 'package:melos/src/common/glob.dart';
import 'package:melos/src/package.dart';
import 'package:melos/src/workspace.dart';
import 'package:melos/src/workspace_configs.dart';
import 'package:path/path.dart' as p;
import 'package:pubspec/pubspec.dart';
import 'package:test/test.dart';

Expand Down Expand Up @@ -135,6 +136,19 @@ The packages that caused the problem are:
}),
);

test('load workspace config when workspace contains broken symlink',
() async {
final workspaceDir = createTemporaryWorkspaceDirectory();

final link = Link(p.join(workspaceDir.path, 'link'));
await link.create(p.join(workspaceDir.path, 'does-not-exist'));

await MelosWorkspace.fromConfig(
await MelosWorkspaceConfig.fromDirectory(workspaceDir),
logger: TestLogger(),
);
});

group('package filtering', () {
group('--include-dependencies', () {
test(
Expand Down

0 comments on commit 7009436

Please sign in to comment.