Unverified Commit febd04d0 authored by hatch01's avatar hatch01 Committed by GitHub
Browse files

melos: init at 6.2.0 (#334461)

parent c8ce709a
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
diff --git a/bin/melos.dart b/bin/melos.dart
index 0db7013..218276f 100644
--- a/bin/melos.dart
+++ b/bin/melos.dart
@@ -1,11 +1,37 @@
+import 'dart:io';
 import 'package:cli_launcher/cli_launcher.dart';
 import 'package:melos/src/command_runner.dart';
 
-Future<void> main(List<String> arguments) async => launchExecutable(
-      arguments,
-      LaunchConfig(
+Future<void> main(List<String> arguments) async {
+  final melosYamlPath = findMelosYaml();
+
+  if (melosYamlPath == null) {
+    print('Error: melos.yaml not found in the project.');
+    // Handle the error as needed
+    return;
+  }
+
+  melosEntryPoint(
+    arguments,
+    LaunchContext(
+      directory: Directory.current,
+      localInstallation: ExecutableInstallation(
         name: ExecutableName('melos'),
-        launchFromSelf: false,
-        entrypoint: melosEntryPoint,
+        isSelf: false,
+        packageRoot: melosYamlPath,
       ),
-    );
+    ),
+  );
+}
+
+Directory? findMelosYaml() {
+  var directory = Directory.current;
+  while (directory.path != directory.parent.path) {
+    final melosYamlPath = '${directory.path}/melos.yaml';
+    if (File(melosYamlPath).existsSync()) {
+      return directory;
+    }
+    directory = directory.parent;
+  }
+  return null;
+}
+44 −0
Original line number Diff line number Diff line
{
  lib,
  fetchFromGitHub,
  buildDartApplication,
}:
let
  pname = "melos";
  version = "6.2.0";
  src = fetchFromGitHub {
    owner = "invertase";
    repo = "melos";
    rev = "melos-v${version}";
    hash = "sha256-00K/LwrwjvO4LnXM2PDooQMJ6sXcJy9FBErtEwoMZlM=";
  };
in
buildDartApplication {
  inherit pname version src;

  sourceRoot = "${src.name}/packages/melos";

  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
    ./add-generic-main.patch
  ];

  pubspecLock = lib.importJSON ./pubspec.lock.json;

  # hard code the path to the melos templates
  preBuild = ''
    substituteInPlace lib/src/common/utils.dart --replace-fail "final melosPackageFileUri = await Isolate.resolvePackageUri(melosPackageUri);" "return \"$out\";"
    substituteInPlace lib/src/common/utils.dart --replace-fail "return p.normalize('\''${melosPackageFileUri!.toFilePath()}/../..');" " "
    mkdir -p $out
    cp -r templates $out/
  '';

  meta = {
    homepage = "https://github.com/invertase/melos";
    description = "A tool for managing Dart projects with multiple packages. With IntelliJ and Vscode IDE support. Supports automated versioning, changelogs & publishing via Conventional Commits. ";
    mainProgram = "melos";
    license = lib.licenses.asl20;
    maintainers = [ lib.maintainers.eymeric ];
  };
}
+749 −0

File added.

Preview size limit exceeded, changes collapsed.