Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get environment variables from npm #7

Merged
merged 3 commits into from May 2, 2019

Conversation

TiagoDanin
Copy link
Contributor

@TiagoDanin TiagoDanin commented Mar 30, 2019

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

@TiagoDanin
Copy link
Contributor Author

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

@TiagoDanin TiagoDanin mentioned this pull request Mar 31, 2019
@sindresorhus sindresorhus changed the title Get environment variables of NPM Get environment variables from npm Apr 1, 2019
@sindresorhus
Copy link
Owner

Can you add a test?

@TiagoDanin
Copy link
Contributor Author

@sindresorhus Two problems: Sugestions?

  • The process.env in test.js with import is not loading in index.js

  • Required reloads the package for different tests

  • test.a.js (All Falid!)

import test from 'ava';
import execa from 'execa';
import globalDirs from '.';

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!)
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 ...//
  • test.c.js (All falid!)
const test = require('ava');
const execa = require('execa');
const globalDirs = require('.');

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 TiagoDanin changed the title Get environment variables from npm [WIP] Get environment variables from npm Apr 12, 2019
@TiagoDanin TiagoDanin changed the title [WIP] Get environment variables from npm Get environment variables from npm Apr 14, 2019
@TiagoDanin
Copy link
Contributor Author

@sindresorhus Done! Added new test.

@sindresorhus
Copy link
Owner

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

@TiagoDanin TiagoDanin reopened this May 1, 2019
@sindresorhus sindresorhus merged commit c1a0e56 into sindresorhus:master May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not respecting the NPM_CONFIG_PREFIX env variable
2 participants