node: added url support to loadFile (#6507)

This commit is contained in:
FloVanGH 2024-10-10 11:43:32 +00:00 committed by GitHub
parent be2af11a08
commit f01ac8fc39
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 95 additions and 89 deletions

View file

@ -605,7 +605,7 @@ function loadSlint(loadData: LoadData): Object {
* main.greeting = "Hello friends";
* ```
*
* @param filePath The path to the file to load. Relative paths are resolved against the process' current working directory.
* @param filePath The path to the file to load as `string` or `URL`. Relative paths are resolved against the process' current working directory.
* @param options An optional {@link LoadFileOptions} to configure additional Slint compilation settings,
* such as include search paths, library imports, or the widget style.
* @returns Returns an object that is immutable and provides a constructor function for each exported Window component found in the `.slint` file.
@ -614,9 +614,13 @@ function loadSlint(loadData: LoadData): Object {
* For further information on the available properties, refer to [Instantiating A Component](../index.html#md:instantiating-a-component).
* @throws {@link CompileError} if errors occur during compilation.
*/
export function loadFile(filePath: string, options?: LoadFileOptions): Object {
export function loadFile(
filePath: string | URL,
options?: LoadFileOptions,
): Object {
const pathname = filePath instanceof URL ? filePath.pathname : filePath;
return loadSlint({
fileData: { filePath, options },
fileData: { filePath: pathname, options },
from: "file",
});
}