melos icon indicating copy to clipboard operation
melos copied to clipboard

fix: Melos scripts `exec` only works if globally installed

Open Tandashi opened this issue 2 years ago • 3 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues.

Version

3.0.1

Description

Melos throws an error if not globally installed when running scripts that use exec. This might be due to melos not running with the path it is currently executed from but rather assumes its globally installed.

Why is this a problem? We currently face the issue that we can't run melos script that use exec in our CI/CD without installing it globally.

Potential solution: Maybe the usage of Platform.script can be helpful to use the correct melos path.

// https://github.com/invertase/melos/blob/main/packages/melos/lib/src/scripts.dart#L280
final parts = [Platform.executable, Platform.script.path, 'exec'];

(not tested)

Steps to reproduce

melos.yaml

name: test

packages:
  - packages/*

scripts:
  test:
    name: test
    exec: echo Hi

pubspec.yaml

name: test_workspace

environment:
  sdk: '>=2.18.0 <3.0.0'

dev_dependencies:
  melos: ^3.0.1

Running the following will cause an error:

> flutter pub run melos run test
melos run test
  â””> melos exec -- "echo Hi"
     â””> RUNNING

/bin/sh: melos: command not found


melos run test
  â””> melos exec -- "echo Hi"
     â””> FAILED
ScriptException: The script test failed to execute.
pub finished with exit code 1

Expected behavior

No failure when running the script since all other features work without the need of having melos installed globally.

Screenshots

No response

Additional context and comments

No response

Tandashi avatar May 04 '23 18:05 Tandashi

Same problem

zhyky avatar Aug 29 '23 09:08 zhyky

@Tandashi @zhyky do you still face this problem?

spydon avatar Dec 04 '23 18:12 spydon

@spydon Yes the problem still exists even with melos 3.4.0 installed.

> dart run melos run test
/bin/sh: melos: command not found

Tandashi avatar Dec 05 '23 11:12 Tandashi