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 prettier error for unknown file types in writeIfChanged #421

Merged
merged 1 commit into from
Sep 1, 2023

Conversation

MoSattler
Copy link
Contributor

@MoSattler MoSattler commented Sep 1, 2023

Description:

This PR addresses an issue where running Prettier on created svg files throws an error. The issue is caused by Prettier not recognizing the .svg file format by default.

Steps to Reproduce:

  1. Create a new epic-stack project.
  2. Observe the error when the writeIfChanged function attempts to run Prettier on the sprite.svg file.
  3. With the changes in this PR, the error should no longer occur.

Changes:

  • Added the --ignore-unknown flag to the prettier --write command in the writeIfChanged function. This ensures that Prettier will gracefully ignore file types it does not recognize, rather than throwing an error.
async function writeIfChanged(filepath: string, newContent: string) {
	const currentContent = await fsExtra
		.readFile(filepath, 'utf8')
		.catch(() => '')
	if (currentContent === newContent) return false
	await fsExtra.writeFile(filepath, newContent, 'utf8')
-       await $`prettier --write ${filepath}`
+       await $`prettier --write ${filepath} --ignore-unknown`
	return true
}

Relevant Documentation:

Prettier's --ignore-unknown flag is used to ignore unknown files matched by patterns.

Fixes:

Thank you @sergio-codel-io for reporting the issue

@MoSattler MoSattler changed the title Fix Prettier Error for Unknown File Types in writeIfChanged fix prettier error for unknown file types in writeIfChanged Sep 1, 2023
Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Thanks!

@kentcdodds kentcdodds merged commit 4fd50cd into epicweb-dev:main Sep 1, 2023
5 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.

2 participants