-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.ts
More file actions
30 lines (26 loc) · 1.01 KB
/
module.ts
File metadata and controls
30 lines (26 loc) · 1.01 KB
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
/**
* @fileoverview Lazy-loader for `node:module`. See `node/fs.ts` for
* the design rationale shared across all `node/*.ts` lazy-loaders.
*/
// eslint-disable-next-line n/prefer-node-protocol
import type * as NodeModule from 'node:module'
let _module: typeof NodeModule | undefined
/*@__NO_SIDE_EFFECTS__*/
export function getNodeModule(): typeof NodeModule {
return (_module ??= /*@__PURE__*/ require('node:module') as typeof NodeModule)
}
/**
* Lazy + cached reference to `node:module`'s `isBuiltin(name)`. First
* call resolves the binding; subsequent calls dispatch through the
* cached function reference. Safe to detach — `isBuiltin` is
* `this`-free.
*
* Single source of truth for "is this a Node builtin?" probes across
* socket-lib (used by the smol-binding loaders to gate
* `require('node:smol-*')`).
*/
let _isBuiltin: ((name: string) => boolean) | undefined
/*@__NO_SIDE_EFFECTS__*/
export function isNodeBuiltin(name: string): boolean {
return (_isBuiltin ??= getNodeModule().isBuiltin)(name)
}