Skip to content

Commit

Permalink
fix cc build (#6079)
Browse files Browse the repository at this point in the history
* fix cc build

* add changeset

* throw error if build fails

* fix entry points

* add changeset

* fix lockfile

* Add test

* update workflow

* try resolve

* lint 🙄

* Use xfail

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: freddyaboulton <alfonsoboulton@gmail.com>
  • Loading branch information
3 people committed Oct 24, 2023
1 parent 6b82a97 commit 3b2d9ea
Show file tree
Hide file tree
Showing 76 changed files with 1,767 additions and 3,969 deletions.
7 changes: 7 additions & 0 deletions .changeset/weak-games-sing.md
@@ -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
Expand Up @@ -168,6 +168,7 @@ jobs:
with:
path: |
gradio/templates/*
gradio/node/*
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
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
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
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
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
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]
].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),
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`;
}
}
}
}
});
} catch (e) {
console.error(e);
throw e;
}
}
}
} catch (e) {
console.error(e);
throw e;
}
}
4 changes: 0 additions & 4 deletions js/preview/test/imageslider/backend/imageslider/__init__.py

This file was deleted.

0 comments on commit 3b2d9ea

Please sign in to comment.