UNPKG

@cloudflare/unenv-preset

Version:
259 lines (258 loc) 5.17 kB
import { hrtime as UnenvHrTime } from "unenv/node/internal/process/hrtime"; import { Process as UnenvProcess } from "unenv/node/internal/process/process"; const globalProcess = globalThis["process"]; export const getBuiltinModule = globalProcess.getBuiltinModule; const workerdProcess = getBuiltinModule("node:process"); const isWorkerdProcessV2 = globalThis.Cloudflare.compatibilityFlags.enable_nodejs_process_v2; const unenvProcess = new UnenvProcess({ env: globalProcess.env, // `hrtime` is only available from workerd process v2 hrtime: isWorkerdProcessV2 ? workerdProcess.hrtime : UnenvHrTime, // `nextTick` is available from workerd process v1 nextTick: workerdProcess.nextTick }); export const { exit, features, platform } = workerdProcess; export const { // Always implemented by workerd env, // Only implemented in workerd v2 hrtime, // Always implemented by workerd nextTick } = unenvProcess; export const { _channel, _disconnect, _events, _eventsCount, _handleQueue, _maxListeners, _pendingMessage, _send, assert, disconnect, mainModule } = unenvProcess; export const { // @ts-expect-error `_debugEnd` is missing typings _debugEnd, // @ts-expect-error `_debugProcess` is missing typings _debugProcess, // @ts-expect-error `_exiting` is missing typings _exiting, // @ts-expect-error `_fatalException` is missing typings _fatalException, // @ts-expect-error `_getActiveHandles` is missing typings _getActiveHandles, // @ts-expect-error `_getActiveRequests` is missing typings _getActiveRequests, // @ts-expect-error `_kill` is missing typings _kill, // @ts-expect-error `_linkedBinding` is missing typings _linkedBinding, // @ts-expect-error `_preload_modules` is missing typings _preload_modules, // @ts-expect-error `_rawDebug` is missing typings _rawDebug, // @ts-expect-error `_startProfilerIdleNotifier` is missing typings _startProfilerIdleNotifier, // @ts-expect-error `_stopProfilerIdleNotifier` is missing typings _stopProfilerIdleNotifier, // @ts-expect-error `_tickCallback` is missing typings _tickCallback, abort, addListener, allowedNodeEnvironmentFlags, arch, argv, argv0, availableMemory, // @ts-expect-error `binding` is missing typings binding, channel, chdir, config, connected, constrainedMemory, cpuUsage, cwd, debugPort, dlopen, // @ts-expect-error `domain` is missing typings domain, emit, emitWarning, eventNames, execArgv, execPath, exitCode, finalization, getActiveResourcesInfo, getegid, geteuid, getgid, getgroups, getMaxListeners, getuid, hasUncaughtExceptionCaptureCallback, // @ts-expect-error `initgroups` is missing typings initgroups, kill, listenerCount, listeners, loadEnvFile, memoryUsage, // @ts-expect-error `moduleLoadList` is missing typings moduleLoadList, off, on, once, // @ts-expect-error `openStdin` is missing typings openStdin, permission, pid, ppid, prependListener, prependOnceListener, rawListeners, // @ts-expect-error `reallyExit` is missing typings reallyExit, ref, release, removeAllListeners, removeListener, report, resourceUsage, send, setegid, seteuid, setgid, setgroups, setMaxListeners, setSourceMapsEnabled, setuid, setUncaughtExceptionCaptureCallback, sourceMapsEnabled, stderr, stdin, stdout, throwDeprecation, title, traceDeprecation, umask, unref, uptime, version, versions } = isWorkerdProcessV2 ? workerdProcess : unenvProcess; const _process = { abort, addListener, allowedNodeEnvironmentFlags, hasUncaughtExceptionCaptureCallback, setUncaughtExceptionCaptureCallback, loadEnvFile, sourceMapsEnabled, arch, argv, argv0, chdir, config, connected, constrainedMemory, availableMemory, cpuUsage, cwd, debugPort, dlopen, disconnect, emit, emitWarning, env, eventNames, execArgv, execPath, exit, finalization, features, getBuiltinModule, getActiveResourcesInfo, getMaxListeners, hrtime, kill, listeners, listenerCount, memoryUsage, nextTick, on, off, once, pid, platform, ppid, prependListener, prependOnceListener, rawListeners, release, removeAllListeners, removeListener, report, resourceUsage, setMaxListeners, setSourceMapsEnabled, stderr, stdin, stdout, title, throwDeprecation, traceDeprecation, umask, uptime, version, versions, // @ts-expect-error old API domain, initgroups, moduleLoadList, reallyExit, openStdin, assert, binding, send, exitCode, channel, getegid, geteuid, getgid, getgroups, getuid, setegid, seteuid, setgid, setgroups, setuid, permission, mainModule, _events, _eventsCount, _exiting, _maxListeners, _debugEnd, _debugProcess, _fatalException, _getActiveHandles, _getActiveRequests, _kill, _preload_modules, _rawDebug, _startProfilerIdleNotifier, _stopProfilerIdleNotifier, _tickCallback, _disconnect, _handleQueue, _pendingMessage, _channel, _send, _linkedBinding }; export default _process;