Skip to content

Commit 1ac2443

Browse files
committed
add globalThis to protect against potentially missing process symbol
1 parent 06f3baf commit 1ac2443

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

src/diagnostics.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,19 @@ function resolveDiagnosticsChannel(): DiagnosticsChannelModule | undefined {
7575
let dc: DiagnosticsChannelModule | undefined;
7676
try {
7777
if (
78-
typeof process !== 'undefined' &&
79-
typeof (process as { getBuiltinModule?: (id: string) => unknown })
80-
.getBuiltinModule === 'function'
81-
) {
82-
dc = (
83-
process as {
84-
getBuiltinModule: (id: string) => DiagnosticsChannelModule;
78+
// eslint-disable-next-line n/no-unsupported-features/node-builtins
79+
typeof (
80+
globalThis as {
81+
process?: { getBuiltinModule?: (id: string) => unknown };
8582
}
86-
).getBuiltinModule('node:diagnostics_channel');
83+
)?.process?.getBuiltinModule === 'function'
84+
) {
85+
// eslint-disable-next-line n/no-unsupported-features/node-builtins
86+
dc = globalThis.process.getBuiltinModule(
87+
'node:diagnostics_channel',
88+
) as DiagnosticsChannelModule;
8789
}
90+
// TODO: remove this code when we drop support for Node < 20.16>.
8891
/* c8 ignore next 6 */
8992
if (!dc && typeof require === 'function') {
9093
// CJS fallback for runtimes that lack `process.getBuiltinModule`

0 commit comments

Comments
 (0)