forked from TypeStrong/ts-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
child-require.ts
27 lines (24 loc) · 987 Bytes
/
child-require.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
interface EventEmitterInternals {
_events: Record<string, Function | Array<Function>>;
}
const _process = process as any as EventEmitterInternals;
// Not shown here: Additional logic to correctly interact with process's events, either using this direct manipulation, or via the API
let originalOnWarning: Function | undefined;
if (Array.isArray(_process._events.warning)) {
originalOnWarning = _process._events.warning[0];
_process._events.warning[0] = onWarning;
} else {
originalOnWarning = _process._events.warning;
_process._events.warning = onWarning;
}
const messageMatch = /(?:--(?:experimental-)?loader\b|\bCustom ESM Loaders\b)/;
function onWarning(this: any, warning: Error, ...rest: any[]) {
// Suppress warning about how `--loader` is experimental
if (
warning?.name === 'ExperimentalWarning' &&
messageMatch.test(warning?.message)
)
return;
// Will be undefined if `--no-warnings`
return originalOnWarning?.call(this, warning, ...rest);
}