Skip to content

Commit

Permalink
feat(nodejs): ✨ handle engine versions and package installs (#617)
Browse files Browse the repository at this point in the history
When using `package.json`, Node can define a number of `engines` and the
relative versions that are needed for it. This was not directly
supported while we were already looking at `package.json` to figure out
the version of node to be installed.

This now adds support to ensure that `npm`, `pnpm`, `yarn`, `electron`
and other engines are installed in the required versions for the current
environment. This also creates an isolation path for node to run `npm
install -g` and install tools only for the current work directory.

This also adds support for running `npm install`, `pnpm install` or
`yarn install` automatically depending on the lock files that are
present in the directory, as well as the `engines` listed in the
`package.json` file.

Both those behaviors default to be enabled, but can be disabled by
setting `install_engines` and `install_packages` to `false` when setting
up the `node` operation.

Closes #293
Closes #294
  • Loading branch information
XaF authored Jul 2, 2024
1 parent f49f278 commit dbb7273
Show file tree
Hide file tree
Showing 16 changed files with 487 additions and 134 deletions.
7 changes: 0 additions & 7 deletions .omni.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
up:
- rust
- node: auto
- custom:
name: Install yarn & dependencies
dir: website
meet: |
npm install -g yarn
yarn
unmeet: rm -rf node_modules

commands:
create-tag:
Expand Down
95 changes: 2 additions & 93 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ num-integer = "0.1.46"
num-traits = "0.2.18"
once_cell = "1.19.0"
openssl = { version = "0.10", features = ["vendored"] }
package-json = "0.4.0"
path-clean = "1.0.1"
pathdiff = "0.2.1"
petname = "2.0.2"
Expand Down
13 changes: 4 additions & 9 deletions src/internal/config/up/asdf_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ impl UpConfigAsdfBase {

fn update_cache(&self, progress_handler: &dyn ProgressHandler) {
let workdir = workdir(".");
let repo_id = match workdir.id() {
Some(repo_id) => repo_id,
let wd_id = match workdir.id() {
Some(wd_id) => wd_id,
None => return,
};
let version = match self.version() {
Expand All @@ -394,12 +394,7 @@ impl UpConfigAsdfBase {
progress_handler.progress("updating cache".to_string());

if let Err(err) = AsdfOperationCache::exclusive(|asdf_cache| {
asdf_cache.add_installed(
&repo_id,
&self.tool,
&version,
self.tool_real_name.as_deref(),
)
asdf_cache.add_installed(&wd_id, &self.tool, &version, self.tool_real_name.as_deref())
}) {
progress_handler.progress(format!("failed to update tool cache: {}", err));
return;
Expand All @@ -412,7 +407,7 @@ impl UpConfigAsdfBase {
}

up_env.add_version(
&repo_id,
&wd_id,
&self.tool,
self.tool_real_name.as_deref(),
&version,
Expand Down
2 changes: 1 addition & 1 deletion src/internal/config/up/homebrew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ impl HomebrewTap {
brew_repo.stdout(std::process::Stdio::piped());
brew_repo.stderr(std::process::Stdio::piped());

let output = get_command_output(&mut brew_repo, RunConfig::new());
let output = get_command_output(&mut brew_repo, RunConfig::default());
let brew_repo_path = match output {
Err(err) => {
let msg = format!("failed to get tap repository path: {}", err);
Expand Down
Loading

0 comments on commit dbb7273

Please sign in to comment.