invertase / melos

🌋 A tool for managing Dart projects with multiple packages. With IntelliJ and Vscode IDE support. Supports automated versioning, changelogs & publishing via Conventional Commits.
https://melos.invertase.dev/~melos-latest
Apache License 2.0
1.07k stars 193 forks source link

fix: maintain working directory across script steps #711

Open jessicatarra opened 1 month ago

jessicatarra commented 1 month ago

This PR addresses the issue raised in #470, where the working directory is not maintained across multiple steps in a script.

For example, consider the following script:

fail:
  steps:
    - cd packages/
    - pwd

When running this script using melos run, the output will show the workspace root directory, not the packages/ directory as expected.

This PR introduces a change to ensure that the working directory is properly maintained across multiple steps in a script.

The key changes are:

By running the script defined in the issue with the fix implemented in this PR, the output is now:

➜  melos git:(bugfix/melos_run_script_steps_working_directory) ✗ melos success
Building package executable...
Built melos:melos.
melos run success
  └> cd packages/
     └> RUNNING

melos run success
  └> cd packages/
     └> SUCCESS

melos run success
  └> pwd
     └> RUNNING

/Users/jessicatarra/Development/melos/packages

melos run success
  └> pwd
     └> SUCCESS

Type of Change

spydon commented 1 month ago

Any progress on this @jessicatarra? :blush:

jessicatarra commented 2 weeks ago

Hey everyone, @spydon Sorry for the late reply. Work's been pretty busy lately, but I finally got some time this weekend to dig back into this fix. I managed to make things work, but now I'm stuck on figuring out how to keep the logs consistent with our current style. The issue is, this persistent shell (as it is implemented) makes it tricky to track the results of individual commands. To help us brainstorm a solution, I'm sharing my implementation so far. Let's see what we can come up with together.

Example script

melos:test:
  steps:
    - cd packages/melos
    - pwd
    - dart test .





Output

melos run melos:test
➡️ step: cd packages/melos
➡️ step: pwd
/Users/jessicatarra/Development/melos/packages/melos
➡️ step: dart test .

… (long logs from dart test step)


ERROR: Shell process completed with errors.
Shell process completed some steps successfully.