From 9d1c6a5e4ae339811294da3591488b55c4e9a397 Mon Sep 17 00:00:00 2001 From: thatmattlove Date: Tue, 2 Apr 2024 16:27:07 -0400 Subject: [PATCH] remove deprecated `next export` from UI build --- hyperglass/frontend/__init__.py | 58 +++++++++++++++++---------------- hyperglass/ui/next.config.js | 19 +++++------ 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/hyperglass/frontend/__init__.py b/hyperglass/frontend/__init__.py index e0165eb6..f0971a56 100644 --- a/hyperglass/frontend/__init__.py +++ b/hyperglass/frontend/__init__.py @@ -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 @@ -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) diff --git a/hyperglass/ui/next.config.js b/hyperglass/ui/next.config.js index c4cb95e0..8e953956 100644 --- a/hyperglass/ui/next.config.js +++ b/hyperglass/ui/next.config.js @@ -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} */ @@ -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;