Skip to content

Commit

Permalink
feat: fail with message when lockfile missing (#848)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMcC399 authored Mar 28, 2023
1 parent 06cb5ea commit 91a7479
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 13 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74454,20 +74454,31 @@ const packageLockFilename = path.join(
)

const useYarn = () => fs.existsSync(yarnFilename)

const usePnpm = () => fs.existsSync(pnpmLockFilename)
const useNpm = () => fs.existsSync(packageLockFilename)

const lockHash = () => {
const lockFilename = useYarn()
? yarnFilename
: usePnpm()
? pnpmLockFilename
: packageLockFilename
: useNpm()
? packageLockFilename
: noLockFile()
const fileHash = hasha.fromFileSync(lockFilename)
debug(`Hash from file ${lockFilename} is ${fileHash}`)
return fileHash
}

const noLockFile = () => {
core.error(
`Action failed. Missing package manager lockfile. ` +
`Expecting one of package-lock.json (npm), pnpm-lock.yaml (pnpm) or yarn.lock (yarn) in working-directory ` +
workingDirectory
)
process.exit(1)
}

// enforce the same NPM cache folder across different operating systems
const NPM_CACHE_FOLDER = path.join(homeDirectory, '.npm')
const getNpmCache = () => {
Expand Down
15 changes: 13 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,31 @@ const packageLockFilename = path.join(
)

const useYarn = () => fs.existsSync(yarnFilename)

const usePnpm = () => fs.existsSync(pnpmLockFilename)
const useNpm = () => fs.existsSync(packageLockFilename)

const lockHash = () => {
const lockFilename = useYarn()
? yarnFilename
: usePnpm()
? pnpmLockFilename
: packageLockFilename
: useNpm()
? packageLockFilename
: noLockFile()
const fileHash = hasha.fromFileSync(lockFilename)
debug(`Hash from file ${lockFilename} is ${fileHash}`)
return fileHash
}

const noLockFile = () => {
core.error(
`Action failed. Missing package manager lockfile. ` +
`Expecting one of package-lock.json (npm), pnpm-lock.yaml (pnpm) or yarn.lock (yarn) in working-directory ` +
workingDirectory
)
process.exit(1)
}

// enforce the same NPM cache folder across different operating systems
const NPM_CACHE_FOLDER = path.join(homeDirectory, '.npm')
const getNpmCache = () => {
Expand Down

0 comments on commit 91a7479

Please sign in to comment.