@@ -17,33 +17,6 @@ export type PropertyMetaSchema = string
17
17
| { kind : 'event' , type : string , schema : PropertyMetaSchema [ ] ; }
18
18
| { kind : 'object' , type : string , schema : Record < string , PropertyMeta > ; } ;
19
19
20
- /**
21
- * Helper array to map internal properties added by vue to any components
22
- *
23
- * @example
24
- * ```ts
25
- * import { createComponentMetaChecker, ComponentInternalProperties } from 'vue-component-meta'
26
- *
27
- * const checker = createComponentMetaChecker('path/to/tsconfig.json')
28
- * const meta = checker.getComponentMeta('path/to/component.vue')
29
- * const props = meta.props.filter(prop => !ComponentInternalProperties.includes(prop.name))
30
- * ```
31
- */
32
- export const ComponentInternalProperties = [
33
- 'ref' ,
34
- 'key' ,
35
- 'ref_for' ,
36
- 'ref_key' ,
37
- 'onVnodeBeforeMount' ,
38
- 'onVnodeMounted' ,
39
- 'onVnodeBeforeUpdate' ,
40
- 'onVnodeBeforeUnmount' ,
41
- 'onVnodeUpdated' ,
42
- 'onVnodeUnmounted' ,
43
- 'class' ,
44
- 'style' ,
45
- ] ;
46
-
47
20
function createSchemaResolvers ( typeChecker : ts . TypeChecker , symbolNode : ts . Expression ) {
48
21
function reducer ( acc : any , cur : any ) {
49
22
acc [ cur . name ] = cur ;
@@ -128,6 +101,7 @@ export function createComponentMetaChecker(tsconfigPath: string) {
128
101
readFile : ts . sys . readFile ,
129
102
} , tsconfigPath ) ;
130
103
const scriptSnapshot : Record < string , ts . IScriptSnapshot > = { } ;
104
+ const globalComponentName = tsconfigPath . replace ( / \\ / g, '/' ) + '.global.ts' ;
131
105
const core = vue . createLanguageContext ( {
132
106
...ts . sys ,
133
107
getDefaultLibFileName : ( options ) => ts . getDefaultLibFilePath ( options ) , // should use ts.getDefaultLibFilePath not ts.getDefaultLibFileName
@@ -137,13 +111,27 @@ export function createComponentMetaChecker(tsconfigPath: string) {
137
111
return [
138
112
...parsedCommandLine . fileNames ,
139
113
...parsedCommandLine . fileNames . map ( getMetaFileName ) ,
114
+ globalComponentName ,
115
+ getMetaFileName ( globalComponentName ) ,
140
116
] ;
141
117
} ,
142
118
getProjectReferences : ( ) => parsedCommandLine . projectReferences ,
143
119
getScriptVersion : ( fileName ) => '0' ,
144
120
getScriptSnapshot : ( fileName ) => {
145
121
if ( ! scriptSnapshot [ fileName ] ) {
146
- const fileText = fileName . endsWith ( '.meta.ts' ) ? getMetaScriptContent ( fileName ) : ts . sys . readFile ( fileName ) ;
122
+ let fileText : string | undefined ;
123
+ if ( fileName . endsWith ( '.meta.ts' ) ) {
124
+ fileText = getMetaScriptContent ( fileName ) ;
125
+ }
126
+ else if ( fileName === globalComponentName ) {
127
+ fileText = `
128
+ import { defineComponent } from 'vue';
129
+ export default defineComponent({});
130
+ ` ;
131
+ }
132
+ else {
133
+ fileText = ts . sys . readFile ( fileName ) ;
134
+ }
147
135
if ( fileText !== undefined ) {
148
136
scriptSnapshot [ fileName ] = ts . ScriptSnapshot . fromString ( fileText ) ;
149
137
}
@@ -158,10 +146,29 @@ export function createComponentMetaChecker(tsconfigPath: string) {
158
146
const typeChecker = program . getTypeChecker ( ) ;
159
147
160
148
return {
149
+ getGlobalPropNames,
161
150
getExportNames,
162
151
getComponentMeta,
163
152
} ;
164
153
154
+ /**
155
+ * Get helper array to map internal properties added by vue to any components
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * import { createComponentMetaChecker } from 'vue-component-meta'
160
+ *
161
+ * const checker = createComponentMetaChecker('path/to/tsconfig.json')
162
+ * const meta = checker.getComponentMeta('path/to/component.vue')
163
+ * const globalPropNames = checker.getGlobalPropNames();
164
+ * const props = meta.props.filter(prop => !globalPropNames.includes(prop.name))
165
+ * ```
166
+ */
167
+ function getGlobalPropNames ( ) {
168
+ const meta = getComponentMeta ( globalComponentName ) ;
169
+ return meta . props . map ( prop => prop . name ) ;
170
+ }
171
+
165
172
function getMetaFileName ( fileName : string ) {
166
173
return ( fileName . endsWith ( '.vue' ) ? fileName : fileName . substring ( 0 , fileName . lastIndexOf ( '.' ) ) ) + '.meta.ts' ;
167
174
}
0 commit comments