Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix windows paths #5745

Merged
merged 9 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dark-cups-see.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@gradio/preview": minor
---

feat:Fix windows paths
17 changes: 14 additions & 3 deletions js/preview/src/dev_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,25 @@ function find_frontend_folders(
return results;
}

function to_posix(_path: string): string {
const isExtendedLengthPath = /^\\\\\?\\/.test(_path);
const hasNonAscii = /[^\u0000-\u0080]+/.test(_path); // eslint-disable-line no-control-regex

if (isExtendedLengthPath || hasNonAscii) {
return _path;
}

return _path.replace(/\\/g, '/');
}

function generate_imports(component_dir: string): string {
const components = find_frontend_folders(component_dir);

const imports = components.reduce((acc, component) => {
const x = {
interactive: join(component.dir, "interactive"),
static: join(component.dir, "static"),
example: join(component.dir, "example")
interactive: to_posix(join(component.dir, "interactive")),
static: to_posix(join(component.dir, "static")),
example: to_posix(join(component.dir, "example"))
};

const interactive = fs.existsSync(x.interactive) ? `interactive: () => import("${x.interactive}"),\n` : ""
Expand Down
Loading