Skip to content

Commit

Permalink
Merge pull request #679 from rfrm/replace-optimist-with-yargs
Browse files Browse the repository at this point in the history
Update dependencies to fix security warnings
  • Loading branch information
wzrdtales committed Apr 8, 2020
2 parents 4caaf39 + bebfb2b commit 94222a8
Show file tree
Hide file tree
Showing 20 changed files with 1,014 additions and 1,315 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -0,0 +1 @@
test/migrations
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,6 +12,7 @@ database.json
*.sublime-workspace
archive
.db-migraterc
coverage.html

# Vim swap files
.*.sw[a-z]
12 changes: 12 additions & 0 deletions .labrc.js
@@ -0,0 +1,12 @@
module.exports = {
coverage: true,
threshold: 74,
lint: true,
globals: 'verbose,dryRun,SharedArrayBuffer,Atomics,BigUint64Array,BigInt64Array,BigInt,URL,URLSearchParams,TextEncoder,TextDecoder,queueMicrotask',
assert: '@hapi/code',
verbose: true,
'coverage-exclude': [
'lib/interface',
'lib/transitions',
]
};
8 changes: 0 additions & 8 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -70,7 +70,7 @@ module.exports.getInstance = function (
callback
) {
delete require.cache[require.resolve('./api.js')];
delete require.cache[require.resolve('optimist')];
delete require.cache[require.resolve('yargs')];
var Mod = require('./api.js');
var plugins = {};

Expand Down
4 changes: 2 additions & 2 deletions lib/commands/create-migration.js
Expand Up @@ -5,7 +5,7 @@ const log = require('db-migrate-shared').log;
const mkdirp = Promise.promisify(require('mkdirp'));
const fs = require('fs');
const stat = Promise.promisify(fs.stat);
const optimist = require('optimist');
const yargs = require('yargs');
const util = require('util');

async function createMigrationDir (dir) {
Expand Down Expand Up @@ -33,7 +33,7 @@ async function executeCreateMigration (internals, config) {
if (internals.argv._.length === 0) {
log.error("'migrationName' is required.");
if (!internals.isModule) {
optimist.showHelp();
yargs.showHelp();
}

throw new Error("'migrationName' is required.");
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/run.js
@@ -1,7 +1,7 @@
'use strict';

var log = require('db-migrate-shared').log;
var optimist = require('optimist');
var yargs = require('yargs');
var load = require('./');
var transition = load('transition');

Expand Down Expand Up @@ -117,7 +117,7 @@ function run (internals, config) {
'Invalid Action: Must be [up|down|check|create|reset|sync|' +
'db|transition].'
);
optimist.showHelp();
yargs.showHelp();
process.exit(1);
}
break;
Expand Down
22 changes: 9 additions & 13 deletions lib/commands/set-default-argv.js
@@ -1,4 +1,4 @@
var optimist = require('optimist');
var yargs = require('yargs');
var log = require('db-migrate-shared').log;

module.exports = function (internals, isModule) {
Expand All @@ -20,7 +20,7 @@ module.exports = function (internals, isModule) {
};

if (!isModule) {
internals.argv = optimist
internals.argv = yargs
.default(defaultConfig)
.usage(
'Usage: db-migrate [up|down|check|reset|sync|create|db|transition] ' +
Expand Down Expand Up @@ -110,29 +110,25 @@ module.exports = function (internals, isModule) {
.describe('ignore-completed-migrations', 'Start at the first migration')
.boolean('ignore-completed-migrations')
.describe('log-level', 'Set the log-level, for example sql|warn')
.string('log-level');
.string('log-level')
.parse();
} else {
const _internalsArgv = Object.assign(defaultConfig, internals.cmdOptions);
internals.argv = {
get argv () {
return _internalsArgv;
}
};
internals.argv = Object.assign(defaultConfig, internals.cmdOptions);
}

var plugins = internals.plugins;
var plugin = plugins.hook('init:cli:config:hook');
var _config = internals.argv.argv.config;
var _config = internals.argv.config;

if (plugin) {
plugin.forEach(function (plugin) {
// var configs = plugin['init:cli:config:hook']();
// if (!configs) return;
// hook not yet used, we look into migrating away from optimist first
// hook not yet used, we look into migrating away from yargs first
});
}

internals.argv = deepExtend(internals.argv.argv, rc('db-migrate', {}));
internals.argv = deepExtend(internals.argv, rc('db-migrate', {}));
internals.argv.rcconfig = internals.argv.config;
internals.argv.config = internals.argv.configFile || _config;

Expand All @@ -142,7 +138,7 @@ module.exports = function (internals, isModule) {
}

if (!isModule && (internals.argv.help || internals.argv._.length === 0)) {
optimist.showHelp();
yargs.showHelp();
process.exit(1);
}

Expand Down

0 comments on commit 94222a8

Please sign in to comment.