Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Reusable and Modular Justfiles in Monorepos (Namespaces) #2215

Closed
bukowa opened this issue Jul 2, 2024 · 3 comments
Closed

Support for Reusable and Modular Justfiles in Monorepos (Namespaces) #2215

bukowa opened this issue Jul 2, 2024 · 3 comments

Comments

@bukowa
Copy link
Contributor

bukowa commented Jul 2, 2024

Originally posted in issue tracking mod, but I feel like it doesn't really belong there.

I am thinking about creating a reusable justfile that can work as a standalone file but can also be copied and imported where needed. For example, environment variables in each justfile represent a standalone application (created with a template) in subdirectories (like a monorepo). The main justfile at the root should be able to build all of them, but independently they should work as standalone applications. However, the root justfile should be able to modify the variables (it should also work for recipes) before building (e.g., to give them different names).

Imagine these justfiles created with a template (which anyone can provide with their frameworks, etc.) and placed in different subdirectories within a monorepo:

# app1/justfile
export APP_NAME := "app-name"

build:
    echo building $APP_NAME
# app2/justfile
export APP_NAME  := "app-name"

build:
    echo building $APP_NAME
# justfile
import 'app1/justfile' with {prefix_vars('app1'}
import 'app2/justfile' with {prefix_vars('app2'}

export app1_APP_NAME = "app-name-1"
export app2_APP_NAME = "app-name-2"

build:
    echo "Building...."
    just app1_build
    just app2_build
$ just build
Building...
building app-name-1
building app-name-2

In my opinion, this would allow the redistribution of applications with justfiles, which could create interesting reusable build processes. Keep in mind that the examples I gave were made up quickly.

@casey
Copy link
Owner

casey commented Jul 4, 2024

Not sure what the ultimate syntax should look like, but having a way of overriding variables in imported modules seems reasonable to me.

Maybe something like:

import 'app2/justfile' with APP_NAME = "app-name-1"

@bukowa
Copy link
Contributor Author

bukowa commented Jul 4, 2024

Not sure what the ultimate syntax should look like, but having a way of overriding variables in imported modules seems reasonable to me.

Maybe something like:

import 'app2/justfile' with APP_NAME = "app-name-1"

I am thinking about {} because it would allow to implement more functions later.
So basically making it somehow extendable in the future where each function is implementation detail.
Trying to get down to key-value method as much as posisble.

import 'app1/justfile' with <func1>,<func2> ?

import 'app1/justfile' with {
    APP_NAME="?"
}

# chaining
import 'app1/justfile' with [
    custom_vars{
        APP_NAME="?"
    },
    renamed_recipes{
        build=build_app1
    },
    prefixed_vars{
       `APP1_`
    },
    future_idea{
        key=value,
        key2=value2
    },
]

@bukowa
Copy link
Contributor Author

bukowa commented Jul 6, 2024

It looks a bit too complicated, it's better to work with modules and passing env vars explicitly but I'm still afraid that in a large nested structure I will accidentally overwrite the variables of a recipe that I don't want

@bukowa bukowa closed this as not planned Won't fix, can't repro, duplicate, stale Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants