@rehearsal/service
Advanced tools
Comparing version 1.0.20-beta to 2.0.0-beta
@@ -1,6 +0,8 @@ | ||
import { type GlintLanguageServer, type TransformManager } from '@glint/core'; | ||
import * as ts from 'typescript'; | ||
import { DiagnosticSeverity, type Diagnostic, type Range, type CodeAction } from 'vscode-languageserver'; | ||
import { Service } from './rehearsal-service.js'; | ||
import type { GlintLanguageServer, TransformManager } from '@glint/core'; | ||
type TS = typeof import('typescript'); | ||
export type GlintCore = typeof import('@glint/core'); | ||
export type PathUtils = GlintCore['pathUtils']; | ||
export { Range, Diagnostic }; | ||
@@ -11,4 +13,5 @@ export declare class GlintService implements Service { | ||
readonly ts: TS; | ||
readonly pathUtils: PathUtils; | ||
private tsService; | ||
constructor(glintProjectDir: string); | ||
constructor(glintCore: GlintCore, glintProjectDir: string); | ||
/** | ||
@@ -15,0 +18,0 @@ * Gets the content of the file from its latest in-memory state |
@@ -1,2 +0,1 @@ | ||
import { analyzeProject, pathUtils, } from '@glint/core'; | ||
// This is disabled because vscode-uri is a commonjs module, which causes TS and Eslint to disagree | ||
@@ -9,4 +8,5 @@ // about how it should be imported (╯°□°)╯︵ ┻━┻ | ||
export class GlintService { | ||
constructor(glintProjectDir) { | ||
const { languageServer, transformManager, glintConfig } = analyzeProject(glintProjectDir); | ||
constructor(glintCore, glintProjectDir) { | ||
this.pathUtils = glintCore.pathUtils; | ||
const { languageServer, transformManager, glintConfig } = glintCore.analyzeProject(glintProjectDir); | ||
this.service = languageServer; | ||
@@ -73,4 +73,4 @@ this.transformManager = transformManager; | ||
: 0; | ||
const start = pathUtils.positionToOffset(sourceFile.text, diagnostic.range.start); | ||
const finish = pathUtils.positionToOffset(sourceFile.text, diagnostic.range.end); | ||
const start = this.pathUtils.positionToOffset(sourceFile.text, diagnostic.range.start); | ||
const finish = this.pathUtils.positionToOffset(sourceFile.text, diagnostic.range.end); | ||
return { | ||
@@ -93,4 +93,4 @@ source: diagnostic.source, | ||
range: { | ||
start: pathUtils.offsetToPosition(diagnostic.file.text, diagnostic.start), | ||
end: pathUtils.offsetToPosition(diagnostic.file.text, diagnostic.start + diagnostic.length), | ||
start: this.pathUtils.offsetToPosition(diagnostic.file.text, diagnostic.start), | ||
end: this.pathUtils.offsetToPosition(diagnostic.file.text, diagnostic.start + diagnostic.length), | ||
}, | ||
@@ -116,4 +116,4 @@ }; | ||
textChanges: change.edits.map((edit) => { | ||
const start = pathUtils.positionToOffset(fixSourceFile.text, edit.range.start); | ||
const finish = pathUtils.positionToOffset(fixSourceFile.text, edit.range.end); | ||
const start = this.pathUtils.positionToOffset(fixSourceFile.text, edit.range.start); | ||
const finish = this.pathUtils.positionToOffset(fixSourceFile.text, edit.range.end); | ||
return { | ||
@@ -120,0 +120,0 @@ newText: edit.newText, |
@@ -1,7 +0,7 @@ | ||
export { Plugin, PluginOptions, PluginsRunnerContext, PluginsRunner } from './plugin.js'; | ||
export { DummyPlugin, Plugin, PluginFactory, PluginOptions, PluginsRunnerContext, PluginsRunner, } from './plugin.js'; | ||
export { RehearsalService, type Service } from './rehearsal-service.js'; | ||
export { RehearsalServiceHost } from './rehearsal-service-host.js'; | ||
export { GlintService, type Range } from './glint-service.js'; | ||
export { GlintService, type Range, type PathUtils } from './glint-service.js'; | ||
export * from './glint-utils.js'; | ||
export type { PluginResult } from './plugin.js'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export { PluginsRunner } from './plugin.js'; | ||
export { DummyPlugin, Plugin, PluginsRunner, } from './plugin.js'; | ||
export { RehearsalService } from './rehearsal-service.js'; | ||
@@ -3,0 +3,0 @@ export { RehearsalServiceHost } from './rehearsal-service-host.js'; |
import { Reporter } from '@rehearsal/reporter'; | ||
import { Logger } from 'winston'; | ||
import { Service } from './rehearsal-service.js'; | ||
export interface Plugin<PluginOptions> { | ||
run(fileName: string, context: PluginsRunnerContext, options: PluginOptions): PluginResult; | ||
export declare abstract class Plugin<Options extends PluginOptions = PluginOptions> { | ||
fileName: string; | ||
context: PluginsRunnerContext; | ||
options: Options; | ||
constructor(fileName: string, context: PluginsRunnerContext, options: Options); | ||
abstract run(): Promise<string[]>; | ||
} | ||
export declare class DummyPlugin extends Plugin { | ||
run(): Promise<string[]>; | ||
} | ||
export type PluginFactory<PluginType extends Plugin = Plugin, PluginOptionsType extends PluginOptions = PluginOptions> = new (fileName: string, context: PluginsRunnerContext, options: PluginOptionsType) => PluginType; | ||
export interface PluginOptions { | ||
filter?: (fileName: string) => boolean; | ||
} | ||
@@ -21,9 +28,24 @@ export type PluginResult = Promise<string[]>; | ||
export declare class PluginsRunner { | ||
plugins: { | ||
plugin: Plugin<PluginOptions>; | ||
options: PluginOptions; | ||
layers: { | ||
plugin: PluginFactory; | ||
options?: PluginOptions; | ||
filter?: (fileName: string) => boolean; | ||
}[]; | ||
context: PluginsRunnerContext; | ||
constructor(context: PluginsRunnerContext); | ||
queue<P extends Plugin<PluginOptions>>(plugin: P, options: P extends Plugin<infer O> ? O : never): this; | ||
/** | ||
* This accounts for all the call signatures. The final call signature needs | ||
* to account for all permutations. | ||
* | ||
* ``` | ||
* .queue(SomePlugin) | ||
* .queue(SomePlugin, { someOption: true }) | ||
* .queue(SomePlugin, function someFiler() { return true; }) | ||
* .queue(SomePlugin, { someOption: true }, function someFiler() { return true; }) | ||
*``` | ||
*/ | ||
queue<PluginType extends Plugin = Plugin, PluginOptionsType extends PluginOptions = PluginOptions>(plugin: PluginFactory<PluginType, PluginOptionsType>): this; | ||
queue<PluginType extends Plugin = Plugin, PluginOptionsType extends PluginOptions = PluginOptions>(plugin: PluginFactory<PluginType, PluginOptionsType>, filter: (fileName: string) => boolean): this; | ||
queue<PluginType extends Plugin = Plugin, PluginOptionsType extends PluginOptions = PluginOptions>(plugin: PluginFactory<PluginType, PluginOptionsType>, options: PluginOptionsType): this; | ||
queue<PluginType extends Plugin = Plugin, PluginOptionsType extends PluginOptions = PluginOptions>(plugin: PluginFactory<PluginType, PluginOptionsType>, options: PluginOptionsType, filter: (fileName: string) => boolean): this; | ||
run(fileNames: string[], logger?: PluginLogger): AsyncGenerator<string>; | ||
@@ -30,0 +52,0 @@ processFilesGenerator(fileNames: string[], logger?: PluginLogger): AsyncGenerator<string>; |
@@ -0,8 +1,40 @@ | ||
export class Plugin { | ||
constructor(fileName, context, options) { | ||
this.fileName = fileName; | ||
this.context = context; | ||
this.options = options; | ||
} | ||
} | ||
export class DummyPlugin extends Plugin { | ||
run() { | ||
return Promise.resolve([]); | ||
} | ||
} | ||
export class PluginsRunner { | ||
constructor(context) { | ||
this.plugins = []; | ||
this.layers = []; | ||
this.context = context; | ||
} | ||
queue(plugin, options) { | ||
this.plugins.push({ plugin, options }); | ||
queue(plugin, ...optionsOrFilter) { | ||
if (optionsOrFilter.length === 2) { | ||
const [options, filter] = optionsOrFilter; | ||
this.layers.push({ plugin: plugin, options, filter }); | ||
} | ||
else if (optionsOrFilter.length === 1) { | ||
if (typeof optionsOrFilter[0] === 'object') { | ||
this.layers.push({ | ||
plugin: plugin, | ||
options: optionsOrFilter[0], | ||
}); | ||
} | ||
else { | ||
this.layers.push({ | ||
plugin: plugin, | ||
filter: optionsOrFilter[0], | ||
}); | ||
} | ||
} | ||
else { | ||
this.layers.push({ plugin }); | ||
} | ||
return this; | ||
@@ -41,5 +73,5 @@ } | ||
async *processPlugins(fileName, allChangedFiles) { | ||
for (const plugin of this.plugins) { | ||
if (plugin.options.filter) { | ||
if (!plugin.options.filter(fileName)) { | ||
for (const layer of this.layers) { | ||
if (layer.filter) { | ||
if (!layer.filter(fileName)) { | ||
yield allChangedFiles; | ||
@@ -49,3 +81,4 @@ continue; | ||
} | ||
const changedFiles = await plugin.plugin.run(fileName, this.context, plugin.options); | ||
const plugin = new layer.plugin(fileName, this.context, layer.options ? layer.options : {}); | ||
const changedFiles = await plugin.run(); | ||
allChangedFiles = new Set([...allChangedFiles, ...changedFiles]); | ||
@@ -52,0 +85,0 @@ yield allChangedFiles; |
{ | ||
"name": "@rehearsal/service", | ||
"version": "1.0.20-beta", | ||
"version": "2.0.0-beta", | ||
"description": "Rehearsal Service", | ||
@@ -35,9 +35,9 @@ "keywords": [ | ||
"winston": "^3.8.2", | ||
"@rehearsal/reporter": "1.0.20-beta", | ||
"@rehearsal/utils": "1.0.20-beta" | ||
"@rehearsal/reporter": "2.0.0-beta", | ||
"@rehearsal/utils": "2.0.0-beta" | ||
}, | ||
"devDependencies": { | ||
"type-fest": "^3.6.1", | ||
"vitest": "^0.29.2", | ||
"@rehearsal/test-support": "1.0.20-beta" | ||
"@vitest/coverage-c8": "^0.30.1", | ||
"type-fest": "^3.8.0", | ||
"vitest": "^0.29.8" | ||
}, | ||
@@ -60,3 +60,3 @@ "peerDependencies": { | ||
"lint:tsc-test": "tsc --noEmit --project test/tsconfig.json", | ||
"test": "vitest --run --config ./vitest.config.ts", | ||
"test": "vitest --run --config ./vitest.config.ts --coverage", | ||
"test:slow": "vitest --run", | ||
@@ -63,0 +63,0 @@ "test:watch": "vitest --coverage --watch", |
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
311577
681
1
+ Added@rehearsal/reporter@2.0.0-beta(transitive)
+ Added@rehearsal/utils@2.0.0-beta(transitive)
+ Addedchalk@5.4.1(transitive)
+ Addedcompare-versions@6.0.0-rc.1(transitive)
+ Addedglob@9.3.5(transitive)
+ Addedlru-cache@10.4.3(transitive)
+ Addedminimatch@8.0.4(transitive)
+ Addedminipass@4.2.87.1.2(transitive)
+ Addedpath-scurry@1.11.1(transitive)
- Removed@rehearsal/reporter@1.0.20-beta(transitive)
- Removed@rehearsal/utils@1.0.20-beta(transitive)
- Removedchalk@4.1.2(transitive)
- Removedcompare-versions@5.0.3(transitive)
- Removedget-tsconfig@4.10.0(transitive)
- Removedglob@8.1.0(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedinflight@1.0.6(transitive)
- Removedminimatch@5.1.6(transitive)
- Removedonce@1.4.0(transitive)
- Removedresolve-pkg-maps@1.0.0(transitive)
- Removedsupports-color@7.2.0(transitive)
- Removedwrappy@1.0.2(transitive)
Updated@rehearsal/utils@2.0.0-beta