A thin library that enables ts-morph (TypeScript compiler API wrapper) to understand Vue single-file components (.vue files). Current version 0.1.0 wraps ts-morph ^24.0.0. Unlike Volar or Vetur, which implement custom LanguageServiceHosts, vue-ts-morph works at the FileSystemHost level—creating virtual .vue.ts files that shadow real .vue files. This makes it the only option for using ts-morph's AST manipulation API (e.g., refactoring, code generation) directly on Vue SFCs without a full language server. Released as experimental (no stable release cadence). Not recommended for production; major limitations: no <template> support, no simultaneous <script setup> + <script> blocks.
npm install vue-ts-morphVerified import paths — ran on the pinned version, not inferred.
Shows how to create a ts-morph Project that can read .vue files, add source files from tsconfig, then access the virtual .vue.ts file to query TypeScript AST.
Do not rely on template AST. Use a Vue compiler (e.g., @vue/compiler-sfc) separately if template analysis is needed.
Use only <script setup> or a single <script> block. Merge or split into separate files if both are needed.
Always re-create the file system host (or project) after external modifications to .vue files.
Consider using Volar's language service API if you need production-grade Vue TypeScript support.
Use the provided createVueFileSystemHost() factory function instead of custom implementations.
Run: npm install ts-morph@^24.0.0
Retrieve the virtual file: const vueFile = project.getSourceFileOrThrow('src/App.vue.ts');