Skip to content

Commit 74eb576

Browse files
authored
Fix check for package.json path (#167)
This pull request includes minor version updates and improvements to the directory traversal logic in the `run` command.
2 parents af8b82d + 0738087 commit 74eb576

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

badges/coverage.svg

+1-1
Loading

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@github/local-action",
33
"description": "Local Debugging for GitHub Actions",
4-
"version": "3.1.0",
4+
"version": "3.1.1",
55
"type": "module",
66
"author": "Nick Alteen <[email protected]>",
77
"private": false,

src/commands/run.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,23 @@ export async function action(): Promise<void> {
119119
// Starting at the target action's entrypoint, find the package.json file.
120120
const dirs = path.dirname(EnvMeta.entrypoint).split(path.sep)
121121
let packageJsonPath
122+
let found = false
122123

123124
// Move up the directory tree until we find a package.json directory.
124125
while (dirs.length > 0) {
125-
packageJsonPath = path.join(process.env.TARGET_ACTION_PATH!, 'package.json')
126+
packageJsonPath = path.resolve(dirs.join(path.sep), 'package.json')
126127

127128
// Check if the current directory has a package.json file.
128-
if (fs.existsSync(packageJsonPath)) break
129+
if (fs.existsSync(packageJsonPath)) {
130+
found = true
131+
break
132+
}
129133

130134
// Move up the directory tree.
131135
dirs.pop()
132136
}
133137

134-
if (dirs.length === 0 || !packageJsonPath)
138+
if (!found || !packageJsonPath)
135139
throw new Error(
136140
'No package.json file found in the action directory or any parent directories.'
137141
)

0 commit comments

Comments
 (0)