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 cc build #6079

Merged
merged 11 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
7 changes: 7 additions & 0 deletions .changeset/weak-games-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@gradio/preview": minor
"gradio": minor
"gradio_test": minor
---

feat:fix cc build
1 change: 1 addition & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ jobs:
with:
path: |
gradio/templates/*
gradio/node/*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

key: gradio-lib-front-end-${{ hashFiles('js/**', 'client/js/**')}}
- name: Install pnpm
if: steps.frontend-cache.outputs.cache-hit != 'true'
Expand Down
6 changes: 4 additions & 2 deletions gradio/cli/commands/components/_create_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ def delete_contents(directory: str | Path) -> None:
shutil.rmtree(child)


def _create_frontend(name: str, component: ComponentFiles, directory: Path):
def _create_frontend(
name: str, component: ComponentFiles, directory: Path, package_name: str
):
frontend = directory / "frontend"
frontend.mkdir(exist_ok=True)

Expand All @@ -217,7 +219,7 @@ def ignore(s, names):
ignore=ignore,
)
source_package_json = json.loads(Path(frontend / "package.json").read_text())
source_package_json["name"] = name.lower()
source_package_json["name"] = package_name
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tweaked this so the name in the package.json is the name in pyproject.toml

source_package_json = _modify_js_deps(source_package_json, "dependencies", p)
source_package_json = _modify_js_deps(source_package_json, "devDependencies", p)
(frontend / "package.json").write_text(json.dumps(source_package_json, indent=2))
Expand Down
5 changes: 3 additions & 2 deletions gradio/cli/commands/components/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def _build(

node = shutil.which("node")
if not node:
raise ValueError("node must be installed in order to run dev mode.")
raise ValueError(
"node must be installed in order to run build command."
)

node_cmds = [
node,
Expand All @@ -47,7 +49,6 @@ def _build(
"--mode",
"build",
]

pipe = subprocess.run(node_cmds, capture_output=True, text=True)
if pipe.returncode != 0:
live.update(":red_square: Build failed!")
Expand Down
4 changes: 3 additions & 1 deletion gradio/cli/commands/components/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def _create(
_create_utils._create_backend(name, component, directory, package_name)
live.update(":snake: Created backend code", add_sleep=0.2)

_create_utils._create_frontend(name.lower(), component, directory=directory)
_create_utils._create_frontend(
name.lower(), component, directory=directory, package_name=package_name
)
live.update(":art: Created frontend code", add_sleep=0.2)

if install:
Expand Down
18 changes: 12 additions & 6 deletions js/preview/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from "fs";
import { join } from "path";
import { build } from "vite";
import { plugins, make_gradio_plugin } from "./plugins";

import type { PreRenderedChunk } from "rollup";
import { examine_module } from "./index";

interface BuildOptions {
Expand All @@ -29,7 +29,7 @@ export async function make_build({

const exports: string[][] = [
["component", pkg.exports["."] as string],
["exmaple", pkg.exports["./example"] as string]
["example", pkg.exports["./example"] as string]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

horrendous typo

].filter(([_, path]) => !!path);

for (const [entry, path] of exports) {
Expand All @@ -43,23 +43,29 @@ export async function make_build({
emptyOutDir: true,
outDir: join(template_dir, entry),
lib: {
entry: join(source_dir, entry, "index.ts"),
entry: join(source_dir, path),
Copy link
Member Author

@pngwn pngwn Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo didn't matter however because we were looking for Index.svelte/index.ts and Example.svelte/index.ts which is nonsensical.

fileName: "index.js",
formats: ["es"]
},
minify: true,
rollupOptions: {
output: {
entryFileNames: "[name].js"
entryFileNames: (chunkInfo: PreRenderedChunk) => {
if (chunkInfo.isEntry) {
return "index.js";
}
return `${chunkInfo.name.toLocaleLowerCase()}.js`;
}
Comment on lines +53 to +58
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I've changed this so we always get an index.js for the main entry point (which is what we look for when serving the custom component). Nice thing is this will even work if users change their entrypoints in the package.json.

}
}
}
});
} catch (e) {
console.error(e);
throw e;
}
}
}
} catch (e) {
console.error(e);
throw e;
Comment on lines +64 to +69
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were squashing errors in the try/catch which is why this didn't error out as it should have. This will now fail noisily if the build doesn't succeed.

}
}
4 changes: 0 additions & 4 deletions js/preview/test/imageslider/backend/imageslider/__init__.py

This file was deleted.

Loading
Loading