Skip to content

Commit

Permalink
remove deprecated next export from UI build
Browse files Browse the repository at this point in the history
  • Loading branch information
thatmattlove committed Apr 2, 2024
1 parent 8be5562 commit 9d1c6a5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 39 deletions.
58 changes: 30 additions & 28 deletions hyperglass/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# Project
from hyperglass.log import log
from hyperglass.util import copyfiles, check_path, dotenv_to_dict
from hyperglass.util import copyfiles, check_path, dotenv_to_dict, move_files

if t.TYPE_CHECKING:
# Project
Expand Down Expand Up @@ -108,36 +108,38 @@ async def build_ui(app_path: Path):

ui_dir = Path(__file__).parent.parent / "ui"
build_dir = app_path / "static" / "ui"
out_dir = ui_dir / "out"

build_command = "node_modules/.bin/next build"
export_command = "node_modules/.bin/next export -o {f}".format(f=build_dir)
build_command = "node_modules/.bin/next build --no-lint"

all_messages = []
for command in (build_command, export_command):
try:
proc = await asyncio.create_subprocess_shell(
cmd=command,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
cwd=ui_dir,
)

stdout, stderr = await asyncio.wait_for(proc.communicate(), timeout=timeout)
messages = stdout.decode("utf-8").strip()
errors = stderr.decode("utf-8").strip()

if proc.returncode != 0:
raise RuntimeError(f"\nMessages:\n{messages}\nErrors:\n{errors}")

await proc.wait()
all_messages.append(messages)

except asyncio.TimeoutError as err:
raise RuntimeError(f"{timeout} second timeout exceeded while building UI") from err

except Exception as err:
log.error(err)
raise RuntimeError(str(err)) from err
try:
proc = await asyncio.create_subprocess_shell(
cmd=build_command,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
cwd=ui_dir,
)

stdout, stderr = await asyncio.wait_for(proc.communicate(), timeout=timeout)
messages = stdout.decode("utf-8").strip()
errors = stderr.decode("utf-8").strip()

if proc.returncode != 0:
raise RuntimeError(f"\nMessages:\n{messages}\nErrors:\n{errors}")

await proc.wait()
all_messages.append(messages)

except asyncio.TimeoutError as err:
raise RuntimeError(f"{timeout} second timeout exceeded while building UI") from err

except Exception as err:
log.error(err)
raise RuntimeError(str(err)) from err

shutil.copytree(out_dir, build_dir)
log.bind(src=out_dir, dst=build_dir).debug("Migrated Next.JS build output")

return "\n".join(all_messages)

Expand Down
19 changes: 8 additions & 11 deletions hyperglass/ui/next.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
const rewrites = async () => {
if (process.env.NODE_ENV === 'production') {
return [];
}
return [
{ source: '/api/query', destination: `${process.env.HYPERGLASS_URL}api/query` },
{ source: '/images/:image*', destination: `${process.env.HYPERGLASS_URL}images/:image*` },
];
};

/**
* @type {import('next').NextConfig}
*/
Expand All @@ -19,7 +9,14 @@ const nextConfig = {
},
swcMinify: true,
productionBrowserSourceMaps: true,
rewrites,
output: 'export',
};

if (process.env.NODE_ENV === 'development') {
nextConfig.rewrites = [
{ source: '/api/query', destination: `${process.env.HYPERGLASS_URL}api/query` },
{ source: '/images/:image*', destination: `${process.env.HYPERGLASS_URL}images/:image*` },
];
}

module.exports = nextConfig;

0 comments on commit 9d1c6a5

Please sign in to comment.