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

@rehearsal/service

Package Overview
Dependencies
Maintainers
3
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rehearsal/service - npm Package Compare versions

Comparing version 1.0.5-beta to 1.0.6-beta

2

dist/src/index.d.ts

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

export { Plugin } from './plugin';
export { Plugin, PluginOptions, PluginsRunnerContext, PluginsRunner } from './plugin';
export { RehearsalService } from './rehearsal-service';

@@ -3,0 +3,0 @@ export { RehearsalServiceHost } from './rehearsal-service-host';

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RehearsalServiceHost = exports.RehearsalService = exports.Plugin = void 0;
exports.RehearsalServiceHost = exports.RehearsalService = exports.PluginsRunner = void 0;
var plugin_1 = require("./plugin");
Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return plugin_1.Plugin; } });
Object.defineProperty(exports, "PluginsRunner", { enumerable: true, get: function () { return plugin_1.PluginsRunner; } });
var rehearsal_service_1 = require("./rehearsal-service");

@@ -7,0 +7,0 @@ Object.defineProperty(exports, "RehearsalService", { enumerable: true, get: function () { return rehearsal_service_1.RehearsalService; } });

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

import type { Reporter } from '@rehearsal/reporter';
import type { Logger } from 'winston';
import type { RehearsalService } from './rehearsal-service';
export declare class Plugin {
protected readonly logger?: Logger;
protected readonly reporter: Reporter;
protected readonly service: RehearsalService;
constructor(service: RehearsalService, reporter: Reporter, logger?: Logger);
run(fileName: string): PluginResult;
import { Reporter } from '@rehearsal/reporter';
import { Logger } from 'winston';
import { RehearsalService } from './rehearsal-service';
export interface Plugin<PluginOptions> {
run(fileName: string, context: PluginsRunnerContext, options: PluginOptions): PluginResult;
}
export interface PluginOptions {
}
export type PluginResult = Promise<string[]>;
export interface PluginsRunnerContext {
basePath: string;
rehearsal: RehearsalService;
reporter: Reporter;
logger?: Logger;
}
export interface PluginLogger {
log(message: string): void;
}
export declare class PluginsRunner {
plugins: {
plugin: Plugin<PluginOptions>;
options: PluginOptions;
}[];
context: PluginsRunnerContext;
constructor(context: PluginsRunnerContext);
queue<P extends Plugin<PluginOptions>>(plugin: P, options: P extends Plugin<infer O> ? O : never): this;
run(fileNames: string[], logger?: PluginLogger): Promise<void>;
processFilesGenerator(fileNames: string[], logger?: PluginLogger): AsyncGenerator<void>;
processPlugins(fileName: string, allChangedFiles: Set<string>): AsyncGenerator<Set<string>>;
}
//# sourceMappingURL=plugin.d.ts.map
"use strict";
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Plugin = void 0;
class Plugin {
constructor(service, reporter, logger) {
this.service = service;
this.logger = logger;
this.reporter = reporter;
exports.PluginsRunner = void 0;
class PluginsRunner {
constructor(context) {
this.plugins = [];
this.context = context;
}
async run(fileName) {
return [fileName];
queue(plugin, options) {
this.plugins.push({ plugin, options });
return this;
}
async run(fileNames, logger) {
var _a, e_1, _b, _c;
const fileIteratorProcessor = this.processFilesGenerator(fileNames, logger);
try {
for (var _d = true, fileIteratorProcessor_1 = __asyncValues(fileIteratorProcessor), fileIteratorProcessor_1_1; fileIteratorProcessor_1_1 = await fileIteratorProcessor_1.next(), _a = fileIteratorProcessor_1_1.done, !_a;) {
_c = fileIteratorProcessor_1_1.value;
_d = false;
try {
const _ = _c;
const next = async () => {
const { done } = await fileIteratorProcessor.next();
if (!done) {
setImmediate(next);
}
};
await next();
}
finally {
_d = true;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_d && !_a && (_b = fileIteratorProcessor_1.return)) await _b.call(fileIteratorProcessor_1);
}
finally { if (e_1) throw e_1.error; }
}
}
// Async generator to process files
// Since this is a long-running process, we need to yield to the event loop
// So we don't block the main thread
processFilesGenerator(fileNames, logger) {
return __asyncGenerator(this, arguments, function* processFilesGenerator_1() {
var _a, e_2, _b, _c;
for (const fileName of fileNames) {
logger === null || logger === void 0 ? void 0 : logger.log(`processing file: ${fileName.replace(this.context.basePath, '')}`);
const allChangedFiles = new Set();
const pluginIteratorProcessor = this.processPlugins(fileName, allChangedFiles);
try {
for (var _d = true, pluginIteratorProcessor_1 = (e_2 = void 0, __asyncValues(pluginIteratorProcessor)), pluginIteratorProcessor_1_1; pluginIteratorProcessor_1_1 = yield __await(pluginIteratorProcessor_1.next()), _a = pluginIteratorProcessor_1_1.done, !_a;) {
_c = pluginIteratorProcessor_1_1.value;
_d = false;
try {
const changedFile = _c;
const next = async () => {
const { done } = await pluginIteratorProcessor.next();
// Save file to the filesystem
changedFile.forEach((file) => this.context.rehearsal.saveFile(file));
if (!done) {
setImmediate(next);
}
};
yield __await(next());
}
finally {
_d = true;
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (!_d && !_a && (_b = pluginIteratorProcessor_1.return)) yield __await(_b.call(pluginIteratorProcessor_1));
}
finally { if (e_2) throw e_2.error; }
}
yield yield __await(void 0);
}
});
}
processPlugins(fileName, allChangedFiles) {
return __asyncGenerator(this, arguments, function* processPlugins_1() {
for (const plugin of this.plugins) {
const changedFiles = yield __await(plugin.plugin.run(fileName, this.context, plugin.options));
allChangedFiles = new Set([...allChangedFiles, ...changedFiles]);
yield yield __await(allChangedFiles);
}
});
}
}
exports.Plugin = Plugin;
exports.PluginsRunner = PluginsRunner;
//# sourceMappingURL=plugin.js.map

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

import { LanguageServiceHost } from 'typescript';
import { ApplyCodeActionCommandResult, InstallPackageOptions, LanguageServiceHost } from 'typescript';
import type { CompilerOptions, IScriptSnapshot } from 'typescript';

@@ -16,3 +16,6 @@ /**

private readonly files;
private seenTypingsRequest;
private typeRootVersion;
constructor(compilerOptions: CompilerOptions, fileNames: string[]);
getTypeRootsVersion(): number;
/**

@@ -22,2 +25,3 @@ * Updates a snapshot state in memory and increases its version.

setScriptSnapshot(fileName: string, snapshot: IScriptSnapshot): IScriptSnapshot;
installPackage(options: InstallPackageOptions): Promise<ApplyCodeActionCommandResult>;
/**

@@ -28,2 +32,3 @@ * Gets the latest snapshot

getScriptSnapshot(fileName: string): IScriptSnapshot | undefined;
isKnownTypesPackageName(_name: string): boolean;
getCompilationSettings: () => CompilerOptions;

@@ -30,0 +35,0 @@ getCurrentDirectory: () => string;

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RehearsalServiceHost = void 0;
const path_1 = require("path");
const typescript_1 = require("typescript");
const utils_1 = require("@rehearsal/utils");
const findup_sync_1 = __importDefault(require("findup-sync"));
/**

@@ -16,2 +22,4 @@ * ServiceHost represents the layer between the LanguageServer and the permanent storage.

this.files = {};
this.seenTypingsRequest = new Map();
this.typeRootVersion = 0;
this.getCompilationSettings = () => this.compilerOptions;

@@ -33,2 +41,5 @@ this.getCurrentDirectory = () => this.currentDirectory;

}
getTypeRootsVersion() {
return this.typeRootVersion;
}
/**

@@ -45,2 +56,23 @@ * Updates a snapshot state in memory and increases its version.

}
async installPackage(options) {
if (this.seenTypingsRequest.has(options.fileName)) {
return { successMessage: `Succussfully installed ${options.packageName}` };
}
// Save the intall request information so we don't continuously download
this.seenTypingsRequest.set(options.fileName, options.packageName);
const nearestPackageJSON = (0, findup_sync_1.default)('package.json', {
cwd: (0, path_1.dirname)(options.fileName),
});
if (nearestPackageJSON) {
// Note: the TSServer is going to swallow the success and failures
// @see https://github.com/microsoft/TypeScript/blob/10941888dca8dc68a64fe1729258cf9ffef861ec/src/server/session.ts#L2804
await (0, utils_1.addDep)([options.packageName], true, { cwd: (0, path_1.dirname)(nearestPackageJSON) });
// We must increment this version here so that when the language server
// synchronizes it knows that we need re-create the program with the new
// types we just downloaded
this.typeRootVersion++;
return { successMessage: `Succussfully installed ${options.packageName}` };
}
return Promise.reject({ error: `Could not install ${options.packageName}` });
}
/**

@@ -59,4 +91,8 @@ * Gets the latest snapshot

}
isKnownTypesPackageName(_name) {
// try all packages that come through here
return true;
}
}
exports.RehearsalServiceHost = RehearsalServiceHost;
//# sourceMappingURL=rehearsal-service-host.js.map

@@ -39,7 +39,3 @@ import { RehearsalServiceHost } from './rehearsal-service-host';

getSuggestionDiagnostics(fileName: string): DiagnosticWithLocation[];
/**
* Provides a path to a module file by its name
*/
resolveModuleName(moduleName: string, containingFile: string): string | undefined;
}
//# sourceMappingURL=rehearsal-service.d.ts.map

@@ -61,12 +61,4 @@ "use strict";

}
/**
* Provides a path to a module file by its name
*/
resolveModuleName(moduleName, containingFile) {
var _a;
const result = (0, typescript_1.resolveModuleName)(moduleName, containingFile, this.host.getCompilationSettings(), typescript_1.sys);
return (_a = result === null || result === void 0 ? void 0 : result.resolvedModule) === null || _a === void 0 ? void 0 : _a.resolvedFileName;
}
}
exports.RehearsalService = RehearsalService;
//# sourceMappingURL=rehearsal-service.js.map
{
"name": "@rehearsal/service",
"version": "1.0.5-beta",
"version": "1.0.6-beta",
"description": "Rehearsal Service",

@@ -23,7 +23,9 @@ "keywords": [

"dependencies": {
"@rehearsal/reporter": "1.0.5-beta",
"winston": "^3.6.0"
"@rehearsal/reporter": "1.0.6-beta",
"@rehearsal/utils": "1.0.6-beta",
"findup-sync": "^5.0.0",
"winston": "^3.8.2"
},
"devDependencies": {
"vitest": "^0.23.4"
"vitest": "^0.28.4"
},

@@ -30,0 +32,0 @@ "peerDependencies": {

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

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