From 93a061d737dc769663652368e8586e4202267b9e Mon Sep 17 00:00:00 2001 From: Gar Date: Mon, 22 Mar 2021 11:51:38 -0700 Subject: [PATCH] fix(usage): add action items to error output PR-URL: https://github.com/npm/cli/pull/2917 Credit: @wraithgar Close: #2917 Reviewed-by: @ruyadorno --- lib/cli.js | 2 +- lib/run-script.js | 2 +- test/lib/run-script.js | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 0879224654b7e..46859f150e3b9 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -67,7 +67,7 @@ module.exports = (process) => { if (cmd) { const didYouMean = require('./utils/did-you-mean.js') const suggestions = await didYouMean(npm, npm.localPrefix, cmd) - npm.output(`Unknown command: "${cmd}"${suggestions}`) + npm.output(`Unknown command: "${cmd}"${suggestions}\n\nTo see a list of supported npm commands, run:\n npm help`) } else npm.output(npm.usage) process.exitCode = 1 diff --git a/lib/run-script.js b/lib/run-script.js index 61572561a9ec8..0297061adc21d 100644 --- a/lib/run-script.js +++ b/lib/run-script.js @@ -91,7 +91,7 @@ class RunScript extends BaseCommand { return const suggestions = await didYouMean(this.npm, path, event) - throw new Error(`Missing script: "${event}"${suggestions}`) + throw new Error(`Missing script: "${event}"${suggestions}\n\nTo see a list of scripts, run:\n npm run`) } // positional args only added to the main event, not pre/post diff --git a/test/lib/run-script.js b/test/lib/run-script.js index 265565705ad30..f7eb46fedf5eb 100644 --- a/test/lib/run-script.js +++ b/test/lib/run-script.js @@ -896,27 +896,27 @@ t.test('workspaces', t => { t.match(RUN_SCRIPTS, []) t.strictSame(LOG.map(cleanOutput), [ 'Lifecycle script `missing-script` failed with error:', - 'Error: Missing script: "missing-script"', + 'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run', ' in workspace: a@1.0.0', ' at location: {CWD}/test/lib/run-script-workspaces/packages/a', 'Lifecycle script `missing-script` failed with error:', - 'Error: Missing script: "missing-script"', + 'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run', ' in workspace: b@2.0.0', ' at location: {CWD}/test/lib/run-script-workspaces/packages/b', 'Lifecycle script `missing-script` failed with error:', - 'Error: Missing script: "missing-script"', + 'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run', ' in workspace: c@1.0.0', ' at location: {CWD}/test/lib/run-script-workspaces/packages/c', 'Lifecycle script `missing-script` failed with error:', - 'Error: Missing script: "missing-script"', + 'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run', ' in workspace: d@1.0.0', ' at location: {CWD}/test/lib/run-script-workspaces/packages/d', 'Lifecycle script `missing-script` failed with error:', - 'Error: Missing script: "missing-script"', + 'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run', ' in workspace: e', ' at location: {CWD}/test/lib/run-script-workspaces/packages/e', 'Lifecycle script `missing-script` failed with error:', - 'Error: Missing script: "missing-script"', + 'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run', ' in workspace: noscripts@1.0.0', ' at location: {CWD}/test/lib/run-script-workspaces/packages/noscripts', ], 'should log error msgs for each workspace script') @@ -937,11 +937,11 @@ t.test('workspaces', t => { t.match(RUN_SCRIPTS, []) t.strictSame(LOG.map(cleanOutput), [ 'Lifecycle script `test` failed with error:', - 'Error: Missing script: "test"', + 'Error: Missing script: "test"\n\nTo see a list of scripts, run:\n npm run', ' in workspace: a@1.0.0', ' at location: {CWD}/test/lib/run-script-workspaces/packages/a', 'Lifecycle script `test` failed with error:', - 'Error: Missing script: "test"', + 'Error: Missing script: "test"\n\nTo see a list of scripts, run:\n npm run', ' in workspace: b@2.0.0', ' at location: {CWD}/test/lib/run-script-workspaces/packages/b', ], 'should log error msgs for each workspace script')