Skip to content

Prettier config at repo root is never picked up (resolveConfig given a directory, returns null) #478

@franck-mahieu

Description

@franck-mahieu

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+

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions