Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

copin

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

copin - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

28

dist/index.js

@@ -95,9 +95,9 @@ 'use strict';

function checkModeConfig(modeConfig, noModeConfig) {
if (!modeConfig && noModeConfig) {
function checkModeConfig(modeConfig, noNodeEnvConfig) {
if (!modeConfig && noNodeEnvConfig) {
var err = 'config not found for NODE_ENV "' + NODE_ENV + '"';
if (noModeConfig === 'warn') {
if (noNodeEnvConfig === 'warn') {
return console.log('WARN: ' + err);
}
// noModeConfig === 'error'
// noNodeEnvConfig === 'error'
throw new Error(err);

@@ -123,16 +123,16 @@ }

dir = _ref2$dir === undefined ? 'config' : _ref2$dir,
_ref2$noEnvMode = _ref2.noEnvMode,
noEnvMode = _ref2$noEnvMode === undefined ? 'test' : _ref2$noEnvMode,
_ref2$fresh = _ref2.fresh,
fresh = _ref2$fresh === undefined ? false : _ref2$fresh,
_ref2$noModeConfig = _ref2.noModeConfig,
noModeConfig = _ref2$noModeConfig === undefined ? null : _ref2$noModeConfig,
_ref2$fileOnlyNodeEnv = _ref2.fileOnlyNodeEnv,
fileOnlyNodeEnv = _ref2$fileOnlyNodeEnv === undefined ? 'test' : _ref2$fileOnlyNodeEnv,
_ref2$reload = _ref2.reload,
reload = _ref2$reload === undefined ? false : _ref2$reload,
_ref2$noNodeEnvConfig = _ref2.noNodeEnvConfig,
noNodeEnvConfig = _ref2$noNodeEnvConfig === undefined ? null : _ref2$noNodeEnvConfig,
_ref2$isGlobal = _ref2.isGlobal,
isGlobal = _ref2$isGlobal === undefined ? true : _ref2$isGlobal;
if (isGlobal && GLOBAL_CONFIG && !fresh) {
if (isGlobal && GLOBAL_CONFIG && !reload) {
return GLOBAL_CONFIG;
}
(0, _assert2.default)(!noModeConfig || (0, _includes3.default)(['warn', 'error'], noModeConfig), '\'noModeConfig\' must be one of null (default), \'warn\', or \'error\', not ' + noModeConfig);
(0, _assert2.default)(!noNodeEnvConfig || (0, _includes3.default)(['warn', 'error'], noNodeEnvConfig), '\'noNodeEnvConfig\' must be one of null (default), \'warn\', or \'error\', not ' + noNodeEnvConfig);

@@ -142,7 +142,7 @@ var defaultConfig = loadConfig(dir + '/default.yaml');

var modeConfig = loadConfig(dir + '/' + NODE_ENV + '.yaml');
checkModeConfig(modeConfig, noModeConfig);
checkModeConfig(modeConfig, noNodeEnvConfig);
var mergedConfig = (0, _merge3.default)({}, defaultConfig || {}, modeConfig || {});
if (NODE_ENV !== noEnvMode) {
if (NODE_ENV !== fileOnlyNodeEnv) {
var envConfig = loadConfig(dir + '/ENV_MAP.yaml');

@@ -149,0 +149,0 @@ (0, _merge3.default)(mergedConfig, convertEnvConfig({ source: envConfig, location: '', result: {} }));

{
"name": "copin",
"version": "0.0.2",
"version": "0.0.3",
"description": "Opinionated Config",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -1,3 +0,3 @@

Configure your Node.js Applications
===================================
Config for Node.js Apps
=======================

@@ -106,3 +106,3 @@ Introduction

`Copin([{ dir, fresh, noEnvMode, noModeConfig, isGlobal }]);`
`Copin([{ dir, reload, fileOnlyNodeEnv, noNodeEnvConfig, isGlobal }]);`

@@ -120,5 +120,5 @@ Get an instance of Copin. In normal use it's likely you will not need to specify

dir | {String} | relative path to the config directory. defaults to `config`
fresh | {Boolean} | if true, config will be reloaded. defaults to false
noEnvMode | {String} | a NODE_ENV value for which environmental variables should not be merged into the config. defaults to `test`
noModeConfig | {String} | what to do if there is no config for the current mode (NODE_ENV). may be `null`, 'war', or 'error'. Defaults to null.
reload | {Boolean} | if true, config will be reloaded. defaults to false
fileOnlyNodeEnv | {String} | a NODE_ENV value for which environmental variables should not be merged into the config. defaults to `test`
noNodeEnvConfig | {String} | what to do if there is no config for the current NODE_ENV. May be `null`, `'warn'`, or `'error'`. Defaults to null.
isGlobal | {Boolean} | if true then imports of the same installation of Copin will share the config object. Defaults to `true`

@@ -141,4 +141,4 @@

May be freely distributed under the [MIT license](https://raw.githubusercontent.com/lorenwest/node-config/master/LICENSE).
May be freely distributed under the [MIT license](https://raw.githubusercontent.com/lecstor/copin/master/LICENSE).
Copyright (c) 2017 Jason Galea

@@ -5,3 +5,3 @@ import * as fs from 'fs';

const defaultOpts = { dir: './src/__tests__/config', fresh: true, isGlobal: false, noEnvMode: null };
const defaultOpts = { dir: './src/__tests__/config', reload: true, isGlobal: false, fileOnlyNodeEnv: null };

@@ -14,6 +14,7 @@ describe('load config', () => {

expect(config.fromEnv).toBeUndefined();
console.log({ config });
});
it('loads the default config (fresh: true)', () => {
const config = Copin({ fresh: true, noEnvMode: null });
it('loads the default config (reload: true)', () => {
const config = Copin({ reload: true, fileOnlyNodeEnv: null });
expect(config).toBeDefined();

@@ -25,3 +26,3 @@ expect(config.test).toBe('hurrah!');

it('loads the default config (isGlobal: false)', () => {
const config = Copin({ isGlobal: false, noEnvMode: null });
const config = Copin({ isGlobal: false, fileOnlyNodeEnv: null });
expect(config).toBeDefined();

@@ -41,3 +42,3 @@ expect(config.test).toBe('hurrah!');

const config = Copin({ ...defaultOpts, isGlobal: true });
const config2 = Copin({ ...defaultOpts, isGlobal: true, fresh: false });
const config2 = Copin({ ...defaultOpts, isGlobal: true, reload: false });
expect(config).toBe(config2);

@@ -52,4 +53,4 @@ });

it('throws an error on invalid noModeConfig option', () => {
expect(() => Copin({ ...defaultOpts, noModeConfig: 'WRONG' })).toThrow();
it('throws an error on invalid noNodeEnvConfig option', () => {
expect(() => Copin({ ...defaultOpts, noNodeEnvConfig: 'WRONG' })).toThrow();
});

@@ -76,3 +77,3 @@

};
const config = Copin({ ...defaultOpts, dir: './src/__tests__/config-no-mode', noModeConfig: 'warn' });
const config = Copin({ ...defaultOpts, dir: './src/__tests__/config-no-mode', noNodeEnvConfig: 'warn' });
console.log = origLog;

@@ -85,3 +86,3 @@ expect(log[0]).toEqual('WARN: config not found for NODE_ENV "test"');

it('throws an error on missing mode config', () => {
expect(() => Copin({ ...defaultOpts, dir: './src/__tests__/config-no-mode', noModeConfig: 'error' })).toThrow();
expect(() => Copin({ ...defaultOpts, dir: './src/__tests__/config-no-mode', noNodeEnvConfig: 'error' })).toThrow();
});

@@ -103,3 +104,3 @@ });

};
const config = Copin({ ...defaultOpts, dir: './src/__tests__/config-empty-mode', noModeConfig: 'warn' });
const config = Copin({ ...defaultOpts, dir: './src/__tests__/config-empty-mode', noNodeEnvConfig: 'warn' });
console.log = origLog;

@@ -112,3 +113,3 @@ expect(log[0]).toEqual('WARN: config not found for NODE_ENV "test"');

it('errors on empty mode config', () => {
expect(() => Copin({ ...defaultOpts, dir: './src/__tests__/config-empty-mode', noModeConfig: 'error' })).toThrow();
expect(() => Copin({ ...defaultOpts, dir: './src/__tests__/config-empty-mode', noNodeEnvConfig: 'error' })).toThrow();
});

@@ -119,3 +120,3 @@ });

it('loads ENV vars according to ENV_MAP', () => {
const config = Copin({ ...defaultOpts, noEnvMode: null });
const config = Copin({ ...defaultOpts, fileOnlyNodeEnv: null });
expect(config.node.env).toBe('test');

@@ -125,3 +126,3 @@ });

it('ENV vars override mode and default config', () => {
const config = Copin({ ...defaultOpts, noEnvMode: null });
const config = Copin({ ...defaultOpts, fileOnlyNodeEnv: null });
expect(config.fromEnv).toBe('test');

@@ -128,0 +129,0 @@ });

@@ -49,9 +49,9 @@ import path from 'path';

function checkModeConfig (modeConfig, noModeConfig) {
if (!modeConfig && noModeConfig) {
function checkModeConfig (modeConfig, noNodeEnvConfig) {
if (!modeConfig && noNodeEnvConfig) {
const err = `config not found for NODE_ENV "${NODE_ENV}"`;
if (noModeConfig === 'warn') {
if (noNodeEnvConfig === 'warn') {
return console.log(`WARN: ${err}`);
}
// noModeConfig === 'error'
// noNodeEnvConfig === 'error'
throw new Error(err);

@@ -75,8 +75,8 @@ }

dir = 'config',
noEnvMode = 'test',
fresh = false,
noModeConfig = null,
fileOnlyNodeEnv = 'test',
reload = false,
noNodeEnvConfig = null,
isGlobal = true
} = {}) {
if (isGlobal && GLOBAL_CONFIG && !fresh) {
if (isGlobal && GLOBAL_CONFIG && !reload) {
return GLOBAL_CONFIG;

@@ -86,4 +86,4 @@ }

assert(
!noModeConfig || _includes(['warn', 'error'], noModeConfig),
`'noModeConfig' must be one of null (default), 'warn', or 'error', not ${noModeConfig}`
!noNodeEnvConfig || _includes(['warn', 'error'], noNodeEnvConfig),
`'noNodeEnvConfig' must be one of null (default), 'warn', or 'error', not ${noNodeEnvConfig}`
);

@@ -94,7 +94,7 @@

const modeConfig = loadConfig(`${dir}/${NODE_ENV}.yaml`);
checkModeConfig(modeConfig, noModeConfig);
checkModeConfig(modeConfig, noNodeEnvConfig);
const mergedConfig = _merge({}, defaultConfig || {}, modeConfig || {});
if (NODE_ENV !== noEnvMode) {
if (NODE_ENV !== fileOnlyNodeEnv) {
const envConfig = loadConfig(`${dir}/ENV_MAP.yaml`);

@@ -101,0 +101,0 @@ _merge(mergedConfig, convertEnvConfig({ source: envConfig, location: '', result: {} }));

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc