casey / just

🤖 Just a command runner
https://just.systems
Creative Commons Zero v1.0 Universal
17.59k stars 399 forks source link

Wrong working directory for recipes inside imported justfile #1978

Open Ziqi-Yang opened 1 month ago

Ziqi-Yang commented 1 month ago

Directory Structure

/tmp/experiment took 5s 
❯ tree .
.
└── just
    ├── a.just
    └── b.just

File content:

❯ cat ./just/a.just
#!/usr/bin/env -S just --working-directory . --justfile

import 'b.just'

a: b
  pwd
❯ cat ./just/b.just
b:
  pwd

When I run ./just/a.just, it produces:

/tmp/experiment 
❯ ./just/a.just
pwd
/tmp/experiment/just
pwd
/tmp/experiment
Ziqi-Yang commented 1 month ago

This is the source: https://github.com/casey/just/blob/610aa0c52cf8c3d20a79ee641bb9f799ca3027fc/src/recipe.rs#L130
It's intentionally set, but I think it's arguable to make the working directory of the imported recipe different than the command line argument. It may be better to provide a option for import clause or something else.

Ziqi-Yang commented 1 month ago

I see there is [no-cd] clause, but it's for single recipe, but not for the whole justfile. And it we have complicated function call hierarchy like python name: (jpg-copy-template name "python") && (jpg-replace-builtin name) then we need to put [no-cd] attribute to all of the recipes here.

Ziqi-Yang commented 1 month ago

This is the source:

https://github.com/casey/just/blob/610aa0c52cf8c3d20a79ee641bb9f799ca3027fc/src/recipe.rs#L130

It's intentionally set, but I think it's arguable to make the working directory of the imported recipe different than the command line argument. It may be better to provide a option for import clause or something else.

Also, I don't think using self.working_directory makes much sense, since it's neither the path that the user is at (maybe is, when the user is at the directory that holds the entry justfile), nor the path that the imported justfile is at.