Skip to content

Commit fb5724f

Browse files
authored
facts.npm: check directory exists before cd-ing
1 parent 52cfa3a commit fb5724f

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/pyinfra/facts/npm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def requires_command(self, directory=None) -> str:
3030
@override
3131
def command(self, directory=None):
3232
if directory:
33-
return ("cd {0} && npm list -g --depth=0").format(directory)
33+
return ("! test -d {0} || (cd {0} && npm list -g --depth=0)").format(directory)
3434
return "npm list -g --depth=0"
3535

3636
@override

tests/facts/npm.NpmPackages/local_packages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"arg": "somedir",
3-
"command": "cd somedir && npm list -g --depth=0",
3+
"command": "! test -d somedir || (cd somedir && npm list -g --depth=0)",
44
"requires_command": "npm",
55
"output": [
66
"├── [email protected]",

0 commit comments

Comments
 (0)