Skip to content

Allow npm-Based Formatters to Pin Transitive Dependencies by Populating overrides in package.json #2534

Open

Description

@jGleitz

When using an npm package to format code, and that npm package has a range dependency onto another library, the formatting output can change silently. This just happened to us: we use prettier-plugin-sql, which has a ^-dependency on sql-formatter. sql-formatter released a new version that changed the formatting output, and our project’s build broke because the checked-in SQL files didn’t match the expected format.

Proposal: add the configuration method dependencyOverrides to PrettierFormatterStep. This method accepts a Map<String, String> to populate the overrides field in the generated package.json. This mechanism could work exactly like the one populating the devDependencies.

Activity

  1. simschla commented on Jul 7, 2025

    @simschla
    Contributor

    Seems like a reasonable proposal. I'd suggest to add the dependencyOverrides to all npm-based formatters and keep it in sync with devDependencies configuration.

    Will do this as soon as I find time - or, feel free to create a PR yourself if I'm taking to long ❤️

  2. Pankraz76 commented on Nov 8, 2026

    @Pankraz76

    @jGleitz @simschla I opened #3178 for this, following the proposal here and @simschla's suggestion: dependencyOverrides is available on all npm-based formatters (prettier, ESLint, tsfmt), for both Gradle and Maven, and configured just like devDependencies. The entries go into the overrides field of the generated package.json.

    Your prettier-plugin-sql case is covered by an end-to-end test:

    prettier(['prettier': '3.3.3', 'prettier-plugin-sql': '0.20.0'])
      .config(['plugins': ['prettier-plugin-sql'], 'parser': 'sql'])
      .dependencyOverrides(['sql-formatter': '15.7.0'])
    <dependencyOverrides>
      <sql-formatter>15.7.0</sql-formatter>
    </dependencyOverrides>

    Without the override, npm currently resolves sql-formatter 15.9.0; with it, exactly 15.7.0 is installed. If no overrides are configured, the generated package.json stays byte-identical to before, so existing setups don't reinstall anything.

    Feedback very welcome:

    1. @jGleitz: does this cover your build?
    2. @simschla: Maven can't express scoped packages (@scope/pkg) as XML element names, same as <devDependencies>. Should I add a dependencyOverrideProperties counterpart to devDependencyProperties in this PR, or as a follow-up?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions