Browse Source

Use npm on windows (#117)

Nikhil Rao 2 years ago
parent
commit
ba2ae70ee4
3 changed files with 19 additions and 17 deletions
  1. 1 1
      pynecone/constants.py
  2. 17 15
      pynecone/utils.py
  3. 1 1
      pyproject.toml

+ 1 - 1
pynecone/constants.py

@@ -35,7 +35,7 @@ WEB_DIR = ".web"
 # The name of the utils file.
 UTILS_DIR = "utils"
 # The name of the state file.
-STATE_PATH = os.path.join(UTILS_DIR, "state")
+STATE_PATH = "/".join([UTILS_DIR, "state"])
 # The directory where the app pages are compiled to.
 WEB_PAGES_DIR = os.path.join(WEB_DIR, "pages")
 # The directory where the static build is located.

+ 17 - 15
pynecone/utils.py

@@ -298,26 +298,24 @@ def get_config() -> Config:
         return Config(app_name="")
 
 
-def get_bun_path() -> str:
-    """Get the path to the bun executable.
+def get_package_manager() -> str:
+    """Get the package manager executable.
 
     Returns:
-        The path to the bun executable.
+        The path to the package manager.
 
     Raises:
         FileNotFoundError: If bun or npm is not installed.
     """
     # On Windows, we use npm instead of bun.
     if platform.system() == "Windows":
-        if which("npm") is None:
+        npm_path = which("npm")
+        if npm_path is None:
             raise FileNotFoundError("Pynecone requires npm to be installed on Windows.")
-        return "npm"
+        return npm_path
 
     # On other platforms, we use bun.
-    bun_path = os.path.expandvars(get_config().bun_path)
-    if which(bun_path) is None:
-        raise FileNotFoundError("Pynecone requires bun to be installed.")
-    return bun_path
+    return os.path.expandvars(get_config().bun_path)
 
 
 def get_app() -> ModuleType:
@@ -376,7 +374,7 @@ def install_bun():
         return
 
     # Only install if bun is not already installed.
-    if not os.path.exists(get_bun_path()):
+    if not os.path.exists(get_package_manager()):
         console.log("Installing bun...")
         os.system(constants.INSTALL_BUN)
 
@@ -384,13 +382,17 @@ def install_bun():
 def install_frontend_packages():
     """Install the frontend packages."""
     # Install the base packages.
-    subprocess.run([get_bun_path(), "install"], cwd=constants.WEB_DIR, stdout=PIPE)
+    subprocess.run(
+        [get_package_manager(), "install"], cwd=constants.WEB_DIR, stdout=PIPE
+    )
 
     # Install the app packages.
     packages = get_config().frontend_packages
     if len(packages) > 0:
         subprocess.run(
-            [get_bun_path(), "add", *packages], cwd=constants.WEB_DIR, stdout=PIPE
+            [get_package_manager(), "add", *packages],
+            cwd=constants.WEB_DIR,
+            stdout=PIPE,
         )
 
 
@@ -417,7 +419,7 @@ def export_app(app: App, zip: bool = False):
     rm(constants.WEB_STATIC_DIR)
 
     # Export the Next app.
-    subprocess.run([get_bun_path(), "run", "export"], cwd=constants.WEB_DIR)
+    subprocess.run([get_package_manager(), "run", "export"], cwd=constants.WEB_DIR)
 
     # Zip up the app.
     if zip:
@@ -452,7 +454,7 @@ def run_frontend(app: App):
 
     # Run the frontend in development mode.
     console.rule("[bold green]App Running")
-    subprocess.Popen([get_bun_path(), "run", "dev"], cwd=constants.WEB_DIR)
+    subprocess.Popen([get_package_manager(), "run", "dev"], cwd=constants.WEB_DIR)
 
 
 def run_frontend_prod(app: App):
@@ -468,7 +470,7 @@ def run_frontend_prod(app: App):
     export_app(app)
 
     # Run the frontend in production mode.
-    subprocess.Popen([get_bun_path(), "run", "prod"], cwd=constants.WEB_DIR)
+    subprocess.Popen([get_package_manager(), "run", "prod"], cwd=constants.WEB_DIR)
 
 
 def get_num_workers() -> int:

+ 1 - 1
pyproject.toml

@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "pynecone-io"
-version = "0.1.8"
+version = "0.1.9"
 description = "The easiest way to build web apps."
 license = "Apache-2.0"
 authors = [