Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): pass in parser to prettier format to avoid deprecation warning #662

Merged
merged 2 commits into from
Jan 10, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/cli/src/dirCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { promises as fs } from 'fs'
import * as path from 'path'
import { grey, white } from 'chalk'
import { loadConfig, Config } from '@svgr/core'
import { format, resolveConfig } from 'prettier'
import { format, resolveConfig, getFileInfo } from 'prettier'
import {
convertFile,
transformFilename,
Expand Down Expand Up @@ -100,7 +100,9 @@ export const dirCommand: SvgrCommand = async (
const prettierRcConfig = opts.runtimeConfig
? await resolveConfig(filepath, { editorconfig: true })
: {}
const prettierFileInfo = await getFileInfo(filepath)
Copy link
Owner

Choose a reason for hiding this comment

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

Need to be in a Promise.all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did some more digging in the prettier source code. getFileInfo ends up using resolveConfig again and inferring based on filepath. So to avoid extra work (and extra IO) it's better to just pass in file path as an option. Updated the code and verified by running the CLI.

return format(fileContent, {
parser: prettierFileInfo.inferredParser,
...prettierRcConfig,
...opts.prettierConfig,
})
Expand Down