vuejs / create-vue

🛠️ The recommended way to start a Vite-powered Vue project
Other
3.71k stars 423 forks source link

Feat project references #549

Open unshame opened 1 month ago

unshame commented 1 month ago

Description

Fixes duplicate typechecking and error reporting when running type-check with vitest or cypress component tests enabled. This should also speed up typechecking.

Adds usage of project references to vitest and cypress component test tsconfigs. Adds declaration emit to the tsconfig.app.json. Only includes test files in unit testing tsconfigs.

Fixes https://github.com/vuejs/create-vue/issues/437

Running pnpm run type-check in typescript-vitest after:

image image

Running pnpm run type-check in typescript-vitest before (2 duplicate errors):

image

Note: due to the fact that typescript stops checking if a project reference has errors, the errors in test files appear only after errors in the app are fixed (when running vue-tsc, it doesn't affect how IDEs display errors). There's an upcoming typescript feature that will fix this, but I don't think it's a big deal even without the fix. Definitely better than having errors reported twice.

Thanks to @codethief for the idea.

E2E tests

I didn't touch tsconfigs for e2e tests. They most likely can be setup the same way as unit tests, I don't see why they need to be in a separate folder. There are more changes that need to be made to achieve this though, that should be done in a separate PR.

The nightwatch config is the weirdest case - there is just a copy of tsconfig.app.json in it that overwrites the original one. I tried to set it up to work the same way as cypress-ct does, but looks like the vue plugin doesn't have any types, so it was giving me errors. I deleted that instead of copying the new content of tsconfig.app.json into it.

cexbrayat commented 1 month ago

Let's hear from @sodatea what he thinks about this setup

codethief commented 1 month ago

Thanks so much for picking this up, @unshame ! :)

codethief commented 1 month ago

@unshame Since our conversation in https://github.com/vuejs/create-vue/issues/437, I have run into https://github.com/vuejs/language-tools/issues/3526 with increasing frequency. Right now it blocks me from introducing project references in the frontend project at my day job. I'd therefore be hesitant to merge this PR before the upstream issue gets fixed. :\

unshame commented 1 month ago

Interesting.

I do see the error in vscode: image

Webstorm on the other hand has no issues with it and it's using the same version of vue language server. image image

I also don't have issues with vue-tsc, it reports the errors correctly and doesn't infer the type of the component as any: image

So looks like a vscode extension bug?

codethief commented 1 month ago

@unshame Interesting. My coworker has been reporting issues at least in IntelliJ, though. Would you mind re-posting your comment in https://github.com/vuejs/language-tools/issues/3526 together with the exact versions of vue-tsc, VSCode extension, WebStorm, WebStorm Vue extension etc.?

messenjer commented 1 month ago

They just released a new version of volar and vue-tsc (2.4.0) : https://github.com/volarjs/volar.js/releases/tag/v2.4.0

codethief commented 1 month ago

@messenjer vue-tsc is still at 2.0.29, see https://www.npmjs.com/package/vue-tsc . I don't know which Volar version vue-tsc 2.0.29 uses¹ but it was released ~a month ago. (¹ There are no release notes and no git tag for 2.0.29 on https://github.com/vuejs/language-tools yet.)

Meanwhile, @vuejs/language-tools master updated to Volar 2.4.0 only 2 days ago. So we'll have to wait for a new vue-tsc version that uses Volar 2.4.0.

In any case, let's please continue this discussion in https://github.com/vuejs/language-tools/issues/3526.

codethief commented 1 week ago

Since my last comments a lot has happened: One ticket has been closed, another (new) ticket is still open. Personally, I decided the remaining issue is no longer a blocker, since it only affects IDE support in minor ways and type checking is not affected. So in our project I went ahead and implemented project references throughout and until now I haven't received any major complaints from my coworkers.

For create-vue the considerations might be different, though, I don't know.