Skip to content

Commit

Permalink
update nix archive version used for node and bun (#1106)
Browse files Browse the repository at this point in the history
* update nix archive version used for node and bun

* update node custom version docker test

* update node canvas example

* remove multiple provider tests

* update node-canvas

* update snapshot tests
  • Loading branch information
coffee-cup authored May 18, 2024
1 parent 47cf6c8 commit cdac3d8
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 712 deletions.
4 changes: 0 additions & 4 deletions examples/multiple-providers/nixpacks.toml

This file was deleted.

662 changes: 79 additions & 583 deletions examples/node-canvas/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/node-canvas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"start": "node index.js"
},
"dependencies": {
"canvas": "^2.9.1"
"canvas": "^2.11.2"
},
"engines": {
"node": "16.x"
"node": "20.x"
}
}
2 changes: 1 addition & 1 deletion examples/node-custom-version/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"start": "./start.sh"
},
"engines": {
"node": "21.x"
"node": "22.x"
}
}
22 changes: 19 additions & 3 deletions src/providers/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ mod turborepo;

pub const NODE_OVERLAY: &str = "https://github.com/railwayapp/nix-npm-overlay/archive/main.tar.gz";

const NODE_NIXPKGS_ARCHIVE: &str = "bf744fe90419885eefced41b3e5ae442d732712d";
const NODE_NIXPKGS_ARCHIVE: &str = "bf446f08bff6814b569265bef8374cfdd3d8f0e0";

// We need to use a specific commit hash for Node versions <16 since it is EOL in the latest Nix packages
const NODE_LT_16_ARCHIVE: &str = "bf744fe90419885eefced41b3e5ae442d732712d";

const DEFAULT_NODE_VERSION: u32 = 18;
const AVAILABLE_NODE_VERSIONS: &[u32] = &[14, 16, 18, 20, 21];
const AVAILABLE_NODE_VERSIONS: &[u32] = &[14, 16, 18, 20, 22];

const YARN_CACHE_DIR: &str = "/usr/local/share/.cache/yarn/v6";
const PNPM_CACHE_DIR: &str = "/root/.local/share/pnpm/store/v3";
Expand Down Expand Up @@ -112,7 +115,7 @@ impl Provider for NodeProvider {
fn get_build_plan(&self, app: &App, env: &Environment) -> Result<Option<BuildPlan>> {
// Setup
let mut setup = Phase::setup(Some(NodeProvider::get_nix_packages(app, env)?));
setup.set_nix_archive(NODE_NIXPKGS_ARCHIVE.into());
setup.set_nix_archive(NodeProvider::get_nix_archive(app)?);

if NodeProvider::uses_node_dependency(app, "prisma") {
setup.add_nix_pkgs(&[Pkg::new("openssl")]);
Expand Down Expand Up @@ -423,6 +426,19 @@ impl NodeProvider {
.to_string()
}

/// Returns the Nix archive to use for the Node and related packages
pub fn get_nix_archive(app: &App) -> Result<String> {
let package_json: PackageJson = app.read_json("package.json").unwrap_or_default();
let node_pkg = NodeProvider::get_nix_node_pkg(&package_json, app, &Environment::default())?;
let uses_le_16 = node_pkg.name.contains("14") || node_pkg.name.contains("16");

if uses_le_16 {
Ok(NODE_LT_16_ARCHIVE.to_string())
} else {
Ok(NODE_NIXPKGS_ARCHIVE.to_string())
}
}

/// Returns the nodejs nix package and the appropriate package manager nix image.
pub fn get_nix_packages(app: &App, env: &Environment) -> Result<Vec<Pkg>> {
let package_json: PackageJson = if app.includes_file("package.json") {
Expand Down
11 changes: 1 addition & 10 deletions tests/docker_run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ async fn test_node_nx_express() {
async fn test_node_custom_version() {
let name = simple_build("./examples/node-custom-version").await;
let output = run_image(&name, None).await;
assert!(output.contains("Node version: v21"));
assert!(output.contains("Node version: v22"));
}

#[tokio::test]
Expand Down Expand Up @@ -1175,15 +1175,6 @@ async fn test_cobol_no_index() {
);
}

#[tokio::test]
async fn test_multiple_providers() {
let name = simple_build("./examples/multiple-providers").await;
let output = run_image(&name, None).await;
assert!(output.contains("Python"));
assert!(output.contains("go"));
assert!(output.contains("deno"));
}

#[tokio::test]
async fn test_django_pipfile() {
// Create the network
Expand Down
104 changes: 0 additions & 104 deletions tests/snapshots/generate_plan_tests__multiple_providers.snap

This file was deleted.

4 changes: 2 additions & 2 deletions tests/snapshots/generate_plan_tests__node_canvas.snap
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ expression: plan
"setup": {
"name": "setup",
"nixPkgs": [
"nodejs_16",
"npm-8_x"
"nodejs_20",
"npm-9_x"
],
"nixLibs": [
"libuuid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ expression: plan
"setup": {
"name": "setup",
"nixPkgs": [
"nodejs_21",
"nodejs_22",
"npm-8_x"
],
"nixOverlays": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ expression: plan
"setup": {
"name": "setup",
"nixPkgs": [
"nodejs_21",
"nodejs_22",
"pnpm-8_x"
],
"nixOverlays": [
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/generate_plan_tests__node_turborepo.snap
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ expression: plan
"setup": {
"name": "setup",
"nixPkgs": [
"nodejs_21",
"nodejs_22",
"npm-8_x"
],
"nixOverlays": [
Expand Down

0 comments on commit cdac3d8

Please sign in to comment.