Skip to content

Commit 9a96c0a

Browse files
committed
Fixing up and adding tests
1 parent 76e57a5 commit 9a96c0a

File tree

4 files changed

+131
-27
lines changed

4 files changed

+131
-27
lines changed

crates/turborepo-lib/src/query/mod.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,26 +334,38 @@ impl Query {
334334
Ok(File::new(self.run.clone(), abs_path))
335335
}
336336

337+
/// Get the files that have changed between the `base` and `head` commits.
338+
///
339+
/// # Arguments
340+
///
341+
/// * `base`: Defaults to `main` or `master`
342+
/// * `head`: Defaults to `HEAD`
343+
/// * `include_uncommitted`: Defaults to `true` if `head` is not provided
344+
/// * `allow_unknown_objects`: Defaults to `false`
345+
/// * `merge_base`: Defaults to `true`
346+
///
347+
/// returns: Result<Array<File>, Error>
337348
async fn affected_files(
338349
&self,
339350
base: Option<String>,
340351
head: Option<String>,
341-
/// Defaults to true if `head` is not provided
342352
include_uncommitted: Option<bool>,
343-
/// Defaults to true
353+
allow_unknown_objects: Option<bool>,
344354
merge_base: Option<bool>,
345355
) -> Result<Array<File>, Error> {
346356
let base = base.as_deref();
347357
let head = head.as_deref();
348358
let include_uncommitted = include_uncommitted.unwrap_or_else(|| head.is_none());
349359
let merge_base = merge_base.unwrap_or(true);
360+
let allow_unknown_objects = allow_unknown_objects.unwrap_or(false);
361+
350362
let repo_root = self.run.repo_root();
351363
let change_result = self.run.scm().changed_files(
352364
repo_root,
353365
base,
354366
head,
355367
include_uncommitted,
356-
false,
368+
allow_unknown_objects,
357369
merge_base,
358370
)?;
359371

turborepo-tests/integration/tests/affected.t

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,21 @@ Do the same thing with the `query` command
5757
}
5858

5959
Also with `affectedFiles` in `turbo query`
60-
$ ${TURBO} query "query { affectedFiles(base: \"main\", head: \"HEAD\") { items { path } } }"
60+
$ ${TURBO} query "query { affectedFiles { items { path, affectedPackages { items { name } } } } }"
61+
WARNING query command is experimental and may change in the future
6162
{
6263
"data": {
6364
"affectedFiles": {
6465
"items": [
6566
{
66-
"path": "apps/my-app/new.js"
67+
"path": "apps/my-app/new.js",
68+
"affectedPackages": {
69+
"items": [
70+
{
71+
"name": "my-app"
72+
}
73+
]
74+
}
6775
}
6876
]
6977
}
@@ -118,13 +126,21 @@ Do the same thing with the `query` command
118126
}
119127

120128
Also with `affectedFiles` in `turbo query`
121-
$ ${TURBO} query "query { affectedFiles(base: \"main\", head: \"HEAD\") { items { path } } }"
129+
$ ${TURBO} query "query { affectedFiles { items { path, affectedPackages { items { name } } } } }"
130+
WARNING query command is experimental and may change in the future
122131
{
123132
"data": {
124133
"affectedFiles": {
125134
"items": [
126135
{
127-
"path": "apps/my-app/package.json"
136+
"path": "apps/my-app/package.json",
137+
"affectedPackages": {
138+
"items": [
139+
{
140+
"name": "my-app"
141+
}
142+
]
143+
}
128144
}
129145
]
130146
}
@@ -206,6 +222,17 @@ Do the same thing with the `query` command
206222
}
207223
}
208224
225+
Also with `affectedFiles` in `turbo query`
226+
$ ${TURBO} query "query { affectedFiles(base: \"HEAD\") { items { path, affectedPackages { items { name } } } } }"
227+
WARNING query command is experimental and may change in the future
228+
{
229+
"data": {
230+
"affectedFiles": {
231+
"items": []
232+
}
233+
}
234+
}
235+
209236
Override the SCM head to be main, so nothing runs
210237
$ TURBO_SCM_HEAD="main" ${TURBO} run build --affected --log-order grouped
211238
\xe2\x80\xa2 Packages in scope: (esc)
@@ -237,6 +264,17 @@ Do the same thing with the `query` command
237264
}
238265
}
239266
267+
Also with `affectedFiles` in `turbo query`
268+
$ ${TURBO} query "query { affectedFiles(head: \"main\") { items { path, affectedPackages { items { name } } } } }"
269+
WARNING query command is experimental and may change in the future
270+
{
271+
"data": {
272+
"affectedFiles": {
273+
"items": []
274+
}
275+
}
276+
}
277+
240278
Now add a commit to `main` so the merge base is different from `main`
241279
$ git checkout main --quiet
242280
$ echo "foo" >> packages/util/index.js
@@ -286,6 +324,28 @@ Do the same thing with the `query` command
286324
}
287325
}
288326
327+
Also with `affectedFiles` in `turbo query`
328+
$ ${TURBO} query "query { affectedFiles { items { path, affectedPackages { items { name } } } } }"
329+
WARNING query command is experimental and may change in the future
330+
{
331+
"data": {
332+
"affectedFiles": {
333+
"items": [
334+
{
335+
"path": "apps/my-app/package.json",
336+
"affectedPackages": {
337+
"items": [
338+
{
339+
"name": "my-app"
340+
}
341+
]
342+
}
343+
}
344+
]
345+
}
346+
}
347+
}
348+
289349
Now do some magic to change the repo to be shallow
290350
$ SHALLOW=$(git rev-parse --show-toplevel)/.git/shallow
291351
$ git rev-parse HEAD > "$SHALLOW"

turborepo-tests/integration/tests/command-query.t

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,30 @@ Run the query
167167
]
168168
}
169169
}
170+
}
171+
172+
Query a file
173+
$ ${TURBO} query "query { file(path: \"apps/my-app/package.json\") { path, contents } }"
174+
WARNING query command is experimental and may change in the future
175+
{
176+
"data": {
177+
"file": {
178+
"path": "apps/my-app/package.json",
179+
"contents": "{\n \"name\": \"my-app\",\n \"scripts\": {\n \"build\": \"echo building\",\n \"maybefails\": \"exit 4\"\n },\n \"dependencies\": {\n \"util\": \"*\"\n }\n}\n"
180+
}
181+
}
182+
}
183+
184+
Get the file's package
185+
$ ${TURBO} query "query { file(path: \"apps/my-app/package.json\") { path, package { ... on Package { name } } } }"
186+
WARNING query command is experimental and may change in the future
187+
{
188+
"data": {
189+
"file": {
190+
"path": "apps/my-app/package.json",
191+
"package": {
192+
"name": "my-app"
193+
}
194+
}
195+
}
170196
}

turborepo-tests/integration/tests/turbo-trace.t

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,55 @@ Setup
1111
}
1212
}
1313
14-
$ ${TURBO} query "query { file(path: \"main.ts\") { path, dependencies { path } } }"
14+
$ ${TURBO} query "query { file(path: \"main.ts\") { path, fileDependencies { items { path } } } }"
1515
WARNING query command is experimental and may change in the future
1616
{
1717
"data": {
1818
"file": {
1919
"path": "main.ts",
20-
"dependencies": [
21-
{
22-
"path": "button.tsx"
23-
},
24-
{
25-
"path": "foo.js"
26-
},
27-
{
28-
"path": "node_modules(\/|\\\\)repeat-string(\/|\\\\)index.js" (re)
29-
}
30-
]
20+
"fileDependencies": {
21+
"items": [
22+
{
23+
"path": "button.tsx"
24+
},
25+
{
26+
"path": "foo.js"
27+
},
28+
{
29+
"path": "node_modules(\/|\\\\)repeat-string(\/|\\\\)index.js" (re)
30+
}
31+
]
32+
}
3133
}
3234
}
3335
}
3436
35-
$ ${TURBO} query "query { file(path: \"button.tsx\") { path, dependencies { path } } }"
37+
$ ${TURBO} query "query { file(path: \"button.tsx\") { path, fileDependencies { items { path } } } }"
3638
WARNING query command is experimental and may change in the future
3739
{
3840
"data": {
3941
"file": {
4042
"path": "button.tsx",
41-
"dependencies": []
43+
"fileDependencies": {
44+
"items": []
45+
}
4246
}
4347
}
4448
}
4549
46-
$ ${TURBO} query "query { file(path: \"circular.ts\") { path, dependencies { path } } }"
50+
$ ${TURBO} query "query { file(path: \"circular.ts\") { path, fileDependencies { items { path } } } }"
4751
WARNING query command is experimental and may change in the future
4852
{
4953
"data": {
5054
"file": {
5155
"path": "circular.ts",
52-
"dependencies": [
53-
{
54-
"path": "circular2.ts"
55-
}
56-
]
56+
"fileDependencies": {
57+
"items": [
58+
{
59+
"path": "circular2.ts"
60+
}
61+
]
62+
}
5763
}
5864
}
5965
}

0 commit comments

Comments
 (0)