mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 23:40:45 +00:00
23 lines
664 B
TypeScript
23 lines
664 B
TypeScript
export function resolveNodeRequireFromMeta(
|
|
metaUrl: string,
|
|
): ((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;
|
|
};
|
|
const createRequire =
|
|
typeof moduleNamespace.createRequire === "function" ? moduleNamespace.createRequire : null;
|
|
return createRequire ? createRequire(metaUrl) : null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|