prettier-cli icon indicating copy to clipboard operation
prettier-cli copied to clipboard

test: migrate `infer-plugins-ext-dir` test cases

Open 43081j opened this issue 10 months ago • 16 comments

Pulls the infer-plugins-ext-dir tests from prettier.

43081j avatar Feb 03 '25 10:02 43081j

What's the blocker for this PR, interpreting *.foo as if it was **/*.foo?

fabiospampinato avatar Feb 23 '25 17:02 fabiospampinato

it should be good to merge and we can track the *.foo stuff separately

basically globs with no path are treated like **/{glob}. e.g. *.* is **/*.* in prettier. and *.js is **/*.js

43081j avatar Feb 23 '25 18:02 43081j

So in order to select files actually matching *.js one has to write ./*.js?

fabiospampinato avatar Feb 23 '25 20:02 fabiospampinato

I think treating *.js as **/*.foo idea comes from ESLint, but the link https://github.com/prettier/prettier/blob/de30788d30990b35534832ca554f5d5add2d4221/src/config/resolve-config.js#L105 is broken, so I'm not really sure.

fisker avatar Feb 23 '25 20:02 fisker

@fisker presumably it isn't worth changing this, right? 🤔 how it works currently just seems incorrect to me, if I'm understanding it right.

fabiospampinato avatar Feb 23 '25 20:02 fabiospampinato

@fisker random question, but if *.js is interpreted as **/*.js, how do we actually pick only the js files in the current directory? is ./*.js the answer?

fabiospampinato avatar Mar 06 '25 01:03 fabiospampinato

I don't understand "pick", are we talking about files in overrides?

fisker avatar Mar 06 '25 07:03 fisker

Basically I think a non relative wildcard would be assumed to mean ./.

So internally:

  • * becomes ./**/*
  • *.js becomes ./**/*.js
  • foo becomes ./**/foo
  • ./* is left as is
  • **/*.js is left as is (isn't a standalone single *)

That would be like prettier right now I think

43081j avatar Mar 06 '25 08:03 43081j

As I said, the files in override logic part is from ESLint, in previous ESLint config system(now it's called "Legacy config") it works the same.

Related code in Prettier core https://github.com/prettier/prettier/blob/0d10f1f846351274922cd205f1d4997206183151/src/config/resolve-config.js#L107

The comment in that file can also confirm the fact, though the link is broken now.

fisker avatar Apr 25 '25 14:04 fisker

If I run the tests just for this I don't see it ever exiting (after a few minutes at least):

NODE_OPTIONS=--experimental-vm-modules npx jest --rootDir test/__tests__ infer-plugins-ext-dir.js --testTimeout 60000

Does this work for you, @43081j?

fabiospampinato avatar May 13 '25 23:05 fabiospampinato

mentioned in discord too:

its because the worker exits successfully but worktank doesn't propagate this

that means we continue waiting for the worker even though it exited long ago

under the hood, webworker-shim does emit close events. so worktank should probably listen to those and pass them back to the caller

then inside the CLI, we can decide how to deal with it

43081j avatar May 14 '25 12:05 43081j

its because the worker exits successfully but worktank doesn't propagate this

It sounds potentially like a bug on my end, but why is the worker exiting in the first place? 🤔

fabiospampinato avatar May 14 '25 13:05 fabiospampinato

its because the worker exits successfully but worktank doesn't propagate this

It sounds potentially like a bug on my end, but why is the worker exiting in the first place? 🤔

because the plugin doesn't exist (which is what the test is testing I assume? I'll have to re-read them to be sure)

either way, its a valid case I think. plugin doesn't exist, so it exits with an error

43081j avatar May 14 '25 13:05 43081j

Is it exiting from inside prettier/standalone or on our end? In my mental model prettier/standalone would never just force-exit 🤔 But I guess we should handle that, I think I missed this edge case in worktank, I'll update it 👍

fabiospampinato avatar May 14 '25 13:05 fabiospampinato

it is our exit, not prettier's

when you call prettier (via prettier_parallel or serial), we call our own function to load the specified plugins

once we have those, we call prettier core.

but if the load failed, we exit

43081j avatar May 14 '25 14:05 43081j

Aaaaah yeah, ok I get it now, I'll fix this in worktank 👍

fabiospampinato avatar May 19 '25 12:05 fabiospampinato

I've just pushed a new version of worktank (v3) that handles workers exiting themselves, among other things. In this case it would throw custom WorkerError that we could check against.

BUT, on a second thought I think it may be cleaner to just not exit where we are exiting, and instead just throwing a custom error, and then checking against that error and exiting then, from the main thread.

fabiospampinato avatar Jun 01 '25 15:06 fabiospampinato