mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 03:18:26 +00:00
refactor(logging): share node createRequire resolution
This commit is contained in:
@@ -1,27 +1,7 @@
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { resolveNodeRequireFromMeta } from "./node-require.js";
|
||||
|
||||
function resolveNodeRequire(): ((id: string) => NodeJS.Require) | null {
|
||||
const getBuiltinModule = (
|
||||
process as NodeJS.Process & {
|
||||
getBuiltinModule?: (id: string) => unknown;
|
||||
}
|
||||
).getBuiltinModule;
|
||||
if (typeof getBuiltinModule !== "function") {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
const moduleNamespace = getBuiltinModule("module") as {
|
||||
createRequire?: (id: string) => NodeJS.Require;
|
||||
};
|
||||
return typeof moduleNamespace.createRequire === "function"
|
||||
? moduleNamespace.createRequire
|
||||
: null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const requireConfig = resolveNodeRequire()?.(import.meta.url) ?? null;
|
||||
const requireConfig = resolveNodeRequireFromMeta(import.meta.url);
|
||||
|
||||
export type RedactSensitiveMode = "off" | "tools";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user