@d-es-ign/stryker-js-util 9.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +13 -0
- package/dist/src/child-process-as-promised.d.ts +5 -0
- package/dist/src/child-process-as-promised.d.ts.map +1 -0
- package/dist/src/child-process-as-promised.js +6 -0
- package/dist/src/child-process-as-promised.js.map +1 -0
- package/dist/src/deep-merge.d.ts +10 -0
- package/dist/src/deep-merge.d.ts.map +1 -0
- package/dist/src/deep-merge.js +25 -0
- package/dist/src/deep-merge.js.map +1 -0
- package/dist/src/errors.d.ts +6 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +27 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/find-unserializables.d.ts +6 -0
- package/dist/src/find-unserializables.d.ts.map +1 -0
- package/dist/src/find-unserializables.js +60 -0
- package/dist/src/find-unserializables.js.map +1 -0
- package/dist/src/i.d.ts +8 -0
- package/dist/src/i.d.ts.map +1 -0
- package/dist/src/i.js +2 -0
- package/dist/src/i.js.map +1 -0
- package/dist/src/immutable.d.ts +12 -0
- package/dist/src/immutable.d.ts.map +1 -0
- package/dist/src/immutable.js +32 -0
- package/dist/src/immutable.js.map +1 -0
- package/dist/src/index.d.ts +17 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +17 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/known-keys.d.ts +8 -0
- package/dist/src/known-keys.d.ts.map +1 -0
- package/dist/src/known-keys.js +2 -0
- package/dist/src/known-keys.js.map +1 -0
- package/dist/src/noop-logger.d.ts +15 -0
- package/dist/src/noop-logger.d.ts.map +1 -0
- package/dist/src/noop-logger.js +39 -0
- package/dist/src/noop-logger.js.map +1 -0
- package/dist/src/not-empty.d.ts +2 -0
- package/dist/src/not-empty.d.ts.map +1 -0
- package/dist/src/not-empty.js +4 -0
- package/dist/src/not-empty.js.map +1 -0
- package/dist/src/platform.d.ts +9 -0
- package/dist/src/platform.d.ts.map +1 -0
- package/dist/src/platform.js +11 -0
- package/dist/src/platform.js.map +1 -0
- package/dist/src/primitive.d.ts +2 -0
- package/dist/src/primitive.d.ts.map +1 -0
- package/dist/src/primitive.js +2 -0
- package/dist/src/primitive.js.map +1 -0
- package/dist/src/require-resolve.d.ts +11 -0
- package/dist/src/require-resolve.d.ts.map +1 -0
- package/dist/src/require-resolve.js +18 -0
- package/dist/src/require-resolve.js.map +1 -0
- package/dist/src/split.d.ts +2 -0
- package/dist/src/split.d.ts.map +1 -0
- package/dist/src/split.js +15 -0
- package/dist/src/split.js.map +1 -0
- package/dist/src/string-utils.d.ts +41 -0
- package/dist/src/string-utils.d.ts.map +1 -0
- package/dist/src/string-utils.js +47 -0
- package/dist/src/string-utils.js.map +1 -0
- package/dist/src/stryker-error.d.ts +5 -0
- package/dist/src/stryker-error.d.ts.map +1 -0
- package/dist/src/stryker-error.js +9 -0
- package/dist/src/stryker-error.js.map +1 -0
- package/dist/src/task.d.ts +23 -0
- package/dist/src/task.d.ts.map +1 -0
- package/dist/src/task.js +56 -0
- package/dist/src/task.js.map +1 -0
- package/dist/src/test-files-provided.d.ts +4 -0
- package/dist/src/test-files-provided.d.ts.map +1 -0
- package/dist/src/test-files-provided.js +4 -0
- package/dist/src/test-files-provided.js.map +1 -0
- package/package.json +43 -0
- package/src/child-process-as-promised.ts +6 -0
- package/src/deep-merge.ts +29 -0
- package/src/errors.ts +31 -0
- package/src/find-unserializables.ts +71 -0
- package/src/i.ts +7 -0
- package/src/immutable.ts +58 -0
- package/src/index.ts +16 -0
- package/src/known-keys.ts +11 -0
- package/src/noop-logger.ts +38 -0
- package/src/not-empty.ts +3 -0
- package/src/platform.ts +10 -0
- package/src/primitive.ts +1 -0
- package/src/require-resolve.ts +19 -0
- package/src/split.ts +16 -0
- package/src/string-utils.ts +76 -0
- package/src/stryker-error.ts +12 -0
- package/src/task.ts +71 -0
- package/src/test-files-provided.ts +5 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export const noopLogger = {
|
|
2
|
+
isTraceEnabled(): boolean {
|
|
3
|
+
return false;
|
|
4
|
+
},
|
|
5
|
+
isDebugEnabled(): boolean {
|
|
6
|
+
return false;
|
|
7
|
+
},
|
|
8
|
+
isInfoEnabled(): boolean {
|
|
9
|
+
return false;
|
|
10
|
+
},
|
|
11
|
+
isWarnEnabled(): boolean {
|
|
12
|
+
return false;
|
|
13
|
+
},
|
|
14
|
+
isErrorEnabled(): boolean {
|
|
15
|
+
return false;
|
|
16
|
+
},
|
|
17
|
+
isFatalEnabled(): boolean {
|
|
18
|
+
return false;
|
|
19
|
+
},
|
|
20
|
+
trace(): void {
|
|
21
|
+
// noop
|
|
22
|
+
},
|
|
23
|
+
debug(): void {
|
|
24
|
+
// noop
|
|
25
|
+
},
|
|
26
|
+
info(): void {
|
|
27
|
+
// noop
|
|
28
|
+
},
|
|
29
|
+
warn(): void {
|
|
30
|
+
// noop
|
|
31
|
+
},
|
|
32
|
+
error(): void {
|
|
33
|
+
// noop
|
|
34
|
+
},
|
|
35
|
+
fatal(): void {
|
|
36
|
+
// noop
|
|
37
|
+
},
|
|
38
|
+
};
|
package/src/not-empty.ts
ADDED
package/src/platform.ts
ADDED
package/src/primitive.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Primitive = boolean | number | string | null | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Require a module from the current working directory (or a different base dir)
|
|
5
|
+
* @see https://nodejs.org/api/modules.html#modules_require_resolve_paths_request
|
|
6
|
+
*/
|
|
7
|
+
export function requireResolve(id: string, from = process.cwd()): unknown {
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
return require(resolveFromCwd(id, from));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Resolves a module from the current working directory (or a different base dir)
|
|
14
|
+
* @see https://nodejs.org/api/modules.html#modules_require_resolve_paths_request
|
|
15
|
+
*/
|
|
16
|
+
export function resolveFromCwd(id: string, cwd = process.cwd()): string {
|
|
17
|
+
const require = createRequire(import.meta.url);
|
|
18
|
+
return require.resolve(id, { paths: [cwd] });
|
|
19
|
+
}
|
package/src/split.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function split<T>(
|
|
2
|
+
values: Iterable<T>,
|
|
3
|
+
predicate: (value: T, index: number) => boolean,
|
|
4
|
+
): [T[], T[]] {
|
|
5
|
+
const left: T[] = [];
|
|
6
|
+
const right: T[] = [];
|
|
7
|
+
let index = 0;
|
|
8
|
+
for (const value of values) {
|
|
9
|
+
if (predicate(value, index++)) {
|
|
10
|
+
left.push(value);
|
|
11
|
+
} else {
|
|
12
|
+
right.push(value);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return [left, right];
|
|
16
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { KnownKeys } from './known-keys.js';
|
|
2
|
+
import { Primitive } from './primitive.js';
|
|
3
|
+
|
|
4
|
+
type OnlyObject<T> = Exclude<T, Primitive>;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Consolidates multiple consecutive white spaces into a single space.
|
|
8
|
+
* @param str The string to be normalized
|
|
9
|
+
*/
|
|
10
|
+
export function normalizeWhitespaces(str: string): string {
|
|
11
|
+
return str.replace(/\s+/g, ' ').trim();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Normalizes line endings as unix style.
|
|
16
|
+
*/
|
|
17
|
+
export function normalizeLineEndings(text: string): string {
|
|
18
|
+
return text.replace(/\r\n/g, '\n');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface PropertyPathOverloads<T> {
|
|
22
|
+
(key: KnownKeys<T>): string;
|
|
23
|
+
<TProp1 extends KnownKeys<T>>(
|
|
24
|
+
key: TProp1,
|
|
25
|
+
key2: KnownKeys<OnlyObject<T[TProp1]>>,
|
|
26
|
+
): string;
|
|
27
|
+
<
|
|
28
|
+
TProp1 extends KnownKeys<T>,
|
|
29
|
+
TProp2 extends KnownKeys<OnlyObject<T[TProp1]>>,
|
|
30
|
+
>(
|
|
31
|
+
key: TProp1,
|
|
32
|
+
key2: TProp2,
|
|
33
|
+
key3: KnownKeys<OnlyObject<OnlyObject<T[TProp1]>[TProp2]>>,
|
|
34
|
+
): string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Given a base type, allows type safe access to the name of a property.
|
|
39
|
+
* @param prop The property name
|
|
40
|
+
*/
|
|
41
|
+
export function propertyPath<T>(): PropertyPathOverloads<T> {
|
|
42
|
+
const fn: PropertyPathOverloads<T> = ((...args: string[]) =>
|
|
43
|
+
args.join('.')) as unknown as PropertyPathOverloads<T>;
|
|
44
|
+
return fn;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
|
|
49
|
+
*/
|
|
50
|
+
export function escapeRegExpLiteral(input: string): string {
|
|
51
|
+
return input.replace(/[.*+\-?^${}()|[\]\\/]/g, '\\$&'); // $& means the whole matched string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
|
|
56
|
+
*/
|
|
57
|
+
export function escapeRegExp(input: string): string {
|
|
58
|
+
return input.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Normalizes relative or absolute file names to be in posix format (forward slashes '/')
|
|
63
|
+
*/
|
|
64
|
+
export function normalizeFileName(fileName: string): string {
|
|
65
|
+
return fileName.replace(/\\/g, '/');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Creates a URL to the page where you can report a bug.
|
|
70
|
+
* @param titleSuggestion The title to be prefilled in.
|
|
71
|
+
*/
|
|
72
|
+
export function strykerReportBugUrl(titleSuggestion: string): string {
|
|
73
|
+
return `https://github.com/stryker-mutator/stryker-js/issues/new?assignees=&labels=%F0%9F%90%9B+Bug&template=bug_report.md&title=${encodeURIComponent(
|
|
74
|
+
titleSuggestion,
|
|
75
|
+
)}`;
|
|
76
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { errorToString } from './errors.js';
|
|
2
|
+
|
|
3
|
+
export class StrykerError extends Error {
|
|
4
|
+
constructor(
|
|
5
|
+
message: string,
|
|
6
|
+
public readonly innerError?: unknown,
|
|
7
|
+
) {
|
|
8
|
+
super(
|
|
9
|
+
`${message}${innerError ? `. Inner error: ${errorToString(innerError)}` : ''}`,
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
}
|
package/src/task.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps a promise in a Task api for convenience.
|
|
3
|
+
*/
|
|
4
|
+
export class Task<T = void> {
|
|
5
|
+
protected _promise: Promise<T>;
|
|
6
|
+
private resolveFn!: (value: PromiseLike<T> | T) => void;
|
|
7
|
+
private rejectFn!: (reason: any) => void;
|
|
8
|
+
private _isCompleted = false;
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
this._promise = new Promise<T>((resolve, reject) => {
|
|
12
|
+
this.resolveFn = resolve;
|
|
13
|
+
this.rejectFn = reject;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public get promise(): Promise<T> {
|
|
18
|
+
return this._promise;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public get isCompleted(): boolean {
|
|
22
|
+
return this._isCompleted;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public resolve = (result: PromiseLike<T> | T): void => {
|
|
26
|
+
this._isCompleted = true;
|
|
27
|
+
this.resolveFn(result);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
public reject: (reason: any) => void = (reason: any): void => {
|
|
31
|
+
this._isCompleted = true;
|
|
32
|
+
this.rejectFn(reason);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A task that can expire after the given time.
|
|
38
|
+
*/
|
|
39
|
+
export class ExpirableTask<T = void> extends Task<
|
|
40
|
+
T | typeof ExpirableTask.TimeoutExpired
|
|
41
|
+
> {
|
|
42
|
+
public static readonly TimeoutExpired: unique symbol =
|
|
43
|
+
Symbol('TimeoutExpired');
|
|
44
|
+
|
|
45
|
+
constructor(timeoutMS: number) {
|
|
46
|
+
super();
|
|
47
|
+
this._promise = ExpirableTask.timeout(this._promise, timeoutMS);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public static timeout<K>(
|
|
51
|
+
promise: Promise<K>,
|
|
52
|
+
ms: number,
|
|
53
|
+
): Promise<K | typeof ExpirableTask.TimeoutExpired> {
|
|
54
|
+
const sleep = new Promise<K | typeof ExpirableTask.TimeoutExpired>(
|
|
55
|
+
(res, rej) => {
|
|
56
|
+
const timer = setTimeout(() => res(ExpirableTask.TimeoutExpired), ms);
|
|
57
|
+
promise
|
|
58
|
+
.then((result) => {
|
|
59
|
+
clearTimeout(timer);
|
|
60
|
+
res(result);
|
|
61
|
+
})
|
|
62
|
+
.catch((error: unknown) => {
|
|
63
|
+
clearTimeout(timer);
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
65
|
+
rej(error);
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
return sleep;
|
|
70
|
+
}
|
|
71
|
+
}
|