@vue/typescript-plugin 2.0.2 → 2.0.4

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,5 @@
1
1
  import type * as ts from 'typescript';
2
+ import type { NamedPipeServer } from './utils';
2
3
  export declare function collectExtractProps(...args: Parameters<typeof import('./requests/collectExtractProps.js')['collectExtractProps']>): Promise<{
3
4
  name: string;
4
5
  type: string;
@@ -11,3 +12,4 @@ export declare function getComponentEvents(...args: Parameters<typeof import('./
11
12
  export declare function getTemplateContextProps(...args: Parameters<typeof import('./requests/componentInfos.js')['getTemplateContextProps']>): Promise<string[] | null | undefined>;
12
13
  export declare function getComponentNames(...args: Parameters<typeof import('./requests/componentInfos.js')['getComponentNames']>): Promise<string[] | null | undefined>;
13
14
  export declare function getElementAttrs(...args: Parameters<typeof import('./requests/componentInfos.js')['getElementAttrs']>): Promise<string[] | null | undefined>;
15
+ export declare function searchNamedPipeServerForFile(fileName: string): Promise<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.searchNamedPipeServerForFile = 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,59 @@ 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 server = await searchNamedPipeServerForFile(request.args[0]);
66
+ if (!server) {
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 = await (0, utils_1.connect)(server.path);
71
+ if (!client) {
72
+ console.warn('[Vue Named Pipe Client] Failed to connect to', server.path);
73
+ return;
74
+ }
75
+ return await sendRequestWorker(request, client);
71
76
  }
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);
77
+ async function searchNamedPipeServerForFile(fileName) {
78
+ if (!fs.existsSync(utils_1.pipeTable)) {
79
+ return;
80
+ }
81
+ const servers = JSON.parse(fs.readFileSync(utils_1.pipeTable, 'utf8'));
82
+ const configuredServers = servers
83
+ .filter(item => item.serverKind === 1);
84
+ const inferredServers = servers
85
+ .filter(item => item.serverKind === 0)
86
+ .sort((a, b) => b.currentDirectory.length - a.currentDirectory.length);
87
+ for (const server of configuredServers) {
88
+ const client = await (0, utils_1.connect)(server.path);
89
+ if (client) {
90
+ const response = await sendRequestWorker({ type: 'containsFile', args: [fileName] }, client);
84
91
  if (response) {
85
- return server.pipeFile;
92
+ return server;
86
93
  }
87
94
  }
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;
95
+ }
96
+ for (const server of inferredServers) {
97
+ if (!path.relative(server.currentDirectory, fileName).startsWith('..')) {
98
+ const client = await (0, utils_1.connect)(server.path);
99
+ if (client) {
100
+ return server;
92
101
  }
93
102
  }
94
103
  }
95
104
  }
96
- function _sendRequest(request, pipeFile) {
105
+ exports.searchNamedPipeServerForFile = searchNamedPipeServerForFile;
106
+ function sendRequestWorker(request, client) {
97
107
  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
- }
108
+ let dataChunks = [];
109
+ client.on('data', chunk => {
110
+ dataChunks.push(chunk);
111
+ });
112
+ client.on('end', () => {
113
+ const data = Buffer.concat(dataChunks);
114
+ const text = data.toString();
115
+ resolve(JSON.parse(text));
116
+ });
117
+ client.write(JSON.stringify(request));
117
118
  });
118
119
  }
119
120
  //# 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;
@@ -62,19 +62,20 @@ function startNamedPipeServer(serverKind) {
62
62
  console.warn('[Vue Named Pipe Server] Unknown request type:', request.type);
63
63
  connection.write(JSON.stringify(null));
64
64
  }
65
+ connection.end();
65
66
  });
66
67
  connection.on('error', err => console.error('[Vue Named Pipe Server]', err.message));
67
68
  });
68
- clearupPipeTable();
69
+ cleanupPipeTable();
69
70
  if (!fs.existsSync(utils_1.pipeTable)) {
70
- fs.writeFileSync(utils_1.pipeTable, JSON.stringify({}));
71
+ fs.writeFileSync(utils_1.pipeTable, JSON.stringify([]));
71
72
  }
72
73
  const table = JSON.parse(fs.readFileSync(utils_1.pipeTable, 'utf8'));
73
- table[process.pid] = {
74
- pid: process.pid,
75
- pipeFile,
74
+ table.push({
75
+ path: pipeFile,
76
76
  serverKind,
77
- };
77
+ currentDirectory,
78
+ });
78
79
  fs.writeFileSync(utils_1.pipeTable, JSON.stringify(table, undefined, 2));
79
80
  try {
80
81
  fs.unlinkSync(pipeFile);
@@ -83,24 +84,21 @@ function startNamedPipeServer(serverKind) {
83
84
  server.listen(pipeFile);
84
85
  }
85
86
  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
- });
87
+ function cleanupPipeTable() {
88
+ if (!fs.existsSync(utils_1.pipeTable)) {
89
+ return;
90
+ }
91
+ for (const server of JSON.parse(fs.readFileSync(utils_1.pipeTable, 'utf8'))) {
92
+ (0, utils_1.connect)(server.path).then(client => {
93
+ if (client) {
94
+ client.end();
101
95
  }
102
- catch { }
103
- }
96
+ else {
97
+ let table = JSON.parse(fs.readFileSync(utils_1.pipeTable, 'utf8'));
98
+ table = table.filter(item => item.path !== server.path);
99
+ fs.writeFileSync(utils_1.pipeTable, JSON.stringify(table, undefined, 2));
100
+ }
101
+ });
104
102
  }
105
103
  }
106
104
  //# 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.4",
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.4",
17
17
  "@vue/shared": "^3.4.0"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/node": "latest"
21
21
  },
22
- "gitHead": "b377d5f990ffe7ef44f0d1871fcb8b5c2deafad1"
22
+ "gitHead": "241300968fd3084c7c09139d05691a51a7800fdc"
23
23
  }