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

The --loader flag is ignored #174

Closed
arcanis opened this issue Jun 17, 2024 · 14 comments · Fixed by #175
Closed

The --loader flag is ignored #174

arcanis opened this issue Jun 17, 2024 · 14 comments · Fixed by #175

Comments

@arcanis
Copy link

arcanis commented Jun 17, 2024

When using PnP, SyncKit automatically adds the --loader flag. Unfortunately, this doesn't work in Node.js, the --loader flag is accidentally ignored for workers.

Instead, I suggest you try calling module.register from within the worker thread itself, as an implementation detail of the runAsWorker function.

@fmal
Copy link
Contributor

fmal commented Jun 19, 2024

@JounQin fixing this would solve the following issues:
microsoft/vscode-eslint#1856
yarnpkg/berry#6335

the community would be really greatful ❤️

@JounQin
Copy link
Member

JounQin commented Jun 19, 2024

Sorry I'm not familiar with these concepts and don't quite have enough time recently :(

If anyone can raise a PR that would be really appreciate.

fmal added a commit to fmal/synckit that referenced this issue Jun 20, 2024
@fmal
Copy link
Contributor

fmal commented Jun 20, 2024

@arcanis i tried to follow your suggestion and created a draft PR here https://github.com/un-ts/synckit/pull/175/files, but the prettier plugin still seems to fail in latest vscode with yarn pnp. Did I misunderstand something?

fmal added a commit to fmal/synckit that referenced this issue Jun 20, 2024
fmal added a commit to fmal/synckit that referenced this issue Jun 20, 2024
@hanyufoodles
Copy link

@arcanis i tried to follow your suggestion and created a draft PR here https://github.com/un-ts/synckit/pull/175/files, but the prettier plugin still seems to fail in latest vscode with yarn pnp. Did I misunderstand something?

Did you lint on typescript files? To my understanding what's been ignored is here:

synckit/src/index.ts

Lines 211 to 213 in 22387b4

if (!execArgv.includes('--loader')) {
execArgv = ['--loader', `${TsRunner.TsNode}/esm`, ...execArgv]
}

@fmal
Copy link
Contributor

fmal commented Jun 20, 2024

@hanyufoodles see yarnpkg/berry#6335 (comment) pls, from my understanding this https://github.com/prettier/eslint-plugin-prettier/blob/de9751c85d059678904035322501bfce120f61b7/worker.js#L36 import fails because of lack of pnp loader in the context of a worker.
I also tried linting regular .js files with my attempted patch but the issue persists :(
I'm not sure if TsRunner is relevant in this particular case, however since it's added through --loader arg it would probably need a similar workaround for node 20 :(

fmal added a commit to fmal/synckit that referenced this issue Jul 1, 2024
@fmal
Copy link
Contributor

fmal commented Jul 1, 2024

With latest vscode (1.90.2) and eslint-plugin-prettier and synckit packages unplugged it seems that runAsWorker is not executed because the early return in https://github.com/un-ts/synckit/blob/main/src/index.ts#L560 kicks in, so the problem must occur earlier when starting worker thread, but i'm not able to figure it out.

@imccausl
Copy link

imccausl commented Jul 2, 2024

With latest vscode (1.90.2) and eslint-plugin-prettier and synckit packages unplugged it seems that runAsWorker is not executed because the early return in https://github.com/un-ts/synckit/blob/main/src/index.ts#L560 kicks in, so the problem must occur earlier when starting worker thread, but i'm not able to figure it out.

FWIW, your PR is working for me. Latest vscode and eslint-plugin-prettier. I cloned your forked repo, and linked synckit and voila! Eslint is working again. I'm also using latest yarn and latest yarn sdks for eslint.

@fmal
Copy link
Contributor

fmal commented Jul 2, 2024

@imccausl interesting! and you're also using pnp mode i suppose? I actually used pretty naive approach of directly editing the unplugged package code to verify if this works. I'll retest that tomorrow by building the code from PR and "linking" to a local synckit package. Thanks for the hint <3

@imccausl
Copy link

imccausl commented Jul 2, 2024

@imccausl interesting! and you're also using pnp mode i suppose?

Yep. pnp mode 💯. I was also poking around at this issue and ended up basically with the same solution as you, so I was surprised to see it wasn't working for you.

@arcanis
Copy link
Author

arcanis commented Jul 3, 2024

I can also confirm it fixes the issues we had at work with ESLint in VSCode when using eslint-plugin-mdx (I manually patched our local synckit package using yarn patch).

Note that you probably have to update both the .cjs file (which is used by ESLint) and the .js file (which is used by the ESM worker).

@fmal
Copy link
Contributor

fmal commented Jul 4, 2024

@arcanis thanks a lot for the update! not updating both cjs and esm files in the unplugged package was exactly the reason it didn't work for me!

Setting

  "resolutions": {
    "synckit": "file:../synckit"
  }

with both files compiled makes it work for me too!

@fmal
Copy link
Contributor

fmal commented Jul 4, 2024

@JounQin now that we were able to confirm #175 solves the issue with pnp loader in node 20, would you be able to review it and hopefully merge and release? Thanks!

JounQin pushed a commit to fmal/synckit that referenced this issue Jul 14, 2024
JounQin pushed a commit to fmal/synckit that referenced this issue Jul 14, 2024
@JounQin
Copy link
Member

JounQin commented Jul 14, 2024

https://github.com/un-ts/synckit/releases/tag/v0.9.1 released

@fmal
Copy link
Contributor

fmal commented Jul 17, 2024

@JounQin thanks a lot ❤️

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 a pull request may close this issue.

5 participants