Replies: 8 comments
-
One more-general note: typically build tools like Turborepo hand you a directory and all of your outputs get dumped into that directory. It's distinct and disconnected from your repository. That you can colocate your generated assets with your source is both novel, and, as you can see, dangerous. Normally we would tell you to ignore the output folder using Here is the test case I used to reproduce your situation, on top of diff --git a/apps/generated/package.json b/apps/generated/package.json
new file mode 100644
index 0000000..a376845
--- /dev/null
+++ b/apps/generated/package.json
@@ -0,0 +1,6 @@
+{
+ "name": "generated",
+ "scripts": {
+ "generate": "date >> src/output/date.txt"
+ }
+}
\ No newline at end of file
diff --git a/apps/generated/src/.gitignore b/apps/generated/src/.gitignore
new file mode 100644
index 0000000..9b1960e
--- /dev/null
+++ b/apps/generated/src/.gitignore
@@ -0,0 +1 @@
+output/
\ No newline at end of file
diff --git a/apps/generated/src/input.txt b/apps/generated/src/input.txt
new file mode 100644
index 0000000..81229b4
--- /dev/null
+++ b/apps/generated/src/input.txt
@@ -0,0 +1 @@
+date
\ No newline at end of file
diff --git a/turbo.json b/turbo.json
index b510892..151c04b 100644
--- a/turbo.json
+++ b/turbo.json
@@ -5,6 +5,10 @@
"build": {
"outputs": [".next/**"]
},
+ "generate": {
+ "inputs": ["src/**"],
+ "outputs": ["src/output/**"]
+ },
"lint": {},
"dev": {
"cache": false, If you remove The ideal pattern for your case is actually this:
We actually can't make the change as you're proposing it because any task can write to its inputs (or the inputs of other tasks) and that isn't something that we can say is or is not valid from our position outside of the task. The only option we have from our perspective would be to do something like a microsyntax, for example I'm not going to close this, but I am going to rename the issue, and hold it open to see who else shows up to discuss and gauge community interest. |
Beta Was this translation helpful? Give feedback.
-
The output of this task is actually on a .gitignore allready, hovewer using the default It might be fine, but still having the input be as tight as possible is our endgoal here. Allowing true-negative globs, would probably be the go to solution then. But that doesn't mean that turbo, shouldn't be able to work with such task, so: having a microsyntax like you proposed is a handy shortcut, but definitely needs good documentation for discoverability, it might even make sense to expose it more by making it a field on tasks? |
Beta Was this translation helpful? Give feedback.
-
Sometimes in life you write something, and then go do a thing, that just gives you the exact opposite insight as you just wrote: And especially for these linting task you don't want the output ignored! |
Beta Was this translation helpful? Give feedback.
-
To be clear, the "ideal" sketch in my previous comment here works in the current version, you don't need to go all the way into doublestar glob implementation details. !-prefixed patterns are negated; much simpler to write than the complicated pattern you came up with. I personally agree that outputs shouldn't clobber inputs, but the system isn't designed that way right now and we can't make that change without making it opt in. The ongoing tragedy of having something that people are using where we can't break people to fix our own past transgressions. !gitignore could also be a way to specify include excludes. Or maybe !gitindex because you can have files in index that are otherwise ignored. |
Beta Was this translation helpful? Give feedback.
-
Also, making it a flag whose default state we can toggle at a major version bump is a clever proposal! That's easier to help people through the situation. |
Beta Was this translation helpful? Give feedback.
-
(Yup, lint --fix is our canonical example. And it reaches fixed point in two.) |
Beta Was this translation helpful? Give feedback.
-
The !-prefixed patterns didn't work in my testing (and trying it again, still don't in v1.8.3). "!gitignore" or "!gitindex" (or maybe even a more special looking solution like |
Beta Was this translation helpful? Give feedback.
-
I've got some thoughts on this one:
(4 cont) These globs overlap each other and, if I want to exclude the outputs, I need to add a negative glob. Additionally, if that negative glob were to be added, the intent would still be clear.
At this point, you can probably tell that I'm not necessarily in favor of this one. 😄 This use case seems to have solutions that are fairly clear both by editing |
Beta Was this translation helpful? Give feedback.
-
Which project is this feature idea for?
Turborepo
Describe the feature you'd like to request
I think this sits somewhere between feature and bug.
Currently when you have an output directory that also matches an input glob, turbo treats all files in that output directory relevant for the cache-key. Effectively making every output-input combination it's own cache. Which intern hinders efficient caching.
Example: (other code left out for readability)
Describe the solution you'd like
Turbo should check if a file is matched by an output glob before considering it for the cache key.
Describe alternatives you've considered
Negative matches would be a also a solution, but one the user has to find themselves.
Either with a negation-syntax in the "input" array, or a more explicit "ignore" field on tasks.
Workaround (that at least seams to work for now, but no definite answer yet was burned before by a wrong input-glob) is using negative character classes from https://github.com/bmatcuk/doublestar#character-classes :
inputs: ["src/[!_]*/**", "src/[!_]*"]
.But you need to have 2 globs for that to work, and arguably it gets less readably this way.
And this probably doesn't work for all cases!
Beta Was this translation helpful? Give feedback.
All reactions