Skip to content

Commit 343ea44

Browse files
committedSep 15, 2023
[Fix] allow npx resolve to work (#316)
Fixes #316.
1 parent 4441c5f commit 343ea44

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
 

‎.github/workflows/executable.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: resolve executable
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
_:
7+
name: cli
8+
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: ljharb/actions/node/install@main
14+
- run: "[ $(./bin/resolve fs) = 'fs' ]"
15+
name: run inside the package with a direct path
16+
- run: "npm link && [ $(resolve fs) = 'fs' ] && npm uninstall -g resolve"
17+
name: run linked as a global in the PATH
18+
- run: "[ $(npx resolve fs) = 'fs' ]"
19+
name: run via npx

‎bin/resolve

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (
1111
!process.argv
1212
|| process.argv.length < 2
1313
|| (process.argv[1] !== __filename && fs.statSync(process.argv[1]).ino !== fs.statSync(__filename).ino)
14-
|| (process.env._ && fs.realpathSync(path.resolve(process.env._)) !== __filename)
14+
|| (process.env.npm_lifecycle_event !== 'npx' && process.env._ && fs.realpathSync(path.resolve(process.env._)) !== __filename)
1515
)
1616
) {
1717
console.error('Error: `resolve` must be run directly as an executable');

0 commit comments

Comments
 (0)
Please sign in to comment.