Skip to content

Commit

Permalink
Use deprecated-obj + add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jan 3, 2019
1 parent 89dcf79 commit c723d66
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
35 changes: 12 additions & 23 deletions lib/deprecated.js
@@ -1,29 +1,18 @@
const _ = require('lodash');
const Log = require('./log');
const deprecated = require('../conf/deprecated.json');
const Deprecated = require('deprecated-obj');

const log = new Log();
let counter = 0;

const deprecate = (config, dep, keys = []) => {
_.forOwn(dep, (value, deprecatedKey) => {
const deprecatedPath = [...keys, deprecatedKey];
if (_.isObject(value)) {
deprecate(config, value, deprecatedPath);
} else {
if (_.has(config, deprecatedPath)) {
const currentPath = _.get(deprecated, deprecatedPath);
counter++ || log.warn(`Deprecated configuration options found. Please migrate before the next major release.`);
log.warn(
`The "${deprecatedPath.join('.')}" option is deprecated.${
currentPath ? ` Please use "${currentPath}" instead.` : ''
}`
);
_.set(config, currentPath, _.get(config, deprecatedPath));
}
}
});
return config;
module.exports = config => {
const deprecations = new Deprecated(deprecated, config);
const compliant = deprecations.getCompliant();
const violations = deprecations.getViolations();
if (Object.keys(violations).length > 0) {
log.warn(`Deprecated configuration options found. Please migrate before the next major release.`);
}
for (const d in violations) {
log.warn(`The "${d}" option is deprecated.${violations[d] ? ` Please use "${violations[d]}" instead.` : ''}`);
}
return compliant;
};

module.exports = config => deprecate(config, deprecated);
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -59,6 +59,7 @@
"conventional-recommended-bump": "4.0.4",
"cpy": "7.0.1",
"debug": "4.1.1",
"deprecated-obj": "1.0.0",
"globby": "8.0.1",
"got": "8.3.2",
"inquirer": "6.2.1",
Expand Down
31 changes: 31 additions & 0 deletions test/deprecated.js
@@ -0,0 +1,31 @@
const test = require('tape');
const mockStdIo = require('mock-stdio');
const deprecated = require('../lib/deprecated');

test('should show deprecation warnings and return compliant object', t => {
mockStdIo.start();
const config = deprecated({
buildCommand: 'foo',
safeBump: false,
src: {
commit: false,
commitMessage: 'bar'
}
});
const { stdout } = mockStdIo.end();
t.ok(stdout.includes('Deprecated configuration options found. Please migrate before the next major release'));
t.ok(stdout.includes('The "buildCommand" option is deprecated. Please use "scripts.beforeStage" instead'));
t.ok(stdout.includes('The "safeBump" option is deprecated.'));
t.ok(stdout.includes('The "src.commit" option is deprecated. Please use "git.commit" instead'));
t.ok(stdout.includes('The "src.commitMessage" option is deprecated. Please use "git.commitMessage" instead'));
t.deepEqual(config, {
scripts: {
beforeStage: 'foo'
},
git: {
commit: false,
commitMessage: 'bar'
}
});
t.end();
});

0 comments on commit c723d66

Please sign in to comment.