vue-component-meta 1.3.13 → 1.3.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/out/index.d.ts CHANGED
@@ -25,7 +25,7 @@ export declare function createComponentMetaChecker(tsconfigPath: string, checker
25
25
  tsLs: ts.LanguageService;
26
26
  };
27
27
  };
28
- export declare function baseCreate(_host: vue.VueLanguageServiceHost, checkerOptions: MetaCheckerOptions, globalComponentName: string, ts: typeof import('typescript/lib/tsserverlibrary')): {
28
+ export declare function baseCreate(_host: vue.VueLanguageServiceHost, checkerOptions: MetaCheckerOptions, globalComponentName: string, ts: typeof import('typescript/lib/tsserverlibrary'), embeddedTypes: boolean): {
29
29
  getExportNames: (componentPath: string) => string[];
30
30
  getComponentMeta: (componentPath: string, exportName?: string) => ComponentMeta;
31
31
  __internal__: {
package/out/index.js CHANGED
@@ -63,7 +63,7 @@ function createComponentMetaCheckerWorker(loadParsedCommandLine, checkerOptions,
63
63
  getVueCompilationSettings: () => parsedCommandLine.vueOptions,
64
64
  };
65
65
  return {
66
- ...baseCreate(_host, checkerOptions, globalComponentName, ts),
66
+ ...baseCreate(_host, checkerOptions, globalComponentName, ts, false),
67
67
  updateFile(fileName, text) {
68
68
  fileName = fileName.replace(/\\/g, '/');
69
69
  scriptSnapshots.set(fileName, ts.ScriptSnapshot.fromString(text));
@@ -87,7 +87,7 @@ function createComponentMetaCheckerWorker(loadParsedCommandLine, checkerOptions,
87
87
  },
88
88
  };
89
89
  }
90
- function baseCreate(_host, checkerOptions, globalComponentName, ts) {
90
+ function baseCreate(_host, checkerOptions, globalComponentName, ts, embeddedTypes) {
91
91
  const globalComponentSnapshot = ts.ScriptSnapshot.fromString('<script setup lang="ts"></script>');
92
92
  const metaSnapshots = {};
93
93
  const host = new Proxy({
@@ -103,7 +103,7 @@ function baseCreate(_host, checkerOptions, globalComponentName, ts) {
103
103
  getScriptSnapshot: fileName => {
104
104
  if (isMetaFileName(fileName)) {
105
105
  if (!metaSnapshots[fileName]) {
106
- metaSnapshots[fileName] = ts.ScriptSnapshot.fromString(getMetaScriptContent(fileName));
106
+ metaSnapshots[fileName] = ts.ScriptSnapshot.fromString(getMetaScriptContent(fileName, embeddedTypes));
107
107
  }
108
108
  return metaSnapshots[fileName];
109
109
  }
@@ -159,18 +159,50 @@ function baseCreate(_host, checkerOptions, globalComponentName, ts) {
159
159
  function getMetaFileName(fileName) {
160
160
  return (fileName.endsWith('.vue') ? fileName : fileName.substring(0, fileName.lastIndexOf('.'))) + '.meta.ts';
161
161
  }
162
- function getMetaScriptContent(fileName) {
163
- return `
162
+ function getMetaScriptContent(fileName, embeddedTypes) {
163
+ const importCode = embeddedTypes ? '' : `import('vue-component-type-helpers').`;
164
+ let code = `
164
165
  import * as Components from '${fileName.substring(0, fileName.length - '.meta.ts'.length)}';
165
166
  export default {} as { [K in keyof typeof Components]: ComponentMeta<typeof Components[K]>; };
166
167
 
167
168
  interface ComponentMeta<T> {
168
- props: import('vue-component-type-helpers').ComponentProps<T>;
169
- emit: import('vue-component-type-helpers').ComponentEmit<T>;
170
- slots: import('vue-component-type-helpers').${vueCompilerOptions.target < 3 ? 'Vue2ComponentSlots' : 'ComponentSlots'}<T>;
171
- exposed: import('vue-component-type-helpers').ComponentExposed<T>;
172
- };
173
- `.trim();
169
+ props: ${importCode}ComponentProps<T>;
170
+ emit: ${importCode}ComponentEmit<T>;
171
+ slots: ${importCode}${vueCompilerOptions.target < 3 ? 'Vue2ComponentSlots' : 'ComponentSlots'}<T>;
172
+ exposed: ${importCode}ComponentExposed<T>;
173
+ };`.trim();
174
+ if (embeddedTypes) {
175
+ code += `
176
+ type ComponentProps<T> =
177
+ T extends (props: infer P, ...args: any) => any ? P :
178
+ T extends new () => { $props: infer P } ? NonNullable<P> :
179
+ {};
180
+
181
+ type ComponentSlots<T> =
182
+ T extends (props: any, ctx: { slots: infer S }, ...args: any) => any ? NonNullable<S> :
183
+ T extends new () => { $slots: infer S } ? NonNullable<S> :
184
+ {};
185
+
186
+ type ComponentEmit<T> =
187
+ T extends (props: any, ctx: { emit: infer E }, ...args: any) => any ? NonNullable<E> :
188
+ T extends new () => { $emit: infer E } ? NonNullable<E> :
189
+ {};
190
+
191
+ type ComponentExposed<T> =
192
+ T extends (props: any, ctx: { expose(exposed: infer E): any }, ...args: any) => any ? NonNullable<E> :
193
+ T extends new () => infer E ? E :
194
+ {};
195
+
196
+ /**
197
+ * Vue 2.x
198
+ */
199
+
200
+ type Vue2ComponentSlots<T> =
201
+ T extends (props: any, ctx: { slots: infer S }, ...args: any) => any ? NonNullable<S> :
202
+ T extends new () => { $scopedSlots: infer S } ? NonNullable<S> :
203
+ {};`;
204
+ }
205
+ return code;
174
206
  }
175
207
  function getExportNames(componentPath) {
176
208
  const program = tsLs.getProgram();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-component-meta",
3
- "version": "1.3.13",
3
+ "version": "1.3.15",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,13 +13,13 @@
13
13
  "directory": "packages/vue-component-meta"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "1.4.0-alpha.7",
17
- "@volar/vue-language-core": "1.3.13",
16
+ "@volar/language-core": "1.4.0-alpha.8",
17
+ "@volar/vue-language-core": "1.3.15",
18
18
  "typesafe-path": "^0.2.2"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "typescript": "*",
22
22
  "vue-component-type-helpers": "1.3.12"
23
23
  },
24
- "gitHead": "f1f2e7de96e46599a2c84c801f43ecf91d08d4b7"
24
+ "gitHead": "90ce6c89a12bf04b0d36b00add11b9b2af7eb618"
25
25
  }