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

refactor: write real files to FS for global types #4736

Merged
merged 4 commits into from
Aug 28, 2024
Merged

Conversation

johnsoncodehk
Copy link
Member

@johnsoncodehk johnsoncodehk commented Aug 28, 2024

Fixes #4717

Background information

  • Global types that can be shared by all files should be generated in a single file. Compared with generating these types for each file, sharing global types will greatly speed up type checking.
  • The implementation until 2.0.28 is to place the global type in the virtual code of the first valid root Vue file. This is the best method so far, but there are some limitations:
    1. Possible conflict in Monorepo: Global types are repeatedly defined in monorepo #4717
    2. When the file holding the global type is deleted, the types of all other Vue files will be damaged, and the language server must be restarted.

Current solution

  • TS plugin (Hybrid Mode), vue-tsc: Global types will be written to node_modules/vue/__globalTypes_${vueCompilerOptions.target}_${vueCompilerOptions.strictTemplates}.d.ts.
  • Language server, vue-component-meta: The real file is not written, but the __globalTypes_xxx.d.ts file is provided through the proxy languageServiceHost's fileExists and getScriptSnapshot API.

There is a chance that vue-tsc can be refactored to proxy the getSourceFile method without writing a real file, but the TS plugin currently must write a real file due to the limitations of tsserver.

Copy link

pkg-pr-new bot commented Aug 28, 2024

commit: 2eac87b

vue-component-meta

pnpm add https://pkg.pr.new/vuejs/language-tools/vue-component-meta@4736

vue-component-type-helpers

pnpm add https://pkg.pr.new/vuejs/language-tools/vue-component-type-helpers@4736

@vue/language-core

pnpm add https://pkg.pr.new/vuejs/language-tools/@vue/language-core@4736

@vue/language-plugin-pug

pnpm add https://pkg.pr.new/vuejs/language-tools/@vue/language-plugin-pug@4736

@vue/language-server

pnpm add https://pkg.pr.new/vuejs/language-tools/@vue/language-server@4736

@vue/language-service

pnpm add https://pkg.pr.new/vuejs/language-tools/@vue/language-service@4736

vue-tsc

pnpm add https://pkg.pr.new/vuejs/language-tools/vue-tsc@4736

@vue/typescript-plugin

pnpm add https://pkg.pr.new/vuejs/language-tools/@vue/typescript-plugin@4736

Open in Stackblitz

@johnsoncodehk johnsoncodehk merged commit 38c1e48 into master Aug 28, 2024
9 checks passed
@johnsoncodehk johnsoncodehk deleted the globalTypes branch August 28, 2024 23:09
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 this pull request may close these issues.

Global types are repeatedly defined in monorepo
1 participant