Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/nodejs/supply/supply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/nodejs/supply/supply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
})
})
Loading