vue-component-meta 0.40.0 → 0.40.3

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
@@ -1,6 +1,17 @@
1
+ import * as vue from '@volar/vue-language-core';
1
2
  import * as ts from 'typescript/lib/tsserverlibrary';
2
3
  import type { MetaCheckerOptions, ComponentMeta, EventMeta, ExposeMeta, MetaCheckerSchemaOptions, PropertyMeta, PropertyMetaSchema, SlotMeta } from './types';
3
4
  export type { MetaCheckerOptions, ComponentMeta, EventMeta, ExposeMeta, MetaCheckerSchemaOptions, PropertyMeta, PropertyMetaSchema, SlotMeta };
5
+ export declare type ComponentMetaChecker = ReturnType<typeof createComponentMetaCheckerBase>;
6
+ export declare function createComponentMetaCheckerByJsonConfig(root: string, json: any, checkerOptions?: MetaCheckerOptions): {
7
+ getExportNames: (componentPath: string) => string[];
8
+ getComponentMeta: (componentPath: string, exportName?: string) => ComponentMeta;
9
+ __internal__: {
10
+ program: ts.Program;
11
+ tsLs: ts.LanguageService;
12
+ typeChecker: ts.TypeChecker;
13
+ };
14
+ };
4
15
  export declare function createComponentMetaChecker(tsconfigPath: string, checkerOptions?: MetaCheckerOptions): {
5
16
  getExportNames: (componentPath: string) => string[];
6
17
  getComponentMeta: (componentPath: string, exportName?: string) => ComponentMeta;
@@ -10,3 +21,12 @@ export declare function createComponentMetaChecker(tsconfigPath: string, checker
10
21
  typeChecker: ts.TypeChecker;
11
22
  };
12
23
  };
24
+ declare function createComponentMetaCheckerBase(tsconfigPath: string, parsedCommandLine: vue.ParsedCommandLine, checkerOptions: MetaCheckerOptions): {
25
+ getExportNames: (componentPath: string) => string[];
26
+ getComponentMeta: (componentPath: string, exportName?: string) => ComponentMeta;
27
+ __internal__: {
28
+ program: ts.Program;
29
+ tsLs: ts.LanguageService;
30
+ typeChecker: ts.TypeChecker;
31
+ };
32
+ };
package/out/index.js CHANGED
@@ -1,19 +1,35 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.createComponentMetaChecker = void 0;
2
+ exports.createComponentMetaChecker = exports.createComponentMetaCheckerByJsonConfig = void 0;
3
3
  const vue = require("@volar/vue-language-core");
4
4
  const vue_language_core_1 = require("@volar/vue-language-core");
5
5
  const ts = require("typescript/lib/tsserverlibrary");
6
+ const parseConfigHost = {
7
+ useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
8
+ readDirectory: (path, extensions, exclude, include, depth) => {
9
+ return ts.sys.readDirectory(path, [...extensions, '.vue'], exclude, include, depth);
10
+ },
11
+ fileExists: ts.sys.fileExists,
12
+ readFile: ts.sys.readFile,
13
+ };
14
+ function createComponentMetaCheckerByJsonConfig(root, json, checkerOptions = {}) {
15
+ const parsedCommandLine = vue.createParsedCommandLineByJson(ts, parseConfigHost, root, json);
16
+ for (const error of parsedCommandLine.errors) {
17
+ console.error(error);
18
+ }
19
+ return createComponentMetaCheckerBase(root + '/jsconfig.json', parsedCommandLine, checkerOptions);
20
+ }
21
+ exports.createComponentMetaCheckerByJsonConfig = createComponentMetaCheckerByJsonConfig;
6
22
  function createComponentMetaChecker(tsconfigPath, checkerOptions = {}) {
7
- const parsedCommandLine = vue.createParsedCommandLine(ts, {
8
- useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
9
- readDirectory: (path, extensions, exclude, include, depth) => {
10
- return ts.sys.readDirectory(path, [...extensions, '.vue'], exclude, include, depth);
11
- },
12
- fileExists: ts.sys.fileExists,
13
- readFile: ts.sys.readFile,
14
- }, tsconfigPath);
23
+ const parsedCommandLine = vue.createParsedCommandLine(ts, parseConfigHost, tsconfigPath);
24
+ for (const error of parsedCommandLine.errors) {
25
+ console.error(error);
26
+ }
27
+ return createComponentMetaCheckerBase(tsconfigPath, parsedCommandLine, checkerOptions);
28
+ }
29
+ exports.createComponentMetaChecker = createComponentMetaChecker;
30
+ function createComponentMetaCheckerBase(tsconfigPath, parsedCommandLine, checkerOptions) {
15
31
  const scriptSnapshot = {};
16
- const globalComponentName = tsconfigPath.replace(/\\/g, '/') + '.global.ts';
32
+ const globalComponentName = tsconfigPath.replace(/\\/g, '/') + '.global.vue';
17
33
  const host = Object.assign(Object.assign({}, ts.sys), { getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options), useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames, getCompilationSettings: () => parsedCommandLine.options, getScriptFileNames: () => {
18
34
  return [
19
35
  ...parsedCommandLine.fileNames,
@@ -24,14 +40,11 @@ function createComponentMetaChecker(tsconfigPath, checkerOptions = {}) {
24
40
  }, getProjectReferences: () => parsedCommandLine.projectReferences, getScriptVersion: (fileName) => '0', getScriptSnapshot: (fileName) => {
25
41
  if (!scriptSnapshot[fileName]) {
26
42
  let fileText;
27
- if (fileName.endsWith('.meta.ts')) {
43
+ if (isMetaFileName(fileName)) {
28
44
  fileText = getMetaScriptContent(fileName);
29
45
  }
30
46
  else if (fileName === globalComponentName) {
31
- fileText = `
32
- import { defineComponent } from 'vue';
33
- export default defineComponent({});
34
- `;
47
+ fileText = `<script setup lang="ts"></script>`;
35
48
  }
36
49
  else {
37
50
  fileText = ts.sys.readFile(fileName);
@@ -76,6 +89,9 @@ function createComponentMetaChecker(tsconfigPath, checkerOptions = {}) {
76
89
  typeChecker,
77
90
  },
78
91
  };
92
+ function isMetaFileName(fileName) {
93
+ return fileName.endsWith('.meta.ts');
94
+ }
79
95
  function getMetaFileName(fileName) {
80
96
  return (fileName.endsWith('.vue') ? fileName : fileName.substring(0, fileName.lastIndexOf('.'))) + '.meta.ts';
81
97
  }
@@ -125,7 +141,7 @@ function createComponentMetaChecker(tsconfigPath, checkerOptions = {}) {
125
141
  const printer = checkerOptions.printer ? ts.createPrinter(checkerOptions.printer) : undefined;
126
142
  const snapshot = host.getScriptSnapshot(componentPath);
127
143
  const vueDefaults = componentPath.endsWith('.vue') && exportName === 'default'
128
- ? readVueComponentDefaultProps(core, snapshot.getText(0, snapshot.getLength()), printer)
144
+ ? readVueComponentDefaultProps(core, snapshot, printer)
129
145
  : {};
130
146
  const tsDefaults = !componentPath.endsWith('.vue') ? readTsComponentDefaultProps(componentPath.substring(componentPath.lastIndexOf('.') + 1), // ts | js | tsx | jsx
131
147
  snapshot.getText(0, snapshot.getLength()), exportName, printer) : {};
@@ -211,7 +227,6 @@ function createComponentMetaChecker(tsconfigPath, checkerOptions = {}) {
211
227
  };
212
228
  }
213
229
  }
214
- exports.createComponentMetaChecker = createComponentMetaChecker;
215
230
  function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: options }) {
216
231
  var _a;
217
232
  const enabled = !!options;
@@ -346,14 +361,14 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
346
361
  resolveSchema,
347
362
  };
348
363
  }
349
- function readVueComponentDefaultProps(core, vueFileText, printer) {
364
+ function readVueComponentDefaultProps(core, vueFileScript, printer) {
350
365
  let result = {};
351
366
  scriptSetupWorker();
352
367
  scriptWorker();
353
368
  return result;
354
369
  function scriptSetupWorker() {
355
370
  var _a;
356
- const vueSourceFile = vue.createSourceFile('/tmp.vue', vueFileText, {}, ts, core.plugins);
371
+ const vueSourceFile = vue.createSourceFile('/tmp.vue', vueFileScript, {}, ts, core.plugins);
357
372
  const descriptor = vueSourceFile.sfc;
358
373
  const scriptSetupRanges = descriptor.scriptSetupAst ? (0, vue_language_core_1.parseScriptSetupRanges)(ts, descriptor.scriptSetupAst) : undefined;
359
374
  if (descriptor.scriptSetup && (scriptSetupRanges === null || scriptSetupRanges === void 0 ? void 0 : scriptSetupRanges.withDefaultsArg)) {
@@ -395,7 +410,7 @@ function readVueComponentDefaultProps(core, vueFileText, printer) {
395
410
  }
396
411
  }
397
412
  function scriptWorker() {
398
- const vueSourceFile = vue.createSourceFile('/tmp.vue', vueFileText, {}, ts, core.plugins);
413
+ const vueSourceFile = vue.createSourceFile('/tmp.vue', vueFileScript, {}, ts, core.plugins);
399
414
  const descriptor = vueSourceFile.sfc;
400
415
  if (descriptor.script) {
401
416
  const scriptResult = readTsComponentDefaultProps(descriptor.script.lang, descriptor.script.content, 'default', printer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-component-meta",
3
- "version": "0.40.0",
3
+ "version": "0.40.3",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,10 +13,10 @@
13
13
  "directory": "packages/vue-component-meta"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/vue-language-core": "0.40.0"
16
+ "@volar/vue-language-core": "0.40.3"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "typescript": "*"
20
20
  },
21
- "gitHead": "9207e74225db0e0e262f805063bc549dfed6a436"
21
+ "gitHead": "51eca3c36ac576626807e6093f56994dc2e6a4ce"
22
22
  }