这是indexloc提供的服务,不要输入任何密码
Skip to content

feat(turbo.json): allow for trailing commas #10537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/turborepo-lib/src/turbo_json/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ impl RawTurboJson {
pub fn parse(text: &str, file_path: &str) -> Result<RawTurboJson, Error> {
let result = deserialize_from_json_str::<RawTurboJson>(
text,
JsonParserOptions::default().with_allow_comments(),
JsonParserOptions::default()
.with_allow_comments()
.with_allow_trailing_commas(),
file_path,
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://turborepo.com/schema.json",,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For whatever reason, double , with trailing commas really creates a wild output that isn't useful when snapshot. The error could be better, but ITG as the first error still highlights the double ,,

turbo_json_parse_error                                                                                                                                                        
                                                                                                                                                                              
  × Failed to parse turbo.json.                                                                                                                                               
  ├─▶   × expected `}` but instead found `,`                                                                                                                                  
  │      ╭─[turbo.json:2:50]                                                                                                                                                  
  │    1 │ {                                                                                                                                                                  
  │    2 │   "$schema": "https://turborepo.com/schema.json",,                                                                                                                 
  │      ·                                                  ─                                                                                                                 
  │    3 │   "ui": "tui",                                                                                                                                                     
  │      ╰────                                                                                                                                                                
  ├─▶   × End of file expected                                                                                                                                                
  │      ╭─[turbo.json:3:3]                                                                                                                                                   
  │    2 │   "$schema": "https://turborepo.com/schema.json",,                                                                                                                 
  │    3 │   "ui": "tui",                                                                                                                                                     
  │      ·   ────                                                                                                                                                             
  │    4 │   "tasks": {                                                                                                                                                       
  │      ╰────                                                                                                                                                                
  ├─▶   × End of file expected                                                                                                                                                
  │      ╭─[turbo.json:3:7]
  │    2 │   "$schema": "https://turborepo.com/schema.json",,
  │    3 │   "ui": "tui",
  │      ·       ─
  │    4 │   "tasks": {
  │      ╰────
  ├─▶   × End of file expected
  │      ╭─[turbo.json:3:9]
  │    2 │   "$schema": "https://turborepo.com/schema.json",,
  │    3 │   "ui": "tui",
  │      ·         ─────
  │    4 │   "tasks": {
  │      ╰────
  ├─▶   × End of file expected
  │      ╭─[turbo.json:3:14]
  │    2 │   "$schema": "https://turborepo.com/schema.json",,
  │    3 │   "ui": "tui",
  │      ·              ─
  │    4 │   "tasks": {
  │      ╰────
  ├─▶   × End of file expected
  │      ╭─[turbo.json:4:3]
  │    3 │   "ui": "tui",
  │    4 │   "tasks": {
  │      ·   ───────
  │    5 │     "build": {
  │      ╰────
  ├─▶   × End of file expected
  │      ╭─[turbo.json:4:10]
  │    3 │   "ui": "tui",
  │    4 │   "tasks": {
  │      ·          ─
  │    5 │     "build": {
  │      ╰────
  ├─▶   × End of file expected
  │       ╭─[turbo.json:4:12]
  │     3 │       "ui": "tui",
  │     4 │ ╭─▶   "tasks": {
  │     5 │ │       "build": {
  │     6 │ │         "dependsOn": ["^build"],
  │     7 │ │         "inputs": ["$TURBO_DEFAULT$", ".env*"],
  │     8 │ │         "outputs": [".next/**", "!.next/cache/**"],
  │     9 │ │       },
  │    10 │ │       "lint": {
  │    11 │ │         "dependsOn": ["^lint"]
  │    12 │ │       },
  │    13 │ │       "check-types": {
  │    14 │ │         "dependsOn": ["^check-types"]
  │    15 │ │       },
  │    16 │ │       "dev": {
  │    17 │ │         "cache": false,
  │    18 │ │         "persistent": true
  │    19 │ │       }
  │    20 │ ╰─▶   }
  │    21 │     }
  │       ╰────
  ├─▶   × End of file expected
  │       ╭─[turbo.json:21:1]
  │    20 │   }
  │    21 │ }
  │       · ─
  │       ╰────
  ╰─▶   × turbo.json has an incorrect type, expected an object, but received an array.

"$schema": "https://turborepo.com/schema.json",
"globalDependencies": ["foo.txt"],
"globalEnv": ["SOME_ENV_VAR"],
"tasks": {
Expand Down
7 changes: 0 additions & 7 deletions turborepo-tests/integration/tests/bad-turbo-json.t
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@ Run build with syntax errors in turbo.json
turbo_json_parse_error

x Failed to parse turbo.json.
|-> x Expected a property but instead found ','.
| ,-[turbo.json:2:50]
| 1 | {
| 2 | "$schema": "https://turborepo.com/schema.json",,
| : ^
| 3 | "globalDependencies": ["foo.txt"],
| `----
|-> x expected `,` but instead found `42`
| ,-[turbo.json:12:46]
| 11 | "my-app#build": {
Expand Down
Loading