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

Fnm and node for POSIX #1606

Merged
merged 34 commits into from
Aug 25, 2023
Merged

Fnm and node for POSIX #1606

merged 34 commits into from
Aug 25, 2023

Conversation

ElijahAhianyo
Copy link
Collaborator

@ElijahAhianyo ElijahAhianyo commented Aug 16, 2023

Description

This pull request aims to enhance the installation process of Node.js by replacing the previous usage of NVM with FNM. This change not only introduces cross-platform compatibility but also leverages FNM's capability to generate release binaries for Linux, macOS, and Windows distributions. Furthermore, the installation of dependencies has been streamlined to align with platform conventions.

Changes Made

  • Replaced NVM-based Node.js installation with FNM.
  • Introduced cross-platform compatibility by adopting FNM.
  • Enhanced Windows support by previously merged PR (v0.2.5) that installs Node.js using FNM.
  • Adjusted the installation of dependencies to platform-specific directories:
    • Windows: C:/Users/<username>/AppData/Local/reflex
    • macOS: ~/Library/Application Support/reflex
    • Linux: ~/.local/share/reflex

Additional Context

The motivation behind this PR is to provide a unified and reliable installation experience for Node.js across different operating systems. The transition from NVM to FNM enables seamless management of Node.js versions while addressing Windows compatibility limitations that existed with NVM. The adoption of platform-specific directories ensures clean separation of dependencies, enhancing organization and system integration.

It's worth noting that FNM generates release binaries for Linux, macOS, and Windows distributions, which aligns perfectly with the multi-platform approach of this project.

This PR builds upon the previous Windows-related PR #1566 (merged for v0.2.5), and its successful testing and merging indicate that this solution is ready for wider adoption.

Closes #1585

@ElijahAhianyo
Copy link
Collaborator Author

should be reviewed/merged after #1566

@ElijahAhianyo ElijahAhianyo marked this pull request as ready for review August 21, 2023 18:47
@ElijahAhianyo ElijahAhianyo requested a review from Lendemor August 21, 2023 19:46
masenf
masenf previously approved these changes Aug 23, 2023
Comment on lines 307 to 308
# fnm only support Linux, macOS and Windows distros.
return
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so what will happen in this case? can the user install and run their own copy of node in these environments? asking because it looks like we set NODE_BIN_PATH in an FNM-specific way

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats a good question, Previously(when users had to install node themselves), we checked for node on the host machine (which node or use the node command and check for errors) and used that. We can do that as well as expose a config knob (just like we do for bun) to allow users specify custom paths to node binaries, but Im open to suggestions. What do you think?
cc: @masenf @picklelo @Lendemor @jackie-pc

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should fall back to using shutil.which() if fnm is not available. Down the road we might allow users to "bring your own node", but for now, lets keep it simple as a fallback when our installation mechanism fails.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the which solution sounds reasonable to me. Should we log something (even if debug level) when we fall through to such cases. I.e. either we use which node or straight give up. Note this should be a pretty rare case and so it's worth logging something. I.e. we are talking about an environment that is NOT Windows, Linux or Mac (roughly)

Copy link
Contributor

@picklelo picklelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality works great on my Mac :) just some small comments

reflex/constants.py Outdated Show resolved Hide resolved
@@ -18,6 +19,28 @@
IS_WINDOWS = platform.system() == "Windows"


def get_fnm_name() -> Optional[str]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function can be moved to prerequisites.py

reflex/constants.py Outdated Show resolved Hide resolved
reflex/constants.py Show resolved Hide resolved
reflex/constants.py Outdated Show resolved Hide resolved
# The directory to store fnm.
FNM_DIR = os.path.join(REFLEX_DIR, "fnm")
FNM_FILENAME = get_fnm_name()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be moved to prerequisites.py

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FNM_FILENAME is needed to construct the URL to the release binary (FNM_INSTALL_URL). Do you mean to move that as well (i.e move get_fnm_name, FNM_FILE_NAME and FNM_INSTALL_URL to prerequisites)?

@masenf masenf added this to the v0.2.7 milestone Aug 23, 2023
if platform_os == "Windows":
return "fnm-windows"
elif platform_os == "Darwin":
return "fnm-macos"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there no ARM vs Intel distinction for Windows and Mac?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would assume macos is using fat binaries and windows is probably falling back to x86 emulation... but yeah, would definitely be good to test. i have windows arm, but i don't have x86 mac to test on.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about Windows, but looking at their install script, I would assume the binaries for ARM are specific to LInux.

Comment on lines 307 to 308
# fnm only support Linux, macOS and Windows distros.
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the which solution sounds reasonable to me. Should we log something (even if debug level) when we fall through to such cases. I.e. either we use which node or straight give up. Note this should be a pretty rare case and so it's worth logging something. I.e. we are talking about an environment that is NOT Windows, Linux or Mac (roughly)

reflex/utils/prerequisites.py Outdated Show resolved Hide resolved
reflex/utils/exec.py Outdated Show resolved Hide resolved
@ElijahAhianyo ElijahAhianyo marked this pull request as draft August 24, 2023 19:27
@ElijahAhianyo ElijahAhianyo marked this pull request as ready for review August 24, 2023 22:35
@picklelo picklelo merged commit dbaa6a1 into main Aug 25, 2023
@picklelo picklelo deleted the elijah/posix_fnm branch September 16, 2023 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Fnm for node installation on POSIX
4 participants