vue-component-meta 0.39.5 → 0.40.2
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 +20 -0
- package/out/index.js +37 -18
- package/package.json +3 -3
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,16 +1,33 @@
|
|
|
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
|
+
const vue_language_core_1 = require("@volar/vue-language-core");
|
|
4
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;
|
|
5
22
|
function createComponentMetaChecker(tsconfigPath, checkerOptions = {}) {
|
|
6
|
-
const parsedCommandLine = vue.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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) {
|
|
14
31
|
const scriptSnapshot = {};
|
|
15
32
|
const globalComponentName = tsconfigPath.replace(/\\/g, '/') + '.global.ts';
|
|
16
33
|
const host = Object.assign(Object.assign({}, ts.sys), { getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options), useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames, getCompilationSettings: () => parsedCommandLine.options, getScriptFileNames: () => {
|
|
@@ -23,7 +40,7 @@ function createComponentMetaChecker(tsconfigPath, checkerOptions = {}) {
|
|
|
23
40
|
}, getProjectReferences: () => parsedCommandLine.projectReferences, getScriptVersion: (fileName) => '0', getScriptSnapshot: (fileName) => {
|
|
24
41
|
if (!scriptSnapshot[fileName]) {
|
|
25
42
|
let fileText;
|
|
26
|
-
if (fileName
|
|
43
|
+
if (isMetaFileName(fileName)) {
|
|
27
44
|
fileText = getMetaScriptContent(fileName);
|
|
28
45
|
}
|
|
29
46
|
else if (fileName === globalComponentName) {
|
|
@@ -75,6 +92,9 @@ function createComponentMetaChecker(tsconfigPath, checkerOptions = {}) {
|
|
|
75
92
|
typeChecker,
|
|
76
93
|
},
|
|
77
94
|
};
|
|
95
|
+
function isMetaFileName(fileName) {
|
|
96
|
+
return fileName.endsWith('.meta.ts');
|
|
97
|
+
}
|
|
78
98
|
function getMetaFileName(fileName) {
|
|
79
99
|
return (fileName.endsWith('.vue') ? fileName : fileName.substring(0, fileName.lastIndexOf('.'))) + '.meta.ts';
|
|
80
100
|
}
|
|
@@ -124,7 +144,7 @@ function createComponentMetaChecker(tsconfigPath, checkerOptions = {}) {
|
|
|
124
144
|
const printer = checkerOptions.printer ? ts.createPrinter(checkerOptions.printer) : undefined;
|
|
125
145
|
const snapshot = host.getScriptSnapshot(componentPath);
|
|
126
146
|
const vueDefaults = componentPath.endsWith('.vue') && exportName === 'default'
|
|
127
|
-
? readVueComponentDefaultProps(
|
|
147
|
+
? readVueComponentDefaultProps(core, snapshot, printer)
|
|
128
148
|
: {};
|
|
129
149
|
const tsDefaults = !componentPath.endsWith('.vue') ? readTsComponentDefaultProps(componentPath.substring(componentPath.lastIndexOf('.') + 1), // ts | js | tsx | jsx
|
|
130
150
|
snapshot.getText(0, snapshot.getLength()), exportName, printer) : {};
|
|
@@ -210,7 +230,6 @@ function createComponentMetaChecker(tsconfigPath, checkerOptions = {}) {
|
|
|
210
230
|
};
|
|
211
231
|
}
|
|
212
232
|
}
|
|
213
|
-
exports.createComponentMetaChecker = createComponentMetaChecker;
|
|
214
233
|
function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: options }) {
|
|
215
234
|
var _a;
|
|
216
235
|
const enabled = !!options;
|
|
@@ -345,16 +364,16 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
|
|
|
345
364
|
resolveSchema,
|
|
346
365
|
};
|
|
347
366
|
}
|
|
348
|
-
function readVueComponentDefaultProps(
|
|
367
|
+
function readVueComponentDefaultProps(core, vueFileScript, printer) {
|
|
349
368
|
let result = {};
|
|
350
369
|
scriptSetupWorker();
|
|
351
370
|
scriptWorker();
|
|
352
371
|
return result;
|
|
353
372
|
function scriptSetupWorker() {
|
|
354
373
|
var _a;
|
|
355
|
-
const vueSourceFile = vue.createSourceFile('/tmp.vue',
|
|
356
|
-
const descriptor = vueSourceFile.
|
|
357
|
-
const scriptSetupRanges =
|
|
374
|
+
const vueSourceFile = vue.createSourceFile('/tmp.vue', vueFileScript, {}, ts, core.plugins);
|
|
375
|
+
const descriptor = vueSourceFile.sfc;
|
|
376
|
+
const scriptSetupRanges = descriptor.scriptSetupAst ? (0, vue_language_core_1.parseScriptSetupRanges)(ts, descriptor.scriptSetupAst) : undefined;
|
|
358
377
|
if (descriptor.scriptSetup && (scriptSetupRanges === null || scriptSetupRanges === void 0 ? void 0 : scriptSetupRanges.withDefaultsArg)) {
|
|
359
378
|
const defaultsText = descriptor.scriptSetup.content.substring(scriptSetupRanges.withDefaultsArg.start, scriptSetupRanges.withDefaultsArg.end);
|
|
360
379
|
const ast = ts.createSourceFile('/tmp.' + descriptor.scriptSetup.lang, '(' + defaultsText + ')', ts.ScriptTarget.Latest);
|
|
@@ -394,8 +413,8 @@ function readVueComponentDefaultProps(vueFileText, printer) {
|
|
|
394
413
|
}
|
|
395
414
|
}
|
|
396
415
|
function scriptWorker() {
|
|
397
|
-
const vueSourceFile = vue.createSourceFile('/tmp.vue',
|
|
398
|
-
const descriptor = vueSourceFile.
|
|
416
|
+
const vueSourceFile = vue.createSourceFile('/tmp.vue', vueFileScript, {}, ts, core.plugins);
|
|
417
|
+
const descriptor = vueSourceFile.sfc;
|
|
399
418
|
if (descriptor.script) {
|
|
400
419
|
const scriptResult = readTsComponentDefaultProps(descriptor.script.lang, descriptor.script.content, 'default', printer);
|
|
401
420
|
for (const [key, value] of Object.entries(scriptResult)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-component-meta",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.40.2",
|
|
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.
|
|
16
|
+
"@volar/vue-language-core": "0.40.2"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"typescript": "*"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "baa87a77b8cb56cf31dab158e5f76af42fe65b39"
|
|
22
22
|
}
|