vue-component-meta 0.40.1 → 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 +33 -15
- 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,17 +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
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
32
|
const globalComponentName = tsconfigPath.replace(/\\/g, '/') + '.global.ts';
|
|
17
33
|
const host = Object.assign(Object.assign({}, ts.sys), { getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options), useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames, getCompilationSettings: () => parsedCommandLine.options, getScriptFileNames: () => {
|
|
@@ -24,7 +40,7 @@ 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
|
|
43
|
+
if (isMetaFileName(fileName)) {
|
|
28
44
|
fileText = getMetaScriptContent(fileName);
|
|
29
45
|
}
|
|
30
46
|
else if (fileName === globalComponentName) {
|
|
@@ -76,6 +92,9 @@ function createComponentMetaChecker(tsconfigPath, checkerOptions = {}) {
|
|
|
76
92
|
typeChecker,
|
|
77
93
|
},
|
|
78
94
|
};
|
|
95
|
+
function isMetaFileName(fileName) {
|
|
96
|
+
return fileName.endsWith('.meta.ts');
|
|
97
|
+
}
|
|
79
98
|
function getMetaFileName(fileName) {
|
|
80
99
|
return (fileName.endsWith('.vue') ? fileName : fileName.substring(0, fileName.lastIndexOf('.'))) + '.meta.ts';
|
|
81
100
|
}
|
|
@@ -125,7 +144,7 @@ function createComponentMetaChecker(tsconfigPath, checkerOptions = {}) {
|
|
|
125
144
|
const printer = checkerOptions.printer ? ts.createPrinter(checkerOptions.printer) : undefined;
|
|
126
145
|
const snapshot = host.getScriptSnapshot(componentPath);
|
|
127
146
|
const vueDefaults = componentPath.endsWith('.vue') && exportName === 'default'
|
|
128
|
-
? readVueComponentDefaultProps(core, snapshot
|
|
147
|
+
? readVueComponentDefaultProps(core, snapshot, printer)
|
|
129
148
|
: {};
|
|
130
149
|
const tsDefaults = !componentPath.endsWith('.vue') ? readTsComponentDefaultProps(componentPath.substring(componentPath.lastIndexOf('.') + 1), // ts | js | tsx | jsx
|
|
131
150
|
snapshot.getText(0, snapshot.getLength()), exportName, printer) : {};
|
|
@@ -211,7 +230,6 @@ function createComponentMetaChecker(tsconfigPath, checkerOptions = {}) {
|
|
|
211
230
|
};
|
|
212
231
|
}
|
|
213
232
|
}
|
|
214
|
-
exports.createComponentMetaChecker = createComponentMetaChecker;
|
|
215
233
|
function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: options }) {
|
|
216
234
|
var _a;
|
|
217
235
|
const enabled = !!options;
|
|
@@ -346,14 +364,14 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
|
|
|
346
364
|
resolveSchema,
|
|
347
365
|
};
|
|
348
366
|
}
|
|
349
|
-
function readVueComponentDefaultProps(core,
|
|
367
|
+
function readVueComponentDefaultProps(core, vueFileScript, printer) {
|
|
350
368
|
let result = {};
|
|
351
369
|
scriptSetupWorker();
|
|
352
370
|
scriptWorker();
|
|
353
371
|
return result;
|
|
354
372
|
function scriptSetupWorker() {
|
|
355
373
|
var _a;
|
|
356
|
-
const vueSourceFile = vue.createSourceFile('/tmp.vue',
|
|
374
|
+
const vueSourceFile = vue.createSourceFile('/tmp.vue', vueFileScript, {}, ts, core.plugins);
|
|
357
375
|
const descriptor = vueSourceFile.sfc;
|
|
358
376
|
const scriptSetupRanges = descriptor.scriptSetupAst ? (0, vue_language_core_1.parseScriptSetupRanges)(ts, descriptor.scriptSetupAst) : undefined;
|
|
359
377
|
if (descriptor.scriptSetup && (scriptSetupRanges === null || scriptSetupRanges === void 0 ? void 0 : scriptSetupRanges.withDefaultsArg)) {
|
|
@@ -395,7 +413,7 @@ function readVueComponentDefaultProps(core, vueFileText, printer) {
|
|
|
395
413
|
}
|
|
396
414
|
}
|
|
397
415
|
function scriptWorker() {
|
|
398
|
-
const vueSourceFile = vue.createSourceFile('/tmp.vue',
|
|
416
|
+
const vueSourceFile = vue.createSourceFile('/tmp.vue', vueFileScript, {}, ts, core.plugins);
|
|
399
417
|
const descriptor = vueSourceFile.sfc;
|
|
400
418
|
if (descriptor.script) {
|
|
401
419
|
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.
|
|
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.40.
|
|
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
|
}
|