From 1e230d16ea4baf62c9db2d0a0f3211aa6bcca8d8 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 15 Sep 2023 13:07:59 -0700 Subject: [PATCH] [Fix] allow `npx resolve` to work Fixes #316. --- .github/workflows/executable.yml | 19 +++++++++++++++++++ bin/resolve | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/executable.yml diff --git a/.github/workflows/executable.yml b/.github/workflows/executable.yml new file mode 100644 index 0000000..cbbb147 --- /dev/null +++ b/.github/workflows/executable.yml @@ -0,0 +1,19 @@ +name: resolve executable + +on: [push, pull_request] + +jobs: + _: + name: cli + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: ljharb/actions/node/install@main + - run: "[ $(./bin/resolve fs) = 'fs' ]" + name: run inside the package with a direct path + - run: "npm link && [ $(resolve fs) = 'fs' ] && npm uninstall -g resolve" + name: run linked as a global in the PATH + - run: "[ $(npx resolve fs) = 'fs' ]" + name: run via npx diff --git a/bin/resolve b/bin/resolve index 4c1884a..21d1a87 100755 --- a/bin/resolve +++ b/bin/resolve @@ -11,7 +11,7 @@ if ( !process.argv || process.argv.length < 2 || (process.argv[1] !== __filename && fs.statSync(process.argv[1]).ino !== fs.statSync(__filename).ino) - || (process.env._ && fs.realpathSync(path.resolve(process.env._)) !== __filename) + || (process.env.npm_lifecycle_event !== 'npx' && process.env._ && fs.realpathSync(path.resolve(process.env._)) !== __filename) ) ) { console.error('Error: `resolve` must be run directly as an executable');