Gathering detailed insights and metrics for @dumijs/vue-meta
Gathering detailed insights and metrics for @dumijs/vue-meta
Gathering detailed insights and metrics for @dumijs/vue-meta
Gathering detailed insights and metrics for @dumijs/vue-meta
npm install @dumijs/vue-meta
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
5
1
5
Extracting the metadata of Vue components more effectively.
This project is heavily inspired by vue-component-meta, and reuses a significant amount of its code.
1pnpm i @dumijs/vue-meta
@dumijs/vue-meta
uses TypeScript's TypeChecker for metadata extraction.
[!NOTE] When configuring tsconfig.json, set strictNullCheck to false
1{ 2 "compilerOptions": { 3 "strictNullChecks": false 4 } 5}
1import { createProject } from '@dumijs/vue-meta'; 2import * as path from 'path'; 3 4const projectRoot = '<project-root>'; 5const project = createProject({ 6 rootPath: projectRoot, 7 // If tsconfigPath is not set, tsconfig will be <rootPath>/tsconfig.json 8 tsconfigPath: path.resolve(projectRoot, './tsconfig.json'); 9}); 10 11const entry = path.resolve(projectRoot, './src/index.ts'); 12 13const meta = project.service.getComponentLibraryMeta(entry); 14 15meta.components['Button']; 16 17// Reusable types, queried and referenced through `ref` 18// (`ref` is the md5 value calculated from the name of the file where the type is located and its type name.) 19meta.types;
After updating the file locally, use patchFiles
to update the file in memory, and TypeChecker will recheck.
1project.patchFiles([ 2 { 3 action: 'add', 4 fileName: '...', 5 text: '...', 6 }, 7 { 8 update: 'add', 9 fileName: '....', 10 text: '....', 11 }, 12]); 13 14// Then you can get the new type metadata 15const meta = project.service.getComponentLibraryMeta(entry);
Create a meta checker for Vue project with rootPath
If no parameters are passed in, tsconfig.json in the current workspace will be read.
1export declare function createProject(rootPath?: string): Project;
1import { createProject } from '@dumijs/vue-meta'; 2createProject();
rootPath
string Project
Create a meta checker for Vue project by options
1export declare function createProject(options: CheckerProjectOptions): Project;
1import { createProject } from '@dumijs/vue-meta';
2// Manually pass in the tsconfig.json path
3createProject({
4 // If neither rootPath nor tsconfigPath is set, rootPath will be process.cwd()
5 rootPath: '<project-root>',
6 // If tsconfigPath is not set, tsconfig will be <rootPath>/tsconfig.json
7 tsconfigPath: '<project-root>/tsconfig.json',
8 checkerOptions: {},
9});
options
CheckerProjectOptionsProject
Create component metadata checker through json configuration
1export declare function createProjectByJson( 2 options: CheckerProjectJsonOptions, 3): Project;
options
CheckerProjectJsonOptionsProject
Checker Options
1export interface MetaCheckerOptions extends MetaCheckerSchemaOptions
Extends: MetaCheckerSchemaOptions
disableGit
boolean
Prohibit obtaining git repo URL, git revision, and other information through git commands, the default is false
disableSources
boolean
Disable production of source links, the default is false
filterExposed
boolean
Whether to enable filtering for exposed attributes, the default is true.
If true, only methods or properties identified by release tags like @public
will be exposed in jsx
filterGlobalProps
boolean
Whether to filter global props, the default is true
If it is true, global props in vue, such as key and ref, will be filtered out
forceUseTs
boolean
gitRemote
string
Default is "origin"
gitRevision
string
printer
ts.PrinterOptions
sourceLinkTemplate
string
source link template, must be set when you set disableGit
.
A typical template looks like this: https://github.com/umijs/dumi/{gitRevision}/{path}#L{line}
.
The parser will replace the parts {gitRevision|path|line}
Schema resolver options
1export interface MetaCheckerSchemaOptions
disableExternalLinkAutoDectect
boolean
By default, this option is false, the resolver will automatically capture the MDN links contained in the comments of all declaration files under node_modules/typescript/lib. Users do not need to configure externalSymbolLinkMappings themselves.
Of course, you can also overwrite the captured links through externalSymbolLinkMappings
exclude
string | RegExp | (string | RegExp)[] | ((name: string) => boolean)
By default, type resolution in node_module will be abandoned.
externalSymbolLinkMappings
Record<string, Record<string, string>>
The types/interfaces mapping method is provided as follows:
1{ 2 typescript: { 3 Promise: 4 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise', 5 }, 6},
For more complex mapping methods, please use unknownSymbolResolvers
ignore
(string | ((name: string, type: ts.Type, typeChecker: ts.TypeChecker) => boolean | void | undefined | null))[]
A list of type names to be ignored in expending in schema. Can be functions to ignore types dynamically.
ignoreTypeArgs
boolean
In addition to ignoring the type itself, whether to ignore the type parameters it carries. By default, the type parameters it carries will be parsed. For example, Promise<{ a: string }>
, if you use optionexclude
or ignore
to ignore Promise
, { a: string }
will still be parsed by default.
propertyResovlers
PropertySchemaResolver<PropertyMeta>[]
Property schema resolvers for some special props definition methods, such as vue-types
unknownSymbolResolvers
UnknownSymbolResolver[]
unknownSymbol resolver
property schema resolver
1export type PropertySchemaResolver<T extends ComponentItemMeta> = ( 2 originMeta: Partial<T>, 3 options: { 4 ts: typeof import('typescript/lib/tsserverlibrary'); 5 typeChecker: ts.TypeChecker; 6 schemaOptions: MetaCheckerSchemaOptions; 7 symbolNode: ts.Expression; 8 prop: ts.Symbol; 9 targetNode?: ts.Declaration; 10 targetType?: ts.Type; 11 }, 12) => Partial<T>;
References: ComponentItemMeta, MetaCheckerSchemaOptions
1export type UnknownSymbolResolver< 2 T extends PropertyMetaSchema = PropertyMetaSchema, 3> = (options: { 4 ts: typeof import('typescript/lib/tsserverlibrary'); 5 typeChecker: ts.TypeChecker; 6 targetSymbol: ts.Symbol; 7 schemaOptions: MetaCheckerSchemaOptions; 8 targetNode: ts.Declaration; 9}) => Partial<T>;
References: PropertyMetaSchema, MetaCheckerSchemaOptions
Provide component metadata checker services
1export declare class TypeCheckService
Constructs a new instance of the TypeCheckService
class
Constructs a new instance of the TypeCheckService
class
Close the Type checker service
Get component metadata through the entry file, this method will automatically filter vue components
Get metadata of single component If the component to be obtained is not a vue component, an error will be thrown
Get the export
only get value export
[!NOTE] It is recommended to define events in props so that you can get complete JSDoc support
Description of the property.
When the prop option default
uses as function, default
will be ignored. In this case, you can use @default
to override it.
1defineComponent({ 2 props: { 3 /** 4 * @default {} 5 */ 6 foo: { 7 default() { 8 return {}; 9 }, 10 }, 11 }, 12});
This is used to distinguish between ordinary functions and function components.
Currently, there are two situations that cannot be automatically recognized as components:
1/** 2 * @component 3 */ 4function InternalComponent(props: { a: string }) { 5 return h('div', props.a); 6}
1/** 2 * @component 3 */ 4export const GenericComponent = defineComponent( 5 <T>(props: { item: T }) => { 6 return () => (<div>{item}</div>); 7 }, 8);
It needs to be annotated with @component, otherwise it will be recognized as a function
[!NOTE] These release tags cannot take effect in defineEmits
For methods on the component instance itself, use release tags like @public
to expose
1defineExpose({ 2 /** 3 * @public 4 */ 5 focus() {}, 6});
If you set filterExposed
in MetaCheckerOptions to false, those release tags will become invalid.
The component instance of vue will not only expose the properties and methods exposed through
expose
, but also expose the props passed in from the outside.
Properties marked with @ignore
or @internal
will not be checked.
No vulnerabilities found.
No security vulnerabilities found.