Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vue/typescript-plugin

Package Overview
Dependencies
Maintainers
0
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vue/typescript-plugin - npm Package Compare versions

Comparing version 2.0.26 to 2.0.28

16

index.js

@@ -9,17 +9,13 @@ "use strict";

const vueOptions = getVueCompilerOptions();
const languagePlugin = vue.createVueLanguagePlugin(ts, id => id, () => info.languageServiceHost.getProjectVersion?.() ?? '', info.project.projectKind === ts.server.ProjectKind.Inferred
const languagePlugin = vue.createVueLanguagePlugin2(ts, id => id, info.project.projectKind === ts.server.ProjectKind.Inferred
? () => true
: fileName => {
const fileMap = new vue.FileMap(info.languageServiceHost.useCaseSensitiveFileNames?.() ?? false);
for (const vueFileName of createLanguageServicePlugin_1.externalFiles.get(info.project) ?? []) {
fileMap.set(vueFileName, undefined);
}
return fileMap.has(fileName);
}, info.languageServiceHost.getCompilationSettings(), vueOptions);
: vue.createRootFileChecker(info.languageServiceHost.getProjectVersion ? () => info.languageServiceHost.getProjectVersion() : undefined, () => createLanguageServicePlugin_1.externalFiles.get(info.project) ?? [], info.languageServiceHost.useCaseSensitiveFileNames?.() ?? false), info.languageServiceHost.getCompilationSettings(), vueOptions);
return {
languagePlugins: [languagePlugin],
setup: language => {
server_1.projects.set(info.project, { info, language, vueOptions });
info.languageService = (0, common_1.proxyLanguageServiceForVue)(ts, language, info.languageService, vueOptions, fileName => fileName);
(0, server_1.startNamedPipeServer)(ts, info.project.projectKind, info.project.getCurrentDirectory());
if (info.project.projectKind === ts.server.ProjectKind.Configured
|| info.project.projectKind === ts.server.ProjectKind.Inferred) {
(0, server_1.startNamedPipeServer)(ts, info, language, info.project.projectKind);
}
// #3963

@@ -26,0 +22,0 @@ const timer = setInterval(() => {

@@ -69,3 +69,3 @@ "use strict";

async function sendRequest(request) {
const server = (await (0, utils_1.searchNamedPipeServerForFile)(request.args[0]))?.server;
const server = (await (0, utils_1.searchNamedPipeServerForFile)(request.args[0]));
if (!server) {

@@ -75,9 +75,6 @@ console.warn('[Vue Named Pipe Client] No server found for', request.args[0]);

}
const client = await (0, utils_1.connect)(server.path);
if (!client) {
console.warn('[Vue Named Pipe Client] Failed to connect to', server.path);
return;
}
return await (0, utils_1.sendRequestWorker)(request, client);
const res = await (0, utils_1.sendRequestWorker)(request, server.socket);
server.socket.end();
return res;
}
//# sourceMappingURL=client.js.map

@@ -1,12 +0,12 @@

import type { Language, VueCompilerOptions } from '@vue/language-core';
import type { Language } from '@vue/language-core';
import type * as ts from 'typescript';
export interface Request {
type: 'projectInfoForFile' | 'collectExtractProps' | 'getImportPathForFile' | 'getPropertiesAtLocation' | 'getQuickInfoAtPosition' | 'getComponentProps' | 'getComponentEvents' | 'getTemplateContextProps' | 'getComponentNames' | 'getElementAttrs';
type: 'containsFile' | 'projectInfo' | 'collectExtractProps' | 'getImportPathForFile' | 'getPropertiesAtLocation' | 'getQuickInfoAtPosition' | 'getComponentProps' | 'getComponentEvents' | 'getTemplateContextProps' | 'getComponentNames' | 'getElementAttrs';
args: [fileName: string, ...rest: any];
}
export declare function startNamedPipeServer(ts: typeof import('typescript'), serverKind: ts.server.ProjectKind, currentDirectory: string): void;
export declare const projects: Map<ts.server.Project, {
info: ts.server.PluginCreateInfo;
language: Language<string>;
vueOptions: VueCompilerOptions;
}>;
export interface ProjectInfo {
name: string;
kind: ts.server.ProjectKind;
currentDirectory: string;
}
export declare function startNamedPipeServer(ts: typeof import('typescript'), info: ts.server.PluginCreateInfo, language: Language<string>, projectKind: ts.server.ProjectKind.Inferred | ts.server.ProjectKind.Configured): Promise<void>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.projects = void 0;
exports.startNamedPipeServer = startNamedPipeServer;

@@ -13,118 +12,114 @@ const fs = require("fs");

const utils_1 = require("./utils");
let started = false;
function startNamedPipeServer(ts, serverKind, currentDirectory) {
if (started) {
return;
}
started = true;
const pipeFile = process.platform === 'win32'
? `\\\\.\\pipe\\vue-tsp-${process.pid}`
: `/tmp/vue-tsp-${process.pid}`;
async function startNamedPipeServer(ts, info, language, projectKind) {
const server = net.createServer(connection => {
connection.on('data', data => {
const text = data.toString();
if (text === 'ping') {
connection.write('pong');
return;
}
const request = JSON.parse(text);
const fileName = request.args[0];
const project = getProject(ts.server.toNormalizedPath(fileName));
if (request.type === 'projectInfoForFile') {
connection.write(JSON.stringify(project
? {
name: project.info.project.getProjectName(),
kind: project.info.project.projectKind,
}
: null));
if (request.type === 'containsFile') {
sendResponse(info.project.containsFile(ts.server.toNormalizedPath(fileName)));
}
else if (project) {
const requestContext = {
typescript: ts,
languageService: project.info.languageService,
languageServiceHost: project.info.languageServiceHost,
language: project.language,
isTsPlugin: true,
getFileId: (fileName) => fileName,
};
if (request.type === 'collectExtractProps') {
const result = collectExtractProps_1.collectExtractProps.apply(requestContext, request.args);
connection.write(JSON.stringify(result ?? null));
}
else if (request.type === 'getImportPathForFile') {
const result = getImportPathForFile_1.getImportPathForFile.apply(requestContext, request.args);
connection.write(JSON.stringify(result ?? null));
}
else if (request.type === 'getPropertiesAtLocation') {
const result = getPropertiesAtLocation_1.getPropertiesAtLocation.apply(requestContext, request.args);
connection.write(JSON.stringify(result ?? null));
}
else if (request.type === 'getQuickInfoAtPosition') {
const result = getQuickInfoAtPosition_1.getQuickInfoAtPosition.apply(requestContext, request.args);
connection.write(JSON.stringify(result ?? null));
}
// Component Infos
else if (request.type === 'getComponentProps') {
const result = componentInfos_1.getComponentProps.apply(requestContext, request.args);
connection.write(JSON.stringify(result ?? null));
}
else if (request.type === 'getComponentEvents') {
const result = componentInfos_1.getComponentEvents.apply(requestContext, request.args);
connection.write(JSON.stringify(result ?? null));
}
else if (request.type === 'getTemplateContextProps') {
const result = componentInfos_1.getTemplateContextProps.apply(requestContext, request.args);
connection.write(JSON.stringify(result ?? null));
}
else if (request.type === 'getComponentNames') {
const result = componentInfos_1.getComponentNames.apply(requestContext, request.args);
connection.write(JSON.stringify(result ?? null));
}
else if (request.type === 'getElementAttrs') {
const result = componentInfos_1.getElementAttrs.apply(requestContext, request.args);
connection.write(JSON.stringify(result ?? null));
}
else {
console.warn('[Vue Named Pipe Server] Unknown request type:', request.type);
}
if (request.type === 'projectInfo') {
sendResponse({
name: info.project.getProjectName(),
kind: info.project.projectKind,
currentDirectory: info.project.getCurrentDirectory(),
});
}
const requestContext = {
typescript: ts,
languageService: info.languageService,
languageServiceHost: info.languageServiceHost,
language: language,
isTsPlugin: true,
getFileId: (fileName) => fileName,
};
if (request.type === 'collectExtractProps') {
const result = collectExtractProps_1.collectExtractProps.apply(requestContext, request.args);
sendResponse(result);
}
else if (request.type === 'getImportPathForFile') {
const result = getImportPathForFile_1.getImportPathForFile.apply(requestContext, request.args);
sendResponse(result);
}
else if (request.type === 'getPropertiesAtLocation') {
const result = getPropertiesAtLocation_1.getPropertiesAtLocation.apply(requestContext, request.args);
sendResponse(result);
}
else if (request.type === 'getQuickInfoAtPosition') {
const result = getQuickInfoAtPosition_1.getQuickInfoAtPosition.apply(requestContext, request.args);
sendResponse(result);
}
// Component Infos
else if (request.type === 'getComponentProps') {
const result = componentInfos_1.getComponentProps.apply(requestContext, request.args);
sendResponse(result);
}
else if (request.type === 'getComponentEvents') {
const result = componentInfos_1.getComponentEvents.apply(requestContext, request.args);
sendResponse(result);
}
else if (request.type === 'getTemplateContextProps') {
const result = componentInfos_1.getTemplateContextProps.apply(requestContext, request.args);
sendResponse(result);
}
else if (request.type === 'getComponentNames') {
const result = componentInfos_1.getComponentNames.apply(requestContext, request.args);
sendResponse(result);
}
else if (request.type === 'getElementAttrs') {
const result = componentInfos_1.getElementAttrs.apply(requestContext, request.args);
sendResponse(result);
}
else {
console.warn('[Vue Named Pipe Server] No project found for:', fileName);
console.warn('[Vue Named Pipe Server] Unknown request type:', request.type);
}
connection.end();
});
connection.on('error', err => console.error('[Vue Named Pipe Server]', err.message));
function sendResponse(data) {
connection.write(JSON.stringify(data ?? null) + '\n\n');
}
});
cleanupPipeTable();
const table = (0, utils_1.readPipeTable)();
table.push({
path: pipeFile,
serverKind,
currentDirectory,
});
(0, utils_1.updatePipeTable)(table);
try {
fs.unlinkSync(pipeFile);
for (let i = 0; i < 20; i++) {
const path = (0, utils_1.getNamedPipePath)(projectKind, i);
const socket = await (0, utils_1.connect)(path, 100);
if (typeof socket === 'object') {
socket.end();
}
const namedPipeOccupied = typeof socket === 'object' || socket === 'timeout';
if (namedPipeOccupied) {
continue;
}
const success = await tryListen(server, path);
if (success) {
break;
}
}
catch { }
server.listen(pipeFile);
}
function cleanupPipeTable() {
for (const server of (0, utils_1.readPipeTable)()) {
(0, utils_1.connect)(server.path).then(client => {
if (client) {
client.end();
function tryListen(server, namedPipePath) {
return new Promise(resolve => {
const onSuccess = () => {
server.off('error', onError);
resolve(true);
};
const onError = (err) => {
if (err.code === 'ECONNREFUSED') {
try {
console.log('[Vue Named Pipe Client] Deleting:', namedPipePath);
fs.promises.unlink(namedPipePath);
}
catch { }
}
else {
let table = (0, utils_1.readPipeTable)();
table = table.filter(item => item.path !== server.path);
(0, utils_1.updatePipeTable)(table);
}
});
}
server.off('error', onError);
server.close();
resolve(false);
};
server.listen(namedPipePath, onSuccess);
server.on('error', onError);
});
}
exports.projects = new Map();
function getProject(filename) {
for (const [project, data] of exports.projects) {
if (project.containsFile(filename)) {
return data;
}
}
}
//# sourceMappingURL=server.js.map
import * as net from 'net';
import type * as ts from 'typescript';
import type { Request } from './server';
import type { ProjectInfo, Request } from './server';
export { TypeScriptProjectHost } from '@volar/typescript';
export interface NamedPipeServer {
path: string;
serverKind: ts.server.ProjectKind;
currentDirectory: string;
}
export declare function readPipeTable(): NamedPipeServer[];
export declare function updatePipeTable(servers: NamedPipeServer[]): void;
export declare function connect(path: string): Promise<net.Socket | undefined>;
export declare const onSomePipeReadyCallbacks: (() => void)[];
export declare function getNamedPipePath(projectKind: ts.server.ProjectKind.Configured | ts.server.ProjectKind.Inferred, key: number): string;
export declare function getReadyNamedPipePaths(): {
configured: string[];
inferred: string[];
};
export declare function connect(namedPipePath: string, timeout?: number): Promise<net.Socket | "error" | "timeout">;
export declare function searchNamedPipeServerForFile(fileName: string): Promise<{
server: NamedPipeServer;
projectInfo: {
name: string;
kind: ts.server.ProjectKind;
};
} | {
server: NamedPipeServer;
projectInfo: undefined;
socket: net.Socket;
projectInfo: ProjectInfo;
} | undefined>;
export declare function sendRequestWorker<T>(request: Request, client: net.Socket): Promise<T | null | undefined>;
export declare function sendRequestWorker<T>(request: Request, socket: net.Socket): Promise<T | null | undefined>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.readPipeTable = readPipeTable;
exports.updatePipeTable = updatePipeTable;
exports.onSomePipeReadyCallbacks = void 0;
exports.getNamedPipePath = getNamedPipePath;
exports.getReadyNamedPipePaths = getReadyNamedPipePaths;
exports.connect = connect;
exports.searchNamedPipeServerForFile = searchNamedPipeServerForFile;
exports.sendRequestWorker = sendRequestWorker;
const fs = require("fs");
const net = require("net");
const os = require("os");
const net = require("net");
const path = require("path");
const fs = require("fs");
const { version } = require('../package.json');
const pipeTableFile = path.join(os.tmpdir(), `vue-tsp-table-${version}.json`);
function readPipeTable() {
if (!fs.existsSync(pipeTableFile)) {
return [];
const platform = os.platform();
const pipeDir = platform === 'win32'
? `\\\\.\\pipe`
: `/tmp`;
const toFullPath = (file) => {
if (platform === 'win32') {
return pipeDir + '\\' + file;
}
try {
const servers = JSON.parse(fs.readFileSync(pipeTableFile, 'utf8'));
return servers;
else {
return pipeDir + '/' + file;
}
catch {
fs.unlinkSync(pipeTableFile);
return [];
}
};
const configuredNamedPipePathPrefix = toFullPath(`vue-named-pipe-${version}-configured-`);
const inferredNamedPipePathPrefix = toFullPath(`vue-named-pipe-${version}-inferred-`);
const pipes = new Map();
exports.onSomePipeReadyCallbacks = [];
function watchNamedPipeReady(namedPipePath) {
const socket = net.connect(namedPipePath);
const start = Date.now();
socket.on('connect', () => {
console.log('[Vue Named Pipe Client] Connected:', namedPipePath, 'in', (Date.now() - start) + 'ms');
socket.write('ping');
});
socket.on('data', () => {
console.log('[Vue Named Pipe Client] Ready:', namedPipePath, 'in', (Date.now() - start) + 'ms');
pipes.set(namedPipePath, 'ready');
socket.end();
exports.onSomePipeReadyCallbacks.forEach(cb => cb());
});
socket.on('error', err => {
if (err.code === 'ECONNREFUSED') {
try {
console.log('[Vue Named Pipe Client] Deleting:', namedPipePath);
fs.promises.unlink(namedPipePath);
}
catch { }
}
pipes.delete(namedPipePath);
socket.end();
});
}
function updatePipeTable(servers) {
if (servers.length === 0) {
fs.unlinkSync(pipeTableFile);
function getNamedPipePath(projectKind, key) {
return projectKind === 1
? `${configuredNamedPipePathPrefix}${key}`
: `${inferredNamedPipePathPrefix}${key}`;
}
function getReadyNamedPipePaths() {
const configuredPipes = [];
const inferredPipes = [];
for (let i = 0; i < 20; i++) {
const configuredPipe = getNamedPipePath(1, i);
const inferredPipe = getNamedPipePath(0, i);
if (pipes.get(configuredPipe) === 'ready') {
configuredPipes.push(configuredPipe);
}
else if (!pipes.has(configuredPipe)) {
pipes.set(configuredPipe, 'unknown');
watchNamedPipeReady(configuredPipe);
}
if (pipes.get(inferredPipe) === 'ready') {
inferredPipes.push(inferredPipe);
}
else if (!pipes.has(inferredPipe)) {
pipes.set(inferredPipe, 'unknown');
watchNamedPipeReady(inferredPipe);
}
}
else {
fs.writeFileSync(pipeTableFile, JSON.stringify(servers, undefined, 2));
}
return {
configured: configuredPipes,
inferred: inferredPipes,
};
}
function connect(path) {
function connect(namedPipePath, timeout) {
return new Promise(resolve => {
const client = net.connect(path);
client.setTimeout(1000);
client.on('connect', () => {
resolve(client);
});
client.on('error', () => {
return resolve(undefined);
});
client.on('timeout', () => {
return resolve(undefined);
});
const socket = net.connect(namedPipePath);
if (timeout) {
socket.setTimeout(timeout);
}
const onConnect = () => {
cleanup();
resolve(socket);
};
const onError = (err) => {
if (err.code === 'ECONNREFUSED') {
try {
console.log('[Vue Named Pipe Client] Deleting:', namedPipePath);
fs.promises.unlink(namedPipePath);
}
catch { }
}
pipes.delete(namedPipePath);
cleanup();
resolve('error');
};
const onTimeout = () => {
cleanup();
resolve('timeout');
};
const cleanup = () => {
socket.off('connect', onConnect);
socket.off('error', onError);
socket.off('timeout', onTimeout);
};
socket.on('connect', onConnect);
socket.on('error', onError);
socket.on('timeout', onTimeout);
});
}
async function searchNamedPipeServerForFile(fileName) {
const servers = readPipeTable();
const configuredServers = servers
.filter(item => item.serverKind === 1);
const inferredServers = servers
.filter(item => item.serverKind === 0)
.sort((a, b) => b.currentDirectory.length - a.currentDirectory.length);
for (const server of configuredServers.sort((a, b) => sortTSConfigs(fileName, a.currentDirectory, b.currentDirectory))) {
const client = await connect(server.path);
if (client) {
const projectInfo = await sendRequestWorker({ type: 'projectInfoForFile', args: [fileName] }, client);
if (projectInfo) {
return {
server,
projectInfo,
};
}
const paths = await getReadyNamedPipePaths();
const configuredServers = (await Promise.all(paths.configured.map(async (path) => {
// Find existing servers
const socket = await connect(path);
if (typeof socket !== 'object') {
return;
}
// Find servers containing the current file
const containsFile = await sendRequestWorker({ type: 'containsFile', args: [fileName] }, socket);
if (!containsFile) {
socket.end();
return;
}
// Get project info for each server
const projectInfo = await sendRequestWorker({ type: 'projectInfo', args: [fileName] }, socket);
if (!projectInfo) {
socket.end();
return;
}
return {
socket,
projectInfo,
};
}))).filter(server => !!server);
// Sort servers by tsconfig
configuredServers.sort((a, b) => sortTSConfigs(fileName, a.projectInfo.name, b.projectInfo.name));
if (configuredServers.length) {
// Close all but the first server
for (let i = 1; i < configuredServers.length; i++) {
configuredServers[i].socket.end();
}
// Return the first server
return configuredServers[0];
}
for (const server of inferredServers) {
if (!path.relative(server.currentDirectory, fileName).startsWith('..')) {
const client = await connect(server.path);
if (client) {
return {
server,
projectInfo: undefined,
};
}
const inferredServers = (await Promise.all(paths.inferred.map(async (namedPipePath) => {
// Find existing servers
const socket = await connect(namedPipePath);
if (typeof socket !== 'object') {
return;
}
// Get project info for each server
const projectInfo = await sendRequestWorker({ type: 'projectInfo', args: [fileName] }, socket);
if (!projectInfo) {
socket.end();
return;
}
// Check if the file is in the project's directory
if (!path.relative(projectInfo.currentDirectory, fileName).startsWith('..')) {
return {
socket,
projectInfo,
};
}
}))).filter(server => !!server);
// Sort servers by directory
inferredServers.sort((a, b) => b.projectInfo.currentDirectory.replace(/\\/g, '/').split('/').length
- a.projectInfo.currentDirectory.replace(/\\/g, '/').split('/').length);
if (inferredServers.length) {
// Close all but the first server
for (let i = 1; i < inferredServers.length; i++) {
inferredServers[i].socket.end();
}
// Return the first server
return inferredServers[0];
}

@@ -97,39 +205,35 @@ }

}
function sendRequestWorker(request, client) {
function sendRequestWorker(request, socket) {
return new Promise(resolve => {
let dataChunks = [];
client.setTimeout(5000);
client.on('data', chunk => {
const onData = (chunk) => {
dataChunks.push(chunk);
});
client.on('end', () => {
if (!dataChunks.length) {
console.warn('[Vue Named Pipe Client] No response from server for request:', request.type);
resolve(undefined);
return;
}
const data = Buffer.concat(dataChunks);
const text = data.toString();
let json = null;
try {
json = JSON.parse(text);
if (text.endsWith('\n\n')) {
let json = null;
try {
json = JSON.parse(text);
}
catch (e) {
console.error('[Vue Named Pipe Client] Failed to parse response:', text);
}
cleanup();
resolve(json);
}
catch (e) {
console.error('[Vue Named Pipe Client] Failed to parse response:', text);
resolve(undefined);
return;
}
resolve(json);
});
client.on('error', err => {
};
const onError = (err) => {
console.error('[Vue Named Pipe Client] Error:', err.message);
cleanup();
resolve(undefined);
});
client.on('timeout', () => {
console.error('[Vue Named Pipe Client] Timeout');
resolve(undefined);
});
client.write(JSON.stringify(request));
};
const cleanup = () => {
socket.off('data', onData);
socket.off('error', onError);
};
socket.on('data', onData);
socket.on('error', onError);
socket.write(JSON.stringify(request));
});
}
//# sourceMappingURL=utils.js.map
{
"name": "@vue/typescript-plugin",
"version": "2.0.26",
"version": "2.0.28",
"license": "MIT",

@@ -15,4 +15,4 @@ "files": [

"dependencies": {
"@volar/typescript": "~2.4.0-alpha.15",
"@vue/language-core": "2.0.26",
"@volar/typescript": "~2.4.0-alpha.18",
"@vue/language-core": "2.0.28",
"@vue/shared": "^3.4.0"

@@ -23,3 +23,3 @@ },

},
"gitHead": "47924f61e9409501d11ab04e9d3417cc5c86232c"
"gitHead": "0cdbd70996f4fc7ac8d511b0d9fdbe20b7a4f6a3"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc