installer.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. """File for constants related to the installation process. (Bun/Node)."""
  2. from __future__ import annotations
  3. import os
  4. from types import SimpleNamespace
  5. from .base import IS_WINDOWS
  6. from .utils import classproperty
  7. # Bun config.
  8. class Bun(SimpleNamespace):
  9. """Bun constants."""
  10. # The Bun version.
  11. VERSION = "1.2.11"
  12. # Min Bun Version
  13. MIN_VERSION = "1.2.8"
  14. # URL to bun install script.
  15. INSTALL_URL = "https://raw.githubusercontent.com/reflex-dev/reflex/main/scripts/bun_install.sh"
  16. # URL to windows install script.
  17. WINDOWS_INSTALL_URL = (
  18. "https://raw.githubusercontent.com/reflex-dev/reflex/main/scripts/install.ps1"
  19. )
  20. # Path of the bunfig file
  21. CONFIG_PATH = "bunfig.toml"
  22. @classproperty
  23. @classmethod
  24. def ROOT_PATH(cls):
  25. """The directory to store the bun.
  26. Returns:
  27. The directory to store the bun.
  28. """
  29. from reflex.config import environment
  30. return environment.REFLEX_DIR.get() / "bun"
  31. @classproperty
  32. @classmethod
  33. def DEFAULT_PATH(cls):
  34. """Default bun path.
  35. Returns:
  36. The default bun path.
  37. """
  38. return cls.ROOT_PATH / "bin" / ("bun" if not IS_WINDOWS else "bun.exe")
  39. DEFAULT_CONFIG = """
  40. [install]
  41. registry = "{registry}"
  42. """
  43. # Node / NPM config
  44. class Node(SimpleNamespace):
  45. """Node/ NPM constants."""
  46. # The minimum required node version.
  47. MIN_VERSION = "18.18.0"
  48. # Path of the node config file.
  49. CONFIG_PATH = ".npmrc"
  50. DEFAULT_CONFIG = """
  51. registry={registry}
  52. fetch-retries=0
  53. """
  54. def _determine_nextjs_version() -> str:
  55. default_version = "15.3.1"
  56. if (version := os.getenv("NEXTJS_VERSION")) and version != default_version:
  57. from reflex.utils import console
  58. console.warn(
  59. f"You have requested next@{version} but the supported version is {default_version}, abandon all hope ye who enter here."
  60. )
  61. return version
  62. return default_version
  63. class PackageJson(SimpleNamespace):
  64. """Constants used to build the package.json file."""
  65. class Commands(SimpleNamespace):
  66. """The commands to define in package.json."""
  67. DEV = "next dev {flags}"
  68. EXPORT = "next build {flags}"
  69. EXPORT_SITEMAP = "next build {flags} && next-sitemap"
  70. PROD = "next start"
  71. PATH = "package.json"
  72. DEPENDENCIES = {
  73. "@emotion/react": "11.14.0",
  74. "axios": "1.9.0",
  75. "json5": "2.2.3",
  76. "next": _determine_nextjs_version(),
  77. "next-sitemap": "4.2.3",
  78. "next-themes": "0.4.6",
  79. "react": "19.1.0",
  80. "react-dom": "19.1.0",
  81. "react-focus-lock": "2.13.6",
  82. "socket.io-client": "4.8.1",
  83. "universal-cookie": "7.2.2",
  84. }
  85. DEV_DEPENDENCIES = {
  86. "autoprefixer": "10.4.21",
  87. "postcss": "8.5.3",
  88. "postcss-import": "16.1.0",
  89. }
  90. OVERRIDES = {
  91. # This should always match the `react` version in DEPENDENCIES for recharts compatibility.
  92. "react-is": "19.1.0"
  93. }