Closed idahogurl closed 5 months ago
@idahogurl AFAIK, you can use await import()
directly in cjs, can't you? For legacy TypeScript, you can use this hack:
@idahogurl AFAIK, you can use
await import()
directly in cjs, can't you? For legacy TypeScript, you can use this hack:
@JounQin That would work if I was bundling prettier
since esbuild
would convert the ESM to CJS but it is an external dependency.
That doesn't matter with external and no need to bundle at all for regular commonjs, but I'm not so familiar with VSCode/vmscripts.
Regularly, await import('esm.mjs')
is just supported, so await import('prettier')
should just work.
If it doesn't work, then synckit
should be a good choice.
If you need any help, I can help to raise a new PR based on this one later for you.
Can you update the PR title accordingly?
I did some quick debugging and found out there is still a bottleneck with the worker having to load prettier-eslint
, which on my machine takes roughly 2-3 seconds.
Also the preload did nothing for me because, from a VSCode window reload with a document already opened, the extension is only activated when the formatter is run.
I think a solution would be to:
onStartupFinished
to the "activationEvents"
field in the package.json, to make sure the extension is ready after VSCode starts.formatText()
with some dummy document to force the engine to go through the code paths that a real document would go through, and load all the necessary things that way.@netux I think you can just raise a PR for your proposal.
@netux I think you can just raise a PR for your proposal.
Good idea! I have opened #202 🙂.
I think we are just ready to go! Congratulations!
I have opened #206 to address an issue on Windows.
What
Closes #171
Breaking Changes
prettier-eslint
must be installed locally by the userWhy
Prettier 3 added a dynamic
import()
in its .cjs file, making ESM support required. VS Code only supports CommonJS (CJS) however. According to this comment https://github.com/prettier/prettier-vscode/pull/2947#issuecomment-1575066828, VSCode extensions can useworker_threads
and a Worker can executeimport()
.Thus, this PR makes it so that instances of
prettier-eslint
are run on Worker ofworker_threads.