Skip to content

Conversation

@itsyoboieltr
Copy link
Contributor

@itsyoboieltr itsyoboieltr commented Nov 7, 2024

Description

This PR adds prettier.config.ts support, addressing: #16119

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

@itsyoboieltr
Copy link
Contributor Author

I tested that making a prettier.config.ts, and then importing it like import('./prettier.config.ts') works directly using --experimental-strip-types. But I only tested it as a standalone script - I am unsure how to test it with prettier. I modified the functions, but I do not really know how to test it, or how to add this flag if a ts file is detected? or the users should add the flag themselves before running prettier? If the flag --experimental-strip-types is present, the current loadJs function will simply work with typescript files too.

@fisker
Copy link
Member

fisker commented Nov 11, 2024

Add flag here should be able to test

execArgv: ["--trace-deprecation"],

@itsyoboieltr
Copy link
Contributor Author

Reverted the unnecessary changes and added the flag, let me know if there is anything else to do

@itsyoboieltr itsyoboieltr requested a review from fisker November 11, 2024 15:32
execArgv: [
"--trace-deprecation",
"--disable-warning=ExperimentalWarning",
"--experimental-strip-types",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work in Node < 22.6 where this flag was introduced? We should make sure we don’t get any warnings in all supported Node versions and if the flag is not available, there should be a meaningful error about why prettier.config.ts could not load. Docs need to reflect min version for TS config too, unless we want to change the approach and use a built-in transpiler.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be passed via options and only set when testing ts configs.

@fisker fisker mentioned this pull request Nov 24, 2024
11 tasks
@sosukesuzuki sosukesuzuki added this to the 3.5 milestone Nov 24, 2024
@fisker fisker force-pushed the prettier-config-ts branch from 39369c1 to 8f10863 Compare December 4, 2024 02:11
@fisker fisker self-assigned this Dec 4, 2024
@fisker fisker force-pushed the prettier-config-ts branch from 8955900 to 1d8b411 Compare December 4, 2024 03:28
@fisker fisker changed the title feat: prettier.config.ts Add support for TS config files Dec 4, 2024
@fisker fisker requested a review from sosukesuzuki December 4, 2024 06:39
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 16, 2024

Open in Stackblitz

npm i https://pkg.pr.new/prettier@16828

commit: 7864e56

@sosukesuzuki sosukesuzuki merged commit 84de783 into prettier:main Dec 21, 2024
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants