installer.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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.13"
  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 = "20.0.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.2"
  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. def _determine_react_router_version() -> str:
  64. default_version = "7.5.3"
  65. if (version := os.getenv("REACT_ROUTER_VERSION")) and version != default_version:
  66. from reflex.utils import console
  67. console.warn(
  68. f"You have requested react-router@{version} but the supported version is {default_version}, abandon all hope ye who enter here."
  69. )
  70. return version
  71. return default_version
  72. def _determine_react_version() -> str:
  73. default_version = "19.1.0"
  74. if (version := os.getenv("REACT_VERSION")) and version != default_version:
  75. from reflex.utils import console
  76. console.warn(
  77. f"You have requested react@{version} but the supported version is {default_version}, abandon all hope ye who enter here."
  78. )
  79. return version
  80. return default_version
  81. class PackageJson(SimpleNamespace):
  82. """Constants used to build the package.json file."""
  83. class Commands(SimpleNamespace):
  84. """The commands to define in package.json."""
  85. DEV = "react-router dev"
  86. EXPORT = "react-router build"
  87. EXPORT_SITEMAP = EXPORT
  88. PROD = "serve ./build/client"
  89. PATH = "package.json"
  90. _react_version = _determine_react_version()
  91. _react_router_version = _determine_react_router_version()
  92. DEPENDENCIES = {
  93. "axios": "1.9.0",
  94. "json5": "2.2.3",
  95. "react-router": _react_router_version,
  96. "react-router-dom": _react_router_version,
  97. "react-helmet": "6.1.0",
  98. "@react-router/node": _react_router_version,
  99. "serve": "14.2.4",
  100. "react": _react_version,
  101. "react-dom": _react_version,
  102. "isbot": "5.1.26",
  103. "socket.io-client": "4.8.1",
  104. "universal-cookie": "7.2.2",
  105. }
  106. DEV_DEPENDENCIES = {
  107. "@emotion/react": "11.14.0",
  108. "autoprefixer": "10.4.21",
  109. "postcss": "8.5.3",
  110. "postcss-import": "16.1.0",
  111. "@react-router/dev": _react_router_version,
  112. "@react-router/fs-routes": _react_router_version,
  113. "vite-plugin-node-polyfills": "0.23.0",
  114. "vite": "6.2.6",
  115. }
  116. OVERRIDES = {
  117. # This should always match the `react` version in DEPENDENCIES for recharts compatibility.
  118. "react-is": _react_version,
  119. "cookie": "1.0.2",
  120. }