Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use npm on windows #117

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pynecone/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# 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.
Expand Down
32 changes: 17 additions & 15 deletions pynecone/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -376,21 +374,25 @@ 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)


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,
)


Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down