-
-
Notifications
You must be signed in to change notification settings - Fork 460
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
feat: allow prettier to use custom node
#3061
Conversation
import { ChildProcess, fork, ForkOptions } from "child_process"; | ||
import { EventEmitter } from "events"; | ||
|
||
export class ChildProcessWorker { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class mimics Worker
(with on("message", ...)
and postMessage(...)
) except it uses fork
and node's IPC instead.
src/PrettierWorkerInstance.ts
Outdated
@@ -34,12 +39,19 @@ export const PrettierWorkerInstance: PrettierInstanceConstructor = class Prettie | |||
} | |||
> = new Map(); | |||
|
|||
private worker; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any problem with having a non-global worker instance?
}; | ||
} | ||
|
||
module.exports = (parentPort) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is basically just a wrapped version of the existing message handlers that were already in the file, with a small DRY'd up normalizeResult
utility to avoid some existing code duplication.
Adds a `prettier.runtime` configuration option that, when used, invokes a version of `PrettierWorkerInstance` that uses `fork` instead of worker threads. Fixes: prettier#3017 Fixes: prettier#2857
d17fb41
to
a1b0d86
Compare
err.stack | ||
); | ||
await worker.terminate(); | ||
this.createWorker(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Consider throttling this.
This pull request has been labeled as stale due to inactivity. Reply to keep this pull request open. |
@@ -24,6 +24,7 @@ | |||
"ext.config.requireConfig": "排版需要 prettier 組態檔。參閱[可用的組態檔文件](https://prettier.io/docs/en/configuration.html).\n\n> _注意,無標題檔案仍會使用 VS Code 的 prettier 設定進行排版,不受這個設定值影響。_", | |||
"ext.config.requirePragma": "Prettier 可以限制它自己只對包含特殊註解的檔案進行排版,這個特殊的註解成為 pragma ,位於檔案的最頂部。這對於想要對那些大型、未經過排版的程式碼緩步採納 prettier 非常有幫助。", | |||
"ext.config.resolveGlobalModules": "這個套件會在區域的模組找不到 prettier 模組時嘗試使用去全域的 npm 或 yarn 模組中尋找。\n> _這個設定會導致效能的負面影響,特別在 Windows 中有掛載網路磁碟機。只有在你必須使用全域模組的情況下再啟用。_", | |||
"ext.config.runtime": "TODO TRANSLATE ME", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
待办事项 翻译我
Adds a
prettier.runtime
configuration option that, when used, invokes a version ofPrettierWorkerInstance
that usesfork
instead of worker threads.Maybe fixes: #3017
Fixes: #2857
TODO:
prettier.runtime
is set…), but I'm happy for early feedback if this is something the maintainers are willing to consider before moving ahead.CHANGELOG.md
with a summary of your changes