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

feat: allow prettier to use custom node #3061

Closed
wants to merge 2 commits into from

Conversation

izaakschroeder
Copy link

@izaakschroeder izaakschroeder commented Jul 3, 2023

Adds a prettier.runtime configuration option that, when used, invokes a version of PrettierWorkerInstance that uses fork instead of worker threads.

Maybe fixes: #3017
Fixes: #2857

TODO:

  • Run tests – I have a few tests left to fix (not entirely sure why… since the new codepath should only ever be enabled when prettier.runtime is set…), but I'm happy for early feedback if this is something the maintainers are willing to consider before moving ahead.
  • Update the CHANGELOG.md with a summary of your changes
@auto-assign auto-assign bot requested a review from ntotten July 3, 2023 22:09
import { ChildProcess, fork, ForkOptions } from "child_process";
import { EventEmitter } from "events";

export class ChildProcessWorker {
Copy link
Author

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.

@@ -34,12 +39,19 @@ export const PrettierWorkerInstance: PrettierInstanceConstructor = class Prettie
}
> = new Map();

private worker;
Copy link
Author

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) => {
Copy link
Author

@izaakschroeder izaakschroeder Jul 3, 2023

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
err.stack
);
await worker.terminate();
this.createWorker();
Copy link
Author

Choose a reason for hiding this comment

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

TODO: Consider throttling this.

@github-actions
Copy link

github-actions bot commented Sep 4, 2023

This pull request has been labeled as stale due to inactivity. Reply to keep this pull request open.

@github-actions github-actions bot added the Stale label Sep 4, 2023
@github-actions github-actions bot closed this Sep 11, 2023
@@ -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",
Copy link

@dmaskasky dmaskasky Mar 12, 2024

Choose a reason for hiding this comment

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

待办事项 翻译我

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 participants