vue-component-meta 2.0.19 → 2.0.20
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/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/base.d.ts +2 -1
- package/lib/base.js +45 -22
- package/lib/types.d.ts +1 -1
- package/package.json +5 -5
package/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export * from './lib/types';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare const createComponentMetaCheckerByJsonConfig: typeof createCheckerByJson;
|
|
8
8
|
/**
|
|
9
|
-
* @deprecated Use `
|
|
9
|
+
* @deprecated Use `createChecker` instead.
|
|
10
10
|
*/
|
|
11
11
|
export declare const createComponentMetaChecker: typeof createChecker;
|
|
12
12
|
export declare function createCheckerByJson(rootPath: string, json: any, checkerOptions?: MetaCheckerOptions): {
|
package/index.js
CHANGED
|
@@ -23,7 +23,7 @@ __exportStar(require("./lib/types"), exports);
|
|
|
23
23
|
*/
|
|
24
24
|
exports.createComponentMetaCheckerByJsonConfig = createCheckerByJson;
|
|
25
25
|
/**
|
|
26
|
-
* @deprecated Use `
|
|
26
|
+
* @deprecated Use `createChecker` instead.
|
|
27
27
|
*/
|
|
28
28
|
exports.createComponentMetaChecker = createChecker;
|
|
29
29
|
function createCheckerByJson(rootPath, json, checkerOptions = {}) {
|
package/lib/base.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as vue from '@vue/language-core';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
|
+
import { TypeScriptProjectHost } from '@volar/typescript';
|
|
3
4
|
import type { MetaCheckerOptions, ComponentMeta } from './types';
|
|
4
5
|
export * from './types';
|
|
5
6
|
export declare function createCheckerByJsonConfigBase(ts: typeof import('typescript'), rootDir: string, json: any, checkerOptions?: MetaCheckerOptions): {
|
|
@@ -24,7 +25,7 @@ export declare function createCheckerBase(ts: typeof import('typescript'), tscon
|
|
|
24
25
|
tsLs: ts.LanguageService;
|
|
25
26
|
};
|
|
26
27
|
};
|
|
27
|
-
export declare function baseCreate(ts: typeof import('typescript'),
|
|
28
|
+
export declare function baseCreate(ts: typeof import('typescript'), configFileName: string | undefined, projectHost: TypeScriptProjectHost, vueCompilerOptions: vue.VueCompilerOptions, checkerOptions: MetaCheckerOptions, globalComponentName: string): {
|
|
28
29
|
getExportNames: (componentPath: string) => string[];
|
|
29
30
|
getComponentMeta: (componentPath: string, exportName?: string) => ComponentMeta;
|
|
30
31
|
__internal__: {
|
package/lib/base.js
CHANGED
|
@@ -41,8 +41,6 @@ function createCheckerWorker(ts, loadParsedCommandLine, checkerOptions, rootPath
|
|
|
41
41
|
let projectVersion = 0;
|
|
42
42
|
const scriptSnapshots = new Map();
|
|
43
43
|
const projectHost = {
|
|
44
|
-
...ts.sys,
|
|
45
|
-
configFileName,
|
|
46
44
|
getCurrentDirectory: () => rootPath,
|
|
47
45
|
getProjectVersion: () => projectVersion.toString(),
|
|
48
46
|
getCompilationSettings: () => parsedCommandLine.options,
|
|
@@ -57,11 +55,9 @@ function createCheckerWorker(ts, loadParsedCommandLine, checkerOptions, rootPath
|
|
|
57
55
|
}
|
|
58
56
|
return scriptSnapshots.get(fileName);
|
|
59
57
|
},
|
|
60
|
-
scriptIdToFileName: id => id,
|
|
61
|
-
fileNameToScriptId: id => id,
|
|
62
58
|
};
|
|
63
59
|
return {
|
|
64
|
-
...baseCreate(ts, projectHost, parsedCommandLine.vueOptions, checkerOptions, globalComponentName),
|
|
60
|
+
...baseCreate(ts, configFileName, projectHost, parsedCommandLine.vueOptions, checkerOptions, globalComponentName),
|
|
65
61
|
updateFile(fileName, text) {
|
|
66
62
|
fileName = fileName.replace(windowsPathReg, '/');
|
|
67
63
|
scriptSnapshots.set(fileName, ts.ScriptSnapshot.fromString(text));
|
|
@@ -83,12 +79,12 @@ function createCheckerWorker(ts, loadParsedCommandLine, checkerOptions, rootPath
|
|
|
83
79
|
},
|
|
84
80
|
};
|
|
85
81
|
}
|
|
86
|
-
function baseCreate(ts,
|
|
82
|
+
function baseCreate(ts, configFileName, projectHost, vueCompilerOptions, checkerOptions, globalComponentName) {
|
|
87
83
|
const globalComponentSnapshot = ts.ScriptSnapshot.fromString('<script setup lang="ts"></script>');
|
|
88
84
|
const metaSnapshots = {};
|
|
89
|
-
const getScriptFileNames =
|
|
90
|
-
const getScriptSnapshot =
|
|
91
|
-
|
|
85
|
+
const getScriptFileNames = projectHost.getScriptFileNames;
|
|
86
|
+
const getScriptSnapshot = projectHost.getScriptSnapshot;
|
|
87
|
+
projectHost.getScriptFileNames = () => {
|
|
92
88
|
const names = getScriptFileNames();
|
|
93
89
|
return [
|
|
94
90
|
...names,
|
|
@@ -97,7 +93,7 @@ function baseCreate(ts, host, vueCompilerOptions, checkerOptions, globalComponen
|
|
|
97
93
|
getMetaFileName(globalComponentName),
|
|
98
94
|
];
|
|
99
95
|
};
|
|
100
|
-
|
|
96
|
+
projectHost.getScriptSnapshot = fileName => {
|
|
101
97
|
if (isMetaFileName(fileName)) {
|
|
102
98
|
if (!metaSnapshots[fileName]) {
|
|
103
99
|
metaSnapshots[fileName] = ts.ScriptSnapshot.fromString(getMetaScriptContent(fileName));
|
|
@@ -111,8 +107,36 @@ function baseCreate(ts, host, vueCompilerOptions, checkerOptions, globalComponen
|
|
|
111
107
|
return getScriptSnapshot(fileName);
|
|
112
108
|
}
|
|
113
109
|
};
|
|
114
|
-
const vueLanguagePlugin = vue.createVueLanguagePlugin(ts, id => id,
|
|
115
|
-
|
|
110
|
+
const vueLanguagePlugin = vue.createVueLanguagePlugin(ts, id => id, () => projectHost.getProjectVersion?.() ?? '', fileName => {
|
|
111
|
+
const fileMap = new vue.FileMap(ts.sys.useCaseSensitiveFileNames);
|
|
112
|
+
for (const vueFileName of projectHost.getScriptFileNames()) {
|
|
113
|
+
fileMap.set(vueFileName, undefined);
|
|
114
|
+
}
|
|
115
|
+
return fileMap.has(fileName);
|
|
116
|
+
}, projectHost.getCompilationSettings(), vueCompilerOptions);
|
|
117
|
+
const language = vue.createLanguage([
|
|
118
|
+
vueLanguagePlugin,
|
|
119
|
+
{
|
|
120
|
+
getLanguageId(fileName) {
|
|
121
|
+
return (0, typescript_1.resolveFileLanguageId)(fileName);
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
], new vue.FileMap(ts.sys.useCaseSensitiveFileNames), fileName => {
|
|
125
|
+
const snapshot = projectHost.getScriptSnapshot(fileName);
|
|
126
|
+
if (snapshot) {
|
|
127
|
+
language.scripts.set(fileName, snapshot);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
language.scripts.delete(fileName);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
language.typescript = {
|
|
134
|
+
sys: ts.sys,
|
|
135
|
+
configFileName,
|
|
136
|
+
asFileName: s => s,
|
|
137
|
+
asScriptId: s => s,
|
|
138
|
+
...(0, typescript_1.createLanguageServiceHost)(ts, ts.sys, language, s => s, projectHost),
|
|
139
|
+
};
|
|
116
140
|
const { languageServiceHost } = language.typescript;
|
|
117
141
|
const tsLs = ts.createLanguageService(languageServiceHost);
|
|
118
142
|
if (checkerOptions.forceUseTs) {
|
|
@@ -231,7 +255,7 @@ ${vueCompilerOptions.target < 3 ? vue2_1.code : vue_component_type_helpers_1.cod
|
|
|
231
255
|
}
|
|
232
256
|
// fill defaults
|
|
233
257
|
const printer = ts.createPrinter(checkerOptions.printer);
|
|
234
|
-
const snapshot =
|
|
258
|
+
const snapshot = projectHost.getScriptSnapshot(componentPath);
|
|
235
259
|
const vueFile = language.scripts.get(componentPath)?.generated?.root;
|
|
236
260
|
const vueDefaults = vueFile && exportName === 'default'
|
|
237
261
|
? (vueFile instanceof vue.VueVirtualCode ? readVueComponentDefaultProps(vueFile, printer, ts, vueCompilerOptions) : {})
|
|
@@ -503,16 +527,15 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
|
|
|
503
527
|
if (sourceFile?.generated) {
|
|
504
528
|
const script = sourceFile.generated.languagePlugin.typescript?.getServiceScript(sourceFile.generated.root);
|
|
505
529
|
if (script) {
|
|
506
|
-
for (const [source,
|
|
507
|
-
const start
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
}
|
|
530
|
+
for (const [source, _, map] of language.maps.forEach(script.code)) {
|
|
531
|
+
for (const [start] of map.getSourceOffsets(declaration.getStart())) {
|
|
532
|
+
for (const [end] of map.getSourceOffsets(declaration.getEnd())) {
|
|
533
|
+
return {
|
|
534
|
+
file: source,
|
|
535
|
+
range: [start, end],
|
|
536
|
+
};
|
|
537
|
+
}
|
|
514
538
|
}
|
|
515
|
-
;
|
|
516
539
|
}
|
|
517
540
|
}
|
|
518
541
|
return undefined;
|
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
|
-
export type ComponentMetaChecker = ReturnType<typeof import('./base')['
|
|
2
|
+
export type ComponentMetaChecker = ReturnType<typeof import('./base')['createCheckerBase']>;
|
|
3
3
|
export interface Declaration {
|
|
4
4
|
file: string;
|
|
5
5
|
range: [number, number];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-component-meta",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.20",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"directory": "packages/component-meta"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@volar/typescript": "~2.
|
|
16
|
-
"@vue/language-core": "2.0.
|
|
15
|
+
"@volar/typescript": "~2.3.0-alpha.14",
|
|
16
|
+
"@vue/language-core": "2.0.20",
|
|
17
17
|
"path-browserify": "^1.0.1",
|
|
18
|
-
"vue-component-type-helpers": "2.0.
|
|
18
|
+
"vue-component-type-helpers": "2.0.20"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"typescript": "*"
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"@types/node": "latest",
|
|
30
30
|
"@types/path-browserify": "latest"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "e1a5d2f136bf60a772c9655f9f5474c7f71a2ff9"
|
|
33
33
|
}
|