From 5b3d0a51e82dfd6ad158bcffa89f856f12b98580 Mon Sep 17 00:00:00 2001 From: Nikhil Rao Date: Fri, 12 May 2023 13:58:46 -0700 Subject: [PATCH] Disable NextJS telemetry prod mode (#1013) --- pynecone/utils/build.py | 23 ++++++++++++++++++++--- pynecone/utils/exec.py | 10 ++-------- tests/test_utils.py | 2 +- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/pynecone/utils/build.py b/pynecone/utils/build.py index 9fb97b673..d6535964a 100644 --- a/pynecone/utils/build.py +++ b/pynecone/utils/build.py @@ -120,25 +120,42 @@ def posix_export(backend: bool = True, frontend: bool = True): os.system(cmd) -def setup_frontend(root: Path): +def setup_frontend(root: Path, disable_telemetry: bool = True): """Set up the frontend. Args: root: root path of the project. + disable_telemetry: Whether to disable the Next telemetry. """ # Initialize the web directory if it doesn't exist. web_dir = prerequisites.create_web_directory(root) - # Install frontend packages + # Install frontend packages. prerequisites.install_frontend_packages(web_dir) - # copy asset files to public folder + # Copy asset files to public folder. path_ops.mkdir(str(root / constants.WEB_ASSETS_DIR)) path_ops.cp( src=str(root / constants.APP_ASSETS_DIR), dest=str(root / constants.WEB_ASSETS_DIR), ) + # Disable the Next telemetry. + if disable_telemetry: + subprocess.Popen( + [ + prerequisites.get_package_manager(), + "run", + "next", + "telemetry", + "disable", + ], + cwd=constants.WEB_DIR, + env=os.environ, + stdout=subprocess.DEVNULL, + stderr=subprocess.STDOUT, + ) + def setup_backend(): """Set up backend. diff --git a/pynecone/utils/exec.py b/pynecone/utils/exec.py index fd3e11c71..68b17d0e2 100644 --- a/pynecone/utils/exec.py +++ b/pynecone/utils/exec.py @@ -51,14 +51,7 @@ def run_frontend(app: App, root: Path, port: str): console.rule("[bold green]App Running") os.environ["PORT"] = get_config().port if port is None else port - subprocess.Popen( - [prerequisites.get_package_manager(), "run", "next", "telemetry", "disable"], - cwd=constants.WEB_DIR, - env=os.environ, - stdout=subprocess.DEVNULL, - stderr=subprocess.STDOUT, - ) - + # Run the frontend in development mode. subprocess.Popen( [prerequisites.get_package_manager(), "run", "dev"], cwd=constants.WEB_DIR, @@ -80,6 +73,7 @@ def run_frontend_prod(app: App, root: Path, port: str): # Export the app. export_app(app) + # Set the port. os.environ["PORT"] = get_config().port if port is None else port # Run the frontend in production mode. diff --git a/tests/test_utils.py b/tests/test_utils.py index 0e6e23715..2a3dc5e40 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -249,7 +249,7 @@ def test_setup_frontend(tmp_path, mocker): mocker.patch("pynecone.utils.prerequisites.install_frontend_packages") - build.setup_frontend(tmp_path) + build.setup_frontend(tmp_path, disable_telemetry=False) assert web_folder.exists() assert web_public_folder.exists() assert (web_public_folder / "favicon.ico").exists()