Unverified Commit 5df6bef4 authored by Aleksana's avatar Aleksana Committed by GitHub
Browse files

melos: 7.1.1 -> 7.3.0 (#458704)

parents 15e695a9 73a427b2
Loading
Loading
Loading
Loading
+52 −17
Original line number Diff line number Diff line
diff --git a/bin/melos.dart b/bin/melos.dart
index 0db7013..218276f 100644
index 2476436..bd79fad 100644
--- a/packages/melos/bin/melos.dart
+++ b/packages/melos/bin/melos.dart
@@ -1,11 +1,37 @@
+import 'dart:io';
@@ -1,11 +1,72 @@
 import 'package:cli_launcher/cli_launcher.dart';
 import 'package:melos/src/command_runner.dart';
+import 'dart:io';
+import 'package:yaml/yaml.dart';
+import 'package:path/path.dart' as path;
 
-Future<void> main(List<String> arguments) async => launchExecutable(
-  arguments,
@@ -15,12 +17,13 @@ index 0db7013..218276f 100644
-    entrypoint: melosEntryPoint,
-  ),
-);
+final ExecutableName executableName = ExecutableName('melos');
+
+Future<void> main(List<String> arguments) async {
+  final melosYamlPath = findMelosYaml();
+  final workspaceRoot = _findLocalInstallation(Directory.current);
+
+  if (melosYamlPath == null) {
+    print('Error: melos.yaml not found in the project.');
+    // Handle the error as needed
+  if (workspaceRoot == null) {
+    print("Error: Could not find your work  ");
+    return;
+  }
+
@@ -29,22 +32,54 @@ index 0db7013..218276f 100644
+    LaunchContext(
+      directory: Directory.current,
+      localInstallation: ExecutableInstallation(
+        name: ExecutableName('melos'),
+        name: executableName,
+        isSelf: false,
+        packageRoot: melosYamlPath,
+        packageRoot: workspaceRoot,
+      ),
+    ),
+  );
+}
+
+Directory? findMelosYaml() {
+  var directory = Directory.current;
+  while (directory.path != directory.parent.path) {
+    final melosYamlPath = '${directory.path}/melos.yaml';
+    if (File(melosYamlPath).existsSync()) {
+      return directory;
+// Stolen then simplified from https://github.com/blaugold/cli_launcher/blob/dcdf11c42b77ddc8e38e7e2445c8cff9b55658ec/lib/cli_launcher.dart#L249
+Directory? _findLocalInstallation(
+  Directory start,
+) {
+  if (path.equals(start.path, start.parent.path)) {
+    return null;
+  }
+
+  final pubspecFile = File(path.join(start.path, 'pubspec.yaml'));
+  if (pubspecFile.existsSync()) {
+    final pubspecString = pubspecFile.readAsStringSync();
+    String? name;
+    YamlMap? dependencies;
+    YamlMap? devDependencies;
+
+    try {
+      final pubspecYaml = loadYamlDocument(
+        pubspecString,
+        sourceUrl: pubspecFile.uri,
+      );
+      final pubspec = pubspecYaml.contents as YamlMap;
+      name = pubspec['name'] as String?;
+      dependencies = pubspec['dependencies'] as YamlMap?;
+      devDependencies = pubspec['dev_dependencies'] as YamlMap?;
+    } catch (error, stackTrace) {
+      throw StateError(
+        'Could not parse pubspec.yaml at ${start.path}.\n$error\n$stackTrace',
+      );
+    }
+
+    final isSelf = name == executableName.package;
+
+    if ((isSelf) ||
+        (dependencies != null &&
+            dependencies.containsKey(executableName.package)) ||
+        (devDependencies != null &&
+            devDependencies.containsKey(executableName.package))) {
+      return start;
+    }
+    directory = directory.parent;
+  }
+  return null;
+
+  return _findLocalInstallation(start.parent);
+}
+4 −4
Original line number Diff line number Diff line
@@ -4,12 +4,12 @@
  buildDartApplication,
}:
let
  version = "7.1.1";
  version = "7.3.0";
  src = fetchFromGitHub {
    owner = "invertase";
    repo = "melos";
    tag = "melos-v${version}";
    hash = "sha256-i75fbo0lqDszo2pDtkWXQMt+3IoWsK7t05YU2IjqTmw=";
    hash = "sha256-XTEhH8F54BoXJ1QNhUIZszHQoDwP0Za1LPQ6Dv9sR08=";
  };
in
buildDartApplication {
@@ -17,8 +17,8 @@ buildDartApplication {
  inherit version src;

  patches = [
    # This patch (created a melos 6.1.0) modify the method melos use to find path to the root of the projects.
    # It is needed because when melos is in the nixstore, it break it and fail to find the projects root with melos.yaml
    # Patch melos entrypoint to bypass cli_launcher which throws because it does not find melos in the "classic" folders eg : .dart_tool or pub cache.
    # https://github.com/blaugold/cli_launcher/blob/dcdf11c42b77ddc8e38e7e2445c8cff9b55658ec/lib/cli_launcher.dart#L236
    ./add-generic-main.patch
  ];

+28 −8
Original line number Diff line number Diff line
@@ -4,21 +4,21 @@
      "dependency": "transitive",
      "description": {
        "name": "_fe_analyzer_shared",
        "sha256": "0eb33edbbe99a02e73b8bbeb6f2b65972023d902117ee8d1bf0ea1a79f83aa7b",
        "sha256": "c209688d9f5a5f26b2fb47a188131a6fb9e876ae9e47af3737c0b4f58a93470d",
        "url": "https://pub.dev"
      },
      "source": "hosted",
      "version": "90.0.0"
      "version": "91.0.0"
    },
    "analyzer": {
      "dependency": "transitive",
      "description": {
        "name": "analyzer",
        "sha256": "711e3a890bb529bf55f07d73b8706f4b7504ad77e90d2f205626b116c048583f",
        "sha256": "f51c8499b35f9b26820cfe914828a6a98a94efd5cc78b37bb7d03debae3a1d08",
        "url": "https://pub.dev"
      },
      "source": "hosted",
      "version": "8.3.0"
      "version": "8.4.1"
    },
    "ansi_styles": {
      "dependency": "transitive",
@@ -184,11 +184,11 @@
      "dependency": "transitive",
      "description": {
        "name": "crypto",
        "sha256": "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855",
        "sha256": "c8ea0233063ba03258fbcf2ca4d6dadfefe14f02fab57702265467a19f27fadf",
        "url": "https://pub.dev"
      },
      "source": "hosted",
      "version": "3.0.6"
      "version": "3.0.7"
    },
    "dart_style": {
      "dependency": "transitive",
@@ -364,11 +364,11 @@
      "dependency": "transitive",
      "description": {
        "name": "mustache_template",
        "sha256": "d9aa84d114368b7f1727b7014b85bb0b234daeafe1518824c82d32703b3964f6",
        "sha256": "daa42be75f2ccfb287c24a75e7ac594f2ea0b32bf9ebe7c15154aa45b2dfb2de",
        "url": "https://pub.dev"
      },
      "source": "hosted",
      "version": "2.0.1"
      "version": "2.0.2"
    },
    "node_preamble": {
      "dependency": "transitive",
@@ -400,6 +400,16 @@
      "source": "hosted",
      "version": "1.9.1"
    },
    "petitparser": {
      "dependency": "transitive",
      "description": {
        "name": "petitparser",
        "sha256": "1a97266a94f7350d30ae522c0af07890c70b8e62c71e8e3920d1db4d23c057d1",
        "url": "https://pub.dev"
      },
      "source": "hosted",
      "version": "7.0.1"
    },
    "platform": {
      "dependency": "transitive",
      "description": {
@@ -690,6 +700,16 @@
      "source": "hosted",
      "version": "1.2.1"
    },
    "xml": {
      "dependency": "transitive",
      "description": {
        "name": "xml",
        "sha256": "971043b3a0d3da28727e40ed3e0b5d18b742fa5a68665cca88e74b7876d5e025",
        "url": "https://pub.dev"
      },
      "source": "hosted",
      "version": "6.6.1"
    },
    "yaml": {
      "dependency": "direct dev",
      "description": {