Summary
cypress-codegen silently falls back to Prettier defaults (double quotes, etc.) even when a valid Prettier config (.prettierrc.json, prettier.config.mjs, …) exists at the project root. Generated files therefore overwrite project-formatted code on every Cypress run.
Root cause
dist/index.js (and dist/cli.js):
const prettierConfig = await resolveConfig(process.cwd()) ?? {};
Prettier 3's resolveConfig(filePath) expects a file path, not a directory. Given a directory, it returns null, so prettierConfig is always {}.
Minimal repro with the bundled prettier@3.3.2, in a repo containing a .prettierrc.json at root:
import { resolveConfig } from 'prettier';
await resolveConfig(process.cwd()); // → null ❌
await resolveConfig(`${process.cwd()}/package.json`); // → { printWidth: 120, singleQuote: true } ✅
Impact
Any project using cypress-codegen + Prettier 3 with a config file at the repo root: every cypress run reformats the regenerated files (cypress/commands/index.ts, the supportFile, custom-command type files) to Prettier defaults, producing noisy diffs that fight the project's actual style.
Suggested fix
Pass a real file path. Any always-present file works:
- const prettierConfig = await resolveConfig(process.cwd()) ?? {};
+ const prettierConfig = await resolveConfig(path.join(process.cwd(), 'package.json')) ?? {};
Both call sites (dist/index.js and dist/cli.js) have the same line. Reproduced on cypress-codegen@2.4.4 and @2.5.3.
Versions
- cypress-codegen: 2.5.3 (also 2.4.4)
- prettier (bundled): 3.3.2
- node: 18+
Summary
cypress-codegensilently falls back to Prettier defaults (double quotes, etc.) even when a valid Prettier config (.prettierrc.json,prettier.config.mjs, …) exists at the project root. Generated files therefore overwrite project-formatted code on every Cypress run.Root cause
dist/index.js(anddist/cli.js):Prettier 3's
resolveConfig(filePath)expects a file path, not a directory. Given a directory, it returnsnull, soprettierConfigis always{}.Minimal repro with the bundled
prettier@3.3.2, in a repo containing a.prettierrc.jsonat root:Impact
Any project using
cypress-codegen+ Prettier 3 with a config file at the repo root: everycypress runreformats the regenerated files (cypress/commands/index.ts, the supportFile, custom-command type files) to Prettier defaults, producing noisy diffs that fight the project's actual style.Suggested fix
Pass a real file path. Any always-present file works:
Both call sites (
dist/index.jsanddist/cli.js) have the same line. Reproduced oncypress-codegen@2.4.4and@2.5.3.Versions