Skip to content

Commit

Permalink
Switch bin to Bash script to avoid "tsx not found" (#593)
Browse files Browse the repository at this point in the history
* Switch bin/preflight.ts to bin/preflight.sh to avoid "tsx not found"

* Fix path in shim

* Try $script_dir path on Linux

* Add debugging

* Add debugging

* Use base path from `pnpm bin --global`

* Remove extra slashes

* Comment out early exit and debugging

* Delete commented debugging code

* Add back debugging

* Use simpler symlink path

* Escape slashes
  • Loading branch information
karlhorky authored Oct 26, 2024
1 parent 2eac499 commit f0d01f9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
20 changes: 20 additions & 0 deletions bin/preflight.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

script_dir="$(cd "$(dirname "$0")" && pwd)"
echo "script_dir: $script_dir"

# Workaround for incorrect path in pnpm shim
# https://github.com/pnpm/pnpm/issues/8704#issuecomment-2439618363
#
# TODO: Remove and switch back to "$script_dir/../node_modules/.bin/tsx"
# when the issue above is resolved
tsx_shim="$script_dir/../node_modules/.bin/tsx"
exec_command=$(awk '/^else$/{flag=1;next}/^fi$/{flag=0}flag' "$tsx_shim" | grep 'exec node')
cli_path=$(echo "$exec_command" | sed -E 's/^[[:space:]]*exec node[[:space:]]+"[^"]+(node_modules\/tsx\/[^"]+)".*/\1/')
cli_path="$(pnpm bin --global)/global/5/.pnpm/$cli_path"
# # pnpm_bin_global="$(pnpm bin --global)/global/5/.pnpm/$cli_path"
# # echo "pnpm_bin_global: $pnpm_bin_global"
# cli_path="${cli_path/$pnpm_bin_global\//$pnpm_bin_global\/global\/5\/.pnpm\/}"
# echo "cli_path: $cli_path"

node "$cli_path" "$script_dir/../src/index.ts"
3 changes: 0 additions & 3 deletions bin/preflight.ts

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"module": "./src/index.ts",
"types": "./src/index.ts",
"bin": {
"preflight": "./bin/preflight.ts"
"preflight": "./bin/preflight.sh"
},
"files": [
"./bin/preflight.js",
Expand Down

0 comments on commit f0d01f9

Please sign in to comment.