New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tsserver-lean

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsserver-lean - npm Package Compare versions

Comparing version 0.0.0-pre-alpha.1 to 0.0.0-pre-alpha.2

62

lib/checker.js

@@ -27,2 +27,4 @@ "use strict";

exports.WorkspaceDiagnosticChecker = void 0;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
const ts = __importStar(require("typescript"));

@@ -38,6 +40,10 @@ const fs = __importStar(require("fs"));

function resolveFirstParty(tsProj, importSpecifier) {
if (!tsProj.options.paths) {
// can't resolve
return undefined;
}
const components = importSpecifier.split('/');
if (components?.[1] === 'lib') {
// resolve the first-party import
const patternTarget = components.slice(0, 2).join('/'); // 'owa-pkg-a/lib'
const patternTarget = components.slice(0, 2).join('/'); // 'owa-pkg-a/lib/foo' => ['owa-pkg-a', 'lib']
for (const [glob, resolvePaths] of Object.entries(tsProj.options.paths)) {

@@ -60,3 +66,3 @@ if (glob.startsWith(patternTarget)) {

}
const exts = ['.ts', '.tsx', '.d.ts', 'css', 'scss'];
const exts = ['.ts', '.tsx', '.d.ts', '.css', '.scss'];
for (const ext of exts) {

@@ -120,2 +126,3 @@ const attempt = fileName + ext;

if (scriptSnapshot) {
// @ts-ignore
sourceFile = ts.createSourceFile(filePath, scriptSnapshot.getText(0, scriptSnapshot.getLength()), undefined);

@@ -128,6 +135,7 @@ }

const importSpecifiers = sourceFile.statements
.filter(stmt => stmt.kind === ts.SyntaxKind.ImportDeclaration)
.map(stmt => stmt)
.map(imp => imp.moduleSpecifier)
.map(mod => mod.text);
.filter((stmt) => stmt.kind === ts.SyntaxKind.ImportDeclaration)
.map((stmt) => stmt)
.map((imp) => imp.moduleSpecifier)
// @ts-ignore
.map((mod) => mod.text);
if (importSpecifiers.length > 0) {

@@ -190,3 +198,3 @@ for (const importSpecifier of importSpecifiers) {

this.rootFileNames = tsProject.fileNames;
this.rootFileNames.forEach(fileName => {
this.rootFileNames.forEach((fileName) => {
this.files[fileName] = { version: 0 };

@@ -206,4 +214,4 @@ });

getScriptFileNames: () => Object.keys(this.files),
getScriptVersion: fileName => this.files[fileName] && this.files[fileName].version.toString(),
getScriptSnapshot: fileName => {
getScriptVersion: (fileName) => this.files[fileName] && this.files[fileName].version.toString(),
getScriptSnapshot: (fileName) => {
if (!fs.existsSync(fileName))

@@ -244,21 +252,24 @@ return undefined;

if (!this.tsProject.projectReferences || this.tsProject.projectReferences.length === 0) {
return;
return Promise.resolve([]);
}
const start = Date.now();
const projectsToCompile = [];
const projectsQueue = [];
const seenProjects = new Set();
const emittedFiles = new Set();
const emitPromises = [];
// build unit of work
// resolve target's direct imports
const resolvedImportSpecifiers = this.dependencyBuilder.gatherDependencies(targetPath, this.tsProject, this.languageServiceHost.getScriptSnapshot.bind(this.languageServiceHost));
// populate the queue
for (const importSpecifier of resolvedImportSpecifiers) {
const relevantProj = getTypescriptProject(importSpecifier.resolvedPath); // todo: could share this with TypeChecker
const resolvedPaths = importSpecifier.specifier
? [importSpecifier.resolvedPath]
: relevantProj.fileNames;
const filesToMaybeEmit = resolvedPaths.filter(p => /\.(ts|tsx)$/g.test(p));
projectsToCompile.push({ project: relevantProj, filesToMaybeEmit });
const resolvedPaths = importSpecifier.specifier ? [importSpecifier.resolvedPath] : relevantProj.fileNames;
const filesToMaybeEmit = resolvedPaths.filter((p) => /\.(ts|tsx)$/g.test(p)) ?? [];
projectsQueue.push({ project: relevantProj, filesToMaybeEmit });
}
while (projectsToCompile.length > 0) {
const { project: referenceProject, filesToMaybeEmit } = projectsToCompile.shift();
// consume the queue
while (projectsQueue.length > 0) {
const cur = projectsQueue.shift();
if (!cur)
continue;
const { project: referenceProject, filesToMaybeEmit } = cur;
if (seenProjects.has(referenceProject.configPath)) {

@@ -279,6 +290,5 @@ continue;

}
const outputFiles = ts.getOutputFileNames(referenceProject.raw, fileToMaybeEmit,
/*forceDtsPaths*/ true);
const declarationOutput = outputFiles.find(p => p.endsWith('.d.ts'));
if (!fs.existsSync(declarationOutput)) {
const outputFiles = ts.getOutputFileNames(referenceProject.raw, fileToMaybeEmit, /*forceDtsPaths*/ true);
const declarationOutput = outputFiles.find((p) => p.endsWith('.d.ts'));
if (declarationOutput && !fs.existsSync(declarationOutput)) {
filesToEmit.push(fileToMaybeEmit);

@@ -331,3 +341,3 @@ continue;

// }
output.outputFiles.forEach(o => {
output.outputFiles.forEach((o) => {
try {

@@ -388,3 +398,3 @@ fs.mkdirSync(path.dirname(o.name), { recursive: true });

mapInternalDiagnostics(fileName, diagnostics, version, elapsed) {
const diagnosticsRaw = diagnostics.filter(d => d.file);
const diagnosticsRaw = diagnostics.filter((d) => !!d.file);
const diagnosticsInternal = [];

@@ -413,3 +423,3 @@ for (const diagnostic of diagnosticsRaw) {

const targetPathAbs = path.resolve(targetPath);
const targetTsconfigPath = ts.findConfigFile(targetPathAbs, ts.sys.fileExists, 'tsconfig.json');
const targetTsconfigPath = this.monorepo.findModuleTsconfigPath(targetPathAbs);
const projectService = this.projectServices.get(targetTsconfigPath);

@@ -416,0 +426,0 @@ if (projectService)

@@ -27,2 +27,4 @@ "use strict";

exports.MonorepoTsConfig = void 0;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
const path = __importStar(require("path"));

@@ -35,2 +37,5 @@ const ts = __importStar(require("typescript"));

const pathsTsconfigProj = this.getTypescriptProject(workspaceDir, tsconfigPathsName);
if (!pathsTsconfigProj.options.paths) {
throw new Error(`The ${tsconfigPathsName} config doesn't have compilerOptions.paths property, which is required.`);
}
for (const [key, value] of Object.entries(pathsTsconfigProj.options.paths)) {

@@ -40,6 +45,13 @@ this.resolvePaths[key] = value;

}
findModuleTsconfigPath(filePath, configName = 'tsconfig.json') {
const configPath = ts.findConfigFile(filePath, ts.sys.fileExists, configName);
if (!configPath) {
throw new Error(`Could not find tsconfig.json for '${filePath}'.`);
}
return path.resolve(configPath);
}
getTypescriptProject(filePath, configName = 'tsconfig.json') {
// configFilePath must be absolute, otherwise ts.findConfigFile won't be able to
// track down `fileNames`, which are crucial for tracking down which files to build in dependencies
const configFilePath = path.resolve(ts.findConfigFile(filePath, ts.sys.fileExists, configName));
const configFilePath = this.findModuleTsconfigPath(filePath, configName);
const projectPath = path.dirname(configFilePath);

@@ -51,9 +63,4 @@ const configFile = ts.readConfigFile(configFilePath, ts.sys.readFile);

const parsedConfig = ts.parseJsonConfigFileContent(configFile.config /* json */, ts.sys /* host */, projectPath /* basePath */, {} /* existingOptions */, configFilePath /* configFileName */);
if (parsedConfig.errors.length > 0) {
// throw new Error(
// `Could not parse ${configName} at '${configFilePath}': ${parsedConfig.errors[0].messageText}.`
// );
}
return {
projectReferences: parsedConfig.projectReferences,
projectReferences: parsedConfig.projectReferences ?? [],
raw: parsedConfig,

@@ -60,0 +67,0 @@ options: {

@@ -27,2 +27,4 @@ "use strict";

exports.Logger = void 0;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
const path = __importStar(require("path"));

@@ -55,7 +57,2 @@ const fs = __importStar(require("fs"));

}
trace(msg) {
const timestamp = new Date().toISOString();
const { body } = msg;
this.logStream.write(`${timestamp} - ${msg.event.toUpperCase()} - ${body.message}\n`);
}
log(msg) {

@@ -70,2 +67,7 @@ if (this.logLevel === "programmatic" /* LogLevel.Programmatic */) {

}
trace(msg) {
const timestamp = new Date().toISOString();
const { body } = msg;
this.logStream.write(`${timestamp} - ${msg.event.toUpperCase()} - ${body.message}\n`);
}
info(body) {

@@ -72,0 +74,0 @@ // todo: map request seq to log seq

@@ -42,13 +42,15 @@ "use strict";

}
files.map(file => this.checker.getDiagnostics(file, (diagnostics) => {
const response = {
type: 'response',
seq: this.getRequestSeq(),
request_seq: requestSeq,
command: request.command,
success: true,
body: diagnostics,
};
this.writeMessage(response);
}));
for (const file of files) {
this.checker.getDiagnostics(file, (diagnostics) => {
const response = {
type: 'response',
seq: this.getRequestSeq(),
request_seq: requestSeq,
command: request.command,
success: true,
body: diagnostics,
};
this.writeMessage(response);
});
}
}

@@ -55,0 +57,0 @@ onMessage(message) {

@@ -0,1 +1,2 @@

#!/usr/bin/env node
"use strict";

@@ -26,4 +27,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {

Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
const readline = __importStar(require("readline"));
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const session_1 = require("./session");

@@ -62,2 +66,5 @@ function parseArguments(argv) {

}
else {
args.workspace = path.resolve(args.workspace);
}
if (!fs.existsSync(args.tsconfigPaths)) {

@@ -90,3 +97,5 @@ console.error(`tsconfigPaths file does not exist: ${args.tsconfigPaths}`);

}
startNodeSessionIO();
if (typeof require !== 'undefined' && require.main !== undefined) {
startNodeSessionIO();
}
//# sourceMappingURL=tsserver.js.map
{
"name": "tsserver-lean",
"description": "lean subset of tsserver that only supports typechecking",
"main": "lib/tsserver.js",

@@ -12,9 +13,12 @@ "license": "MIT",

"sideEffects": false,
"version": "0.0.0-pre-alpha.1",
"version": "0.0.0-pre-alpha.2",
"exports": {
".": {
"types": "./lib/index.d.ts",
"import": "./lib/index.js"
"types": "./lib/tsserver.d.ts",
"import": "./lib/tsserver.js"
}
},
"bin": {
"tsserver-lean": "./lib/tsserver.js"
},
"scripts": {

@@ -21,0 +25,0 @@ "build": "node --max-old-space-size=8192 node_modules/typescript/bin/tsc --sourcemap -p tsconfig.json",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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