skovy / typed-scss-modules

🎁 Generate type definitions (.d.ts) for CSS Modules using SCSS
https://skovy.dev/generating-typescript-definitions-for-css-modules-using-sass/
MIT License
636 stars 67 forks source link

fix: resolve Prettier config based on generated file #225

Closed gmathieu closed 7 months ago

gmathieu commented 7 months ago

Why

Resolves #219.

Recent versions of Prettier have changed the logic for resolving the config. This line appears to be the culprit:

const directory = file ? path.dirname(path.resolve(file)) : undefined;

When attemptPrettier is called, it passes process.cwd() as the "file" in the snippet above. It's common for typed-scss-modules to be executed from the project root, so the config search starts outside the project root and doesn't find anything.

What?

attemptPrettier resolves the prettier config based on the generated file path instead of process.cwd().

skovy commented 7 months ago

@gmathieu is this backwards compatible with previous versions of Prettier? wondering if this could break for people if they upgrade to this version and are not on the latest Prettier version

github-actions[bot] commented 7 months ago

:tada: This PR is included in version 8.0.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

gmathieu commented 7 months ago

@skovy it should be backwards compatible. As I understand it, Prettier was always meant to resolve its config based on a given file. Thanks for the quick turnaround!