@vue/typescript-plugin 2.0.2 → 2.0.3

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.js CHANGED
@@ -43,7 +43,7 @@ function createLanguageServicePlugin() {
43
43
  });
44
44
  (0, decorateLanguageService_1.decorateLanguageService)(files, info.languageService);
45
45
  (0, decorateLanguageServiceHost_1.decorateLanguageServiceHost)(files, info.languageServiceHost, ts);
46
- (0, server_1.startNamedPipeServer)(info.project.projectKind);
46
+ (0, server_1.startNamedPipeServer)(info.project.projectKind, info.project.getCurrentDirectory());
47
47
  const getCompletionsAtPosition = info.languageService.getCompletionsAtPosition;
48
48
  const getCompletionEntryDetails = info.languageService.getCompletionEntryDetails;
49
49
  const getCodeFixesAtPosition = info.languageService.getCodeFixesAtPosition;
package/lib/client.d.ts CHANGED
@@ -1,4 +1,7 @@
1
+ /// <reference types="node" />
2
+ import type * as net from 'net';
1
3
  import type * as ts from 'typescript';
4
+ import type { NamedPipeServer } from './utils';
2
5
  export declare function collectExtractProps(...args: Parameters<typeof import('./requests/collectExtractProps.js')['collectExtractProps']>): Promise<{
3
6
  name: string;
4
7
  type: string;
@@ -11,3 +14,4 @@ export declare function getComponentEvents(...args: Parameters<typeof import('./
11
14
  export declare function getTemplateContextProps(...args: Parameters<typeof import('./requests/componentInfos.js')['getTemplateContextProps']>): Promise<string[] | null | undefined>;
12
15
  export declare function getComponentNames(...args: Parameters<typeof import('./requests/componentInfos.js')['getComponentNames']>): Promise<string[] | null | undefined>;
13
16
  export declare function getElementAttrs(...args: Parameters<typeof import('./requests/componentInfos.js')['getElementAttrs']>): Promise<string[] | null | undefined>;
17
+ export declare function connectForFile(fileName: string): Promise<readonly [net.Socket, NamedPipeServer] | undefined>;
package/lib/client.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getElementAttrs = exports.getComponentNames = exports.getTemplateContextProps = exports.getComponentEvents = exports.getComponentProps = exports.getQuickInfoAtPosition = exports.getPropertiesAtLocation = exports.collectExtractProps = void 0;
4
- const net = require("net");
3
+ exports.connectForFile = exports.getElementAttrs = exports.getComponentNames = exports.getTemplateContextProps = exports.getComponentEvents = exports.getComponentProps = exports.getQuickInfoAtPosition = exports.getPropertiesAtLocation = exports.collectExtractProps = void 0;
5
4
  const fs = require("fs");
5
+ const path = require("path");
6
6
  const utils_1 = require("./utils");
7
7
  function collectExtractProps(...args) {
8
8
  return sendRequest({
@@ -62,58 +62,52 @@ function getElementAttrs(...args) {
62
62
  }
63
63
  exports.getElementAttrs = getElementAttrs;
64
64
  async function sendRequest(request) {
65
- const pipeFile = await getPipeFile(request.args[0]);
66
- if (!pipeFile) {
67
- console.error('[Vue Named Pipe Client] pipeFile not found');
65
+ const connected = await connectForFile(request.args[0]);
66
+ if (!connected) {
67
+ console.warn('[Vue Named Pipe Client] No server found for', request.args[0]);
68
68
  return;
69
69
  }
70
- return await _sendRequest(request, pipeFile);
70
+ const [client] = connected;
71
+ const result = await sendRequestWorker(request, client);
72
+ client.end();
73
+ return result;
71
74
  }
72
- async function getPipeFile(fileName) {
73
- if (fs.existsSync(utils_1.pipeTable)) {
74
- const table = JSON.parse(fs.readFileSync(utils_1.pipeTable, 'utf8'));
75
- const all = Object.values(table);
76
- const configuredServers = all
77
- .filter(item => item.serverKind === 1)
78
- .sort((a, b) => Math.abs(process.pid - a.pid) - Math.abs(process.pid - b.pid));
79
- const inferredServers = all
80
- .filter(item => item.serverKind === 0)
81
- .sort((a, b) => Math.abs(process.pid - a.pid) - Math.abs(process.pid - b.pid));
82
- for (const server of configuredServers) {
83
- const response = await _sendRequest({ type: 'containsFile', args: [fileName] }, server.pipeFile);
75
+ async function connectForFile(fileName) {
76
+ if (!fs.existsSync(utils_1.pipeTable)) {
77
+ return;
78
+ }
79
+ const servers = JSON.parse(fs.readFileSync(utils_1.pipeTable, 'utf8'));
80
+ const configuredServers = servers
81
+ .filter(item => item.serverKind === 1);
82
+ const inferredServers = servers
83
+ .filter(item => item.serverKind === 0)
84
+ .sort((a, b) => b.currentDirectory.length - a.currentDirectory.length);
85
+ for (const server of configuredServers) {
86
+ const client = await (0, utils_1.connect)(server.path);
87
+ if (client) {
88
+ const response = await sendRequestWorker({ type: 'containsFile', args: [fileName] }, client);
84
89
  if (response) {
85
- return server.pipeFile;
90
+ return [client, server];
86
91
  }
87
92
  }
88
- for (const server of inferredServers) {
89
- const response = await _sendRequest({ type: 'containsFile', args: [fileName] }, server.pipeFile);
90
- if (typeof response === 'boolean') {
91
- return server.pipeFile;
93
+ }
94
+ for (const server of inferredServers) {
95
+ if (!path.relative(server.currentDirectory, fileName).startsWith('..')) {
96
+ const client = await (0, utils_1.connect)(server.path);
97
+ if (client) {
98
+ return [client, server];
92
99
  }
93
100
  }
94
101
  }
95
102
  }
96
- function _sendRequest(request, pipeFile) {
103
+ exports.connectForFile = connectForFile;
104
+ function sendRequestWorker(request, client) {
97
105
  return new Promise(resolve => {
98
- try {
99
- const client = net.connect(pipeFile);
100
- client.on('connect', () => {
101
- client.write(JSON.stringify(request));
102
- });
103
- client.on('data', data => {
104
- const text = data.toString();
105
- resolve(JSON.parse(text));
106
- client.end();
107
- });
108
- client.on('error', err => {
109
- console.error('[Vue Named Pipe Client]', err);
110
- return resolve(undefined);
111
- });
112
- }
113
- catch (e) {
114
- console.error('[Vue Named Pipe Client]', e);
115
- return resolve(undefined);
116
- }
106
+ client.once('data', data => {
107
+ const text = data.toString();
108
+ resolve(JSON.parse(text));
109
+ });
110
+ client.write(JSON.stringify(request));
117
111
  });
118
112
  }
119
113
  //# sourceMappingURL=client.js.map
package/lib/server.d.ts CHANGED
@@ -3,4 +3,4 @@ export interface Request {
3
3
  type: 'containsFile' | 'collectExtractProps' | 'getPropertiesAtLocation' | 'getQuickInfoAtPosition' | 'getComponentProps' | 'getComponentEvents' | 'getTemplateContextProps' | 'getComponentNames' | 'getElementAttrs';
4
4
  args: any;
5
5
  }
6
- export declare function startNamedPipeServer(serverKind: ts.server.ProjectKind): void;
6
+ export declare function startNamedPipeServer(serverKind: ts.server.ProjectKind, currentDirectory: string): void;
package/lib/server.js CHANGED
@@ -10,7 +10,7 @@ const getPropertiesAtLocation_1 = require("./requests/getPropertiesAtLocation");
10
10
  const getQuickInfoAtPosition_1 = require("./requests/getQuickInfoAtPosition");
11
11
  const utils_1 = require("./utils");
12
12
  let started = false;
13
- function startNamedPipeServer(serverKind) {
13
+ function startNamedPipeServer(serverKind, currentDirectory) {
14
14
  if (started)
15
15
  return;
16
16
  started = true;
@@ -65,16 +65,16 @@ function startNamedPipeServer(serverKind) {
65
65
  });
66
66
  connection.on('error', err => console.error('[Vue Named Pipe Server]', err.message));
67
67
  });
68
- clearupPipeTable();
68
+ cleanupPipeTable();
69
69
  if (!fs.existsSync(utils_1.pipeTable)) {
70
- fs.writeFileSync(utils_1.pipeTable, JSON.stringify({}));
70
+ fs.writeFileSync(utils_1.pipeTable, JSON.stringify([]));
71
71
  }
72
72
  const table = JSON.parse(fs.readFileSync(utils_1.pipeTable, 'utf8'));
73
- table[process.pid] = {
74
- pid: process.pid,
75
- pipeFile,
73
+ table.push({
74
+ path: pipeFile,
76
75
  serverKind,
77
- };
76
+ currentDirectory,
77
+ });
78
78
  fs.writeFileSync(utils_1.pipeTable, JSON.stringify(table, undefined, 2));
79
79
  try {
80
80
  fs.unlinkSync(pipeFile);
@@ -83,24 +83,21 @@ function startNamedPipeServer(serverKind) {
83
83
  server.listen(pipeFile);
84
84
  }
85
85
  exports.startNamedPipeServer = startNamedPipeServer;
86
- function clearupPipeTable() {
87
- if (fs.existsSync(utils_1.pipeTable)) {
88
- const table = JSON.parse(fs.readFileSync(utils_1.pipeTable, 'utf8'));
89
- for (const pid in table) {
90
- const { pipeFile } = table[pid];
91
- try {
92
- const client = net.connect(pipeFile);
93
- client.on('connect', () => {
94
- client.end();
95
- });
96
- client.on('error', () => {
97
- const table = JSON.parse(fs.readFileSync(utils_1.pipeTable, 'utf8'));
98
- delete table[pid];
99
- fs.writeFileSync(utils_1.pipeTable, JSON.stringify(table, undefined, 2));
100
- });
86
+ function cleanupPipeTable() {
87
+ if (!fs.existsSync(utils_1.pipeTable)) {
88
+ return;
89
+ }
90
+ for (const server of JSON.parse(fs.readFileSync(utils_1.pipeTable, 'utf8'))) {
91
+ (0, utils_1.connect)(server.path).then(client => {
92
+ if (client) {
93
+ client.end();
101
94
  }
102
- catch { }
103
- }
95
+ else {
96
+ let table = JSON.parse(fs.readFileSync(utils_1.pipeTable, 'utf8'));
97
+ table = table.filter(item => item.path !== server.path);
98
+ fs.writeFileSync(utils_1.pipeTable, JSON.stringify(table, undefined, 2));
99
+ }
100
+ });
104
101
  }
105
102
  }
106
103
  //# sourceMappingURL=server.js.map
package/lib/utils.d.ts CHANGED
@@ -1,11 +1,11 @@
1
+ /// <reference types="node" />
1
2
  import type { FileRegistry, VueCompilerOptions } from '@vue/language-core';
3
+ import * as net from 'net';
2
4
  import type * as ts from 'typescript';
3
- export interface PipeTable {
4
- [pid: string]: {
5
- pid: number;
6
- pipeFile: string;
7
- serverKind: ts.server.ProjectKind;
8
- };
5
+ export interface NamedPipeServer {
6
+ path: string;
7
+ serverKind: ts.server.ProjectKind;
8
+ currentDirectory: string;
9
9
  }
10
10
  export declare const pipeTable: string;
11
11
  export declare const projects: Map<ts.server.Project, {
@@ -29,3 +29,4 @@ export declare function getProject(fileName: string): {
29
29
  ts: typeof ts;
30
30
  vueOptions: VueCompilerOptions;
31
31
  } | undefined;
32
+ export declare function connect(path: string): Promise<net.Socket | undefined>;
package/lib/utils.js CHANGED
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getProject = exports.projects = exports.pipeTable = void 0;
3
+ exports.connect = exports.getProject = exports.projects = exports.pipeTable = void 0;
4
4
  const os = require("os");
5
+ const net = require("net");
5
6
  const path = require("path");
6
- exports.pipeTable = path.join(os.tmpdir(), 'vue-tsp-table.json');
7
+ const { version } = require('../package.json');
8
+ exports.pipeTable = path.join(os.tmpdir(), `vue-tsp-table-${version}.json`);
7
9
  exports.projects = new Map();
8
10
  function getProject(fileName) {
9
11
  for (const [project, data] of exports.projects) {
@@ -13,4 +15,16 @@ function getProject(fileName) {
13
15
  }
14
16
  }
15
17
  exports.getProject = getProject;
18
+ function connect(path) {
19
+ return new Promise(resolve => {
20
+ const client = net.connect(path);
21
+ client.on('connect', () => {
22
+ resolve(client);
23
+ });
24
+ client.on('error', () => {
25
+ return resolve(undefined);
26
+ });
27
+ });
28
+ }
29
+ exports.connect = connect;
16
30
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/typescript-plugin",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -13,11 +13,11 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "@volar/typescript": "~2.1.0",
16
- "@vue/language-core": "2.0.2",
16
+ "@vue/language-core": "2.0.3",
17
17
  "@vue/shared": "^3.4.0"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/node": "latest"
21
21
  },
22
- "gitHead": "b377d5f990ffe7ef44f0d1871fcb8b5c2deafad1"
22
+ "gitHead": "fc1e288c8c0c82e6730781006d84a2676b5266ff"
23
23
  }