forked from un-ts/synckit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
75 lines (64 loc) · 1.8 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { MessagePort } from 'node:worker_threads'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type AnyFn<R = any, T extends any[] = any[]> = (...args: T) => R
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type AnyPromise<T = any> = Promise<T>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type AnyAsyncFn<T = any> = AnyFn<Promise<T>>
export type Syncify<T extends AnyAsyncFn> = T extends (
...args: infer Args
) => Promise<infer R>
? (...args: Args) => R
: never
export type PromiseType<T extends AnyPromise> =
T extends Promise<infer R> ? R : never
export type ValueOf<T> = T[keyof T]
export interface MainToWorkerMessage<T extends unknown[]> {
id: number
args: T
}
export interface WorkerData {
sharedBuffer: SharedArrayBuffer
workerPort: MessagePort
pnpLoaderPath: string | undefined
}
export interface DataMessage<T> {
result?: T
error?: unknown
properties?: unknown
}
export interface WorkerToMainMessage<T = unknown> extends DataMessage<T> {
id: number
}
export interface GlobalShim {
moduleName: string
/**
* `undefined` means side effect only
*/
globalName?: string
/**
* 1. `undefined` or empty string means `default`, for example:
* ```js
* import globalName from 'module-name'
* ```
*
* 2. `null` means namespaced, for example:
* ```js
* import * as globalName from 'module-name'
* ```
*
*/
named?: string | null
/**
* If not `false`, the shim will only be applied when the original `globalName` unavailable,
* for example you may only want polyfill `globalThis.fetch` when it's unavailable natively:
* ```js
* import fetch from 'node-fetch'
*
* if (!globalThis.fetch) {
* globalThis.fetch = fetch
* }
* ```
*/
conditional?: boolean
}