Files
openclaw/src/shared/import-specifier.ts
Peter Steinberger cf499101a2 fix(agents): normalize Windows runtime imports (#72731)
* fix(agents): normalize Windows runtime imports

* test(providers): align manifest contract coverage
2026-04-27 10:34:25 +01:00

20 lines
558 B
TypeScript

import path from "node:path";
import { pathToFileURL } from "node:url";
/**
* On Windows, Node's ESM loader requires absolute paths to be expressed as
* file:// URLs. Raw drive-letter paths like C:\... are parsed as URL schemes.
*/
export function toSafeImportPath(specifier: string): string {
if (process.platform !== "win32") {
return specifier;
}
if (specifier.startsWith("file://")) {
return specifier;
}
if (path.win32.isAbsolute(specifier)) {
return pathToFileURL(specifier, { windows: true }).href;
}
return specifier;
}