-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
This won't work if the async result isn't serializable by Structured Clone Algorithm #4
Comments
That's limitation, maybe we should mention that. |
This blocks Jest from using the package as well - we have a custom parser: https://github.com/jestjs/jest/blob/e9125e3f4676fb6a7e926042b39f1dfd5c51ec4b/packages/jest-snapshot/src/InlineSnapshots.ts#L332-L400 |
I believe this can be done with custom worker without depending on What means doing all heavy jobs in the worker, and only return the result from it to bypass the limitations. |
Can this extract to a separate file and pass location as prettier plugin? |
Prettier plugins can be specified using a path, but this puts a limitation on end users. I suggest to add a function like this: /**
* Format content with the Prettier context for the file path.
*
* If the file is ignored by Prettier, the content is returned as-is.
*
* @param {string} filepath
* The file path to resolve the configuration for.
* @param {string} content
* The content to format.
* @param {import('prettier').Options} [options]
* Additional Prettier options to apply.
* @returns {string}
* The formatted content, or the content as-is if it’s ignored by Prettier.
*/
async function formatWithContext(filepath, content, options) {
const fileInfo = await getFileInfo(filepath)
if (fileInfo.ignored) {
return content
}
if (!fileInfo.inferredParser) {
return content
}
const config = await resolveConfig(filepath, { editorconfig: true })
return format(content, { ...config, ...options, filepath })
} This means there is no need to send the Prettier options between workers. I imagine this would even be useful to add to Prettier itself, as I think it’s a common use case to format files like that. |
Structured Clone Algorithm
For example,
plugins
inresolveConfig
.The text was updated successfully, but these errors were encountered: