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

Vetur config file RFC #2378

Merged
merged 13 commits into from
Dec 8, 2020
Merged

Vetur config file RFC #2378

merged 13 commits into from
Dec 8, 2020

Conversation

yoyo930021
Copy link
Member

Vetur configuration file.

Rendered

@victorgarciaesgi
Copy link

This is really great!

I have nothing to comment at the moment, everything seems ideal (I don't use monorepos thought so I can't debate on this)

@IlCallo
Copy link

IlCallo commented Oct 15, 2020

Put configuration to vue.config.js

I'd exclude this alternative, as there are other CLIs (Nuxt, Quasar, etc) which needs Vetur

Into "properties details > definition" you use monorepos property name instead of repos

Have you checked other frameworks config files for tasks similar to this? Angular/React/whatever? If yes, is it possible to have link to relevant resources/inspiration?

@yoyo930021
Copy link
Member Author

yoyo930021 commented Oct 15, 2020

Put configuration to vue.config.js

I'd exclude this alternative, as there are other CLIs (Nuxt, Quasar, etc) which needs Vetur

Into "properties details > definition" you use monorepos property name instead of repos

Have you checked other frameworks config files for tasks similar to this? Angular/React/whatever? If yes, is it possible to have link to relevant resources/inspiration?

Thanks.
I fixed wrong text in RFC.

My first inspiration came from svelte.config.js.
sveltejs/svelte#1101
https://github.com/sveltejs/language-tools/blob/3139ccd5b4306a914be4ba64b0c036fcd8888f78/packages/svelte-vscode/README.md#generic-setup
The Svelte VScode extension read this file.
But the Svelte VScode extension don't have the support of monorepo.

The React and Angular are all officially supported by TypeScript for monorepo support.
They are all based on TypeScript program tsconfig.json,
And they don't have their own unique files to deal with.
PS. TypeScript is direct support for jsx.

@yoyo930021
Copy link
Member Author

I extend repos[].globallyComponents in RFC.
More consideration for customizable component names.

@andrewisaburden
Copy link
Contributor

Grammar for globallyComponents is not correct; perhaps globalComponents or globallyRegisteredComponents?

@yoyo930021
Copy link
Member Author

Grammar for globallyComponents is not correct; perhaps globalComponents or globallyRegisteredComponents?

I rename to globalComponents.

@antfu
Copy link
Member

antfu commented Oct 24, 2020

globalComponents will help a lot to me! Really looking forward to this RFC get implemented! 👍


export interface VeturConfig {
settings?: { [key: string]: boolean | string | Enum },
repos?: Array<{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repos is more connected to git repositories, and I get it, it's coming from monorepos but I feel it's not conveying the purpose.

Suggestion: We can call it projects. (typescript has project references and that makes it some what similar)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe workspaces?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. projects is better.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the "workspaces" name or maybe workingDirectories (stolen from eslint extension 😜)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workspaces also sounds good as package managers have those.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workspaces word is also used for multi roots in VSCode.
It's a bit confusing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as it's clear what it meant, it's ok, so +1 for projects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably also allow a shorthand form, so

Array<string | {
    root: string,
    package?: string,
    tsconfig?: string,
    globalComponents?: Array<Glob | { name: string, path: string }
>

Where string value is root.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good idea.
I changed the RFC.

root: string,
package?: string,
tsconfig?: string,
globalComponents?: Array<Glob | { name: string, path: string }>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "extends" option to share configurations?

e.g.

module.export = {
  projects: [{
    extends: ["vuetify"],
    globalComponents: ["./src/components/**/*.vue"]
  }]
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what this setting means.
I think if we're going to share configurations, we can only use JS. Like require.

PS. When you use vuetify on package.json, we use component date to completion.
So you don't really need to define vuetify here!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to tsconfig but it doesn't makes sense in cjs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@znck I don't feel we need this. When you have:

  • vuetify listed in pointed package.json's dependencies
  • node_modules/vuetify/package.json has vetur key

Everything should work from there.

Unless you meant something else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to support opt-in for external global components. (user can register, only a few components)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@znck What's a use case for that? If I understand you correctly, do you mean for the case when you have 2 UI lib and only want auto-completion for one of them (or only a few components out of a full library)? I feel there isn't much downside to just registering a whole library.

Copy link
Member

@znck znck Oct 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly for type checking global components. If it's opt-in you can control what components are allowed globally.

Copy link
Member Author

@yoyo930021 yoyo930021 Nov 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to use cjs directly.

module.export = {
  projects: [{
    globalComponents: [
      ...require('vuetify').components,
      "./src/components/**/*.vue"
    ]
  }]
}

Copy link
Member Author

@yoyo930021 yoyo930021 Nov 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think there's no point in adding an external lib.
We don't know the details of external libs.
It may be difficult to get the correct TypeScript type when no correct tsconfig.json.

I would be inclined to expand the support for component data.
Let it have a type of marker.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the TS plugin, I am using this to infer component meta. (It has a different structure compared to vetur's spec but includes verbose static information).

rfcs/001-vetur-config-file.md Show resolved Hide resolved
Copy link
Member

@octref octref left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, except 2 small things:

  • repos -> projects
  • Allow projects to be an array of either the shortform (just a string pointing to root) or the longer form (root/package/tsconfig/globalComponents).

rfcs/001-vetur-config-file.md Show resolved Hide resolved

export interface VeturConfig {
settings?: { [key: string]: boolean | string | Enum },
repos?: Array<{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably also allow a shorthand form, so

Array<string | {
    root: string,
    package?: string,
    tsconfig?: string,
    globalComponents?: Array<Glob | { name: string, path: string }
>

Where string value is root.

root: string,
package?: string,
tsconfig?: string,
globalComponents?: Array<Glob | { name: string, path: string }>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@znck What's a use case for that? If I understand you correctly, do you mean for the case when you have 2 UI lib and only want auto-completion for one of them (or only a few components out of a full library)? I feel there isn't much downside to just registering a whole library.

Copy link
Member

@octref octref left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for addressing the feedback.

@znck
Copy link
Member

znck commented Nov 20, 2020

How would named component from external module work?

import { Foo } from 'foo'

app.component('MyFoo', Foo)

@yoyo930021
Copy link
Member Author

yoyo930021 commented Nov 20, 2020

How would named component from external module work?

important { Foo } from 'foo'

app.component('MyFoo', Foo)

This RFC don't solves this problem.
Vetur currently uses component data to do this.
In the long run, we need a type-based mechanism.
I think we can discuss a new RFC about this.

The main goal is to resolve the registration of global components in own project in this RFC.
Not designed for external libraries.

@znck
Copy link
Member

znck commented Nov 20, 2020

In the TS plugin, I am using the following data structure for the project config.

export interface ImportSource {
  moduleName: string
  exportName?: string
}

export interface ProjectConfig {
  root: string
  package?: string
  tsconfig?: string
  globalComponents: Array<string | Record<string, string | ImportSource>>
}

@znck
Copy link
Member

znck commented Nov 20, 2020

What is the purpose of tsconfig option?

@yoyo930021
Copy link
Member Author

In the TS plugin, I am using the following data structure for the project config.

export interface ImportSource {
  moduleName: string
  exportName?: string
}

export interface ProjectConfig {
  root: string
  package?: string
  tsconfig?: string
  globalComponents: Array<string | Record<string, string | ImportSource>>
}

I think we can keep it that way for now.
If vetur introduces such an approach, it will have to face the problem of historical component data.

@yoyo930021
Copy link
Member Author

yoyo930021 commented Nov 20, 2020

What is the purpose of tsconfig option?

The vetur will use this option to open the ts language service.

@znck
Copy link
Member

znck commented Nov 20, 2020

TS Plugin can only use globalComponents, everything else is inherited from the TypeScript project.

@yoyo930021
Copy link
Member Author

TS Plugin can only use globalComponents, everything else is inherited from the TypeScript project.

You may also want to refer to the package.
It can be used to know the Vue version of the project.
What external libraries are used?

@yoyo930021 yoyo930021 merged commit eb4f7f6 into master Dec 8, 2020
@lanseria
Copy link

lanseria commented Dec 9, 2020

Can you set the vetur version here, so that accidental upgrades don't cause problems?

@yoyo930021
Copy link
Member Author

Can you set the vetur version here, so that accidental upgrades don't cause problems?

It's practically impossible.
You only can use vetur.dev.vlsPath option to pin vls version.

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.

None yet

9 participants