Closed boneskull closed 5 years ago
Looks like the tests won't run on Node.js v4. I can add a commit to drop v4 from .travis.yml
(and update engines
field, add new Node.js versions to CI, etc)
another approach would just be to just look for /usr/local/Cellar/node/
in process.execPath
and force it to use /usr/local
as the prefix.
@sindresorhus (ping) I could use some direction here; there's a couple ways to go and I'm not sure which you'd prefer. The choices are:
@boneskull @sindresorhus I think we could drop support for Node.js 4. Just do it. Sindre already.
Sindre has removed support for Node.js 4 in many of his repositories.
I would prefer 1
, adding a special case for Homebrew.
@sindresorhus OK, this should be ready.
I tried to add OSX to the build matrix and install node using homebrew, but was running in to trouble and don't have the time to hack on it further atm.
Before this change:
$ npm test
> global-dirs@0.1.1 test /Users/boneskull/projects/sindresorhus/global-dirs
> xo && ava
{ npm:
{ prefix: '/usr/local/Cellar/node/11.14.0_1',
packages: '/usr/local/Cellar/node/11.14.0_1/lib/node_modules',
binaries: '/usr/local/Cellar/node/11.14.0_1/bin' },
yarn:
{ prefix: '/Users/boneskull/.config/yarn',
packages: '/Users/boneskull/.config/yarn/global/node_modules',
binaries: '/Users/boneskull/.config/yarn/global/node_modules/.bin' } }
1 passed
3 failed
npm.prefix
/Users/boneskull/projects/sindresorhus/global-dirs/test.js:10
9: test('npm.prefix', async t => {
10: t.is(globalDirs.npm.prefix, await npm(['prefix', '--global']));
11: });
Difference:
- '/usr/local/Cellar/node/11.14.0_1'
+ '/usr/local'
npm.packages
/Users/boneskull/projects/sindresorhus/global-dirs/test.js:14
13: test('npm.packages', async t => {
14: t.is(globalDirs.npm.packages, await npm(['root', '--global']));
15: });
Difference:
- '/usr/local/Cellar/node/11.14.0_1/lib/node_modules'
+ '/usr/local/lib/node_modules'
npm.binaries
/Users/boneskull/projects/sindresorhus/global-dirs/test.js:18
17: test('npm.binaries', async t => {
18: t.is(globalDirs.npm.binaries, await npm(['bin', '--global']));
19: });
Difference:
- '/usr/local/Cellar/node/11.14.0_1/bin'
+ '/usr/local/bin'
After this change:
$ npm test
> global-dirs@0.1.1 test /Users/boneskull/projects/sindresorhus/global-dirs
> xo && ava
{ npm:
{ prefix: '/usr/local',
packages: '/usr/local/lib/node_modules',
binaries: '/usr/local/bin' },
yarn:
{ prefix: '/Users/boneskull/.config/yarn',
packages: '/Users/boneskull/.config/yarn/global/node_modules',
binaries: '/Users/boneskull/.config/yarn/global/node_modules/.bin' } }
4 passed
I'll do a new release once the other open PRs are merged.
After poking at this a bit further, I found we'd need extra I/O to make this work in every case.
If, for example, your executable is
ava
, we can't useprocess.env._
because it points to/path/to/ava
. If we instead rannode node_modules/.bin/ava
, thenprocess.env._
would point tonode
in yourPATH
.I've updated the code to check if
node
is indeed what the user executed; if that's the case, we can useprocess.env._
to get at its path. Otherwise, we just useprocess.execPath
. On my system, this is still incorrect when runningava
.If we wanted this to always work, we'd need to use
which
or something to that effect, and I assume you don't want to be invokingchild_process.anything()
here.