Skip to content

Commit dcfd73a

Browse files
committed
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. Fixes #8209
1 parent 5dc8410 commit dcfd73a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

api/node/__test__/api.spec.mts

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ const dirname = path.dirname(
1313

1414
// loadFile api
1515
test("loadFile", (t) => {
16-
const demo = loadFile(path.join(dirname, "resources/test.slint")) as any;
16+
// Test the URL variant here, to ensure that it works (esp. on Windows)
17+
const demo = loadFile(
18+
new URL(
19+
"resources/test.slint",
20+
import.meta.url.replace("build", "__test__"),
21+
),
22+
) as any;
1723
const test = new demo.Test();
1824
t.is(test.check, "Test");
1925

api/node/typescript/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export { ArrayModel } from "./models";
1616

1717
import { Diagnostic } from "../rust-module.cjs";
1818

19+
import { fileURLToPath } from "node:url";
20+
1921
/**
2022
* Represents a two-dimensional point.
2123
*/
@@ -626,7 +628,8 @@ export function loadFile(
626628
filePath: string | URL,
627629
options?: LoadFileOptions,
628630
): Object {
629-
const pathname = filePath instanceof URL ? filePath.pathname : filePath;
631+
const pathname =
632+
filePath instanceof URL ? fileURLToPath(filePath) : filePath;
630633
return loadSlint({
631634
fileData: { filePath: pathname, options },
632635
from: "file",

0 commit comments

Comments
 (0)