t3-oss / create-t3-turbo

Clean and simple starter repo using the T3 Stack along with Expo React Native
https://turbo.t3.gg
MIT License
4.27k stars 350 forks source link

bug: turbo gen failed with extra new line in package.json.hbs file #1052

Closed ImPrankster closed 3 weeks ago

ImPrankster commented 1 month ago

Provide environment information

turbo gen init failed with error Error - Bad control character in string literal in JSON at position 221. Unable to modify to "" Error - Aborted due to previous action failure. Unable to function to ""

It was caused by prettier formats

{
  "name": "@acme/{{ name }}",
  "private": true,
  "version": "0.1.0",
  "type": "module",
  "exports": {
    ".": "./src/index.ts"
  },
  "license": "MIT",
  "scripts": {
    "clean": "rm -rf .turbo node_modules",
    "format": "prettier --check . --ignore-path ../../.gitignore",
    "lint": "eslint",
    "typecheck": "tsc --noEmit"
  },
  "devDependencies": {
    "@acme/eslint-config": "workspace:*",
    "@acme/prettier-config": "workspace:*",
    "@acme/tsconfig": "workspace:*",
    "eslint": "^9.0.0",
    "prettier": "^3.2.5",
    "typescript": "^5.4.3"
  },
  "prettier": "@acme/prettier-config"
}

To

{ "name": "@acme/{{name}}", "private": true, "version": "0.1.0", "type":
"module", "exports": { ".": "./src/index.ts" }, "license": "MIT", "scripts": {
"clean": "rm -rf .turbo node_modules", "format": "prettier --check .
--ignore-path ../../.gitignore", "lint": "eslint", "typecheck": "tsc --noEmit"
}, "devDependencies": { "@acme/eslint-config": "workspace:*",
"@acme/prettier-config": "workspace:*", "@acme/tsconfig": "workspace:*",
"eslint": "^9.0.0", "prettier": "^3.2.5", "typescript": "^5.4.3" }, "prettier":
"@acme/prettier-config" }

The extra new line after prettier --check . caused the problem. I was able to fix it by adding a .prettierignore file and add *.hbs to prevent formatting. I am using vscode prettier plugin on the newest version.

Describe the bug

turbo gen init failed with error Error - Bad control character in string literal in JSON at position 221. Unable to modify to "" Error - Aborted due to previous action failure. Unable to function to ""

Link to reproduction

https://github.com/ImPrankster/henry-test/blob/main/turbo/generators/templates/package.json.hbs

To reproduce

Create a new repo and edit .hbs file to cause a prettier format.

Additional information

No response

aidankinzett commented 3 weeks ago

I ran into the same issue and had to create a .prettierignore to be able to work on the templates, I can open a PR which adds this in

juliusmarminge commented 3 weeks ago

Yea this sucks - I've always just save without formatting when updating this file but it's not the best.

aidankinzett commented 3 weeks ago

I may have come up with a better solution. Since the template files are valid JS and JSON we can tell prettier to treat them as JS or JSON, this way we get full prettier support in the files. I expect this would break if you had more complex handlebar syntax but should work fine for simple templates.

ImPrankster commented 3 weeks ago

I may have come up with a better solution. Since the template files are valid JS and JSON we can tell prettier to treat them as JS or JSON, this way we get full prettier support in the files. I expect this would break if you had more complex handlebar syntax but should work fine for simple templates.

I think prettier supports HBS by default now it's just the behavior is not correct so maybe it's a bug on prettier's side