sindresorhus / global-directory

Get the directory of globally installed packages and binaries
MIT License
75 stars 10 forks source link

Get environment variables from npm #7

Closed TiagoDanin closed 5 years ago

TiagoDanin commented 5 years ago

Fixes #4 Note: "Config values are case-insensitive" (NPM Config Docs: https://docs.npmjs.com/misc/config)

TiagoDanin commented 5 years ago

Problem in Travis CI: XO did not work with node V4

sindresorhus commented 5 years ago

Can you add a test?

TiagoDanin commented 5 years ago

@sindresorhus Two problems: Sugestions?

console.log(globalDirs);

const npm = arguments => execa.stdout('npm', arguments);

test('npm.prefix with env', async t => { process.env.npm_config_PREFIX = '/usr/local/lib' t.is(globalDirs.npm.prefix, '/usr/local/lib'); }); //... all tests ...//


- test.b.js (Working "npm.prefix with env" and others falid!)
```js
const test = require('ava');
const execa = require('execa');

const npm = arguments_ => execa.stdout('npm', arguments_);

test('npm.prefix with env', async t => {
    process.env.npm_config_PREFIX = '/usr/local/lib';
    const globalDirs = require('.');
    console.log(globalDirs);
    t.is(globalDirs.npm.prefix, '/usr/local/lib');
});
//... all tests ...//

console.log(globalDirs);

const npm = arguments => execa.stdout('npm', arguments);

test('npm.prefix with env', async t => { process.env.npm_config_PREFIX = '/usr/local/lib'; const globalDirsEnv = require('.'); t.is(globalDirsEnv.npm.prefix, '/usr/local/lib'); }); //... all tests ...//

TiagoDanin commented 5 years ago

@sindresorhus Done! Added new test.

sindresorhus commented 5 years ago

I don't want to expose a .reload() method just for testing purposes. The correct solution is to use something like https://github.com/sindresorhus/import-fresh