You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add new `globalShims` option, what means you can env `SYNCKIT_GLOBAL_SHIMS=1` to enable auto polyfilling for some modules, for example: `fetch` from `node-fetch`, `performance` from `node:perf_hooks`.
6
+
7
+
You can also pass a custom `globalShims` option as `GlobalShim``Array` to custom your own shims:
8
+
9
+
````ts
10
+
exportinterfaceGlobalShim {
11
+
moduleName:string
12
+
/**
13
+
* `undefined` means side effect only
14
+
*/
15
+
globalName?:string
16
+
/**
17
+
* 1. `undefined` or empty string means `default`, for example:
18
+
* ```js
19
+
* import globalName from 'module-name'
20
+
* ```
21
+
*
22
+
* 2. `null` means namespaced, for example:
23
+
* ```js
24
+
* import * as globalName from 'module-name'
25
+
* ```
26
+
*
27
+
*/
28
+
named?:string|null
29
+
/**
30
+
* If not `false`, the shim will only be applied when the original `globalName` unavailable,
31
+
* for example you may only want polyfill `globalThis.fetch` when it's unavailable natively:
32
+
* ```js
33
+
* import fetch from 'node-fetch'
34
+
*
35
+
* if (!globalThis.fetch) {
36
+
* globalThis.fetch = fetch
37
+
* }
38
+
* ```
39
+
*/
40
+
conditional?:boolean
41
+
}
42
+
````
43
+
44
+
You can aslo reuse the exported `DEFAULT_GLOBAL_SHIMS_PRESET` for extanding:
You must make sure, the `result` is serializable by [`Structured Clone Algorithm`](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
73
74
75
+
### Types
76
+
77
+
````ts
78
+
exportinterfaceGlobalShim {
79
+
moduleName:string
80
+
/**
81
+
* `undefined` means side effect only
82
+
*/
83
+
globalName?:string
84
+
/**
85
+
* 1. `undefined` or empty string means `default`, for example:
86
+
* ```js
87
+
* import globalName from 'module-name'
88
+
* ```
89
+
*
90
+
* 2. `null` means namespaced, for example:
91
+
* ```js
92
+
* import * as globalName from 'module-name'
93
+
* ```
94
+
*
95
+
*/
96
+
named?:string|null
97
+
/**
98
+
* If not `false`, the shim will only be applied when the original `globalName` unavailable,
99
+
* for example you may only want polyfill `globalThis.fetch` when it's unavailable natively:
6.`globalShims`: Similar like env `SYNCKIT_GLOBAL_SHIMS` but much more flexible which can be a `GlobalShim``Array`, see `GlobalShim`'s [definition](#types) for more details
81
120
82
121
### Envs
83
122
84
123
1.`SYNCKIT_BUFFER_SIZE`: `bufferSize` to create `SharedArrayBuffer` for `worker_threads` (default as `1024`)
85
124
2.`SYNCKIT_TIMEOUT`: `timeout` for performing the async job (no default)
86
125
3.`SYNCKIT_EXEC_ARGV`: List of node CLI options passed to the worker, split with comma `,`. (default as `[]`), see also [`node` docs](https://nodejs.org/api/worker_threads.html)
87
126
4.`SYNCKIT_TS_RUNNER`: Which TypeScript runner to be used, it could be very useful for development, could be `'ts-node' | 'esbuild-register' | 'esbuild-runner' | 'swc' | 'tsx'`, `'ts-node'` is used by default, make sure you have installed them already
127
+
5.`SYNCKIT_GLOBAL_SHIMS`: Whether to enable the default `DEFAULT_GLOBAL_SHIMS_PRESET` as `globalShims`
0 commit comments