Skip to content

Commit 94222a8

Browse files
authored
Merge pull request #679 from rfrm/replace-optimist-with-yargs
Update dependencies to fix security warnings
2 parents 4caaf39 + bebfb2b commit 94222a8

20 files changed

+1014
-1315
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/migrations

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ database.json
1212
*.sublime-workspace
1313
archive
1414
.db-migraterc
15+
coverage.html
1516

1617
# Vim swap files
1718
.*.sw[a-z]

.labrc.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
coverage: true,
3+
threshold: 74,
4+
lint: true,
5+
globals: 'verbose,dryRun,SharedArrayBuffer,Atomics,BigUint64Array,BigInt64Array,BigInt,URL,URLSearchParams,TextEncoder,TextDecoder,queueMicrotask',
6+
assert: '@hapi/code',
7+
verbose: true,
8+
'coverage-exclude': [
9+
'lib/interface',
10+
'lib/transitions',
11+
]
12+
};

Makefile

-8
This file was deleted.

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module.exports.getInstance = function (
7070
callback
7171
) {
7272
delete require.cache[require.resolve('./api.js')];
73-
delete require.cache[require.resolve('optimist')];
73+
delete require.cache[require.resolve('yargs')];
7474
var Mod = require('./api.js');
7575
var plugins = {};
7676

lib/commands/create-migration.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const log = require('db-migrate-shared').log;
55
const mkdirp = Promise.promisify(require('mkdirp'));
66
const fs = require('fs');
77
const stat = Promise.promisify(fs.stat);
8-
const optimist = require('optimist');
8+
const yargs = require('yargs');
99
const util = require('util');
1010

1111
async function createMigrationDir (dir) {
@@ -33,7 +33,7 @@ async function executeCreateMigration (internals, config) {
3333
if (internals.argv._.length === 0) {
3434
log.error("'migrationName' is required.");
3535
if (!internals.isModule) {
36-
optimist.showHelp();
36+
yargs.showHelp();
3737
}
3838

3939
throw new Error("'migrationName' is required.");

lib/commands/run.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
var log = require('db-migrate-shared').log;
4-
var optimist = require('optimist');
4+
var yargs = require('yargs');
55
var load = require('./');
66
var transition = load('transition');
77

@@ -117,7 +117,7 @@ function run (internals, config) {
117117
'Invalid Action: Must be [up|down|check|create|reset|sync|' +
118118
'db|transition].'
119119
);
120-
optimist.showHelp();
120+
yargs.showHelp();
121121
process.exit(1);
122122
}
123123
break;

lib/commands/set-default-argv.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var optimist = require('optimist');
1+
var yargs = require('yargs');
22
var log = require('db-migrate-shared').log;
33

44
module.exports = function (internals, isModule) {
@@ -20,7 +20,7 @@ module.exports = function (internals, isModule) {
2020
};
2121

2222
if (!isModule) {
23-
internals.argv = optimist
23+
internals.argv = yargs
2424
.default(defaultConfig)
2525
.usage(
2626
'Usage: db-migrate [up|down|check|reset|sync|create|db|transition] ' +
@@ -110,29 +110,25 @@ module.exports = function (internals, isModule) {
110110
.describe('ignore-completed-migrations', 'Start at the first migration')
111111
.boolean('ignore-completed-migrations')
112112
.describe('log-level', 'Set the log-level, for example sql|warn')
113-
.string('log-level');
113+
.string('log-level')
114+
.parse();
114115
} else {
115-
const _internalsArgv = Object.assign(defaultConfig, internals.cmdOptions);
116-
internals.argv = {
117-
get argv () {
118-
return _internalsArgv;
119-
}
120-
};
116+
internals.argv = Object.assign(defaultConfig, internals.cmdOptions);
121117
}
122118

123119
var plugins = internals.plugins;
124120
var plugin = plugins.hook('init:cli:config:hook');
125-
var _config = internals.argv.argv.config;
121+
var _config = internals.argv.config;
126122

127123
if (plugin) {
128124
plugin.forEach(function (plugin) {
129125
// var configs = plugin['init:cli:config:hook']();
130126
// if (!configs) return;
131-
// hook not yet used, we look into migrating away from optimist first
127+
// hook not yet used, we look into migrating away from yargs first
132128
});
133129
}
134130

135-
internals.argv = deepExtend(internals.argv.argv, rc('db-migrate', {}));
131+
internals.argv = deepExtend(internals.argv, rc('db-migrate', {}));
136132
internals.argv.rcconfig = internals.argv.config;
137133
internals.argv.config = internals.argv.configFile || _config;
138134

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

144140
if (!isModule && (internals.argv.help || internals.argv._.length === 0)) {
145-
optimist.showHelp();
141+
yargs.showHelp();
146142
process.exit(1);
147143
}
148144

0 commit comments

Comments
 (0)