Skip to content

Commit 91a7479

Browse files
authored
feat: fail with message when lockfile missing (#848)
1 parent 06cb5ea commit 91a7479

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

dist/index.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -74454,20 +74454,31 @@ const packageLockFilename = path.join(
7445474454
)
7445574455

7445674456
const useYarn = () => fs.existsSync(yarnFilename)
74457-
7445874457
const usePnpm = () => fs.existsSync(pnpmLockFilename)
74458+
const useNpm = () => fs.existsSync(packageLockFilename)
7445974459

7446074460
const lockHash = () => {
7446174461
const lockFilename = useYarn()
7446274462
? yarnFilename
7446374463
: usePnpm()
7446474464
? pnpmLockFilename
74465-
: packageLockFilename
74465+
: useNpm()
74466+
? packageLockFilename
74467+
: noLockFile()
7446674468
const fileHash = hasha.fromFileSync(lockFilename)
7446774469
debug(`Hash from file ${lockFilename} is ${fileHash}`)
7446874470
return fileHash
7446974471
}
7447074472

74473+
const noLockFile = () => {
74474+
core.error(
74475+
`Action failed. Missing package manager lockfile. ` +
74476+
`Expecting one of package-lock.json (npm), pnpm-lock.yaml (pnpm) or yarn.lock (yarn) in working-directory ` +
74477+
workingDirectory
74478+
)
74479+
process.exit(1)
74480+
}
74481+
7447174482
// enforce the same NPM cache folder across different operating systems
7447274483
const NPM_CACHE_FOLDER = path.join(homeDirectory, '.npm')
7447374484
const getNpmCache = () => {

index.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,31 @@ const packageLockFilename = path.join(
103103
)
104104

105105
const useYarn = () => fs.existsSync(yarnFilename)
106-
107106
const usePnpm = () => fs.existsSync(pnpmLockFilename)
107+
const useNpm = () => fs.existsSync(packageLockFilename)
108108

109109
const lockHash = () => {
110110
const lockFilename = useYarn()
111111
? yarnFilename
112112
: usePnpm()
113113
? pnpmLockFilename
114-
: packageLockFilename
114+
: useNpm()
115+
? packageLockFilename
116+
: noLockFile()
115117
const fileHash = hasha.fromFileSync(lockFilename)
116118
debug(`Hash from file ${lockFilename} is ${fileHash}`)
117119
return fileHash
118120
}
119121

122+
const noLockFile = () => {
123+
core.error(
124+
`Action failed. Missing package manager lockfile. ` +
125+
`Expecting one of package-lock.json (npm), pnpm-lock.yaml (pnpm) or yarn.lock (yarn) in working-directory ` +
126+
workingDirectory
127+
)
128+
process.exit(1)
129+
}
130+
120131
// enforce the same NPM cache folder across different operating systems
121132
const NPM_CACHE_FOLDER = path.join(homeDirectory, '.npm')
122133
const getNpmCache = () => {

0 commit comments

Comments
 (0)