Skip to content

Commit 3d6f3c9

Browse files
authored
fix: handle non zero exit code when running npm ls (#622)
1 parent b837417 commit 3d6f3c9

File tree

37 files changed

+74
-70
lines changed

37 files changed

+74
-70
lines changed

src/algokit/core/compilers/typescript.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ def _find_project_puyats_command(
1515
Try to find PuyaTs command installed at the project level.
1616
"""
1717
try:
18-
result = run([*npm_command, "ls"])
19-
if result.exit_code == 0:
18+
result = run([*npm_command, "ls", "--no-unicode"])
19+
# Normally we would check the exit code, however `npm ls` may return a non zero exit code
20+
# when certain dependencies are not met. We still want to continue processing.
21+
if result.output != "":
2022
compile_command = [*npx_command, PUYATS_NPM_PACKAGE]
2123
for line in result.output.splitlines():
2224
if PUYATS_NPM_PACKAGE in line:

src/algokit/core/typed_client_generation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,10 @@ def find_project_generate_command(
277277
self, npm_command: list[str], npx_command: list[str], version: str | None
278278
) -> list[str] | None:
279279
try:
280-
result = proc.run([*npm_command, "ls"])
281-
if result.exit_code == 0:
280+
result = proc.run([*npm_command, "ls", "--no-unicode"])
281+
# Normally we would check the exit code, however `npm ls` may return a non zero exit code
282+
# when certain dependencies are not met. We still want to continue processing.
283+
if result.output != "":
282284
generate_command = [*npx_command, TYPESCRIPT_NPM_PACKAGE]
283285
for line in result.output.splitlines():
284286
if TYPESCRIPT_NPM_PACKAGE in line:

tests/compile/test_typescript.test_compile_py_help.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
DEBUG: Running 'npm ls' in '{current_working_directory}'
1+
DEBUG: Running 'npm ls --no-unicode' in '{current_working_directory}'
22
DEBUG: npm: STDOUT
33
DEBUG: npm: STDERR
4-
DEBUG: Running 'npm --global ls' in '{current_working_directory}'
4+
DEBUG: Running 'npm --global ls --no-unicode' in '{current_working_directory}'
55
DEBUG: npm: STDOUT
66
DEBUG: npm: STDERR
77
DEBUG: Running 'npx -y @algorandfoundation/puya-ts -h' in '{current_working_directory}'

tests/compile/test_typescript.test_puyats_is_installed_globally.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
DEBUG: Running 'npm ls' in '{current_working_directory}'
1+
DEBUG: Running 'npm ls --no-unicode' in '{current_working_directory}'
22
DEBUG: npm: STDOUT
33
DEBUG: npm: STDERR
4-
DEBUG: Running 'npm --global ls' in '{current_working_directory}'
4+
DEBUG: Running 'npm --global ls --no-unicode' in '{current_working_directory}'
55
DEBUG: npm: └── @algorandfoundation/puya-ts@1.0.0
66
DEBUG: Running 'npx @algorandfoundation/puya-ts --version' in '{current_working_directory}'
77
DEBUG: npx: puya-ts 1.0.0

tests/compile/test_typescript.test_puyats_is_installed_in_project.approved.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
DEBUG: Running 'npm ls' in '{current_working_directory}'
1+
DEBUG: Running 'npm ls --no-unicode' in '{current_working_directory}'
22
DEBUG: npm: └── @algorandfoundation/puya-ts@1.0.0
33
DEBUG: Running 'npx @algorandfoundation/puya-ts --version' in '{current_working_directory}'
44
DEBUG: npx: puya-ts 1.0.0

tests/compile/test_typescript.test_puyats_is_not_installed_anywhere.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
DEBUG: Running 'npm ls' in '{current_working_directory}'
1+
DEBUG: Running 'npm ls --no-unicode' in '{current_working_directory}'
22
DEBUG: npm: STDOUT
33
DEBUG: npm: STDERR
4-
DEBUG: Running 'npm --global ls' in '{current_working_directory}'
4+
DEBUG: Running 'npm --global ls --no-unicode' in '{current_working_directory}'
55
DEBUG: npm: STDOUT
66
DEBUG: npm: STDERR
77
DEBUG: Running 'npx -y @algorandfoundation/puya-ts {current_working_directory}/tests/compile/dummy_contract.py' in '{current_working_directory}'

tests/compile/test_typescript.test_specificed_puyats_version_is_not_installed.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
DEBUG: Running 'npm ls' in '{current_working_directory}'
1+
DEBUG: Running 'npm ls --no-unicode' in '{current_working_directory}'
22
DEBUG: npm: └── @algorandfoundation/puya-ts@1.0.0
3-
DEBUG: Running 'npm --global ls' in '{current_working_directory}'
3+
DEBUG: Running 'npm --global ls --no-unicode' in '{current_working_directory}'
44
DEBUG: npm: └── @algorandfoundation/puya-ts@1.0.0
55
DEBUG: Running 'npx -y @algorandfoundation/puya-ts@1.1.0 {current_working_directory}/tests/compile/dummy_contract.py' in '{current_working_directory}'
66
DEBUG: npx: Compilation successful

tests/generate/test_generate_client.test_generate_client_typescript[linux---output {contract_name}.ts-HelloWorldApp.ts].approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
DEBUG: Searching for project installed client generator
2-
DEBUG: Running 'npm ls' in '{current_working_directory}'
2+
DEBUG: Running 'npm ls --no-unicode' in '{current_working_directory}'
33
DEBUG: npm: STDOUT
44
DEBUG: npm: STDERR
55
DEBUG: Searching for globally installed client generator
6-
DEBUG: Running 'npm --global ls' in '{current_working_directory}'
6+
DEBUG: Running 'npm --global ls --no-unicode' in '{current_working_directory}'
77
DEBUG: npm: STDOUT
88
DEBUG: npm: STDERR
99
DEBUG: No matching installed client generator found, run client generator via npx

tests/generate/test_generate_client.test_generate_client_typescript[linux--l typescript -v 2.6.0-HelloWorldAppClient.ts].approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
DEBUG: Searching for project installed client generator
2-
DEBUG: Running 'npm ls' in '{current_working_directory}'
2+
DEBUG: Running 'npm ls --no-unicode' in '{current_working_directory}'
33
DEBUG: npm: STDOUT
44
DEBUG: npm: STDERR
55
DEBUG: Searching for globally installed client generator
6-
DEBUG: Running 'npm --global ls' in '{current_working_directory}'
6+
DEBUG: Running 'npm --global ls --no-unicode' in '{current_working_directory}'
77
DEBUG: npm: STDOUT
88
DEBUG: npm: STDERR
99
DEBUG: No matching installed client generator found, run client generator via npx

tests/generate/test_generate_client.test_generate_client_typescript[linux--l typescript-HelloWorldAppClient.ts].approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
DEBUG: Searching for project installed client generator
2-
DEBUG: Running 'npm ls' in '{current_working_directory}'
2+
DEBUG: Running 'npm ls --no-unicode' in '{current_working_directory}'
33
DEBUG: npm: STDOUT
44
DEBUG: npm: STDERR
55
DEBUG: Searching for globally installed client generator
6-
DEBUG: Running 'npm --global ls' in '{current_working_directory}'
6+
DEBUG: Running 'npm --global ls --no-unicode' in '{current_working_directory}'
77
DEBUG: npm: STDOUT
88
DEBUG: npm: STDERR
99
DEBUG: No matching installed client generator found, run client generator via npx

0 commit comments

Comments
 (0)