From 6bf6b1aa5f65fbe64ee5bc841037743ece91268b Mon Sep 17 00:00:00 2001 From: cgewecke Date: Wed, 18 Sep 2019 21:36:25 -0700 Subject: [PATCH] Add warnings for deprecated shell commands (#405) * Add ghost-testrpc `0.0.2` dep (mocks $ testrpc-sc) --- dist/bin.js | 8 ++++++++ lib/ui.js | 9 ++++++++- package.json | 4 ++++ test/units/truffle/errors.js | 26 ++++++++++++++++++++++++++ yarn.lock | 8 ++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 dist/bin.js diff --git a/dist/bin.js b/dist/bin.js new file mode 100644 index 0000000..627136e --- /dev/null +++ b/dist/bin.js @@ -0,0 +1,8 @@ +/* + Logs a warning / informational message when user tries to + invoke 'solidity-coverage' as a shell command. This file + is listed as the package.json "bin". +*/ +const AppUI = require('../lib/ui').AppUI; + +(new AppUI()).report('command'); diff --git a/lib/ui.js b/lib/ui.js index eb5fc54..4fac6b0 100644 --- a/lib/ui.js +++ b/lib/ui.js @@ -76,7 +76,14 @@ class AppUI extends UI { 'cleanup': `${ct} ${c.grey('solidity-coverage cleaning up, shutting down ganache server')}`, 'server': `${ct} ${c.bold('server: ')} ${c.grey(args[0])}`, - } + + 'command': `\n${w} ${c.red.bold('solidity-coverage >= 0.7.0 is no longer a shell command.')} ${w}\n` + + `${c.bold('=============================================================')}\n\n` + + `Instead, you should use the plugin produced for your development stack\n` + + `(like Truffle, Buidler) or design a custom workflow using the package API\n\n` + + `> See github.com/sc-forks/solidity-coverage for help with configuration.\n\n` + + `${c.green.bold('Thanks! - sc-forks')}\n`, + }; this._write(kinds[kind]); } diff --git a/package.json b/package.json index 9f0b9aa..2741053 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,9 @@ "description": "", "main": "index.js", "buidler": "dist/buidler.coverage.js", + "bin": { + "solidity-coverage": "./dist/bin.js" + }, "directories": { "test": "test" }, @@ -25,6 +28,7 @@ "chalk": "^2.4.2", "death": "^1.1.0", "ganache-core-sc": "2.7.0-sc.0", + "ghost-testrpc": "^0.0.2", "global-modules": "^2.0.0", "globby": "^10.0.1", "istanbul": "^0.4.5", diff --git a/test/units/truffle/errors.js b/test/units/truffle/errors.js index 2e1448c..63720c8 100644 --- a/test/units/truffle/errors.js +++ b/test/units/truffle/errors.js @@ -193,4 +193,30 @@ describe('Truffle Plugin: error cases', function() { verify.coverageNotGenerated(truffleConfig); }) + + it('user runs "solidity-coverage" as shell command', function(){ + const pathToCommand = './dist/bin.js'; + const pkg = require('../../../package.json'); + + assert( + pkg.bin['solidity-coverage'] === pathToCommand, + 'bin.js should be pkg.bin' + ); + + const output = shell.exec(`node ${pathToCommand}`, {silent:true}).stdout; + + assert( + output.includes('no longer a shell command'), + `should have right info: ${output}` + ); + }); + + it('user runs "testrpc-sc" as shell command', function(){ + const output = shell.exec(`testrpc-sc`, {silent:true}).stdout; + + assert( + output.includes('does not use "testrpc-sc"'), + `should have right info: ${output}` + ); + }); }) diff --git a/yarn.lock b/yarn.lock index 459051a..3e862d8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3230,6 +3230,14 @@ getpass@^0.1.1: dependencies: assert-plus "^1.0.0" +ghost-testrpc@^0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/ghost-testrpc/-/ghost-testrpc-0.0.2.tgz#c4de9557b1d1ae7b2d20bbe474a91378ca90ce92" + integrity sha512-i08dAEgJ2g8z5buJIrCTduwPIhih3DP+hOCTyyryikfV8T0bNvHnGXO67i0DD1H4GBDETTclPy9njZbfluQYrQ== + dependencies: + chalk "^2.4.2" + node-emoji "^1.10.0" + glob-parent@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.0.0.tgz#1dc99f0f39b006d3e92c2c284068382f0c20e954"