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

@volar/typescript

Package Overview
Dependencies
Maintainers
1
Versions
225
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@volar/typescript - npm Package Compare versions

Comparing version 2.4.10 to 2.4.11

8

lib/node/decorateLanguageServiceHost.js

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

languageServiceHost.getScriptSnapshot = fileName => {
const virtualScript = updateVirtualScript(fileName);
const virtualScript = updateVirtualScript(fileName, true);
if (virtualScript) {

@@ -67,3 +67,3 @@ return virtualScript.snapshot;

languageServiceHost.getScriptKind = fileName => {
const virtualScript = updateVirtualScript(fileName);
const virtualScript = updateVirtualScript(fileName, false);
if (virtualScript) {

@@ -75,3 +75,3 @@ return virtualScript.scriptKind;

}
function updateVirtualScript(fileName) {
function updateVirtualScript(fileName, shouldRegister) {
if (crashFileNames.has(fileName)) {

@@ -95,3 +95,3 @@ return;

script = [version];
const sourceScript = language.scripts.get(fileName);
const sourceScript = language.scripts.get(fileName, undefined, shouldRegister);
if (sourceScript?.generated) {

@@ -98,0 +98,0 @@ const serviceScript = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);

@@ -25,4 +25,9 @@ "use strict";

info.languageServiceHost.getScriptSnapshot = fileName => {
if (!initialized && extensions.some(ext => fileName.endsWith(ext))) {
return emptySnapshot;
if (!initialized) {
if (extensions.some(ext => fileName.endsWith(ext))) {
return emptySnapshot;
}
if (getScriptInfo(fileName)?.isScriptOpen()) {
return emptySnapshot;
}
}

@@ -32,4 +37,9 @@ return getScriptSnapshot(fileName);

info.languageServiceHost.getScriptVersion = fileName => {
if (!initialized && extensions.some(ext => fileName.endsWith(ext))) {
return 'initializing...';
if (!initialized) {
if (extensions.some(ext => fileName.endsWith(ext))) {
return 'initializing...';
}
if (getScriptInfo(fileName)?.isScriptOpen()) {
return getScriptVersion(fileName) + ',initializing...';
}
}

@@ -67,18 +77,22 @@ return getScriptVersion(fileName);

{ getLanguageId: common_1.resolveFileLanguageId },
], new language_core_1.FileMap(ts.sys.useCaseSensitiveFileNames), fileName => {
try { // getSnapshot could be crashed if the file is too large
let snapshot = info.project.getScriptInfo(fileName)?.getSnapshot();
], new language_core_1.FileMap(ts.sys.useCaseSensitiveFileNames), (fileName, _, shouldRegister) => {
let snapshot;
if (shouldRegister) {
// We need to trigger registration of the script file with the project, see #250
snapshot = getScriptSnapshot(fileName);
}
else {
snapshot = getScriptInfo(fileName)?.getSnapshot();
if (!snapshot) {
// trigger projectService.getOrCreateScriptInfoNotOpenedByClient
info.project.getScriptVersion(fileName);
snapshot = info.project.getScriptInfo(fileName)?.getSnapshot();
snapshot = getScriptInfo(fileName)?.getSnapshot();
}
if (snapshot) {
language.scripts.set(fileName, snapshot);
}
else {
language.scripts.delete(fileName);
}
}
catch { }
if (snapshot) {
language.scripts.set(fileName, snapshot);
}
else {
language.scripts.delete(fileName);
}
});

@@ -88,9 +102,16 @@ initialize(language);

setup?.(language);
initialized = true;
if ('markAsDirty' in info.project && typeof info.project.markAsDirty === 'function') {
info.project.markAsDirty();
}
initialized = true;
});
}
return info.languageService;
function getScriptInfo(fileName) {
// getSnapshot could be crashed if the file is too large
try {
return info.project.getScriptInfo(fileName);
}
catch { }
}
},

@@ -97,0 +118,0 @@ getExternalFiles(project, updateLevel = 0) {

@@ -28,21 +28,26 @@ "use strict";

exports.projectExternalFileExtensions.set(info.project, extensions);
const getScriptSnapshot = info.languageServiceHost.getScriptSnapshot.bind(info.languageServiceHost);
const language = (0, language_core_1.createLanguage)([
...languagePlugins,
{ getLanguageId: common_1.resolveFileLanguageId },
], new language_core_1.FileMap(ts.sys.useCaseSensitiveFileNames), fileName => {
try { // getSnapshot could be crashed if the file is too large
let snapshot = info.project.getScriptInfo(fileName)?.getSnapshot();
], new language_core_1.FileMap(ts.sys.useCaseSensitiveFileNames), (fileName, _, shouldRegister) => {
let snapshot;
if (shouldRegister) {
// We need to trigger registration of the script file with the project, see #250
snapshot = getScriptSnapshot(fileName);
}
else {
snapshot = getScriptInfo(fileName)?.getSnapshot();
if (!snapshot) {
// trigger projectService.getOrCreateScriptInfoNotOpenedByClient
info.project.getScriptVersion(fileName);
snapshot = info.project.getScriptInfo(fileName)?.getSnapshot();
snapshot = getScriptInfo(fileName)?.getSnapshot();
}
if (snapshot) {
language.scripts.set(fileName, snapshot);
}
else {
language.scripts.delete(fileName);
}
}
catch { }
if (snapshot) {
language.scripts.set(fileName, snapshot);
}
else {
language.scripts.delete(fileName);
}
});

@@ -56,2 +61,9 @@ const { proxy, initialize } = (0, proxyLanguageService_1.createProxyLanguageService)(info.languageService);

return info.languageService;
function getScriptInfo(fileName) {
// getSnapshot could be crashed if the file is too large
try {
return info.project.getScriptInfo(fileName);
}
catch { }
}
},

@@ -58,0 +70,0 @@ getExternalFiles(project, updateLevel = 0) {

@@ -10,3 +10,3 @@ import type * as ts from 'typescript';

extraExtensionsToRemove: string[];
}, _getLanguagePlugins: typeof getLanguagePlugins): void;
}, _getLanguagePlugins: typeof getLanguagePlugins, typescriptObject?: string): void;
/**

@@ -20,4 +20,5 @@ * Replaces the code of typescript to add support for additional extensions and language plugins.

* @param getLanguagePluginsFile - The file to get language plugins from.
* @param typescriptObject - The object to use as typescript.
* @returns The modified typescript code.
*/
export declare function transformTscContent(tsc: string, proxyApiPath: string, extraSupportedExtensions: string[], extraExtensionsToRemove: string[], getLanguagePluginsFile?: string): string;
export declare function transformTscContent(tsc: string, proxyApiPath: string, extraSupportedExtensions: string[], extraExtensionsToRemove: string[], getLanguagePluginsFile?: string, typescriptObject?: string): string;

@@ -7,6 +7,17 @@ "use strict";

const fs = require("fs");
const path = require("path");
let getLanguagePlugins = () => [];
exports.getLanguagePlugins = getLanguagePlugins;
function runTsc(tscPath, options, _getLanguagePlugins) {
function runTsc(tscPath, options, _getLanguagePlugins, typescriptObject) {
exports.getLanguagePlugins = _getLanguagePlugins;
let extraSupportedExtensions;
let extraExtensionsToRemove;
if (Array.isArray(options)) {
extraSupportedExtensions = options;
extraExtensionsToRemove = [];
}
else {
extraSupportedExtensions = options.extraSupportedExtensions;
extraExtensionsToRemove = options.extraExtensionsToRemove;
}
const proxyApiPath = require.resolve('../node/proxyCreateProgram');

@@ -17,13 +28,17 @@ const readFileSync = fs.readFileSync;

let tsc = readFileSync(...args);
let extraSupportedExtensions;
let extraExtensionsToRemove;
if (Array.isArray(options)) {
extraSupportedExtensions = options;
extraExtensionsToRemove = [];
try {
return transformTscContent(tsc, proxyApiPath, extraSupportedExtensions, extraExtensionsToRemove, __filename, typescriptObject);
}
else {
extraSupportedExtensions = options.extraSupportedExtensions;
extraExtensionsToRemove = options.extraExtensionsToRemove;
catch {
// Support the tsc shim used in Typescript v5.7 and up
const requireRegex = /module\.exports\s*=\s*require\((?:"|')(?<path>\.\/\w+\.js)(?:"|')\)/;
const requirePath = requireRegex.exec(tsc)?.groups?.path;
if (requirePath) {
tsc = readFileSync(path.join(path.dirname(tscPath), requirePath), 'utf8');
return transformTscContent(tsc, proxyApiPath, extraSupportedExtensions, extraExtensionsToRemove, __filename, typescriptObject);
}
else {
throw new Error('Failed to locate tsc module path from shim');
}
}
return transformTscContent(tsc, proxyApiPath, extraSupportedExtensions, extraExtensionsToRemove);
}

@@ -48,5 +63,6 @@ return readFileSync(...args);

* @param getLanguagePluginsFile - The file to get language plugins from.
* @param typescriptObject - The object to use as typescript.
* @returns The modified typescript code.
*/
function transformTscContent(tsc, proxyApiPath, extraSupportedExtensions, extraExtensionsToRemove, getLanguagePluginsFile = __filename) {
function transformTscContent(tsc, proxyApiPath, extraSupportedExtensions, extraExtensionsToRemove, getLanguagePluginsFile = __filename, typescriptObject = `new Proxy({}, { get(_target, p, _receiver) { return eval(p); } } )`) {
const neededPatchExtenstions = extraSupportedExtensions.filter(ext => !extraExtensionsToRemove.includes(ext));

@@ -77,3 +93,3 @@ // Add allow extensions

+ [
`new Proxy({}, { get(_target, p, _receiver) { return eval(p); } } )`,
typescriptObject,
`_createProgram`,

@@ -91,3 +107,3 @@ `require(${JSON.stringify(getLanguagePluginsFile)}).getLanguagePlugins`,

if (after === before) {
throw 'Search string not found: ' + JSON.stringify(search.toString());
throw new Error('Failed to replace: ' + search);
}

@@ -94,0 +110,0 @@ return after;

{
"name": "@volar/typescript",
"version": "2.4.10",
"version": "2.4.11",
"license": "MIT",

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

"dependencies": {
"@volar/language-core": "2.4.10",
"@volar/language-core": "2.4.11",
"path-browserify": "^1.0.1",

@@ -23,5 +23,5 @@ "vscode-uri": "^3.0.8"

"@types/path-browserify": "latest",
"@volar/language-service": "2.4.10"
"@volar/language-service": "2.4.11"
},
"gitHead": "03d1e8b07e1e64921b76b635c7064d7b4fcf63b5"
"gitHead": "42ccae005cc8516e07ad38f4d7730cab9b723340"
}
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