Skip to content

Commit

Permalink
do not use corepack for node 14 (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
coffee-cup authored Dec 15, 2022
1 parent 0245597 commit 43c3ed2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/pages/docs/providers/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ For example, To install a specific version of PNPM, add a `packageManager` key t
}
```

Corepack will only be used on Node 16 and above.

## Bun Support

We support Bun, but due to Bun being in alpha, it is unstable and very experimental.
12 changes: 8 additions & 4 deletions src/providers/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Provider for NodeProvider {
}

// Install
let corepack = NodeProvider::uses_corepack(app)?;
let corepack = NodeProvider::uses_corepack(app, env)?;
let mut install = Phase::install(if corepack {
Some("npm install -g corepack && corepack enable".to_string())
} else {
Expand Down Expand Up @@ -167,12 +167,16 @@ impl NodeProvider {
Ok(false)
}

pub fn uses_corepack(app: &App) -> Result<bool> {
pub fn uses_corepack(app: &App, env: &Environment) -> Result<bool> {
let package_json: PackageJson = app.read_json("package.json").unwrap_or_default();
let node_pkg = NodeProvider::get_nix_node_pkg(&package_json, app, env)?;

if let Some(package_manager) = package_json.package_manager {
// The field is not null.
// Corepack is not supported for Node 14
if node_pkg.name.contains("14") {
return Ok(false);
}

if let Some(package_manager) = package_json.package_manager {
if package_manager.starts_with("npm") {
// Fall back to just using the system npm version.
return Ok(false);
Expand Down

0 comments on commit 43c3ed2

Please sign in to comment.