vue-component-meta 2.0.29 → 2.1.0

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 CHANGED
@@ -1,32 +1,24 @@
1
1
  import * as ts from 'typescript';
2
2
  import type { MetaCheckerOptions } from './lib/types';
3
3
  export * from './lib/types';
4
- /**
5
- * @deprecated Use `createCheckerByJson` instead.
6
- */
7
- export declare const createComponentMetaCheckerByJsonConfig: typeof createCheckerByJson;
8
- /**
9
- * @deprecated Use `createChecker` instead.
10
- */
11
- export declare const createComponentMetaChecker: typeof createChecker;
12
4
  export declare function createCheckerByJson(rootPath: string, json: any, checkerOptions?: MetaCheckerOptions): {
5
+ getExportNames: (componentPath: string) => string[];
6
+ getComponentMeta: (componentPath: string, exportName?: string) => import("./lib/types").ComponentMeta;
13
7
  updateFile(fileName: string, text: string): void;
14
8
  deleteFile(fileName: string): void;
15
9
  reload(): void;
16
10
  clearCache(): void;
17
- getExportNames: (componentPath: string) => string[];
18
- getComponentMeta: (componentPath: string, exportName?: string) => import("./lib/types").ComponentMeta;
19
11
  __internal__: {
20
12
  tsLs: ts.LanguageService;
21
13
  };
22
14
  };
23
15
  export declare function createChecker(tsconfig: string, checkerOptions?: MetaCheckerOptions): {
16
+ getExportNames: (componentPath: string) => string[];
17
+ getComponentMeta: (componentPath: string, exportName?: string) => import("./lib/types").ComponentMeta;
24
18
  updateFile(fileName: string, text: string): void;
25
19
  deleteFile(fileName: string): void;
26
20
  reload(): void;
27
21
  clearCache(): void;
28
- getExportNames: (componentPath: string) => string[];
29
- getComponentMeta: (componentPath: string, exportName?: string) => import("./lib/types").ComponentMeta;
30
22
  __internal__: {
31
23
  tsLs: ts.LanguageService;
32
24
  };
package/index.js CHANGED
@@ -14,20 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.createComponentMetaChecker = exports.createComponentMetaCheckerByJsonConfig = void 0;
18
17
  exports.createCheckerByJson = createCheckerByJson;
19
18
  exports.createChecker = createChecker;
20
19
  const ts = require("typescript");
21
20
  const base_1 = require("./lib/base");
22
21
  __exportStar(require("./lib/types"), exports);
23
- /**
24
- * @deprecated Use `createCheckerByJson` instead.
25
- */
26
- exports.createComponentMetaCheckerByJsonConfig = createCheckerByJson;
27
- /**
28
- * @deprecated Use `createChecker` instead.
29
- */
30
- exports.createComponentMetaChecker = createChecker;
31
22
  function createCheckerByJson(rootPath, json, checkerOptions = {}) {
32
23
  return (0, base_1.createCheckerByJsonConfigBase)(ts, rootPath, json, checkerOptions);
33
24
  }
package/lib/base.d.ts CHANGED
@@ -1,33 +1,36 @@
1
1
  import * as vue from '@vue/language-core';
2
2
  import type * as ts from 'typescript';
3
- import { TypeScriptProjectHost } from '@volar/typescript';
4
- import type { MetaCheckerOptions, ComponentMeta } from './types';
3
+ import type { ComponentMeta, MetaCheckerOptions } from './types';
5
4
  export * from './types';
6
5
  export declare function createCheckerByJsonConfigBase(ts: typeof import('typescript'), rootDir: string, json: any, checkerOptions?: MetaCheckerOptions): {
6
+ getExportNames: (componentPath: string) => string[];
7
+ getComponentMeta: (componentPath: string, exportName?: string) => ComponentMeta;
7
8
  updateFile(fileName: string, text: string): void;
8
9
  deleteFile(fileName: string): void;
9
10
  reload(): void;
10
11
  clearCache(): void;
11
- getExportNames: (componentPath: string) => string[];
12
- getComponentMeta: (componentPath: string, exportName?: string) => ComponentMeta;
13
12
  __internal__: {
14
13
  tsLs: ts.LanguageService;
15
14
  };
16
15
  };
17
16
  export declare function createCheckerBase(ts: typeof import('typescript'), tsconfig: string, checkerOptions?: MetaCheckerOptions): {
17
+ getExportNames: (componentPath: string) => string[];
18
+ getComponentMeta: (componentPath: string, exportName?: string) => ComponentMeta;
18
19
  updateFile(fileName: string, text: string): void;
19
20
  deleteFile(fileName: string): void;
20
21
  reload(): void;
21
22
  clearCache(): void;
22
- getExportNames: (componentPath: string) => string[];
23
- getComponentMeta: (componentPath: string, exportName?: string) => ComponentMeta;
24
23
  __internal__: {
25
24
  tsLs: ts.LanguageService;
26
25
  };
27
26
  };
28
- export declare function baseCreate(ts: typeof import('typescript'), projectHost: TypeScriptProjectHost, vueCompilerOptions: vue.VueCompilerOptions, checkerOptions: MetaCheckerOptions, globalComponentName: string): {
27
+ export declare function baseCreate(ts: typeof import('typescript'), getCommandLine: () => vue.ParsedCommandLine, checkerOptions: MetaCheckerOptions, rootPath: string, globalComponentName: string): {
29
28
  getExportNames: (componentPath: string) => string[];
30
29
  getComponentMeta: (componentPath: string, exportName?: string) => ComponentMeta;
30
+ updateFile(fileName: string, text: string): void;
31
+ deleteFile(fileName: string): void;
32
+ reload(): void;
33
+ clearCache(): void;
31
34
  __internal__: {
32
35
  tsLs: ts.LanguageService;
33
36
  };
package/lib/base.js CHANGED
@@ -17,73 +17,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.createCheckerByJsonConfigBase = createCheckerByJsonConfigBase;
18
18
  exports.createCheckerBase = createCheckerBase;
19
19
  exports.baseCreate = baseCreate;
20
+ const typescript_1 = require("@volar/typescript");
20
21
  const vue = require("@vue/language-core");
21
22
  const path = require("path-browserify");
22
23
  const vue_component_type_helpers_1 = require("vue-component-type-helpers");
23
24
  const vue2_1 = require("vue-component-type-helpers/vue2");
24
- const typescript_1 = require("@volar/typescript");
25
25
  __exportStar(require("./types"), exports);
26
26
  const windowsPathReg = /\\/g;
27
27
  function createCheckerByJsonConfigBase(ts, rootDir, json, checkerOptions = {}) {
28
28
  rootDir = rootDir.replace(windowsPathReg, '/');
29
- return createCheckerWorker(ts, () => vue.createParsedCommandLineByJson(ts, ts.sys, rootDir, json), checkerOptions, rootDir, path.join(rootDir, 'jsconfig.json.global.vue'));
29
+ return baseCreate(ts, () => vue.createParsedCommandLineByJson(ts, ts.sys, rootDir, json), checkerOptions, rootDir, path.join(rootDir, 'jsconfig.json.global.vue'));
30
30
  }
31
31
  function createCheckerBase(ts, tsconfig, checkerOptions = {}) {
32
32
  tsconfig = tsconfig.replace(windowsPathReg, '/');
33
- return createCheckerWorker(ts, () => vue.createParsedCommandLine(ts, ts.sys, tsconfig), checkerOptions, path.dirname(tsconfig), tsconfig + '.global.vue');
33
+ return baseCreate(ts, () => vue.createParsedCommandLine(ts, ts.sys, tsconfig), checkerOptions, path.dirname(tsconfig), tsconfig + '.global.vue');
34
34
  }
35
- function createCheckerWorker(ts, loadParsedCommandLine, checkerOptions, rootPath, globalComponentName) {
36
- /**
37
- * Original Host
38
- */
39
- let parsedCommandLine = loadParsedCommandLine();
40
- let fileNames = parsedCommandLine.fileNames.map(path => path.replace(windowsPathReg, '/'));
35
+ function baseCreate(ts, getCommandLine, checkerOptions, rootPath, globalComponentName) {
36
+ let commandLine = getCommandLine();
37
+ let fileNames = commandLine.fileNames.map(path => path.replace(windowsPathReg, '/'));
41
38
  let projectVersion = 0;
42
- const scriptSnapshots = new Map();
43
39
  const projectHost = {
44
40
  getCurrentDirectory: () => rootPath,
45
41
  getProjectVersion: () => projectVersion.toString(),
46
- getCompilationSettings: () => parsedCommandLine.options,
42
+ getCompilationSettings: () => commandLine.options,
47
43
  getScriptFileNames: () => fileNames,
48
- getProjectReferences: () => parsedCommandLine.projectReferences,
49
- getScriptSnapshot: fileName => {
50
- if (!scriptSnapshots.has(fileName)) {
51
- const fileText = ts.sys.readFile(fileName);
52
- if (fileText !== undefined) {
53
- scriptSnapshots.set(fileName, ts.ScriptSnapshot.fromString(fileText));
54
- }
55
- }
56
- return scriptSnapshots.get(fileName);
57
- },
44
+ getProjectReferences: () => commandLine.projectReferences,
58
45
  };
59
- return {
60
- ...baseCreate(ts, projectHost, parsedCommandLine.vueOptions, checkerOptions, globalComponentName),
61
- updateFile(fileName, text) {
62
- fileName = fileName.replace(windowsPathReg, '/');
63
- scriptSnapshots.set(fileName, ts.ScriptSnapshot.fromString(text));
64
- projectVersion++;
65
- },
66
- deleteFile(fileName) {
67
- fileName = fileName.replace(windowsPathReg, '/');
68
- fileNames = fileNames.filter(f => f !== fileName);
69
- projectVersion++;
70
- },
71
- reload() {
72
- parsedCommandLine = loadParsedCommandLine();
73
- fileNames = parsedCommandLine.fileNames.map(path => path.replace(windowsPathReg, '/'));
74
- this.clearCache();
75
- },
76
- clearCache() {
77
- scriptSnapshots.clear();
78
- projectVersion++;
79
- },
80
- };
81
- }
82
- function baseCreate(ts, projectHost, vueCompilerOptions, checkerOptions, globalComponentName) {
83
46
  const globalComponentSnapshot = ts.ScriptSnapshot.fromString('<script setup lang="ts"></script>');
84
- const metaSnapshots = {};
47
+ const scriptSnapshots = new Map();
48
+ const metaSnapshots = new Map();
85
49
  const getScriptFileNames = projectHost.getScriptFileNames;
86
- const getScriptSnapshot = projectHost.getScriptSnapshot;
87
50
  projectHost.getScriptFileNames = () => {
88
51
  const names = getScriptFileNames();
89
52
  return [
@@ -93,21 +56,7 @@ function baseCreate(ts, projectHost, vueCompilerOptions, checkerOptions, globalC
93
56
  getMetaFileName(globalComponentName),
94
57
  ];
95
58
  };
96
- projectHost.getScriptSnapshot = fileName => {
97
- if (isMetaFileName(fileName)) {
98
- if (!metaSnapshots[fileName]) {
99
- metaSnapshots[fileName] = ts.ScriptSnapshot.fromString(getMetaScriptContent(fileName));
100
- }
101
- return metaSnapshots[fileName];
102
- }
103
- else if (fileName === globalComponentName) {
104
- return globalComponentSnapshot;
105
- }
106
- else {
107
- return getScriptSnapshot(fileName);
108
- }
109
- };
110
- const vueLanguagePlugin = vue.createVueLanguagePlugin2(ts, id => id, vue.createRootFileChecker(projectHost.getProjectVersion ? () => projectHost.getProjectVersion() : undefined, () => projectHost.getScriptFileNames(), ts.sys.useCaseSensitiveFileNames), projectHost.getCompilationSettings(), vueCompilerOptions);
59
+ const vueLanguagePlugin = vue.createVueLanguagePlugin(ts, projectHost.getCompilationSettings(), commandLine.vueOptions, id => id);
111
60
  const language = vue.createLanguage([
112
61
  vueLanguagePlugin,
113
62
  {
@@ -116,7 +65,28 @@ function baseCreate(ts, projectHost, vueCompilerOptions, checkerOptions, globalC
116
65
  },
117
66
  },
118
67
  ], new vue.FileMap(ts.sys.useCaseSensitiveFileNames), fileName => {
119
- const snapshot = projectHost.getScriptSnapshot(fileName);
68
+ let snapshot = scriptSnapshots.get(fileName);
69
+ if (fileName === globalComponentName) {
70
+ snapshot = globalComponentSnapshot;
71
+ }
72
+ else if (isMetaFileName(fileName)) {
73
+ if (!metaSnapshots.has(fileName)) {
74
+ metaSnapshots.set(fileName, ts.ScriptSnapshot.fromString(getMetaScriptContent(fileName)));
75
+ }
76
+ snapshot = metaSnapshots.get(fileName);
77
+ }
78
+ else {
79
+ if (!scriptSnapshots.has(fileName)) {
80
+ const fileText = ts.sys.readFile(fileName);
81
+ if (fileText !== undefined) {
82
+ scriptSnapshots.set(fileName, ts.ScriptSnapshot.fromString(fileText));
83
+ }
84
+ else {
85
+ scriptSnapshots.set(fileName, undefined);
86
+ }
87
+ }
88
+ snapshot = scriptSnapshots.get(fileName);
89
+ }
120
90
  if (snapshot) {
121
91
  language.scripts.set(fileName, snapshot);
122
92
  }
@@ -126,11 +96,35 @@ function baseCreate(ts, projectHost, vueCompilerOptions, checkerOptions, globalC
126
96
  });
127
97
  const { languageServiceHost } = (0, typescript_1.createLanguageServiceHost)(ts, ts.sys, language, s => s, projectHost);
128
98
  const tsLs = ts.createLanguageService(languageServiceHost);
99
+ const fileExists = languageServiceHost.fileExists.bind(languageServiceHost);
100
+ const getScriptSnapshot = languageServiceHost.getScriptSnapshot.bind(languageServiceHost);
101
+ const globalTypesName = `__globalTypes_${commandLine.vueOptions.target}_${commandLine.vueOptions.strictTemplates}.d.ts`;
102
+ const snapshots = new Map();
103
+ languageServiceHost.fileExists = path => {
104
+ if (path.endsWith(globalTypesName)) {
105
+ return true;
106
+ }
107
+ return fileExists(path);
108
+ };
109
+ languageServiceHost.getScriptSnapshot = path => {
110
+ if (path.endsWith(globalTypesName)) {
111
+ if (!snapshots.has(path)) {
112
+ const contents = vue.generateGlobalTypes(commandLine.vueOptions.lib, commandLine.vueOptions.target, commandLine.vueOptions.strictTemplates);
113
+ snapshots.set(path, {
114
+ getText: (start, end) => contents.substring(start, end),
115
+ getLength: () => contents.length,
116
+ getChangeRange: () => undefined,
117
+ });
118
+ }
119
+ return snapshots.get(path);
120
+ }
121
+ return getScriptSnapshot(path);
122
+ };
129
123
  if (checkerOptions.forceUseTs) {
130
124
  const getScriptKind = languageServiceHost.getScriptKind?.bind(languageServiceHost);
131
125
  languageServiceHost.getScriptKind = fileName => {
132
126
  const scriptKind = getScriptKind(fileName);
133
- if (vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext))) {
127
+ if (commandLine.vueOptions.extensions.some(ext => fileName.endsWith(ext))) {
134
128
  if (scriptKind === ts.ScriptKind.JS) {
135
129
  return ts.ScriptKind.TS;
136
130
  }
@@ -145,6 +139,25 @@ function baseCreate(ts, projectHost, vueCompilerOptions, checkerOptions, globalC
145
139
  return {
146
140
  getExportNames,
147
141
  getComponentMeta,
142
+ updateFile(fileName, text) {
143
+ fileName = fileName.replace(windowsPathReg, '/');
144
+ scriptSnapshots.set(fileName, ts.ScriptSnapshot.fromString(text));
145
+ projectVersion++;
146
+ },
147
+ deleteFile(fileName) {
148
+ fileName = fileName.replace(windowsPathReg, '/');
149
+ fileNames = fileNames.filter(f => f !== fileName);
150
+ projectVersion++;
151
+ },
152
+ reload() {
153
+ commandLine = getCommandLine();
154
+ fileNames = commandLine.fileNames.map(path => path.replace(windowsPathReg, '/'));
155
+ this.clearCache();
156
+ },
157
+ clearCache() {
158
+ scriptSnapshots.clear();
159
+ projectVersion++;
160
+ },
148
161
  __internal__: {
149
162
  tsLs,
150
163
  },
@@ -153,7 +166,7 @@ function baseCreate(ts, projectHost, vueCompilerOptions, checkerOptions, globalC
153
166
  return fileName.endsWith('.meta.ts');
154
167
  }
155
168
  function getMetaFileName(fileName) {
156
- return (vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext))
169
+ return (commandLine.vueOptions.extensions.some(ext => fileName.endsWith(ext))
157
170
  ? fileName
158
171
  : fileName.substring(0, fileName.lastIndexOf('.'))) + '.meta.ts';
159
172
  }
@@ -170,7 +183,7 @@ interface ComponentMeta<T> {
170
183
  exposed: ComponentExposed<T>;
171
184
  };
172
185
 
173
- ${vueCompilerOptions.target < 3 ? vue2_1.code : vue_component_type_helpers_1.code}
186
+ ${commandLine.vueOptions.target < 3 ? vue2_1.code : vue_component_type_helpers_1.code}
174
187
  `.trim();
175
188
  return code;
176
189
  }
@@ -242,10 +255,10 @@ ${vueCompilerOptions.target < 3 ? vue2_1.code : vue_component_type_helpers_1.cod
242
255
  }
243
256
  // fill defaults
244
257
  const printer = ts.createPrinter(checkerOptions.printer);
245
- const snapshot = projectHost.getScriptSnapshot(componentPath);
258
+ const snapshot = language.scripts.get(componentPath)?.snapshot;
246
259
  const vueFile = language.scripts.get(componentPath)?.generated?.root;
247
260
  const vueDefaults = vueFile && exportName === 'default'
248
- ? (vueFile instanceof vue.VueVirtualCode ? readVueComponentDefaultProps(vueFile, printer, ts, vueCompilerOptions) : {})
261
+ ? (vueFile instanceof vue.VueVirtualCode ? readVueComponentDefaultProps(vueFile, printer, ts, commandLine.vueOptions) : {})
249
262
  : {};
250
263
  const tsDefaults = !vueFile ? readTsComponentDefaultProps(componentPath.substring(componentPath.lastIndexOf('.') + 1), // ts | js | tsx | jsx
251
264
  snapshot.getText(0, snapshot.getLength()), exportName, printer, ts) : {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-component-meta",
3
- "version": "2.0.29",
3
+ "version": "2.1.0",
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.4.0-alpha.18",
16
- "@vue/language-core": "2.0.29",
15
+ "@volar/typescript": "~2.4.1",
16
+ "@vue/language-core": "2.1.0",
17
17
  "path-browserify": "^1.0.1",
18
- "vue-component-type-helpers": "2.0.29"
18
+ "vue-component-type-helpers": "2.1.0"
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": "49ad9563e6f2677595878a000179dfea83fb910c"
32
+ "gitHead": "510063740b90b64caedaee1f0bde70974613a92c"
33
33
  }