-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin): allow fileDescriptions to be injected (#3582)
Allow `fileDescriptions` to be injected in plugins. File descriptions allow plugins to act on the file names discovered in the project (excluding any ignored files). A `FileDescriptions` object contain file names as keys and a new `FileDescription` as value. A file description currently only houses a `mutate` property (of type `MutationDescription`). ```ts class MyChecker { static inject = [commonTokens.fileDescriptions] as const; constructor(fileDescriptions: FileDescriptions) { } } ```
- Loading branch information
Showing
97 changed files
with
2,446 additions
and
1,689 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { MutationRange } from './mutation-range.js'; | ||
|
||
/** | ||
* Input files by file name. | ||
*/ | ||
export type FileDescriptions = Record<string, FileDescription>; | ||
|
||
export type MutateDescription = MutationRange[] | boolean; | ||
|
||
/** | ||
* The metadata of a input file | ||
*/ | ||
export interface FileDescription { | ||
mutate: MutateDescription; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,16 @@ | ||
import { Position } from './position.js'; | ||
|
||
/** | ||
* Represents a range of mutants that the instrumenter should instrument | ||
*/ | ||
export interface MutationRange { | ||
/** | ||
* The filename of the file that this range belongs to | ||
*/ | ||
fileName: string; | ||
|
||
/** | ||
* The start of the range to instrument, by line and column number, inclusive | ||
*/ | ||
start: { | ||
line: number; | ||
column: number; | ||
}; | ||
start: Position; | ||
|
||
/** | ||
* The end of the range to instrument, by line and number, inclusive | ||
*/ | ||
end: { | ||
line: number; | ||
column: number; | ||
}; | ||
end: Position; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import fs from 'fs'; | ||
|
||
import { Task } from '@stryker-mutator/util'; | ||
import { mergeMap, Subject } from 'rxjs'; | ||
import { Disposable } from 'typed-inject'; | ||
|
||
const MAX_CONCURRENT_FILE_IO = 256; | ||
|
||
class FileSystemAction<TOut> { | ||
public readonly task = new Task<TOut>(); | ||
|
||
/** | ||
* @param work The task, where a resource and input is presented | ||
*/ | ||
constructor(private readonly work: () => Promise<TOut>) {} | ||
|
||
public async execute() { | ||
try { | ||
const output = await this.work(); | ||
this.task.resolve(output); | ||
} catch (err) { | ||
this.task.reject(err); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* A wrapper around nodejs's 'fs' core module, for dependency injection purposes. | ||
* | ||
* Also has but with build-in buffering with a concurrency limit (like graceful-fs). | ||
*/ | ||
export class FileSystem implements Disposable { | ||
private readonly todoSubject = new Subject<FileSystemAction<any>>(); | ||
private readonly subscription = this.todoSubject | ||
.pipe( | ||
mergeMap(async (action) => { | ||
await action.execute(); | ||
}, MAX_CONCURRENT_FILE_IO) | ||
) | ||
.subscribe(); | ||
|
||
public dispose(): void { | ||
this.subscription.unsubscribe(); | ||
} | ||
|
||
public readonly readFile = this.forward('readFile'); | ||
public readonly copyFile = this.forward('copyFile'); | ||
public readonly writeFile = this.forward('writeFile'); | ||
public readonly mkdir = this.forward('mkdir'); | ||
public readonly readdir = this.forward('readdir'); | ||
|
||
private forward<TMethod extends keyof typeof fs.promises>(method: TMethod): typeof fs.promises[TMethod] { | ||
return (...args: any[]) => { | ||
const action = new FileSystemAction(() => (fs.promises[method] as any)(...args)); | ||
this.todoSubject.next(action); | ||
return action.task.promise as any; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './file-system.js'; | ||
export * from './project.js'; | ||
export * from './project-file.js'; | ||
export * from './project-reader.js'; |
Oops, something went wrong.