Node.js: Fix support for loadFile() with an URL on Windows

We recommend the use of `loadFile(new URL("...", import.metal.url))`,
but this never worked on Windows, because we're not using the API
the Node.js docs even recommend to correctly covert to a local path on Windows.

(Apply the same logic to initTranslations)

Fixes #8209
This commit is contained in:
Simon Hausmann 2025-04-22 17:07:58 +02:00 committed by Simon Hausmann
parent 5dc8410f0a
commit f94e5a73b0
2 changed files with 12 additions and 3 deletions

View file

@ -16,6 +16,8 @@ export { ArrayModel } from "./models";
import { Diagnostic } from "../rust-module.cjs";
import { fileURLToPath } from "node:url";
/**
* Represents a two-dimensional point.
*/
@ -626,7 +628,8 @@ export function loadFile(
filePath: string | URL,
options?: LoadFileOptions,
): Object {
const pathname = filePath instanceof URL ? filePath.pathname : filePath;
const pathname =
filePath instanceof URL ? fileURLToPath(filePath) : filePath;
return loadSlint({
fileData: { filePath: pathname, options },
from: "file",
@ -948,7 +951,7 @@ export namespace private_api {
* ````
*/
export function initTranslations(domain: string, path: string | URL) {
const pathname = path instanceof URL ? path.pathname : path;
const pathname = path instanceof URL ? fileURLToPath(path) : path;
napi.initTranslations(domain, pathname);
}