diff --git a/buildpacks/nodejs-function-invoker/tests/fixtures/function-with-no-lockfile/.eslintrc b/buildpacks/nodejs-function-invoker/tests/fixtures/function-with-no-lockfile/.eslintrc new file mode 100644 index 00000000..536e636c --- /dev/null +++ b/buildpacks/nodejs-function-invoker/tests/fixtures/function-with-no-lockfile/.eslintrc @@ -0,0 +1,10 @@ +{ + "parserOptions": { + "ecmaVersion": 2017 + }, + "env": { + "es6": true + }, + "rules": { + } +} diff --git a/buildpacks/nodejs-function-invoker/tests/fixtures/function-with-no-lockfile/.mocharc.json b/buildpacks/nodejs-function-invoker/tests/fixtures/function-with-no-lockfile/.mocharc.json new file mode 100644 index 00000000..d6761eaf --- /dev/null +++ b/buildpacks/nodejs-function-invoker/tests/fixtures/function-with-no-lockfile/.mocharc.json @@ -0,0 +1,4 @@ +{ + "test": "./**/*.test.js", + "recursive": true +} diff --git a/buildpacks/nodejs-function-invoker/tests/fixtures/function-with-no-lockfile/index.js b/buildpacks/nodejs-function-invoker/tests/fixtures/function-with-no-lockfile/index.js new file mode 100644 index 00000000..12c301d6 --- /dev/null +++ b/buildpacks/nodejs-function-invoker/tests/fixtures/function-with-no-lockfile/index.js @@ -0,0 +1,4 @@ + module.exports = async function (event, context, logger) { + logger.info("logging info is a fun 1") + return "Hello World".toLowerCase(); +} diff --git a/buildpacks/nodejs-function-invoker/tests/fixtures/function-with-no-lockfile/package.json b/buildpacks/nodejs-function-invoker/tests/fixtures/function-with-no-lockfile/package.json new file mode 100644 index 00000000..42f15e65 --- /dev/null +++ b/buildpacks/nodejs-function-invoker/tests/fixtures/function-with-no-lockfile/package.json @@ -0,0 +1,24 @@ +{ + "name": "myfn-function", + "version": "0.0.1", + "author": "TODO", + "description": "TODO", + "license": "UNLICENSED", + "main": "index.js", + "repository": { + "type": "git" + }, + "engines": { + "node": "^14.0" + }, + "scripts": { + "lint": "eslint . --ext .js --config .eslintrc", + "test": "mocha" + }, + "devDependencies": { + "chai": "^4.3.4", + "eslint": "^6.8.0", + "mocha": "^8.4.0", + "sinon": "^10.0.0" + } +} diff --git a/buildpacks/nodejs-function-invoker/tests/fixtures/function-with-no-lockfile/project.toml b/buildpacks/nodejs-function-invoker/tests/fixtures/function-with-no-lockfile/project.toml new file mode 100644 index 00000000..bd6ffad9 --- /dev/null +++ b/buildpacks/nodejs-function-invoker/tests/fixtures/function-with-no-lockfile/project.toml @@ -0,0 +1,9 @@ +[_] +schema-version = "0.2" + +[com.salesforce] +schema-version = "0.1" +id = "myfn" +description = "A Function" +type = "function" +salesforce-api-version = "53.0" diff --git a/buildpacks/nodejs-function-invoker/tests/integration_test.rs b/buildpacks/nodejs-function-invoker/tests/integration_test.rs index b2f305bb..16be5eaa 100644 --- a/buildpacks/nodejs-function-invoker/tests/integration_test.rs +++ b/buildpacks/nodejs-function-invoker/tests/integration_test.rs @@ -93,6 +93,23 @@ fn test_function_with_implicit_runtime_dependency_ts() { }); } +#[test] +#[ignore] +fn function_with_no_lockfile() { + function_integration_test("./fixtures/function-with-no-lockfile", |ctx| { + assert_contains!(ctx.pack_stdout, "Installing Node.js Function Invoker"); + assert_contains!(ctx.pack_stdout, "Running npm install without a package-lock.json is deprecated. Check in your lockfile to git."); + start_container(&ctx, |container, socket_addr| { + assert_health_check_responds(socket_addr); + let payload = serde_json::json!({}); + let result = invoke_function(socket_addr, &payload); + assert_eq!(result, serde_json::Value::String("hello world".to_string())); + let container_logs = container.logs_now(); + assert_contains!(container_logs.stdout, "logging info is a fun 1"); + }); + }); +} + fn invoke_function(socket_addr: &SocketAddr, payload: &serde_json::Value) -> serde_json::Value { let id = format!("MyFunction-{}", random_hex_string(10)); diff --git a/buildpacks/npm/lib/build.sh b/buildpacks/npm/lib/build.sh index 3180a708..8f6ceb5a 100755 --- a/buildpacks/npm/lib/build.sh +++ b/buildpacks/npm/lib/build.sh @@ -151,6 +151,7 @@ install_modules() { npm install --production=false fi else + warning "Running npm install without a package-lock.json is deprecated. Check in your lockfile to git." info "Installing node modules" npm install --production=false --no-package-lock fi diff --git a/meta-buildpacks/nodejs-function/CHANGELOG.md b/meta-buildpacks/nodejs-function/CHANGELOG.md index 3192f50e..68639b61 100644 --- a/meta-buildpacks/nodejs-function/CHANGELOG.md +++ b/meta-buildpacks/nodejs-function/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Rolled back the changes from [#686](https://github.com/heroku/buildpacks-nodejs/pull/686) to restore the previous npm buildpack due to issues with the detect requirement of `package-lock.json`. ([#706](https://github.com/heroku/buildpacks-nodejs/pull/706)) + ## [2.1.0] - 2023-10-26 ### Changed diff --git a/meta-buildpacks/nodejs-function/buildpack.toml b/meta-buildpacks/nodejs-function/buildpack.toml index 12c080fe..8b503b62 100644 --- a/meta-buildpacks/nodejs-function/buildpack.toml +++ b/meta-buildpacks/nodejs-function/buildpack.toml @@ -17,12 +17,7 @@ id = "heroku/nodejs-engine" version = "2.1.0" [[order.group]] -id = "heroku/nodejs-npm-engine" -version = "2.1.0" -optional = true - -[[order.group]] -id = "heroku/nodejs-npm-install" +id = "heroku/nodejs-npm" version = "2.1.0" [[order.group]] diff --git a/meta-buildpacks/nodejs-function/package.toml b/meta-buildpacks/nodejs-function/package.toml index 606b4af8..b5a5dca6 100644 --- a/meta-buildpacks/nodejs-function/package.toml +++ b/meta-buildpacks/nodejs-function/package.toml @@ -5,10 +5,7 @@ uri = "." uri = "libcnb:heroku/nodejs-engine" [[dependencies]] -uri = "libcnb:heroku/nodejs-npm-engine" - -[[dependencies]] -uri = "libcnb:heroku/nodejs-npm-install" +uri = "../../buildpacks/npm" [[dependencies]] uri = "libcnb:heroku/nodejs-function-invoker"