Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin): support deprecating plugins #906

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/common.js
Expand Up @@ -4,6 +4,7 @@

var os = require('os');
var fs = require('fs');
var util = require('util');
var glob = require('glob');
var shell = require('..');

Expand Down Expand Up @@ -312,7 +313,7 @@ exports.randomFileName = randomFileName;
// command-logging, and other nice things
function wrap(cmd, fn, options) {
options = options || {};
return function () {
var fun = function () {
var retValue = null;

state.currentCmd = cmd;
Expand Down Expand Up @@ -409,6 +410,11 @@ function wrap(cmd, fn, options) {
state.currentCmd = 'shell.js';
return retValue;
};
if (options.deprecated) {
var msg = options.deprecated; // This is the deprecation message.
fun = util.deprecate(fun, msg);
}
return fun;
} // wrap
exports.wrap = wrap;

Expand All @@ -427,6 +433,7 @@ var DEFAULT_WRAP_OPTIONS = {
pipeOnly: false,
wrapOutput: true,
unix: true,
deprecated: '',
};

// This is populated during plugin registration
Expand Down
34 changes: 34 additions & 0 deletions test/plugin.js
Expand Up @@ -165,3 +165,37 @@ test('Cannot overwrite an existing command', t => {
}, 'Command `cat` already exists');
t.is(shell.cat, oldCat);
});

test('Deprecated command', t => {
process.throwDeprecation = true;
const oldThrowDep = process.throwDeprecation;
try {
plugin.register('dep', function dep(opt, arg) { return arg; }, {
cmdOptions: null,
deprecated: 'Use the foo method instead',
});

t.throws(() => {
shell.dep('bar');
}, /Use the foo method instead/);
} finally {
process.throwDeprecation = oldThrowDep;
}
});

test('Deprecated command in pipe', t => {
process.throwDeprecation = true;
plugin.register('depPipe', function depPipe(opt, arg) { return arg; }, {
cmdOptions: null,
deprecated: 'Use the foo pipe instead',
canReceivePipe: true,
});
const oldThrowDep = process.throwDeprecation;
try {
t.throws(() => {
shell.cat('./package.json').depPipe('bar');
}, /Use the foo pipe instead/);
} finally {
process.throwDeprecation = oldThrowDep;
}
});