installer.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.12"
  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.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_version() -> str:
  64. default_version = "19.1.0"
  65. if (version := os.getenv("REACT_VERSION")) and version != default_version:
  66. from reflex.utils import console
  67. console.warn(
  68. f"You have requested react@{version} but the supported version is {default_version}, abandon all hope ye who enter here."
  69. )
  70. return version
  71. return default_version
  72. class PackageJson(SimpleNamespace):
  73. """Constants used to build the package.json file."""
  74. class Commands(SimpleNamespace):
  75. """The commands to define in package.json."""
  76. DEV = "next dev {flags}"
  77. EXPORT = "next build {flags}"
  78. EXPORT_SITEMAP = "next build {flags} && next-sitemap"
  79. PROD = "next start"
  80. PATH = "package.json"
  81. _react_version = _determine_react_version()
  82. DEPENDENCIES = {
  83. "@emotion/react": "11.14.0",
  84. "axios": "1.9.0",
  85. "json5": "2.2.3",
  86. "next": _determine_nextjs_version(),
  87. "next-sitemap": "4.2.3",
  88. "next-themes": "0.4.6",
  89. "react": _react_version,
  90. "react-dom": _react_version,
  91. "react-focus-lock": "2.13.6",
  92. "socket.io-client": "4.8.1",
  93. "universal-cookie": "7.2.2",
  94. }
  95. DEV_DEPENDENCIES = {
  96. "autoprefixer": "10.4.21",
  97. "postcss": "8.5.3",
  98. "postcss-import": "16.1.0",
  99. }
  100. OVERRIDES = {
  101. # This should always match the `react` version in DEPENDENCIES for recharts compatibility.
  102. "react-is": _react_version
  103. }