Browse Source

Disable NextJS telemetry prod mode (#1013)

Nikhil Rao 2 years ago
parent
commit
5b3d0a51e8
3 changed files with 23 additions and 12 deletions
  1. 20 3
      pynecone/utils/build.py
  2. 2 8
      pynecone/utils/exec.py
  3. 1 1
      tests/test_utils.py

+ 20 - 3
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.

+ 2 - 8
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.

+ 1 - 1
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()