From 5f041bf20e07f81369d2dc9b4bbc33ff229f229c Mon Sep 17 00:00:00 2001 From: Colin Casey Date: Wed, 18 Oct 2023 14:17:36 -0300 Subject: [PATCH 1/3] Adds support for using corepack with npm [W-14278473](https://gus.lightning.force.com/lightning/r/a07EE00001cGcjtYAC/view) --- buildpacks/nodejs-corepack/src/cfg.rs | 2 +- .../corepack-template/package-lock.v10.json | 37 +++++++++++++ .../corepack-template/package-lock.v8.json | 52 +++++++++++++++++++ .../nodejs-corepack/tests/integration_test.rs | 50 +++++++++++++++++- meta-buildpacks/nodejs/buildpack.toml | 5 ++ 5 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 buildpacks/nodejs-corepack/tests/fixtures/corepack-template/package-lock.v10.json create mode 100644 buildpacks/nodejs-corepack/tests/fixtures/corepack-template/package-lock.v8.json diff --git a/buildpacks/nodejs-corepack/src/cfg.rs b/buildpacks/nodejs-corepack/src/cfg.rs index 146212c8..e3345d3d 100644 --- a/buildpacks/nodejs-corepack/src/cfg.rs +++ b/buildpacks/nodejs-corepack/src/cfg.rs @@ -5,7 +5,7 @@ use heroku_nodejs_utils::package_json::PackageJson; pub(crate) fn get_supported_package_manager(pkg_json: &PackageJson) -> Option { let pkg_mgr_name = pkg_json.package_manager.clone()?.name; match pkg_mgr_name.as_str() { - "yarn" | "pnpm" => Some(pkg_mgr_name), + "yarn" | "pnpm" | "npm" => Some(pkg_mgr_name), _ => None, } } diff --git a/buildpacks/nodejs-corepack/tests/fixtures/corepack-template/package-lock.v10.json b/buildpacks/nodejs-corepack/tests/fixtures/corepack-template/package-lock.v10.json new file mode 100644 index 00000000..3db30182 --- /dev/null +++ b/buildpacks/nodejs-corepack/tests/fixtures/corepack-template/package-lock.v10.json @@ -0,0 +1,37 @@ +{ + "name": "npm-project", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "npm-project", + "version": "1.0.0", + "license": "MIT", + "dependencies": { + "debug": "^4.3.4" + } + }, + "node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + } + } +} diff --git a/buildpacks/nodejs-corepack/tests/fixtures/corepack-template/package-lock.v8.json b/buildpacks/nodejs-corepack/tests/fixtures/corepack-template/package-lock.v8.json new file mode 100644 index 00000000..f7849bdf --- /dev/null +++ b/buildpacks/nodejs-corepack/tests/fixtures/corepack-template/package-lock.v8.json @@ -0,0 +1,52 @@ +{ + "name": "npm-project", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "npm-project", + "version": "1.0.0", + "license": "MIT", + "dependencies": { + "debug": "^4.3.4" + } + }, + "node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + } + }, + "dependencies": { + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "requires": { + "ms": "2.1.2" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + } + } +} diff --git a/buildpacks/nodejs-corepack/tests/integration_test.rs b/buildpacks/nodejs-corepack/tests/integration_test.rs index 86f23304..81cec68c 100644 --- a/buildpacks/nodejs-corepack/tests/integration_test.rs +++ b/buildpacks/nodejs-corepack/tests/integration_test.rs @@ -1,7 +1,9 @@ #![warn(clippy::pedantic)] use libcnb_test::assert_contains; -use test_support::{nodejs_integration_test_with_config, set_package_manager}; +use test_support::{ + nodejs_integration_test, nodejs_integration_test_with_config, set_package_manager, +}; #[test] #[ignore = "integration test"] @@ -86,3 +88,49 @@ fn corepack_pnpm_8() { }, ); } + +#[test] +#[ignore = "integration test"] +fn corepack_npm_8() { + nodejs_integration_test_with_config( + "./fixtures/corepack-template", + |config| { + config.app_dir_preprocessor(|app_dir| { + set_package_manager(&app_dir, "npm@8.19.4"); + std::fs::rename( + app_dir.join("package-lock.v8.json"), + app_dir.join("package-lock.json"), + ) + .unwrap(); + }); + }, + |ctx| { + assert_contains!(ctx.pack_stdout, "Preparing npm@8.19.4"); + let output = ctx.run_shell_command("npm --version"); + assert_contains!(output.stdout, "8.19.4"); + }, + ); +} + +#[test] +#[ignore = "integration test"] +fn corepack_npm_10() { + nodejs_integration_test_with_config( + "./fixtures/corepack-template", + |config| { + config.app_dir_preprocessor(|app_dir| { + set_package_manager(&app_dir, "npm@10.2.0"); + std::fs::rename( + app_dir.join("package-lock.v10.json"), + app_dir.join("package-lock.json"), + ) + .unwrap(); + }); + }, + |ctx| { + assert_contains!(ctx.pack_stdout, "Preparing npm@10.2.0"); + let output = ctx.run_shell_command("npm --version"); + assert_contains!(output.stdout, "10.2.0"); + }, + ); +} diff --git a/meta-buildpacks/nodejs/buildpack.toml b/meta-buildpacks/nodejs/buildpack.toml index 7334bcbd..2b703456 100644 --- a/meta-buildpacks/nodejs/buildpack.toml +++ b/meta-buildpacks/nodejs/buildpack.toml @@ -54,6 +54,11 @@ optional = true id = "heroku/nodejs-engine" version = "1.1.7" +[[order.group]] +id = "heroku/nodejs-corepack" +version = "1.1.7" +optional = true + [[order.group]] id = "heroku/nodejs-npm-engine" version = "1.1.7" From 6ad10c4cf31406d30e4f6462aef6433e20729210 Mon Sep 17 00:00:00 2001 From: Colin Casey Date: Wed, 18 Oct 2023 14:20:52 -0300 Subject: [PATCH 2/3] Adds support for using corepack with npm [W-14278473](https://gus.lightning.force.com/lightning/r/a07EE00001cGcjtYAC/view) --- buildpacks/nodejs-corepack/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/buildpacks/nodejs-corepack/CHANGELOG.md b/buildpacks/nodejs-corepack/CHANGELOG.md index b32874dc..2c7ca9b2 100644 --- a/buildpacks/nodejs-corepack/CHANGELOG.md +++ b/buildpacks/nodejs-corepack/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- Add support for using corepack to install npm ([#685](https://github.com/heroku/buildpacks-nodejs/pull/685)) + ## [1.1.7] - 2023-10-17 - No changes. From c0cd53e35e092d0faee7fbfed1d66e9aff298494 Mon Sep 17 00:00:00 2001 From: Colin Casey Date: Wed, 18 Oct 2023 14:24:44 -0300 Subject: [PATCH 3/3] Adds support for using corepack with npm [W-14278473](https://gus.lightning.force.com/lightning/r/a07EE00001cGcjtYAC/view) --- buildpacks/nodejs-corepack/tests/integration_test.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/buildpacks/nodejs-corepack/tests/integration_test.rs b/buildpacks/nodejs-corepack/tests/integration_test.rs index 81cec68c..7b3be966 100644 --- a/buildpacks/nodejs-corepack/tests/integration_test.rs +++ b/buildpacks/nodejs-corepack/tests/integration_test.rs @@ -1,9 +1,7 @@ #![warn(clippy::pedantic)] use libcnb_test::assert_contains; -use test_support::{ - nodejs_integration_test, nodejs_integration_test_with_config, set_package_manager, -}; +use test_support::{nodejs_integration_test_with_config, set_package_manager}; #[test] #[ignore = "integration test"]