MCPcopy Create free account
hub / github.com/Noumena-Network/code / getRequireFunction

Function getRequireFunction

src/utils/markdown/nativeFencedCodeRenderer.ts:100–129  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

98}
99
100function getRequireFunction(): RequireFunction | null {
101 if (cachedRequireFn !== undefined) {
102 return cachedRequireFn
103 }
104 const globalWithRequire = globalThis as GlobalWithRequire
105 if (typeof globalWithRequire.require === 'function') {
106 cachedRequireFn = globalWithRequire.require.bind(globalThis) as RequireFunction
107 debugState.requireSource = 'global'
108 return cachedRequireFn
109 }
110 if (typeof module !== 'undefined' && typeof module.require === 'function') {
111 cachedRequireFn = module.require.bind(module)
112 debugState.requireSource = 'module'
113 return cachedRequireFn
114 }
115 if (cachedCreateRequireFn !== undefined) {
116 debugState.requireSource = cachedCreateRequireFn ? 'createRequire' : 'none'
117 return cachedCreateRequireFn
118 }
119 try {
120 cachedCreateRequireFn = createRequire(import.meta.url)
121 debugState.requireSource = 'createRequire'
122 return cachedCreateRequireFn
123 } catch {
124 cachedCreateRequireFn = null
125 }
126 debugState.requireSource = 'none'
127 cachedRequireFn = null
128 return null
129}
130
131function resolveRendererFunction(
132 value: unknown,

Callers 1

loadNativeRendererFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected