@rehearsal/service
Advanced tools
Comparing version 1.0.10-beta to 1.0.11-beta
@@ -1,5 +0,5 @@ | ||
export { Plugin, PluginOptions, PluginsRunnerContext, PluginsRunner } from './plugin'; | ||
export { RehearsalService } from './rehearsal-service'; | ||
export { RehearsalServiceHost } from './rehearsal-service-host'; | ||
export type { PluginResult } from './plugin'; | ||
export { Plugin, PluginOptions, PluginsRunnerContext, PluginsRunner } from './plugin.js'; | ||
export { RehearsalService } from './rehearsal-service.js'; | ||
export { RehearsalServiceHost } from './rehearsal-service-host.js'; | ||
export type { PluginResult } from './plugin.js'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,10 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RehearsalServiceHost = exports.RehearsalService = exports.PluginsRunner = void 0; | ||
var plugin_1 = require("./plugin"); | ||
Object.defineProperty(exports, "PluginsRunner", { enumerable: true, get: function () { return plugin_1.PluginsRunner; } }); | ||
var rehearsal_service_1 = require("./rehearsal-service"); | ||
Object.defineProperty(exports, "RehearsalService", { enumerable: true, get: function () { return rehearsal_service_1.RehearsalService; } }); | ||
var rehearsal_service_host_1 = require("./rehearsal-service-host"); | ||
Object.defineProperty(exports, "RehearsalServiceHost", { enumerable: true, get: function () { return rehearsal_service_host_1.RehearsalServiceHost; } }); | ||
export { PluginsRunner } from './plugin.js'; | ||
export { RehearsalService } from './rehearsal-service.js'; | ||
export { RehearsalServiceHost } from './rehearsal-service-host.js'; | ||
//# sourceMappingURL=index.js.map |
import { Reporter } from '@rehearsal/reporter'; | ||
import { Logger } from 'winston'; | ||
import { RehearsalService } from './rehearsal-service'; | ||
import { RehearsalService } from './rehearsal-service.js'; | ||
export interface Plugin<PluginOptions> { | ||
@@ -5,0 +5,0 @@ run(fileName: string, context: PluginsRunnerContext, options: PluginOptions): PluginResult; |
@@ -1,24 +0,2 @@ | ||
"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.PluginsRunner = void 0; | ||
class PluginsRunner { | ||
export class PluginsRunner { | ||
constructor(context) { | ||
@@ -33,30 +11,12 @@ this.plugins = []; | ||
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(); | ||
for await (const _ of fileIteratorProcessor) { | ||
const next = async () => { | ||
const { done } = await fileIteratorProcessor.next(); | ||
if (!done) { | ||
setImmediate(next); | ||
} | ||
finally { | ||
_d = true; | ||
} | ||
} | ||
}; | ||
await next(); | ||
} | ||
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; } | ||
} | ||
} | ||
@@ -66,52 +26,29 @@ // Async generator to process files | ||
// 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; | ||
} | ||
async *processFilesGenerator(fileNames, logger) { | ||
for (const fileName of fileNames) { | ||
logger?.log(`processing file: ${fileName.replace(this.context.basePath, '')}`); | ||
const allChangedFiles = new Set(); | ||
const pluginIteratorProcessor = this.processPlugins(fileName, allChangedFiles); | ||
for await (const changedFile of pluginIteratorProcessor) { | ||
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); | ||
} | ||
} | ||
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); | ||
}; | ||
await next(); | ||
} | ||
}); | ||
yield; | ||
} | ||
} | ||
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); | ||
} | ||
}); | ||
async *processPlugins(fileName, allChangedFiles) { | ||
for (const plugin of this.plugins) { | ||
const changedFiles = await plugin.plugin.run(fileName, this.context, plugin.options); | ||
allChangedFiles = new Set([...allChangedFiles, ...changedFiles]); | ||
yield allChangedFiles; | ||
} | ||
} | ||
} | ||
exports.PluginsRunner = PluginsRunner; | ||
//# sourceMappingURL=plugin.js.map |
@@ -1,11 +0,6 @@ | ||
"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")); | ||
import { dirname } from 'node:path'; | ||
import ts from 'typescript'; | ||
import { addDep } from '@rehearsal/utils'; | ||
import findupSync from 'findup-sync'; | ||
const { ScriptSnapshot, getDefaultLibFilePath, sys } = ts; | ||
/** | ||
@@ -19,3 +14,3 @@ * ServiceHost represents the layer between the LanguageServer and the permanent storage. | ||
*/ | ||
class RehearsalServiceHost { | ||
export class RehearsalServiceHost { | ||
constructor(compilerOptions, fileNames) { | ||
@@ -27,12 +22,12 @@ this.files = {}; | ||
this.getCurrentDirectory = () => this.currentDirectory; | ||
this.getDefaultLibFileName = (o) => (0, typescript_1.getDefaultLibFilePath)(o); | ||
this.getDefaultLibFileName = (o) => getDefaultLibFilePath(o); | ||
this.getScriptFileNames = () => this.fileNames; | ||
this.getScriptVersion = (fileName) => { var _a; return ((_a = this.files[fileName]) === null || _a === void 0 ? void 0 : _a.version.toString()) || '0'; }; | ||
this.fileExists = typescript_1.sys.fileExists; | ||
this.readFile = typescript_1.sys.readFile; | ||
this.writeFile = typescript_1.sys.writeFile; | ||
this.directoryExists = typescript_1.sys.directoryExists; | ||
this.getDirectories = typescript_1.sys.getDirectories; | ||
this.readDirectory = typescript_1.sys.readDirectory; | ||
this.realpath = typescript_1.sys.realpath; | ||
this.getScriptVersion = (fileName) => this.files[fileName]?.version.toString() || '0'; | ||
this.fileExists = sys.fileExists; | ||
this.readFile = sys.readFile; | ||
this.writeFile = sys.writeFile; | ||
this.directoryExists = sys.directoryExists; | ||
this.getDirectories = sys.getDirectories; | ||
this.readDirectory = sys.readDirectory; | ||
this.realpath = sys.realpath; | ||
this.compilerOptions = compilerOptions; | ||
@@ -49,6 +44,5 @@ this.currentDirectory = process.cwd(); | ||
setScriptSnapshot(fileName, snapshot) { | ||
var _a; | ||
this.files[fileName] = { | ||
snapshot: snapshot, | ||
version: ((_a = this.files[fileName]) === null || _a === void 0 ? void 0 : _a.version) + 1 || 0, | ||
version: this.files[fileName]?.version + 1 || 0, | ||
}; | ||
@@ -63,4 +57,4 @@ return this.files[fileName].snapshot; | ||
this.seenTypingsRequest.set(options.fileName, options.packageName); | ||
const nearestPackageJSON = (0, findup_sync_1.default)('package.json', { | ||
cwd: (0, path_1.dirname)(options.fileName), | ||
const nearestPackageJSON = findupSync('package.json', { | ||
cwd: dirname(options.fileName), | ||
}); | ||
@@ -70,3 +64,3 @@ if (nearestPackageJSON) { | ||
// @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) }); | ||
await addDep([options.packageName], true, { cwd: dirname(nearestPackageJSON) }); | ||
// We must increment this version here so that when the language server | ||
@@ -88,3 +82,3 @@ // synchronizes it knows that we need re-create the program with the new | ||
if (text !== undefined) { | ||
this.setScriptSnapshot(fileName, typescript_1.ScriptSnapshot.fromString(text)); | ||
this.setScriptSnapshot(fileName, ScriptSnapshot.fromString(text)); | ||
} | ||
@@ -99,3 +93,2 @@ } | ||
} | ||
exports.RehearsalServiceHost = RehearsalServiceHost; | ||
//# sourceMappingURL=rehearsal-service-host.js.map |
@@ -1,3 +0,4 @@ | ||
import { RehearsalServiceHost } from './rehearsal-service-host'; | ||
import type { CompilerOptions, DiagnosticWithLocation, LanguageService, SourceFile } from 'typescript'; | ||
import ts from 'typescript'; | ||
import { RehearsalServiceHost } from './rehearsal-service-host.js'; | ||
import type { DiagnosticWithLocation, LanguageService, SourceFile } from 'typescript'; | ||
/** | ||
@@ -10,3 +11,3 @@ * Service represents the list of helper functions wrapped over compiled program context. | ||
protected readonly service: LanguageService; | ||
constructor(compilerOptions: CompilerOptions | undefined, fileNames: string[]); | ||
constructor(compilerOptions: ts.CompilerOptions | undefined, fileNames: string[]); | ||
/** | ||
@@ -32,2 +33,3 @@ * Gets the content of the file from its latest in-memory state | ||
getLanguageService(): LanguageService; | ||
getDiagnostics(fileName: string): DiagnosticWithLocation[]; | ||
/** | ||
@@ -41,3 +43,4 @@ * Gets a list of semantic diagnostic objects only with location information (those have related node in the AST) | ||
getSuggestionDiagnostics(fileName: string): DiagnosticWithLocation[]; | ||
getAdditionalDiagnostics(fileName: string): DiagnosticWithLocation[]; | ||
} | ||
//# sourceMappingURL=rehearsal-service.d.ts.map |
@@ -1,6 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RehearsalService = void 0; | ||
const typescript_1 = require("typescript"); | ||
const rehearsal_service_host_1 = require("./rehearsal-service-host"); | ||
import ts from 'typescript'; | ||
import { RehearsalServiceHost } from './rehearsal-service-host.js'; | ||
const { DiagnosticCategory, ScriptSnapshot, createLanguageService, forEachChild, isFunctionDeclaration, isMethodDeclaration, } = ts; | ||
/** | ||
@@ -10,6 +8,6 @@ * Service represents the list of helper functions wrapped over compiled program context. | ||
*/ | ||
class RehearsalService { | ||
export class RehearsalService { | ||
constructor(compilerOptions = {}, fileNames) { | ||
this.host = new rehearsal_service_host_1.RehearsalServiceHost(compilerOptions, fileNames); | ||
this.service = (0, typescript_1.createLanguageService)(this.host); | ||
this.host = new RehearsalServiceHost(compilerOptions, fileNames); | ||
this.service = createLanguageService(this.host); | ||
} | ||
@@ -21,3 +19,3 @@ /** | ||
const snapshot = this.host.getScriptSnapshot(fileName); | ||
return (snapshot === null || snapshot === void 0 ? void 0 : snapshot.getText(0, snapshot === null || snapshot === void 0 ? void 0 : snapshot.getLength())) || ''; | ||
return snapshot?.getText(0, snapshot?.getLength()) || ''; | ||
} | ||
@@ -28,3 +26,3 @@ /** | ||
setFileText(fileName, text) { | ||
this.host.setScriptSnapshot(fileName, typescript_1.ScriptSnapshot.fromString(text)); | ||
this.host.setScriptSnapshot(fileName, ScriptSnapshot.fromString(text)); | ||
} | ||
@@ -36,3 +34,3 @@ /** | ||
const snapshot = this.host.getScriptSnapshot(fileName); | ||
this.host.writeFile(fileName, (snapshot === null || snapshot === void 0 ? void 0 : snapshot.getText(0, snapshot === null || snapshot === void 0 ? void 0 : snapshot.getLength())) || ''); | ||
this.host.writeFile(fileName, snapshot?.getText(0, snapshot?.getLength()) || ''); | ||
} | ||
@@ -51,2 +49,9 @@ /** | ||
} | ||
getDiagnostics(fileName) { | ||
return [ | ||
...this.getSemanticDiagnosticsWithLocation(fileName), | ||
...this.getSuggestionDiagnostics(fileName), | ||
...this.getAdditionalDiagnostics(fileName), | ||
]; | ||
} | ||
/** | ||
@@ -66,4 +71,23 @@ * Gets a list of semantic diagnostic objects only with location information (those have related node in the AST) | ||
} | ||
getAdditionalDiagnostics(fileName) { | ||
const sourceFile = this.getSourceFile(fileName); | ||
const diagnostics = []; | ||
const visitEveryNode = (node) => { | ||
if ((isFunctionDeclaration(node) || isMethodDeclaration(node)) && node.name && !node.type) { | ||
diagnostics.push({ | ||
file: sourceFile, | ||
start: node.getStart(), | ||
length: node.getEnd() - node.getStart(), | ||
category: DiagnosticCategory.Suggestion, | ||
code: 7050, | ||
messageText: `${node.name.getText()} don't have a return type, but the type may be inferred from usage.`, | ||
}); | ||
return undefined; | ||
} | ||
return forEachChild(node, visitEveryNode); | ||
}; | ||
visitEveryNode(sourceFile); | ||
return diagnostics; | ||
} | ||
} | ||
exports.RehearsalService = RehearsalService; | ||
//# sourceMappingURL=rehearsal-service.js.map |
{ | ||
"name": "@rehearsal/service", | ||
"version": "1.0.10-beta", | ||
"version": "1.0.11-beta", | ||
"description": "Rehearsal Service", | ||
@@ -17,2 +17,10 @@ "keywords": [ | ||
"license": "BSD-2-Clause", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"import": "./dist/src/index.js", | ||
"require": "./dist/src/index.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "dist/src/index.js", | ||
@@ -26,4 +34,4 @@ "types": "dist/src/index.d.ts", | ||
"winston": "^3.8.2", | ||
"@rehearsal/reporter": "1.0.10-beta", | ||
"@rehearsal/utils": "1.0.10-beta" | ||
"@rehearsal/reporter": "1.0.11-beta", | ||
"@rehearsal/utils": "1.0.11-beta" | ||
}, | ||
@@ -30,0 +38,0 @@ "devDependencies": { |
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
79966
Yes
345
+ Added@rehearsal/reporter@1.0.11-beta(transitive)
+ Added@rehearsal/utils@1.0.11-beta(transitive)
+ Addedargparse@2.0.1(transitive)
+ Addedexeca@7.2.0(transitive)
+ Addedhuman-signals@4.3.1(transitive)
+ Addedis-stream@3.0.0(transitive)
+ Addedjs-yaml@4.1.0(transitive)
+ Addedmimic-fn@4.0.0(transitive)
+ Addednpm-run-path@5.3.0(transitive)
+ Addedonetime@6.0.0(transitive)
+ Addedpath-key@4.0.0(transitive)
+ Addedstrip-final-newline@3.0.0(transitive)
- Removed@rehearsal/reporter@1.0.10-beta(transitive)
- Removed@rehearsal/utils@1.0.10-beta(transitive)
- Removedexeca@5.1.1(transitive)
- Removedhuman-signals@2.1.0(transitive)
- Removedmimic-fn@2.1.0(transitive)
- Removednpm-run-path@4.0.1(transitive)
- Removedonetime@5.1.2(transitive)
- Removedstrip-final-newline@2.0.0(transitive)
Updated@rehearsal/utils@1.0.11-beta