mirror of
https://github.com/go-task/task.git
synced 2026-06-29 07:34:18 +00:00
feat(scoped): refactor compiler, add nested includes, document flatten
Refactor compiler.go for better maintainability: - Extract isScopedMode() helper function - Split getVariables() into getScopedVariables() and getLegacyVariables() - Fix directory resolution: parent chain env/vars now resolve from their own directory instead of the current task's directory Add nested includes support and tests: - Add testdata/scoped_taskfiles/inc_a/nested/Taskfile.yml (3 levels deep) - Add test case for nested include inheritance (root → a → nested) - Verify nested includes inherit vars from full parent chain Fix flaky tests: - Remove VAR from print tasks (defined in both inc_a and inc_b) - Test only unique variables (UNIQUE_A, UNIQUE_B, ROOT_VAR) Document flatten: true escape hatch: - Add migration guide step for using flatten: true - Add new section explaining flatten bypasses scoping - Include example and usage recommendations
This commit is contained in:
4
testdata/scoped_taskfiles/inc_a/Taskfile.yml
vendored
4
testdata/scoped_taskfiles/inc_a/Taskfile.yml
vendored
@@ -8,11 +8,13 @@ vars:
|
||||
VAR: value_from_a
|
||||
UNIQUE_A: only_in_a
|
||||
|
||||
includes:
|
||||
nested: ./nested
|
||||
|
||||
tasks:
|
||||
print:
|
||||
desc: Print vars from include A
|
||||
cmds:
|
||||
- echo "A:VAR={{.VAR}}"
|
||||
- echo "A:UNIQUE_A={{.UNIQUE_A}}"
|
||||
- echo "A:ROOT_VAR={{.ROOT_VAR}}"
|
||||
|
||||
|
||||
22
testdata/scoped_taskfiles/inc_a/nested/Taskfile.yml
vendored
Normal file
22
testdata/scoped_taskfiles/inc_a/nested/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
version: "3"
|
||||
|
||||
env:
|
||||
NESTED_ENV: env_from_nested
|
||||
|
||||
vars:
|
||||
NESTED_VAR: from_nested
|
||||
|
||||
tasks:
|
||||
print:
|
||||
desc: Print vars from nested include (3 levels deep)
|
||||
cmds:
|
||||
- echo "NESTED:ROOT_VAR={{.ROOT_VAR}}"
|
||||
- echo "NESTED:UNIQUE_A={{.UNIQUE_A}}"
|
||||
- echo "NESTED:NESTED_VAR={{.NESTED_VAR}}"
|
||||
- echo "NESTED:NESTED_ENV={{.env.NESTED_ENV}}"
|
||||
- echo "NESTED:ROOT_ENV={{.env.ROOT_ENV}}"
|
||||
|
||||
try-access-b:
|
||||
desc: Try to access B's unique var (should fail - sibling isolation)
|
||||
cmds:
|
||||
- echo "NESTED:UNIQUE_B={{.UNIQUE_B}}"
|
||||
1
testdata/scoped_taskfiles/inc_b/Taskfile.yml
vendored
1
testdata/scoped_taskfiles/inc_b/Taskfile.yml
vendored
@@ -12,7 +12,6 @@ tasks:
|
||||
print:
|
||||
desc: Print vars from include B
|
||||
cmds:
|
||||
- echo "B:VAR={{.VAR}}"
|
||||
- echo "B:UNIQUE_B={{.UNIQUE_B}}"
|
||||
- echo "B:ROOT_VAR={{.ROOT_VAR}}"
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
A:VAR=value_from_b
|
||||
A:UNIQUE_A=only_in_a
|
||||
A:ROOT_VAR=from_root
|
||||
B:VAR=value_from_b
|
||||
B:UNIQUE_B=only_in_b
|
||||
B:ROOT_VAR=from_root
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
A:VAR=value_from_a
|
||||
A:UNIQUE_A=only_in_a
|
||||
A:ROOT_VAR=from_root
|
||||
B:VAR=value_from_b
|
||||
B:UNIQUE_B=only_in_b
|
||||
B:ROOT_VAR=from_root
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
A:VAR=value_from_a
|
||||
A:UNIQUE_A=only_in_a
|
||||
A:ROOT_VAR=from_root
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
B:VAR=value_from_b
|
||||
B:UNIQUE_B=only_in_b
|
||||
B:ROOT_VAR=from_root
|
||||
|
||||
5
testdata/scoped_taskfiles/testdata/TestScopedTaskfiles-scoped-nested.golden
vendored
Normal file
5
testdata/scoped_taskfiles/testdata/TestScopedTaskfiles-scoped-nested.golden
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
NESTED:ROOT_VAR=from_root
|
||||
NESTED:UNIQUE_A=only_in_a
|
||||
NESTED:NESTED_VAR=from_nested
|
||||
NESTED:NESTED_ENV=env_from_nested
|
||||
NESTED:ROOT_ENV=env_from_root
|
||||
Reference in New Issue
Block a user