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

vue-component-meta: checker not working with tsconfig that uses references #3896

Open
larsrickert opened this issue Feb 18, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@larsrickert
Copy link

larsrickert commented Feb 18, 2024

When using vue-component-meta with a tsconfig.json that uses references (like the one that is provided by the official Vue starter), the checker will throw an error "Could not find main source file" and does not provide any meta.

Versions

node: 20.10.0
typescript: 5.3.3
vue-component-meta: 1.8.27
vue: 3.4.19
@vue/tsconfig: 0.5.1
@tsconfig/node20: 20.1.2

Reproduction

Vue component:

// src/TestComponent.vue
<script setup lang="ts">
defineProps<{
  /** Test property */
  test: string;
}>();
</script>

<template>Example component</template>

vue-component-meta Code:

// src/test.ts
import path from "node:path";
import { fileURLToPath } from "node:url";
import type { MetaCheckerOptions } from "vue-component-meta";
import { createComponentMetaChecker } from "vue-component-meta";

const __dirname = fileURLToPath(new URL(".", import.meta.url));

const checkerOptions: MetaCheckerOptions = {
  forceUseTs: true,
  noDeclarations: true,
  printer: { newLine: 1 },
};

const checker = createComponentMetaChecker(
  // if you change the file to "tsconfig.app.json" which does not use references, the checker works
  path.join(__dirname, "..", "tsconfig.json"),
  checkerOptions,
);

const componentPath = path.join(__dirname, "./TestComponent.vue");
const meta = checker.getComponentMeta(componentPath);
console.log(JSON.stringify(meta, null, 2));

tsconfig.json file

{
  "files": [],
  "references": [
    { "path": "./tsconfig.node.json" },
    { "path": "./tsconfig.app.json" }
  ]
}

tsconfig.app.json file:

{
  "extends": "@vue/tsconfig/tsconfig.dom.json",
  "include": ["env.d.ts", "src/**/*"],
  "compilerOptions": {
    "composite": true,
    "rootDir": "./src",
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

tsconfig.node.json file:

{
  "extends": "@tsconfig/node20/tsconfig.json",
  "include": ["vite.config.ts"],
  "compilerOptions": {
    "composite": true,
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "types": ["node"]
  }
}
@johnsoncodehk
Copy link
Member

johnsoncodehk commented Apr 8, 2024

This is the expected behavior, project references should not affect the files included in tsconfig. To check TestComponent.vue, you should select tsconfig.app.json to create the checker.

Perhaps what you need is a checker manager that automatically finds a valid tsconfig for a .vue file (considering project references). It is possible to port the relevant logic from the vue language server.

I don't want to give false hope, as this task requires a significant amount of work and I still have other pending tasks, so there is currently no schedule for implementation.

@johnsoncodehk johnsoncodehk added enhancement New feature or request and removed need transfer labels Apr 8, 2024
@chakAs3
Copy link
Contributor

chakAs3 commented Apr 8, 2024

Thank you, @johnsoncodehk, for your feedback. We've opted to specify the tsconfig.app.json path instead. I acknowledge that the proper approach is to pass a valid tsconfig. For now, in the workaround, we explicitly pass the tsconfig to use in the Storybook config file. Ideally, @larsrickert, we should create a lookup manager that automatically detects the first valid tsconfig in references. I'll take care of this part.

@johnsoncodehk
Copy link
Member

@chakAs3
Copy link
Contributor

chakAs3 commented Apr 9, 2024

👌

I was exploring this yesterday 😁 wondering if i'm in the right place ✌️ thanks for guidance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants