@vue/typescript-plugin 2.2.8 → 3.0.0-alpha.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 +2 -2
- package/index.js +102 -9
- package/lib/common.d.ts +1 -3
- package/lib/common.js +75 -2
- package/lib/requests/getElementAttrs.js +14 -17
- package/lib/requests/getElementNames.d.ts +5 -0
- package/lib/requests/getElementNames.js +23 -0
- package/lib/requests/getPropertiesAtLocation.js +1 -0
- package/lib/requests/index.d.ts +14 -0
- package/lib/requests/index.js +3 -0
- package/lib/requests/utils.js +8 -8
- package/package.json +3 -3
- package/lib/client.d.ts +0 -13
- package/lib/client.js +0 -42
- package/lib/requests/componentInfos.d.ts +0 -13
- package/lib/requests/componentInfos.js +0 -249
- package/lib/requests/getComponentInfo.d.ts +0 -5
- package/lib/requests/getComponentInfo.js +0 -23
- package/lib/server.d.ts +0 -25
- package/lib/server.js +0 -260
- package/lib/utils.d.ts +0 -31
- package/lib/utils.js +0 -250
package/lib/utils.js
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.onServerReady = exports.inferredServers = exports.configuredServers = void 0;
|
|
4
|
-
exports.getServerPath = getServerPath;
|
|
5
|
-
exports.getBestServer = getBestServer;
|
|
6
|
-
const language_core_1 = require("@vue/language-core");
|
|
7
|
-
const shared_1 = require("@vue/shared");
|
|
8
|
-
const fs = require("node:fs");
|
|
9
|
-
const net = require("node:net");
|
|
10
|
-
const os = require("node:os");
|
|
11
|
-
const path = require("node:path");
|
|
12
|
-
const { version } = require('../package.json');
|
|
13
|
-
const platform = os.platform();
|
|
14
|
-
const pipeDir = platform === 'win32'
|
|
15
|
-
? `\\\\.\\pipe\\`
|
|
16
|
-
: `/tmp/`;
|
|
17
|
-
function getServerPath(kind, id) {
|
|
18
|
-
if (kind === 1) {
|
|
19
|
-
return `${pipeDir}vue-named-pipe-${version}-configured-${id}`;
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
return `${pipeDir}vue-named-pipe-${version}-inferred-${id}`;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
class NamedPipeServer {
|
|
26
|
-
constructor(kind, id) {
|
|
27
|
-
this.connecting = false;
|
|
28
|
-
this.containsFileCache = new Map();
|
|
29
|
-
this.componentNamesAndProps = new language_core_1.FileMap(false);
|
|
30
|
-
this.seq = 0;
|
|
31
|
-
this.dataChunks = [];
|
|
32
|
-
this.requestHandlers = new Map();
|
|
33
|
-
this.path = getServerPath(kind, id);
|
|
34
|
-
}
|
|
35
|
-
containsFile(fileName) {
|
|
36
|
-
if (this.projectInfo) {
|
|
37
|
-
if (!this.containsFileCache.has(fileName)) {
|
|
38
|
-
this.containsFileCache.set(fileName, (async () => {
|
|
39
|
-
const res = await this.sendRequest('containsFile', fileName);
|
|
40
|
-
if (typeof res !== 'boolean') {
|
|
41
|
-
// If the request fails, delete the cache
|
|
42
|
-
this.containsFileCache.delete(fileName);
|
|
43
|
-
}
|
|
44
|
-
return res;
|
|
45
|
-
})());
|
|
46
|
-
}
|
|
47
|
-
return this.containsFileCache.get(fileName);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
async getComponentProps(fileName, tag) {
|
|
51
|
-
const componentAndProps = this.componentNamesAndProps.get(fileName);
|
|
52
|
-
if (!componentAndProps) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const props = componentAndProps[tag]
|
|
56
|
-
?? componentAndProps[(0, shared_1.camelize)(tag)]
|
|
57
|
-
?? componentAndProps[(0, shared_1.capitalize)((0, shared_1.camelize)(tag))];
|
|
58
|
-
if (props) {
|
|
59
|
-
return props;
|
|
60
|
-
}
|
|
61
|
-
return await this.sendRequest('subscribeComponentProps', fileName, tag);
|
|
62
|
-
}
|
|
63
|
-
update() {
|
|
64
|
-
if (!this.connecting && !this.projectInfo) {
|
|
65
|
-
this.connecting = true;
|
|
66
|
-
this.connect();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
connect() {
|
|
70
|
-
this.socket = net.connect(this.path);
|
|
71
|
-
this.socket.on('data', this.onData.bind(this));
|
|
72
|
-
this.socket.on('connect', async () => {
|
|
73
|
-
const projectInfo = await this.sendRequest('projectInfo', '');
|
|
74
|
-
if (projectInfo) {
|
|
75
|
-
console.log('TSServer project ready:', projectInfo.name);
|
|
76
|
-
this.projectInfo = projectInfo;
|
|
77
|
-
this.containsFileCache.clear();
|
|
78
|
-
exports.onServerReady.forEach(cb => cb());
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
this.close();
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
this.socket.on('error', err => {
|
|
85
|
-
if (err.code === 'ECONNREFUSED') {
|
|
86
|
-
try {
|
|
87
|
-
console.log('Deleteing invalid named pipe file:', this.path);
|
|
88
|
-
fs.promises.unlink(this.path);
|
|
89
|
-
}
|
|
90
|
-
catch { }
|
|
91
|
-
}
|
|
92
|
-
this.close();
|
|
93
|
-
});
|
|
94
|
-
this.socket.on('timeout', () => {
|
|
95
|
-
this.close();
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
close() {
|
|
99
|
-
this.connecting = false;
|
|
100
|
-
this.projectInfo = undefined;
|
|
101
|
-
this.socket?.end();
|
|
102
|
-
}
|
|
103
|
-
onData(chunk) {
|
|
104
|
-
this.dataChunks.push(chunk);
|
|
105
|
-
const data = Buffer.concat(this.dataChunks);
|
|
106
|
-
const text = data.toString();
|
|
107
|
-
if (text.endsWith('\n\n')) {
|
|
108
|
-
this.dataChunks.length = 0;
|
|
109
|
-
const results = text.split('\n\n');
|
|
110
|
-
for (let result of results) {
|
|
111
|
-
result = result.trim();
|
|
112
|
-
if (!result) {
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
try {
|
|
116
|
-
const data = JSON.parse(result.trim());
|
|
117
|
-
if (typeof data[0] === 'number') {
|
|
118
|
-
const [seq, res] = data;
|
|
119
|
-
this.requestHandlers.get(seq)?.(res);
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
const [type, fileName, res] = data;
|
|
123
|
-
this.onNotification(type, fileName, res);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
catch (e) {
|
|
127
|
-
console.error('JSON parse error:', e);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
onNotification(type, fileName, data) {
|
|
133
|
-
// console.log(`[${type}] ${fileName} ${JSON.stringify(data)}`);
|
|
134
|
-
if (type === 'componentNamesUpdated') {
|
|
135
|
-
let components = this.componentNamesAndProps.get(fileName);
|
|
136
|
-
if (!components) {
|
|
137
|
-
components = {};
|
|
138
|
-
this.componentNamesAndProps.set(fileName, components);
|
|
139
|
-
}
|
|
140
|
-
const newNames = data;
|
|
141
|
-
const newNameSet = new Set(newNames);
|
|
142
|
-
for (const name in components) {
|
|
143
|
-
if (!newNameSet.has(name)) {
|
|
144
|
-
delete components[name];
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
for (const name of newNames) {
|
|
148
|
-
if (!components[name]) {
|
|
149
|
-
components[name] = null;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
else if (type === 'componentPropsUpdated') {
|
|
154
|
-
const components = this.componentNamesAndProps.get(fileName) ?? {};
|
|
155
|
-
const [name, props] = data;
|
|
156
|
-
if (name in components) {
|
|
157
|
-
components[name] = props;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
console.error('Unknown notification type:', type);
|
|
162
|
-
debugger;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
sendRequest(requestType, fileName, ...args) {
|
|
166
|
-
return new Promise(resolve => {
|
|
167
|
-
const seq = this.seq++;
|
|
168
|
-
// console.time(`[${seq}] ${requestType} ${fileName}`);
|
|
169
|
-
this.requestHandlers.set(seq, data => {
|
|
170
|
-
// console.timeEnd(`[${seq}] ${requestType} ${fileName}`);
|
|
171
|
-
this.requestHandlers.delete(seq);
|
|
172
|
-
resolve(data);
|
|
173
|
-
clearInterval(retryTimer);
|
|
174
|
-
});
|
|
175
|
-
const retry = () => {
|
|
176
|
-
const data = [seq, requestType, fileName, ...args];
|
|
177
|
-
this.socket.write(JSON.stringify(data) + '\n\n');
|
|
178
|
-
};
|
|
179
|
-
retry();
|
|
180
|
-
const retryTimer = setInterval(retry, 1000);
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
exports.configuredServers = [];
|
|
185
|
-
exports.inferredServers = [];
|
|
186
|
-
exports.onServerReady = [];
|
|
187
|
-
for (let i = 0; i < 10; i++) {
|
|
188
|
-
exports.configuredServers.push(new NamedPipeServer(1, i));
|
|
189
|
-
exports.inferredServers.push(new NamedPipeServer(0, i));
|
|
190
|
-
}
|
|
191
|
-
async function getBestServer(fileName) {
|
|
192
|
-
for (const server of exports.configuredServers) {
|
|
193
|
-
server.update();
|
|
194
|
-
}
|
|
195
|
-
let servers = (await Promise.all(exports.configuredServers.map(async (server) => {
|
|
196
|
-
const projectInfo = server.projectInfo;
|
|
197
|
-
if (!projectInfo) {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
const containsFile = await server.containsFile(fileName);
|
|
201
|
-
if (!containsFile) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
return server;
|
|
205
|
-
}))).filter(server => !!server);
|
|
206
|
-
// Sort servers by tsconfig
|
|
207
|
-
servers.sort((a, b) => sortTSConfigs(fileName, a.projectInfo.name, b.projectInfo.name));
|
|
208
|
-
if (servers.length) {
|
|
209
|
-
// Return the first server
|
|
210
|
-
return servers[0];
|
|
211
|
-
}
|
|
212
|
-
for (const server of exports.inferredServers) {
|
|
213
|
-
server.update();
|
|
214
|
-
}
|
|
215
|
-
servers = (await Promise.all(exports.inferredServers.map(server => {
|
|
216
|
-
const projectInfo = server.projectInfo;
|
|
217
|
-
if (!projectInfo) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
// Check if the file is in the project's directory
|
|
221
|
-
if (path.relative(projectInfo.currentDirectory, fileName).startsWith('..')) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
return server;
|
|
225
|
-
}))).filter(server => !!server);
|
|
226
|
-
// Sort servers by directory
|
|
227
|
-
servers.sort((a, b) => b.projectInfo.currentDirectory.replace(/\\/g, '/').split('/').length
|
|
228
|
-
- a.projectInfo.currentDirectory.replace(/\\/g, '/').split('/').length);
|
|
229
|
-
if (servers.length) {
|
|
230
|
-
// Return the first server
|
|
231
|
-
return servers[0];
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
function sortTSConfigs(file, a, b) {
|
|
235
|
-
const inA = isFileInDir(file, path.dirname(a));
|
|
236
|
-
const inB = isFileInDir(file, path.dirname(b));
|
|
237
|
-
if (inA !== inB) {
|
|
238
|
-
const aWeight = inA ? 1 : 0;
|
|
239
|
-
const bWeight = inB ? 1 : 0;
|
|
240
|
-
return bWeight - aWeight;
|
|
241
|
-
}
|
|
242
|
-
const aLength = a.split('/').length;
|
|
243
|
-
const bLength = b.split('/').length;
|
|
244
|
-
return bLength - aLength;
|
|
245
|
-
}
|
|
246
|
-
function isFileInDir(fileName, dir) {
|
|
247
|
-
const relative = path.relative(dir, fileName);
|
|
248
|
-
return !!relative && !relative.startsWith('..') && !path.isAbsolute(relative);
|
|
249
|
-
}
|
|
250
|
-
//# sourceMappingURL=utils.js.map
|