From 0bdf44cba8aec366154a296e30e1730a0ef45a04 Mon Sep 17 00:00:00 2001 From: "Stijn (\"stain\") Seghers" Date: Thu, 23 Mar 2023 13:00:08 +0100 Subject: [PATCH] Use .node-version for pinning Node.js version (#6057) Closes #6008: allowing Node.js to be used through Node version managers. --- .node-version | 1 + app/gui/docs/CONTRIBUTING.md | 8 ++++---- build-config.yaml | 3 ++- build/build/src/config.rs | 9 +++++++-- build/cli/src/main.rs | 7 ++----- docs/CONTRIBUTING.md | 6 ++++-- 6 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 .node-version diff --git a/.node-version b/.node-version new file mode 100644 index 0000000000..617bcf916b --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +18.14.1 diff --git a/app/gui/docs/CONTRIBUTING.md b/app/gui/docs/CONTRIBUTING.md index d4f04fcaef..650f7236e7 100644 --- a/app/gui/docs/CONTRIBUTING.md +++ b/app/gui/docs/CONTRIBUTING.md @@ -79,10 +79,10 @@ setup: [the latest LTS version of node and npm](https://nodejs.org/en/download). Even minor release changes are known to cause serious issues, thus **we provide support for the latest LTS version only. Please do not report build issues if - you use other versions.** In case you run macOS or Linux the easiest way to - set up the proper version is by installing the - [Node Version Manager](https://github.com/nvm-sh/nvm) and running - `nvm install --lts && nvm use --lts`. + you use other versions.** The easiest way to set up the proper version is by + installing + [a Node version manager that automatically picks up the correct version](https://github.com/shadowspawn/node-version-usage#supporting-products), + like [fnm](https://github.com/Schniz/fnm). - **(Optional) FlatBuffer compiler `flatc`** diff --git a/build-config.yaml b/build-config.yaml index 6254b2effb..9a36095863 100644 --- a/build-config.yaml +++ b/build-config.yaml @@ -3,8 +3,9 @@ wasm-size-limit: 15.50 MiB required-versions: + # NB. The Rust version is pinned in rust-toolchain.toml. + # NB. The Node version is pinned in .node-version. cargo-watch: ^8.1.1 - node: =18.14.1 wasm-pack: ^0.10.2 # TODO [mwu]: Script can install `flatc` later on (if `conda` is present), so this is not required. However it should # be required, if `conda` is missing. diff --git a/build/build/src/config.rs b/build/build/src/config.rs index 40bfebaeb4..9a457ac044 100644 --- a/build/build/src/config.rs +++ b/build/build/src/config.rs @@ -7,8 +7,13 @@ use semver::VersionReq; -pub fn load_yaml(yaml_text: &str) -> Result { - let raw = serde_yaml::from_str::(yaml_text)?; +/// Load the build configuration, based on the `build-config.yaml` and `.node-version` files in +/// the repo root. +pub fn load() -> Result { + let yaml_text = include_str!("../../../build-config.yaml"); + let node_version = include_str!("../../../.node-version").trim(); + let mut raw = serde_yaml::from_str::(yaml_text)?; + raw.required_versions.insert("node".to_owned(), node_version.to_owned()); raw.try_into() } diff --git a/build/cli/src/main.rs b/build/cli/src/main.rs index 8705e8e318..9edf690382 100644 --- a/build/cli/src/main.rs +++ b/build/cli/src/main.rs @@ -6,16 +6,13 @@ use enso_build::prelude::*; -use enso_build::config::Config; -use enso_build::config::ConfigRaw; +use enso_build::config; fn main() -> Result { setup_logging()?; trace!("Starting CLI driver, cwd is {}", ide_ci::env::current_dir()?.display()); - let build_config_yaml = include_str!("../../../build-config.yaml"); - let build_config_raw = serde_yaml::from_str::(build_config_yaml)?; - let build_config = Config::try_from(build_config_raw)?; + let build_config = config::load()?; enso_build_cli::lib_main(Some(build_config)) } diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 6ccd654f29..61780f67b4 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -137,8 +137,10 @@ arising from unsupported configurations will not be fixed by the core team. In order to build and run Enso you will need the following tools: -- [NodeJS](https://nodejs.org/) with the latest LTS version. We recommend using - [`nvm`](https://github.com/nvm-sh/nvm) for managing NodeJS installation. +- [NodeJS](https://nodejs.org/) with the latest LTS version. We recommend + installing + [a Node version manager that automatically picks up the correct version](https://github.com/shadowspawn/node-version-usage#supporting-products), + like [fnm](https://github.com/Schniz/fnm). - [sbt](https://www.scala-sbt.org/) with the same version as specified in [`project/build.properties`](../project/build.properties). - [Maven](https://maven.apache.org/) with version at least 3.6.3.