diff --git a/buildpacks/nodejs-npm-install/CHANGELOG.md b/buildpacks/nodejs-npm-install/CHANGELOG.md index d956430e..078148b2 100644 --- a/buildpacks/nodejs-npm-install/CHANGELOG.md +++ b/buildpacks/nodejs-npm-install/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Default processes will no longer be registered if a Procfile is present. ([#985](https://github.com/heroku/buildpacks-nodejs/pull/985)) + ## [3.3.5] - 2024-12-11 - No changes. diff --git a/buildpacks/nodejs-npm-install/src/main.rs b/buildpacks/nodejs-npm-install/src/main.rs index b50aa1e6..127fb22e 100644 --- a/buildpacks/nodejs-npm-install/src/main.rs +++ b/buildpacks/nodejs-npm-install/src/main.rs @@ -100,7 +100,7 @@ impl Buildpack for NpmInstallBuildpack { let logger = section.end_section(); let section = logger.section("Configuring default processes"); - let build_result = configure_default_processes(&package_json, section.as_ref()); + let build_result = configure_default_processes(&context, &package_json, section.as_ref()); let logger = section.end_section(); configure_npm_runtime_env(&context)?; @@ -198,10 +198,14 @@ fn run_build_scripts( } fn configure_default_processes( + context: &BuildContext, package_json: &PackageJson, _section_logger: &dyn SectionLogger, ) -> Result> { - if package_json.has_start_script() { + if context.app_dir.join("Procfile").exists() { + log_step("Skipping default web process (Procfile detected)"); + BuildResultBuilder::new().build() + } else if package_json.has_start_script() { log_step(format!( "Adding default web process for {}", fmt::value("npm start") diff --git a/buildpacks/nodejs-npm-install/tests/integration_test.rs b/buildpacks/nodejs-npm-install/tests/integration_test.rs index 449e6766..05147d62 100644 --- a/buildpacks/nodejs-npm-install/tests/integration_test.rs +++ b/buildpacks/nodejs-npm-install/tests/integration_test.rs @@ -269,6 +269,25 @@ fn test_skip_build_scripts_from_buildplan() { ); } +#[test] +#[ignore] +fn test_default_web_process_registration_is_skipped_if_procfile_exists() { + nodejs_integration_test_with_config( + "./fixtures/npm-project", + |config| { + config.app_dir_preprocessor(|app_dir| { + std::fs::File::create(app_dir.join("Procfile")).unwrap(); + }); + }, + |ctx| { + assert_contains!( + ctx.pack_stdout, + "Skipping default web process (Procfile detected)" + ); + }, + ); +} + fn add_lockfile_entry(app_dir: &Path, package_name: &str, lockfile_entry: serde_json::Value) { update_json_file(&app_dir.join("package-lock.json"), |json| { let dependencies = json["dependencies"].as_object_mut().unwrap(); diff --git a/buildpacks/nodejs-pnpm-install/CHANGELOG.md b/buildpacks/nodejs-pnpm-install/CHANGELOG.md index 54cd5dd6..8a8eb0a2 100644 --- a/buildpacks/nodejs-pnpm-install/CHANGELOG.md +++ b/buildpacks/nodejs-pnpm-install/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Default processes will no longer be registered if a Procfile is present. ([#985](https://github.com/heroku/buildpacks-nodejs/pull/985)) + ## [3.3.5] - 2024-12-11 - No changes. diff --git a/buildpacks/nodejs-pnpm-install/src/main.rs b/buildpacks/nodejs-pnpm-install/src/main.rs index f045d96c..5c42f2c5 100644 --- a/buildpacks/nodejs-pnpm-install/src/main.rs +++ b/buildpacks/nodejs-pnpm-install/src/main.rs @@ -97,7 +97,11 @@ impl Buildpack for PnpmInstallBuildpack { } let result_builder = BuildResultBuilder::new().store(Store { metadata }); - if pkg_json.has_start_script() { + + if context.app_dir.join("Procfile").exists() { + log_info("Skipping default web process (Procfile detected)"); + result_builder.build() + } else if pkg_json.has_start_script() { result_builder .launch( LaunchBuilder::new() diff --git a/buildpacks/nodejs-pnpm-install/tests/integration_test.rs b/buildpacks/nodejs-pnpm-install/tests/integration_test.rs index 7db24d56..a906af5a 100644 --- a/buildpacks/nodejs-pnpm-install/tests/integration_test.rs +++ b/buildpacks/nodejs-pnpm-install/tests/integration_test.rs @@ -6,7 +6,7 @@ use libcnb::data::buildpack_id; use libcnb_test::{assert_contains, assert_empty, BuildpackReference}; use test_support::{ add_build_script, assert_web_response, custom_buildpack, integration_test_with_config, - nodejs_integration_test, + nodejs_integration_test, nodejs_integration_test_with_config, }; #[test] @@ -215,3 +215,22 @@ fn test_skip_build_scripts_from_buildplan() { ], ); } + +#[test] +#[ignore = "integration test"] +fn test_default_web_process_registration_is_skipped_if_procfile_exists() { + nodejs_integration_test_with_config( + "./fixtures/pnpm-9", + |config| { + config.app_dir_preprocessor(|app_dir| { + std::fs::File::create(app_dir.join("Procfile")).unwrap(); + }); + }, + |ctx| { + assert_contains!( + ctx.pack_stdout, + "Skipping default web process (Procfile detected)" + ); + }, + ); +} diff --git a/buildpacks/nodejs-yarn/CHANGELOG.md b/buildpacks/nodejs-yarn/CHANGELOG.md index 5a756ff8..031a86e3 100644 --- a/buildpacks/nodejs-yarn/CHANGELOG.md +++ b/buildpacks/nodejs-yarn/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Default processes will no longer be registered if a Procfile is present. ([#985](https://github.com/heroku/buildpacks-nodejs/pull/985)) + ## [3.3.5] - 2024-12-11 - No changes. diff --git a/buildpacks/nodejs-yarn/src/main.rs b/buildpacks/nodejs-yarn/src/main.rs index 2e7493e0..0e86e217 100644 --- a/buildpacks/nodejs-yarn/src/main.rs +++ b/buildpacks/nodejs-yarn/src/main.rs @@ -154,7 +154,10 @@ impl Buildpack for YarnBuildpack { } } - if pkg_json.has_start_script() { + if context.app_dir.join("Procfile").exists() { + log_info("Skipping default web process (Procfile detected)"); + BuildResultBuilder::new().build() + } else if pkg_json.has_start_script() { BuildResultBuilder::new() .launch( LaunchBuilder::new() diff --git a/buildpacks/nodejs-yarn/tests/integration_test.rs b/buildpacks/nodejs-yarn/tests/integration_test.rs index a94e11d3..a22e61cd 100644 --- a/buildpacks/nodejs-yarn/tests/integration_test.rs +++ b/buildpacks/nodejs-yarn/tests/integration_test.rs @@ -6,7 +6,7 @@ use libcnb::data::buildpack_id; use libcnb_test::{assert_contains, assert_not_contains, BuildpackReference}; use test_support::{ add_build_script, assert_web_response, custom_buildpack, integration_test_with_config, - nodejs_integration_test, + nodejs_integration_test, nodejs_integration_test_with_config, }; #[test] @@ -214,3 +214,22 @@ fn test_skip_build_scripts_from_buildplan() { ], ); } + +#[test] +#[ignore = "integration test"] +fn test_default_web_process_registration_is_skipped_if_procfile_exists() { + nodejs_integration_test_with_config( + "./fixtures/yarn-project", + |config| { + config.app_dir_preprocessor(|app_dir| { + std::fs::File::create(app_dir.join("Procfile")).unwrap(); + }); + }, + |ctx| { + assert_contains!( + ctx.pack_stdout, + "Skipping default web process (Procfile detected)" + ); + }, + ); +}