diff --git a/src/nodejs/supply/supply.go b/src/nodejs/supply/supply.go index bcc3e4cab..bdb01e01e 100644 --- a/src/nodejs/supply/supply.go +++ b/src/nodejs/supply/supply.go @@ -439,24 +439,25 @@ func (s *Supplier) ReadPackageJSON() error { } func (s *Supplier) NoPackageLockTip() error { + // Only consider npm lockfiles for this check. lockFiles := []string{"package-lock.json", "npm-shrinkwrap.json"} - if s.UseYarn { - lockFiles = []string{"yarn.lock"} - } + // Determine whether any of the supported npm lock files exist. + anyExists := false for _, lockFile := range lockFiles { - lockFileExists, err := libbuildpack.FileExists(filepath.Join(s.Stager.BuildDir(), lockFile)) + exists, err := libbuildpack.FileExists(filepath.Join(s.Stager.BuildDir(), lockFile)) if err != nil { return err } - - if lockFileExists { - return nil + if exists { + anyExists = true + break } + } - if s.IsVendored { - s.Log.Protip("Warning: package-lock.json not found. The buildpack may reach out to the internet to download module updates, even if they are vendored.", "https://docs.cloudfoundry.org/buildpacks/node/index.html#offline_environments") - } + // Only warn if none of the npm lockfiles exist and the app has vendored deps. + if !anyExists && s.IsVendored { + s.Log.Protip("Warning: package-lock.json or npm-shrinkwrap.json not found. The buildpack may reach out to the internet to download module updates, even if they are vendored.", "https://docs.cloudfoundry.org/buildpacks/node/index.html#offline_environments") } return nil diff --git a/src/nodejs/supply/supply_test.go b/src/nodejs/supply/supply_test.go index c2aaa3bc3..b71bbcaf1 100644 --- a/src/nodejs/supply/supply_test.go +++ b/src/nodejs/supply/supply_test.go @@ -1497,4 +1497,25 @@ export PATH=$PATH:"$HOME/bin":$NODE_PATH/.bin Expect(string(contents)).To(ContainSubstring("export SSL_CERT_DIR=${SSL_CERT_DIR:-/etc/ssl/certs}")) }) }) + + Describe("NoPackageLockTip", func() { + It("does not log when npm-shrinkwrap.json exists and vendored", func() { + Expect(os.WriteFile(filepath.Join(buildDir, "npm-shrinkwrap.json"), []byte("{}"), 0644)).To(Succeed()) + supplier.IsVendored = true + err = supplier.NoPackageLockTip() + Expect(err).To(BeNil()) + Expect(buffer.String()).To(Equal("")) + }) + + It("logs when no lockfile exists and vendored", func() { + // Ensure no lock files are present + os.Remove(filepath.Join(buildDir, "package-lock.json")) + os.Remove(filepath.Join(buildDir, "npm-shrinkwrap.json")) + supplier.IsVendored = true + buffer.Reset() + err = supplier.NoPackageLockTip() + Expect(err).To(BeNil()) + Expect(buffer.String()).To(ContainSubstring("not found")) + }) + }) })