Skip to content

Commit

Permalink
feat(query): include css and json files in trace output (#9346)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang authored Oct 29, 2024
1 parent 10f294b commit 7bf0228
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 126 deletions.
21 changes: 15 additions & 6 deletions cli/turbo.json
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -21,8 +26,12 @@
"../target/release/turbo",
"../target/release/turbo.exe"
],
"dependsOn": ["rust-src"],
"passThroughEnv": ["ProgramData"]
"dependsOn": [
"rust-src"
],
"passThroughEnv": [
"ProgramData"
]
}
}
}
7 changes: 4 additions & 3 deletions crates/turbo-trace/src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ expression: query_output
"path": "button.tsx",
"dependencies": {
"files": {
"items": []
"items": [
{
"path": "button.css"
},
{
"path": "button.json"
}
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ expression: query_output
"dependencies": {
"files": {
"items": [
{
"path": "button.css"
},
{
"path": "button.json"
},
{
"path": "button.tsx"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand All @@ -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,
Expand All @@ -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",
Expand All @@ -81,8 +81,8 @@ expression: query_output
"source": {
"type": "StringLiteral",
"span": {
"start": 52,
"end": 59
"start": 56,
"end": 63
},
"value": "./foo",
"raw": "\"./foo\""
Expand All @@ -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",
Expand All @@ -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\""
Expand All @@ -132,8 +132,8 @@ expression: query_output
{
"type": "VariableDeclaration",
"span": {
"start": 98,
"end": 126
"start": 102,
"end": 130
},
"ctxt": 0,
"kind": "const",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -212,8 +212,8 @@ expression: query_output
"property": {
"type": "Identifier",
"span": {
"start": 135,
"end": 141
"start": 139,
"end": 145
},
"value": "render"
}
Expand All @@ -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",
Expand All @@ -251,8 +251,8 @@ expression: query_output
"expression": {
"type": "StringLiteral",
"span": {
"start": 152,
"end": 157
"start": 156,
"end": 161
},
"value": "foo",
"raw": "\"foo\""
Expand All @@ -263,8 +263,8 @@ expression: query_output
"expression": {
"type": "NumericLiteral",
"span": {
"start": 159,
"end": 160
"start": 163,
"end": 164
},
"value": 5.0,
"raw": "5"
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ expression: query_output
{
"path": "bar.js"
},
{
"path": "button.css"
},
{
"path": "button.json"
},
{
"path": "button.tsx"
},
Expand Down
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions turborepo-tests/integration/fixtures/turbo_trace/button.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import "./button.css";
import "./button.json";

export const Button = ({ children }: { children: React.ReactNode }) => {
return <button>{children}</button>;
};
2 changes: 1 addition & 1 deletion turborepo-tests/integration/fixtures/turbo_trace/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button } from "./button";
import { Button } from "./button.tsx";
import foo from "./foo";
import repeat from "repeat-string";

Expand Down
Loading

0 comments on commit 7bf0228

Please sign in to comment.