Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Merge env and passthroughEvent from package turbo.json with root turbo.json #6798

Closed
weyert opened this issue Dec 15, 2023 · 6 comments
Closed
Labels
needs: investigation The bug / idea needs more investigation owned-by: turborepo

Comments

@weyert
Copy link
Contributor

weyert commented Dec 15, 2023

Which project is this feature idea for?

Turborepo

Describe the feature you'd like to request

I would like to have an option were the env and passthroughEnv defined in a turbo.json-file located in a workspace can be merged with the ones defined in the root turbo.json file.

Currently the root turbo.json is over 900 lines of code. Mostly consisting of defining the environment variables, the rest is the actual actions.

Describe the solution you'd like

I want to be able to define env and passthroughEnv variables on a per workspace level and combine it with a standard set of environment variables used by all projects, such as NODE_ENV, NAMESPACE etc.

Now you need to define all the environment variables in root turbo.json as anything defined in a workspace turbo.json will override the ones in root turbo.json.

This makes it difficult to maintain the environment variables for a mono repo that uses Turborepo with over in total 649 environment variables. All NEXT_PUBLIC_* used in Next.js application and feature flag environments get burdensome to main in the root turbo.json

Describe alternatives you've considered

Allow to opt-in behaviour to merge the configuration settings instead of replacing/overriden

@weyert weyert added needs: triage New issues get this label. Remove it after triage story labels Dec 15, 2023
@mehulkar
Copy link
Contributor

We need to figure out a syntax for this. We've noodled on it before and the options are something like:

  1. Option 1

    {
        "pipeline": {
            "taskname": {
                "some_array_config": [
                    "$inherit$",
                    "custom",
                    "keys"
                ]
            }
        }
    }
  2. Option 2

    {
        "pipeline": {
            "taskname": {
                "some_array_config": {
                    "mergetype": "inherit",
                    "value": [
                        "custom",
                        "keys"
                    ]
                }
            }
        }
    }
  3. Option 3

    {
        "pipeline": {
            "taskname": {
                "some_array_config:inherit": [
                    "custom",
                    "keys"
                ]
            }
        }
    }

We discussed deeply about merge behaviors when doing Workspace Configs and ultimately decided it would be confusing to do something automatically without a way to opt out, so we tabled it.


It's also possible that some v2 of Workspace Configs can allow merging with a template, but that's probably only going to solve the 80% case, and may not work for a repo like yours.

@weyert
Copy link
Contributor Author

weyert commented Dec 22, 2023

I think a flag that decides the behaviour would be sufficient? It's either merging with root config or the existing behaviour?

@mehulkar
Copy link
Contributor

A flag is not sufficient because it cannot target the merge behavior of individual fields or even more granular, individual fields per task per workspace. We will likely be creating an unworkable situation if we add a global flag. We are open to an RFC that thinks through these things however: https://turbo.build/governance#roadmap-and-rfc-process

@mehulkar mehulkar added needs: investigation The bug / idea needs more investigation and removed needs: triage New issues get this label. Remove it after triage labels Jan 23, 2024
@tapico-weyert
Copy link
Contributor

tapico-weyert commented Jan 26, 2024

Why can't you merge the env and passthroughEnv from the global turbo.json for the overrides of turbo.json?

Does look like you are introducing a $TURBO_DEFAULT (see PR #7113) for the inputs so I can imagine a similar approach can use for these two config options? I think that could work. The use case for inputs is not a lot different. $TURBO_DEFAULT or what the name would be, would than reflect the values from the root turbo.json.

This solves the problem needing to re-add all the entries from the root turbo.json in the override turbo.json in the workspace.

@mehulkar
Copy link
Contributor

mehulkar commented Jan 26, 2024

@tapico-weyert yeah, we had resisted adding microsyntaxes for too long, but @tknickman managed to convince us of $TURBO_DEFAULT$.

$TURBO_DEFAULT [...] would than reflect the values from the root turbo.json.

It would definitely need a different token to inherit from root, since this one is about turbo's built-in behavior, not the user's config.

@weyert
Copy link
Contributor Author

weyert commented Jan 27, 2024

Yeah, that seems reasonable. I am not too fussed about naming :) I think earlier a $inherit$ was suggested. That works for me.

@vercel vercel locked and limited conversation to collaborators Feb 21, 2024
@anthonyshew anthonyshew converted this issue into discussion #7452 Feb 21, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
needs: investigation The bug / idea needs more investigation owned-by: turborepo
Projects
None yet
Development

No branches or pull requests

3 participants