Skip to content

Commit

Permalink
fix: too many open files while creating a workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmuttaskiran committed Dec 14, 2024
1 parent e074cb0 commit 1045ef5
Showing 1 changed file with 37 additions and 39 deletions.
76 changes: 37 additions & 39 deletions packages/melos/lib/src/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -531,54 +531,52 @@ class PackageMap {

final packageMap = <String, Package>{};

await Future.wait<void>(
pubspecFiles.map((pubspecFile) async {
final pubspecDirPath = pubspecFile.parent.path;
final pubspec = Pubspec.parse(pubspecFile.readAsStringSync());
final name = pubspec.name;

if (packageMap.containsKey(name)) {
throw MelosConfigException(
'''
await Stream.fromIterable(pubspecFiles).parallel((pubspecFile) async {
final pubspecDirPath = pubspecFile.parent.path;
final pubspec = Pubspec.parse(pubspecFile.readAsStringSync());
final name = pubspec.name;

if (packageMap.containsKey(name)) {
throw MelosConfigException(
'''
Multiple packages with the name `$name` found in the workspace, which is unsupported.
To fix this problem, consider renaming your packages to have a unique name.
The packages that caused the problem are:
- $name at ${printablePath(relativePath(pubspecDirPath, workspacePath))}
- $name at ${printablePath(relativePath(packageMap[name]!.path, workspacePath))}
''',
);
}
);
}

final filteredCategories = <String>[];

categories.forEach((key, value) {
final isCategoryMatching = value.any(
(category) => category.matches(
relativePath(pubspecDirPath, workspacePath),
),
);

if (isCategoryMatching) {
filteredCategories.add(key);
}
});

packageMap[name] = Package(
name: name,
path: pubspecDirPath,
pathRelativeToWorkspace: relativePath(pubspecDirPath, workspacePath),
version: pubspec.version ?? Version.none,
publishTo: pubspec.publishTo.let(Uri.parse),
packageMap: packageMap,
dependencies: pubspec.dependencies.keys.toList(),
devDependencies: pubspec.devDependencies.keys.toList(),
dependencyOverrides: pubspec.dependencyOverrides.keys.toList(),
pubspec: pubspec,
categories: filteredCategories,
final filteredCategories = <String>[];

categories.forEach((key, value) {
final isCategoryMatching = value.any(
(category) => category.matches(
relativePath(pubspecDirPath, workspacePath),
),
);
}),
);

if (isCategoryMatching) {
filteredCategories.add(key);
}
});

packageMap[name] = Package(
name: name,
path: pubspecDirPath,
pathRelativeToWorkspace: relativePath(pubspecDirPath, workspacePath),
version: pubspec.version ?? Version.none,
publishTo: pubspec.publishTo.let(Uri.parse),
packageMap: packageMap,
dependencies: pubspec.dependencies.keys.toList(),
devDependencies: pubspec.devDependencies.keys.toList(),
dependencyOverrides: pubspec.dependencyOverrides.keys.toList(),
pubspec: pubspec,
categories: filteredCategories,
);
}).drain<void>();

return PackageMap(packageMap, logger);
}
Expand Down

0 comments on commit 1045ef5

Please sign in to comment.