From 7bf02281910c032aaad5479d236d0e32c14d4d6f Mon Sep 17 00:00:00 2001 From: Nicholas Yang Date: Tue, 29 Oct 2024 14:44:41 -0400 Subject: [PATCH] feat(query): include css and json files in trace output (#9346) --- cli/turbo.json | 21 ++- crates/turbo-trace/src/tracer.rs | 7 +- ...n.tsx`_with_dependencies_(npm@10.5.0).snap | 9 +- ...id.ts`_with_dependencies_(npm@10.5.0).snap | 6 + ...e_get_`main.ts`_with_ast_(npm@10.5.0).snap | 114 +++++++-------- ...in.ts`_with_dependencies_(npm@10.5.0).snap | 6 + .../fixtures/turbo_trace/button.css | 0 .../fixtures/turbo_trace/button.json | 0 .../fixtures/turbo_trace/button.tsx | 3 + .../integration/fixtures/turbo_trace/main.ts | 2 +- .../integration/tests/turbo-trace.t | 135 ++++++++++-------- 11 files changed, 177 insertions(+), 126 deletions(-) create mode 100644 turborepo-tests/integration/fixtures/turbo_trace/button.css create mode 100644 turborepo-tests/integration/fixtures/turbo_trace/button.json diff --git a/cli/turbo.json b/cli/turbo.json index 40f72bb6de27c..084392ced1b61 100644 --- a/cli/turbo.json +++ b/cli/turbo.json @@ -1,14 +1,19 @@ { "$schema": "../docs/public/schema.json", - "extends": ["//"], + "extends": [ + "//" + ], "tasks": { // A task that is used for detecting if any turborepo Rust sources change "rust-src": { - "env": ["RUNNER_OS"], + "env": [ + "RUNNER_OS" + ], "inputs": [ "../version.txt", - "../crates/turborepo*/**/*.rs", // Rust crates - "../crates/turborepo*/Cargo.toml", + "../crates/**/*.rs", + // Rust crates + "../crates/*/Cargo.toml", "../Cargo.toml", "../Cargo.lock", "!../crates/**/target" @@ -21,8 +26,12 @@ "../target/release/turbo", "../target/release/turbo.exe" ], - "dependsOn": ["rust-src"], - "passThroughEnv": ["ProgramData"] + "dependsOn": [ + "rust-src" + ], + "passThroughEnv": [ + "ProgramData" + ] } } } diff --git a/crates/turbo-trace/src/tracer.rs b/crates/turbo-trace/src/tracer.rs index cd0521280cffe..24db1d2baa4d8 100644 --- a/crates/turbo-trace/src/tracer.rs +++ b/crates/turbo-trace/src/tracer.rs @@ -181,15 +181,16 @@ impl Tracer { ) { let file_resolver = Self::infer_resolver_with_ts_config(&file_path, resolver); - if matches!(file_path.extension(), Some("css") | Some("json")) { - return; - } if seen.contains_key(&file_path) { return; } let entry = seen.entry(file_path.clone()).or_default(); + if matches!(file_path.extension(), Some("css") | Some("json")) { + return; + } + let Some((imports, seen_file)) = Self::get_imports_from_file( &self.source_map, &mut self.errors, diff --git a/crates/turborepo/tests/snapshots/query__turbo_trace_get_`button.tsx`_with_dependencies_(npm@10.5.0).snap b/crates/turborepo/tests/snapshots/query__turbo_trace_get_`button.tsx`_with_dependencies_(npm@10.5.0).snap index 183e2c8e75dd7..570c87caee9d5 100644 --- a/crates/turborepo/tests/snapshots/query__turbo_trace_get_`button.tsx`_with_dependencies_(npm@10.5.0).snap +++ b/crates/turborepo/tests/snapshots/query__turbo_trace_get_`button.tsx`_with_dependencies_(npm@10.5.0).snap @@ -8,7 +8,14 @@ expression: query_output "path": "button.tsx", "dependencies": { "files": { - "items": [] + "items": [ + { + "path": "button.css" + }, + { + "path": "button.json" + } + ] } } } diff --git a/crates/turborepo/tests/snapshots/query__turbo_trace_get_`invalid.ts`_with_dependencies_(npm@10.5.0).snap b/crates/turborepo/tests/snapshots/query__turbo_trace_get_`invalid.ts`_with_dependencies_(npm@10.5.0).snap index 55436189c5f86..c67ae3145901c 100644 --- a/crates/turborepo/tests/snapshots/query__turbo_trace_get_`invalid.ts`_with_dependencies_(npm@10.5.0).snap +++ b/crates/turborepo/tests/snapshots/query__turbo_trace_get_`invalid.ts`_with_dependencies_(npm@10.5.0).snap @@ -9,6 +9,12 @@ expression: query_output "dependencies": { "files": { "items": [ + { + "path": "button.css" + }, + { + "path": "button.json" + }, { "path": "button.tsx" } diff --git a/crates/turborepo/tests/snapshots/query__turbo_trace_get_`main.ts`_with_ast_(npm@10.5.0).snap b/crates/turborepo/tests/snapshots/query__turbo_trace_get_`main.ts`_with_ast_(npm@10.5.0).snap index 863d9791335e2..886d8e1495543 100644 --- a/crates/turborepo/tests/snapshots/query__turbo_trace_get_`main.ts`_with_ast_(npm@10.5.0).snap +++ b/crates/turborepo/tests/snapshots/query__turbo_trace_get_`main.ts`_with_ast_(npm@10.5.0).snap @@ -10,14 +10,14 @@ expression: query_output "type": "Module", "span": { "start": 1, - "end": 169 + "end": 173 }, "body": [ { "type": "ImportDeclaration", "span": { "start": 1, - "end": 35 + "end": 39 }, "specifiers": [ { @@ -44,10 +44,10 @@ expression: query_output "type": "StringLiteral", "span": { "start": 24, - "end": 34 + "end": 38 }, - "value": "./button", - "raw": "\"./button\"" + "value": "./button.tsx", + "raw": "\"./button.tsx\"" }, "typeOnly": false, "with": null, @@ -56,21 +56,21 @@ expression: query_output { "type": "ImportDeclaration", "span": { - "start": 36, - "end": 60 + "start": 40, + "end": 64 }, "specifiers": [ { "type": "ImportDefaultSpecifier", "span": { - "start": 43, - "end": 46 + "start": 47, + "end": 50 }, "local": { "type": "Identifier", "span": { - "start": 43, - "end": 46 + "start": 47, + "end": 50 }, "ctxt": 0, "value": "foo", @@ -81,8 +81,8 @@ expression: query_output "source": { "type": "StringLiteral", "span": { - "start": 52, - "end": 59 + "start": 56, + "end": 63 }, "value": "./foo", "raw": "\"./foo\"" @@ -94,21 +94,21 @@ expression: query_output { "type": "ImportDeclaration", "span": { - "start": 61, - "end": 96 + "start": 65, + "end": 100 }, "specifiers": [ { "type": "ImportDefaultSpecifier", "span": { - "start": 68, - "end": 74 + "start": 72, + "end": 78 }, "local": { "type": "Identifier", "span": { - "start": 68, - "end": 74 + "start": 72, + "end": 78 }, "ctxt": 0, "value": "repeat", @@ -119,8 +119,8 @@ expression: query_output "source": { "type": "StringLiteral", "span": { - "start": 80, - "end": 95 + "start": 84, + "end": 99 }, "value": "repeat-string", "raw": "\"repeat-string\"" @@ -132,8 +132,8 @@ expression: query_output { "type": "VariableDeclaration", "span": { - "start": 98, - "end": 126 + "start": 102, + "end": 130 }, "ctxt": 0, "kind": "const", @@ -142,14 +142,14 @@ expression: query_output { "type": "VariableDeclarator", "span": { - "start": 104, - "end": 125 + "start": 108, + "end": 129 }, "id": { "type": "Identifier", "span": { - "start": 104, - "end": 110 + "start": 108, + "end": 114 }, "ctxt": 0, "value": "button", @@ -159,15 +159,15 @@ expression: query_output "init": { "type": "NewExpression", "span": { - "start": 113, - "end": 125 + "start": 117, + "end": 129 }, "ctxt": 0, "callee": { "type": "Identifier", "span": { - "start": 117, - "end": 123 + "start": 121, + "end": 127 }, "ctxt": 0, "value": "Button", @@ -183,27 +183,27 @@ expression: query_output { "type": "ExpressionStatement", "span": { - "start": 128, - "end": 144 + "start": 132, + "end": 148 }, "expression": { "type": "CallExpression", "span": { - "start": 128, - "end": 143 + "start": 132, + "end": 147 }, "ctxt": 0, "callee": { "type": "MemberExpression", "span": { - "start": 128, - "end": 141 + "start": 132, + "end": 145 }, "object": { "type": "Identifier", "span": { - "start": 128, - "end": 134 + "start": 132, + "end": 138 }, "ctxt": 0, "value": "button", @@ -212,8 +212,8 @@ expression: query_output "property": { "type": "Identifier", "span": { - "start": 135, - "end": 141 + "start": 139, + "end": 145 }, "value": "render" } @@ -225,21 +225,21 @@ expression: query_output { "type": "ExpressionStatement", "span": { - "start": 145, - "end": 162 + "start": 149, + "end": 166 }, "expression": { "type": "CallExpression", "span": { - "start": 145, - "end": 161 + "start": 149, + "end": 165 }, "ctxt": 0, "callee": { "type": "Identifier", "span": { - "start": 145, - "end": 151 + "start": 149, + "end": 155 }, "ctxt": 0, "value": "repeat", @@ -251,8 +251,8 @@ expression: query_output "expression": { "type": "StringLiteral", "span": { - "start": 152, - "end": 157 + "start": 156, + "end": 161 }, "value": "foo", "raw": "\"foo\"" @@ -263,8 +263,8 @@ expression: query_output "expression": { "type": "NumericLiteral", "span": { - "start": 159, - "end": 160 + "start": 163, + "end": 164 }, "value": 5.0, "raw": "5" @@ -277,21 +277,21 @@ expression: query_output { "type": "ExpressionStatement", "span": { - "start": 163, - "end": 169 + "start": 167, + "end": 173 }, "expression": { "type": "CallExpression", "span": { - "start": 163, - "end": 168 + "start": 167, + "end": 172 }, "ctxt": 0, "callee": { "type": "Identifier", "span": { - "start": 163, - "end": 166 + "start": 167, + "end": 170 }, "ctxt": 0, "value": "foo", diff --git a/crates/turborepo/tests/snapshots/query__turbo_trace_get_`main.ts`_with_dependencies_(npm@10.5.0).snap b/crates/turborepo/tests/snapshots/query__turbo_trace_get_`main.ts`_with_dependencies_(npm@10.5.0).snap index d4762d093daf4..60af6161734f8 100644 --- a/crates/turborepo/tests/snapshots/query__turbo_trace_get_`main.ts`_with_dependencies_(npm@10.5.0).snap +++ b/crates/turborepo/tests/snapshots/query__turbo_trace_get_`main.ts`_with_dependencies_(npm@10.5.0).snap @@ -12,6 +12,12 @@ expression: query_output { "path": "bar.js" }, + { + "path": "button.css" + }, + { + "path": "button.json" + }, { "path": "button.tsx" }, diff --git a/turborepo-tests/integration/fixtures/turbo_trace/button.css b/turborepo-tests/integration/fixtures/turbo_trace/button.css new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/turborepo-tests/integration/fixtures/turbo_trace/button.json b/turborepo-tests/integration/fixtures/turbo_trace/button.json new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/turborepo-tests/integration/fixtures/turbo_trace/button.tsx b/turborepo-tests/integration/fixtures/turbo_trace/button.tsx index 0d23cb038dfae..eee8cacf69ee9 100644 --- a/turborepo-tests/integration/fixtures/turbo_trace/button.tsx +++ b/turborepo-tests/integration/fixtures/turbo_trace/button.tsx @@ -1,3 +1,6 @@ +import "./button.css"; +import "./button.json"; + export const Button = ({ children }: { children: React.ReactNode }) => { return ; }; diff --git a/turborepo-tests/integration/fixtures/turbo_trace/main.ts b/turborepo-tests/integration/fixtures/turbo_trace/main.ts index 815521f02dd8d..eb3cb80424d76 100644 --- a/turborepo-tests/integration/fixtures/turbo_trace/main.ts +++ b/turborepo-tests/integration/fixtures/turbo_trace/main.ts @@ -1,4 +1,4 @@ -import { Button } from "./button"; +import { Button } from "./button.tsx"; import foo from "./foo"; import repeat from "repeat-string"; diff --git a/turborepo-tests/integration/tests/turbo-trace.t b/turborepo-tests/integration/tests/turbo-trace.t index 5896b4b6b3d2c..56a1f13dea51d 100644 --- a/turborepo-tests/integration/tests/turbo-trace.t +++ b/turborepo-tests/integration/tests/turbo-trace.t @@ -23,6 +23,12 @@ Setup { "path": "bar.js" }, + { + "path": "button.css" + }, + { + "path": "button.json" + }, { "path": "button.tsx" }, @@ -47,7 +53,14 @@ Setup "path": "button.tsx", "dependencies": { "files": { - "items": [] + "items": [ + { + "path": "button.css" + }, + { + "path": "button.json" + } + ] } } } @@ -83,6 +96,12 @@ Trace file with invalid import "dependencies": { "files": { "items": [ + { + "path": "button.css" + }, + { + "path": "button.json" + }, { "path": "button.tsx" } @@ -111,14 +130,14 @@ Get AST from file "type": "Module", "span": { "start": 1, - "end": 169 + "end": 173 }, "body": [ { "type": "ImportDeclaration", "span": { "start": 1, - "end": 35 + "end": 39 }, "specifiers": [ { @@ -145,10 +164,10 @@ Get AST from file "type": "StringLiteral", "span": { "start": 24, - "end": 34 + "end": 38 }, - "value": "./button", - "raw": "\"./button\"" + "value": "./button.tsx", + "raw": "\"./button.tsx\"" }, "typeOnly": false, "with": null, @@ -157,21 +176,21 @@ Get AST from file { "type": "ImportDeclaration", "span": { - "start": 36, - "end": 60 + "start": 40, + "end": 64 }, "specifiers": [ { "type": "ImportDefaultSpecifier", "span": { - "start": 43, - "end": 46 + "start": 47, + "end": 50 }, "local": { "type": "Identifier", "span": { - "start": 43, - "end": 46 + "start": 47, + "end": 50 }, "ctxt": 0, "value": "foo", @@ -182,8 +201,8 @@ Get AST from file "source": { "type": "StringLiteral", "span": { - "start": 52, - "end": 59 + "start": 56, + "end": 63 }, "value": "./foo", "raw": "\"./foo\"" @@ -195,21 +214,21 @@ Get AST from file { "type": "ImportDeclaration", "span": { - "start": 61, - "end": 96 + "start": 65, + "end": 100 }, "specifiers": [ { "type": "ImportDefaultSpecifier", "span": { - "start": 68, - "end": 74 + "start": 72, + "end": 78 }, "local": { "type": "Identifier", "span": { - "start": 68, - "end": 74 + "start": 72, + "end": 78 }, "ctxt": 0, "value": "repeat", @@ -220,8 +239,8 @@ Get AST from file "source": { "type": "StringLiteral", "span": { - "start": 80, - "end": 95 + "start": 84, + "end": 99 }, "value": "repeat-string", "raw": "\"repeat-string\"" @@ -233,8 +252,8 @@ Get AST from file { "type": "VariableDeclaration", "span": { - "start": 98, - "end": 126 + "start": 102, + "end": 130 }, "ctxt": 0, "kind": "const", @@ -243,14 +262,14 @@ Get AST from file { "type": "VariableDeclarator", "span": { - "start": 104, - "end": 125 + "start": 108, + "end": 129 }, "id": { "type": "Identifier", "span": { - "start": 104, - "end": 110 + "start": 108, + "end": 114 }, "ctxt": 0, "value": "button", @@ -260,15 +279,15 @@ Get AST from file "init": { "type": "NewExpression", "span": { - "start": 113, - "end": 125 + "start": 117, + "end": 129 }, "ctxt": 0, "callee": { "type": "Identifier", "span": { - "start": 117, - "end": 123 + "start": 121, + "end": 127 }, "ctxt": 0, "value": "Button", @@ -284,27 +303,27 @@ Get AST from file { "type": "ExpressionStatement", "span": { - "start": 128, - "end": 144 + "start": 132, + "end": 148 }, "expression": { "type": "CallExpression", "span": { - "start": 128, - "end": 143 + "start": 132, + "end": 147 }, "ctxt": 0, "callee": { "type": "MemberExpression", "span": { - "start": 128, - "end": 141 + "start": 132, + "end": 145 }, "object": { "type": "Identifier", "span": { - "start": 128, - "end": 134 + "start": 132, + "end": 138 }, "ctxt": 0, "value": "button", @@ -313,8 +332,8 @@ Get AST from file "property": { "type": "Identifier", "span": { - "start": 135, - "end": 141 + "start": 139, + "end": 145 }, "value": "render" } @@ -326,21 +345,21 @@ Get AST from file { "type": "ExpressionStatement", "span": { - "start": 145, - "end": 162 + "start": 149, + "end": 166 }, "expression": { "type": "CallExpression", "span": { - "start": 145, - "end": 161 + "start": 149, + "end": 165 }, "ctxt": 0, "callee": { "type": "Identifier", "span": { - "start": 145, - "end": 151 + "start": 149, + "end": 155 }, "ctxt": 0, "value": "repeat", @@ -352,8 +371,8 @@ Get AST from file "expression": { "type": "StringLiteral", "span": { - "start": 152, - "end": 157 + "start": 156, + "end": 161 }, "value": "foo", "raw": "\"foo\"" @@ -364,8 +383,8 @@ Get AST from file "expression": { "type": "NumericLiteral", "span": { - "start": 159, - "end": 160 + "start": 163, + "end": 164 }, "value": 5.0, "raw": "5" @@ -378,21 +397,21 @@ Get AST from file { "type": "ExpressionStatement", "span": { - "start": 163, - "end": 169 + "start": 167, + "end": 173 }, "expression": { "type": "CallExpression", "span": { - "start": 163, - "end": 168 + "start": 167, + "end": 172 }, "ctxt": 0, "callee": { "type": "Identifier", "span": { - "start": 163, - "end": 166 + "start": 167, + "end": 170 }, "ctxt": 0, "value": "foo",