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

oconf

Package Overview
Dependencies
Maintainers
4
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oconf - npm Package Compare versions

Comparing version 3.0.3 to 4.0.0

7

package.json

@@ -5,3 +5,3 @@ {

"description": "Configuration",
"version": "3.0.3",
"version": "4.0.0",
"repository": {

@@ -27,2 +27,3 @@ "type": "git",

"oconf": "bin/oconf",
"oconf-lint": "bin/oconf-lint",
"oconf-extract-option": "bin/oconf-extract-option"

@@ -38,3 +39,3 @@ },

"async": "0.9.0",
"cjson": "0.3.0",
"cjson": "0.3.1",
"glob": "5.0.1",

@@ -52,4 +53,4 @@ "minimatch": "2.0.1",

"mocha": "*",
"unexpected": "5.5.2"
"unexpected": "7.0.0"
}
}

@@ -79,15 +79,15 @@ # OConf

You can lint your configuration files by using `oconf-lint`. It will
not output any of the resolved configuration, but only exit with an
error in case of any formatting errors in the files.
You can lint your configuration files by using the `--lint` flag. It
will not output any of the resolved configuration, but only exit with
an error in case of any formatting errors in the files.
```
$ oconf-lint config.cjson
$ oconf --lint config.cjson
```
By using `oconf-extract-option` you can supply a path to a value as
well:
By using the `--extract-option` flag you can supply a path to a value
as well:
```
$ oconf-extract-option config.cjson obj.foo
$ oconf --extract-option obj.foo config.cjson
bar

@@ -98,13 +98,13 @@ ```

need to pass the configuration to other CLI tools. If you need the
JSON formatted data, you can pass the `--json` option.
JSON formatted data, you can pass the `--option-as-json` option.
```
$ oconf-extract-option --json config.cjson obj.foo
$ oconf --extract-option obj.foo --json config.cjson
"bar"
```
If the key is missing `oconf-extract-option` will exit with status
If the key is missing `oconf --extract-option` will exit with status
code 1. If you need to overwrite that behaviour you can pass the
`--allowmissing` flag to oconf which will make it exit with status
code 0 if no value is found at the given path.
`--allow-missing-option` flag to oconf which will make it exit with
status code 0 if no value is found at the given path.

@@ -111,0 +111,0 @@ ## Tests

@@ -7,30 +7,62 @@ /* global describe, it */

expect.addAssertion('when oconf-linted', function (expect, subject, value) {
this.errorMode = 'nested';
var that = this;
return expect.promise(function (resolve, reject) {
var args;
if (typeof subject === 'string') {
args = subject;
} else {
if (Array.isArray(subject)) {
args = subject.join(' ');
} else {
return reject(new Error('arguments must be supplied as string or array'));
}
}
exec(pathToBin + ' ' + args, function (err, stdout, stderr) {
resolve({
err: err,
code: err && err.code || 0,
stdout: stdout,
stderr: stderr
});
});
}).then(function (value) {
return that.shift(value, 0);
});
});
function testFile(fileName) {
if (!(/\.cjson$/.test(fileName))) {
fileName += '.cjson';
}
return require('path').resolve(__dirname, '..', 'files', fileName);
}
describe('bin/oconf-lint', function () {
it('should exit with no errors if valid', function (done) {
var testFile = require('path').resolve(__dirname, '..', 'files', 'lint', 'valid.cjson');
exec(pathToBin + ' ' + testFile, function (err, stdout, stderr) {
expect(err, 'to be null');
expect(stdout, 'to equal', '');
expect(stderr, 'to equal', 'No linting errors found.\n');
done();
it('should exit with no errors if valid', function () {
return expect(testFile('lint/valid'), 'when oconf-linted', 'to satisfy', {
err: null,
code: 0,
stdout: '',
stderr: 'No linting errors found.\n'
});
});
it('should report the errors if invalid', function (done) {
var testFile = require('path').resolve(__dirname, '..', 'files', 'lint', 'invalid.cjson');
exec(pathToBin + ' ' + testFile, function (err, stdout, stderr) {
expect(err, 'to be an', Error);
expect(err, 'to have property', 'code', 1);
expect(stdout, 'to equal', '');
expect(stderr, 'to equal', [
testFile,
'',
'Parse error on line 2:',
it('should report the errors if invalid', function () {
var filePath = testFile('lint/invalid');
return expect(filePath, 'when oconf-linted', 'to satisfy', {
err: expect.it('to be an', Error),
code: 1,
stdout: '',
stderr: [
'Error: Parse error on line 2:',
'{ "foo": "bar}',
'------------^',
"Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'",
'File: "' + filePath + '"',
''
].join('\n'));
done();
].join('\n')
});
});
});

@@ -7,47 +7,294 @@ /* global describe, it */

function formattedJson(obj) {
return JSON.stringify(obj, null, 4) + '\n';
}
function testFile(fileName) {
if (!(/\.cjson$/.test(fileName))) {
fileName += '.cjson';
}
return require('path').resolve(__dirname, '..', 'files', fileName);
}
expect.addAssertion('when passed as arguments to oconf', function (expect, subject, value) {
this.errorMode = 'nested';
var that = this;
return expect.promise(function (resolve, reject) {
var args;
if (typeof subject === 'string') {
args = subject;
} else {
if (Array.isArray(subject)) {
args = subject.join(' ');
} else {
return reject(new Error('arguments must be supplied as string or array'));
}
}
exec(pathToBin + ' ' + args, function (err, stdout, stderr) {
resolve({
err: err,
code: err && err.code || 0,
stdout: stdout,
stderr: stderr
});
});
}).then(function (value) {
return that.shift(value, 0);
});
});
describe('bin/oconf', function () {
it('should print the resolved json structure to stdout', function (done) {
var testFile = require('path').resolve(__dirname, '..', 'files', 'base.cjson');
exec(pathToBin + ' ' + testFile, function (err, stdout, stderr) {
expect(err, 'to be null');
expect(stdout, 'to equal', [
'{',
' "foo": "overwrite this",',
' "what": "this is from default.cjson."',
'}',
''
].join('\n'));
expect(stderr, 'to equal', '');
done();
describe('basic functionality', function () {
it('should print the resolved json structure to stdout', function () {
return expect(testFile('base'), 'when passed as arguments to oconf', 'to satisfy', {
err: null,
stdout: formattedJson({
foo: "overwrite this",
what: "this is from default.cjson."
}),
stderr: ''
});
});
it('should fail when asked for nonexistant file', function () {
return expect(testFile('nonExistent'), 'when passed as arguments to oconf', 'to satisfy', {
err: expect.it('to be an', Error),
stderr: expect.it('to match', /Error: ENOENT, no such file or directory/)
});
});
it('should fail when resolved file includes non existing file', function () {
return expect(testFile('includeNonExistentFile'), 'when passed as arguments to oconf', 'to satisfy', {
err: expect.it('to be an', Error),
stderr: expect.it('to match', /Error: ENOENT, no such file or directory/)
.and('to match', /nonExistentFile.cjson/)
});
});
it('should not fail when resolved file includes non existing file when passed --ignore', function () {
return expect([
testFile('includeNonExistentFile'),
'--ignore',
testFile('nonExistentFile.cjson')
], 'when passed as arguments to oconf', 'to satisfy', {
err: null,
stdout: formattedJson({
foo: 123
})
});
});
});
it('should fail when asked for nonexistant file', function (done) {
var testFile = require('path').resolve(__dirname, '..', 'files', 'nonExistent.cjson');
exec(pathToBin + ' ' + testFile, function (err, stdout) {
expect(err, 'to be an', Error);
expect(err, 'to satisfy', {
message: /Error: ENOENT, no such file or directory/
describe('--help', function () {
it('should exit with no errors and show the help', function () {
return expect('--help', 'when passed as arguments to oconf', 'to satisfy', {
err: null,
code: 0,
stdout: '',
stderr: expect.it('to match', /Options:/)
});
done();
});
});
it('should fail when resolved file includes non existing file', function (done) {
var testFile = require('path').resolve(__dirname, '..', 'files', 'includeNonExistentFile.cjson');
exec(pathToBin + ' ' + testFile, function (err, stdout) {
expect(err, 'to be an', Error);
expect(err, 'to have property', 'message');
expect(err.message, 'to match', /Error: ENOENT, no such file or directory/);
expect(err.message, 'not to match', /includeNonExistentFile.cjson/);
done();
describe('--lint', function () {
it('should exit with no errors if valid', function () {
return expect([
testFile('lint/valid.cjson'),
'--lint'
], 'when passed as arguments to oconf', 'to satisfy', {
err: null,
stdout: '',
stderr: 'No linting errors found.\n'
});
});
it('should report the errors if invalid', function () {
var filePath = testFile('lint/invalid.cjson');
return expect([
filePath,
'--lint'
], 'when passed as arguments to oconf', 'to satisfy', {
err: expect.it('to be an', Error),
stdout: '',
stderr: [
'Error: Parse error on line 2:',
'{ "foo": "bar}',
'------------^',
"Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'",
'File: "' + filePath + '"',
''
].join('\n')
});
});
});
it('should not fail when resolved file includes non existing file when passed --ignore', function (done) {
var ignoreFile = require('path').resolve(__dirname, '..', 'files', 'nonExistentFile.cjson');
var testFile = require('path').resolve(__dirname, '..', 'files', 'includeNonExistentFile.cjson');
exec(pathToBin + ' --ignore ' + ignoreFile + ' ' + testFile, function (err, stdout) {
expect(err, 'to be null');
expect(stdout, 'to equal', '{\n "foo": 123\n}\n');
done();
describe('--extract-option', function () {
it('should return the option value', function () {
return expect([
testFile('base'),
'--extract-option',
'foo'
], 'when passed as arguments to oconf', 'to satisfy', {
err: null,
stdout: 'overwrite this\n',
stderr: ''
});
});
it('should return the option value as json when passed --option-as-json', function () {
return expect([
testFile('base'),
'--extract-option',
'foo',
'--option-as-json'
], 'when passed as arguments to oconf', 'to satisfy', {
err: null,
stdout: formattedJson('overwrite this'),
stderr: ''
});
});
it('should fail when no such option exists', function () {
return expect([
testFile('base'),
'--extract-option',
'bar'
], 'when passed as arguments to oconf', 'to satisfy', {
err: expect.it('to be an', Error),
code: 1,
stdout: '',
stderr: expect.it('to match', /Key bar not found/)
});
});
it('should not fail when no such option exists when --allow-missing-option passed', function () {
return expect([
testFile('base'),
'--extract-option',
'bar',
'--allow-missing-option'
], 'when passed as arguments to oconf', 'to satisfy', {
err: null,
code: 0,
stdout: '',
stderr: ''
});
});
it('should support dotting out properties (foo.bar)', function () {
return expect([
testFile('deep'),
'--extract-option',
'foo.bar'
], 'when passed as arguments to oconf', 'to satisfy', {
err: null,
stdout: 'qux\n',
stderr: ''
});
});
});
describe('missing --extract-option flag', function () {
it('should return the option value and warn the user', function () {
return expect([
testFile('base'),
'foo'
], 'when passed as arguments to oconf', 'to satisfy', {
err: expect.it('to be an', Error),
code: 1,
stdout: '',
stderr: 'Error: Did you forget the --extract-option flag?\n'
});
});
});
describe('--ignore flag', function () {
it('should work with no other options', function () {
return expect([
testFile('includeNonExistentFile'),
'--ignore',
testFile('nonExistentFile.cjson')
], 'when passed as arguments to oconf', 'to satisfy', {
err: null,
code: 0,
stdout: formattedJson({
foo: 123
})
});
});
it('should work with --extract-option', function () {
return expect([
testFile('includeNonExistentFile'),
'--ignore',
testFile('nonExistentFile.cjson'),
'--extract-option foo'
], 'when passed as arguments to oconf', 'to satisfy', {
err: null,
code: 0,
stdout: formattedJson(123)
});
});
it('should work with --lint', function () {
return expect([
testFile('includeNonExistentFile'),
'--ignore',
testFile('nonExistentFile.cjson'),
'--lint'
], 'when passed as arguments to oconf', 'to satisfy', {
err: null,
code: 0,
stdout: '',
stderr: 'No linting errors found.\n'
});
});
});
describe('should complain about nonsensical flag combinations', function () {
it('should not allow --allow-option-missing with --lint', function () {
return expect([
'foo.cjson',
'--lint',
'--allow-missing-option'
], 'when passed as arguments to oconf', 'to satisfy', {
code: 1,
stderr: /^The flag --allow-missing-option does not make sense/
});
});
it('should not allow --option-as-json with --lint', function () {
return expect([
'foo.cjson',
'--lint',
'--option-as-json'
], 'when passed as arguments to oconf', 'to satisfy', {
code: 1,
stderr: /^The flag --option-as-json does not make sense/
});
});
it('should not allow --option-as-json with no other flags', function () {
return expect([
'foo.cjson',
'--option-as-json'
], 'when passed as arguments to oconf', 'to satisfy', {
code: 1,
stderr: /^The flag --option-as-json does not make sense/
});
});
});
describe('backwards compatibility for removed options', function () {
it('should return the option value as json when passed --json instead of --option-as-json', function () {
return expect([
testFile('base'),
'--extract-option',
'foo',
'--json'
], 'when passed as arguments to oconf', 'to satisfy', {
err: null,
stdout: formattedJson('overwrite this'),
stderr: ''
});
});
it('should not fail when no such option exists when passing --allowmissing instead of --allow-missing-option', function () {
return expect([
testFile('base'),
'--extract-option',
'bar',
'--allowmissing'
], 'when passed as arguments to oconf', 'to satisfy', {
err: null,
code: 0,
stdout: '',
stderr: ''
});
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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