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
222
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.2.0-alpha.2 to 2.2.0-alpha.3

18

lib/node/decorateLanguageServiceHost.js

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

let extraProjectVersion = 0;
const exts = language.plugins
const extensions = language.plugins
.map(plugin => plugin.typescript?.extraFileExtensions.map(ext => '.' + ext.extension) ?? [])

@@ -22,3 +22,3 @@ .flat();

if (extensions) {
for (const ext of exts) {
for (const ext of extensions) {
if (!extensions.includes(ext)) {

@@ -32,11 +32,15 @@ extensions = [...extensions, ...ext];

}
if (language.plugins.some(language => language.typescript?.extraFileExtensions.length)) {
if (extensions.length) {
const resolveModuleName = (0, resolveModuleName_1.createResolveModuleName)(ts, languageServiceHost, language.plugins, fileName => language.scripts.get(fileName));
const getCanonicalFileName = languageServiceHost.useCaseSensitiveFileNames?.()
? (fileName) => fileName
: (fileName) => fileName.toLowerCase();
const moduleResolutionCache = ts.createModuleResolutionCache(languageServiceHost.getCurrentDirectory(), getCanonicalFileName, languageServiceHost.getCompilationSettings());
if (resolveModuleNameLiterals) {
languageServiceHost.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options, ...rest) => {
if (moduleLiterals.every(name => !exts.some(ext => name.text.endsWith(ext)))) {
if (moduleLiterals.every(name => !extensions.some(ext => name.text.endsWith(ext)))) {
return resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, options, ...rest);
}
return moduleLiterals.map(moduleLiteral => {
return resolveModuleName(moduleLiteral.text, containingFile, options, undefined, redirectedReference);
return resolveModuleName(moduleLiteral.text, containingFile, options, moduleResolutionCache, redirectedReference);
});

@@ -47,7 +51,7 @@ };

languageServiceHost.resolveModuleNames = (moduleNames, containingFile, reusedNames, redirectedReference, options, containingSourceFile) => {
if (moduleNames.every(name => !exts.some(ext => name.endsWith(ext)))) {
if (moduleNames.every(name => !extensions.some(ext => name.endsWith(ext)))) {
return resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, options, containingSourceFile);
}
return moduleNames.map(moduleName => {
return resolveModuleName(moduleName, containingFile, options, undefined, redirectedReference).resolvedModule;
return resolveModuleName(moduleName, containingFile, options, moduleResolutionCache, redirectedReference).resolvedModule;
});

@@ -54,0 +58,0 @@ };

@@ -6,2 +6,3 @@ "use strict";

const language_core_1 = require("@volar/language-core");
const resolveModuleName_1 = require("../resolveModuleName");
function proxyCreateProgram(ts, original, getLanguagePlugins, getLanguageId) {

@@ -19,4 +20,3 @@ return new Proxy(original, {

let snapshot;
assert(originalSourceFiles.has(fileName), `originalSourceFiles.has(${fileName})`);
const sourceFile = originalSourceFiles.get(fileName);
const sourceFile = originalHost.getSourceFile(fileName, 99);
if (sourceFile) {

@@ -46,22 +46,7 @@ snapshot = sourceFileToSnapshotMap.get(sourceFile);

});
const originalSourceFiles = new Map();
const parsedSourceFiles = new WeakMap();
const arbitraryExtensions = extensions.map(ext => `.d${ext}.ts`);
const originalHost = options.host;
const moduleResolutionHost = {
...originalHost,
fileExists(fileName) {
for (let i = 0; i < arbitraryExtensions.length; i++) {
if (fileName.endsWith(arbitraryExtensions[i])) {
return originalHost.fileExists(fileName.slice(0, -arbitraryExtensions[i].length) + extensions[i]);
}
}
return originalHost.fileExists(fileName);
},
};
options.host = { ...originalHost };
options.options.allowArbitraryExtensions = true;
options.host.getSourceFile = (fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile) => {
const originalSourceFile = originalHost.getSourceFile(fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile);
originalSourceFiles.set(fileName, originalSourceFile);
if (originalSourceFile && extensions.some(ext => fileName.endsWith(ext))) {

@@ -75,4 +60,4 @@ let sourceFile2 = parsedSourceFiles.get(originalSourceFile);

if (sourceScript.generated?.languagePlugin.typescript) {
const { getServiceScript: getScript, getExtraServiceScripts: getExtraScripts } = sourceScript.generated.languagePlugin.typescript;
const serviceScript = getScript(sourceScript.generated.root);
const { getServiceScript, getExtraServiceScripts } = sourceScript.generated.languagePlugin.typescript;
const serviceScript = getServiceScript(sourceScript.generated.root);
if (serviceScript) {

@@ -82,4 +67,4 @@ scriptKind = serviceScript.scriptKind;

}
if (getExtraScripts) {
console.warn('getExtraScripts() is not available in this use case.');
if (getExtraServiceScripts) {
console.warn('getExtraServiceScripts() is not available in this use case.');
}

@@ -96,13 +81,26 @@ }

};
options.host.resolveModuleNameLiterals = (moduleNames, containingFile, redirectedReference, options) => {
return moduleNames.map(name => {
return resolveModuleName(name.text, containingFile, options, redirectedReference);
});
};
options.host.resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference, options) => {
return moduleNames.map(name => {
return resolveModuleName(name, containingFile, options, redirectedReference).resolvedModule;
});
};
const program = Reflect.apply(target, thisArg, [options]);
if (extensions.length) {
options.options.allowArbitraryExtensions = true;
const resolveModuleName = (0, resolveModuleName_1.createResolveModuleName)(ts, originalHost, language.plugins, fileName => language.scripts.get(fileName));
const resolveModuleNameLiterals = originalHost.resolveModuleNameLiterals;
const resolveModuleNames = originalHost.resolveModuleNames;
const moduleResolutionCache = ts.createModuleResolutionCache(originalHost.getCurrentDirectory(), originalHost.getCanonicalFileName, options.options);
options.host.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, compilerOptions, ...rest) => {
if (resolveModuleNameLiterals && moduleLiterals.every(name => !extensions.some(ext => name.text.endsWith(ext)))) {
return resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, compilerOptions, ...rest);
}
return moduleLiterals.map(moduleLiteral => {
return resolveModuleName(moduleLiteral.text, containingFile, compilerOptions, moduleResolutionCache, redirectedReference);
});
};
options.host.resolveModuleNames = (moduleNames, containingFile, reusedNames, redirectedReference, compilerOptions, containingSourceFile) => {
if (resolveModuleNames && moduleNames.every(name => !extensions.some(ext => name.endsWith(ext)))) {
return resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, compilerOptions, containingSourceFile);
}
return moduleNames.map(moduleName => {
return resolveModuleName(moduleName, containingFile, compilerOptions, moduleResolutionCache, redirectedReference).resolvedModule;
});
};
}
const program = Reflect.apply(target, thisArg, args);
(0, decorateProgram_1.decorateProgram)(language, program);

@@ -112,15 +110,2 @@ // TODO: #128

return program;
function resolveModuleName(name, containingFile, options, redirectedReference) {
const resolved = ts.resolveModuleName(name, containingFile, options, moduleResolutionHost, originalHost.getModuleResolutionCache?.(), redirectedReference);
if (resolved.resolvedModule) {
for (let i = 0; i < arbitraryExtensions.length; i++) {
if (resolved.resolvedModule.resolvedFileName.endsWith(arbitraryExtensions[i])) {
const sourceFileName = resolved.resolvedModule.resolvedFileName.slice(0, -arbitraryExtensions[i].length) + extensions[i];
resolved.resolvedModule.resolvedFileName = sourceFileName;
resolved.resolvedModule.extension = extensions[i];
}
}
}
return resolved;
}
},

@@ -127,0 +112,0 @@ });

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

// TODO: can this share between monorepo packages?
const moduleCache = ts.createModuleResolutionCache(languageServiceHost.getCurrentDirectory(), languageServiceHost.useCaseSensitiveFileNames ? s => s : s => s.toLowerCase(), languageServiceHost.getCompilationSettings());
const moduleCache = ts.createModuleResolutionCache(languageServiceHost.getCurrentDirectory(), languageServiceHost.useCaseSensitiveFileNames?.() ? s => s : s => s.toLowerCase(), languageServiceHost.getCompilationSettings());
const resolveModuleName = (0, resolveModuleName_1.createResolveModuleName)(ts, languageServiceHost, languagePlugins, fileName => language.scripts.get(projectHost.fileNameToScriptId(fileName)));

@@ -49,0 +49,0 @@ let lastSysVersion = projectHost.getSystemVersion?.();

import type { LanguagePlugin, SourceScript } from '@volar/language-core';
import type * as ts from 'typescript';
export declare function createResolveModuleName(ts: typeof import('typescript'), languageServiceHost: ts.LanguageServiceHost, languagePlugins: LanguagePlugin<any>[], getSourceScript: (fileName: string) => SourceScript | undefined): (moduleName: string, containingFile: string, compilerOptions: ts.CompilerOptions, cache?: ts.ModuleResolutionCache, redirectedReference?: ts.ResolvedProjectReference, resolutionMode?: ts.ResolutionMode) => ts.ResolvedModuleWithFailedLookupLocations;
export declare function createResolveModuleName(ts: typeof import('typescript'), host: ts.ModuleResolutionHost, languagePlugins: LanguagePlugin<any>[], getSourceScript: (fileName: string) => SourceScript | undefined): (moduleName: string, containingFile: string, compilerOptions: ts.CompilerOptions, cache?: ts.ModuleResolutionCache, redirectedReference?: ts.ResolvedProjectReference, resolutionMode?: ts.ResolutionMode) => ts.ResolvedModuleWithFailedLookupLocations;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createResolveModuleName = void 0;
function createResolveModuleName(ts, languageServiceHost, languagePlugins, getSourceScript) {
function createResolveModuleName(ts, host, languagePlugins, getSourceScript) {
const toPatchResults = new Map();
const moduleResolutionHost = {
readFile: languageServiceHost.readFile.bind(languageServiceHost),
directoryExists: languageServiceHost.directoryExists?.bind(languageServiceHost),
realpath: languageServiceHost.realpath?.bind(languageServiceHost),
getCurrentDirectory: languageServiceHost.getCurrentDirectory.bind(languageServiceHost),
getDirectories: languageServiceHost.getDirectories?.bind(languageServiceHost),
useCaseSensitiveFileNames: languageServiceHost.useCaseSensitiveFileNames?.bind(languageServiceHost),
readFile: host.readFile.bind(host),
directoryExists: host.directoryExists?.bind(host),
realpath: host.realpath?.bind(host),
getCurrentDirectory: host.getCurrentDirectory?.bind(host),
getDirectories: host.getDirectories?.bind(host),
useCaseSensitiveFileNames: typeof host.useCaseSensitiveFileNames === 'function'
? host.useCaseSensitiveFileNames.bind(host)
: host.useCaseSensitiveFileNames,
fileExists(fileName) {

@@ -28,3 +30,3 @@ for (const { typescript } of languagePlugins) {

}
return languageServiceHost.fileExists(fileName);
return host.fileExists(fileName);
},

@@ -49,4 +51,4 @@ };

function fileExists(fileName) {
if (languageServiceHost.fileExists(fileName)) {
const fileSize = ts.sys.getFileSize?.(fileName) ?? languageServiceHost.readFile(fileName)?.length ?? 0;
if (host.fileExists(fileName)) {
const fileSize = ts.sys.getFileSize?.(fileName) ?? host.readFile(fileName)?.length ?? 0;
return fileSize < 4 * 1024 * 1024;

@@ -53,0 +55,0 @@ }

{
"name": "@volar/typescript",
"version": "2.2.0-alpha.2",
"version": "2.2.0-alpha.3",
"license": "MIT",

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

"dependencies": {
"@volar/language-core": "2.2.0-alpha.2",
"@volar/language-core": "2.2.0-alpha.3",
"path-browserify": "^1.0.1"

@@ -22,5 +22,5 @@ },

"@types/path-browserify": "latest",
"@volar/language-service": "2.2.0-alpha.2"
"@volar/language-service": "2.2.0-alpha.3"
},
"gitHead": "c6a538c915cc8b32ad9a7ca1092a29a326d49161"
"gitHead": "9f3432fabfbcdb2bdda6b7d015653706cfdf108d"
}
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