From 2fd5b3ad6319396193f67f343570f1c1af3e1d13 Mon Sep 17 00:00:00 2001 From: ashiq-firoz Date: Sat, 3 Aug 2024 22:24:23 +0530 Subject: [PATCH 1/4] fixed bug npx docusaurus --version incorrect program termination status #10367 --- packages/docusaurus/bin/docusaurus.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docusaurus/bin/docusaurus.mjs b/packages/docusaurus/bin/docusaurus.mjs index 7429f4f4156e..83801fa31bf2 100755 --- a/packages/docusaurus/bin/docusaurus.mjs +++ b/packages/docusaurus/bin/docusaurus.mjs @@ -257,7 +257,7 @@ function isInternalCommand(command) { // There is no subcommand // TODO: can we use commander to handle this case? -if (process.argv.length < 3 || process.argv[2]?.startsWith('--')) { +if (process.argv.length < 3 || process.argv[2]?.startsWith('--') && process.argv[2]?!="--version") { cli.outputHelp(); process.exit(1); } From 427c3f24d5022f5f17ecdcef1232032d66321b8e Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 8 Aug 2024 14:59:59 +0200 Subject: [PATCH 2/4] fix Docusaurus CLI --- packages/docusaurus/bin/docusaurus.mjs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/packages/docusaurus/bin/docusaurus.mjs b/packages/docusaurus/bin/docusaurus.mjs index 83801fa31bf2..3e773b9f2929 100755 --- a/packages/docusaurus/bin/docusaurus.mjs +++ b/packages/docusaurus/bin/docusaurus.mjs @@ -247,24 +247,16 @@ function isInternalCommand(command) { ); } -// process.argv always looks like this: -// [ -// '/path/to/node', -// '/path/to/docusaurus.mjs', -// '', -// ...subcommandArgs -// ] - -// There is no subcommand -// TODO: can we use commander to handle this case? -if (process.argv.length < 3 || process.argv[2]?.startsWith('--') && process.argv[2]?!="--version") { - cli.outputHelp(); - process.exit(1); +/** + * @param {string | undefined} command + */ +function isExternalCommand(command) { + return !!(command && !isInternalCommand(command) && !command.startsWith('-')); } // There is an unrecognized subcommand // Let plugins extend the CLI before parsing -if (!isInternalCommand(process.argv[2])) { +if (isExternalCommand(process.argv[2])) { // TODO: in this step, we must assume default site structure because there's // no way to know the siteDir/config yet. Maybe the root cli should be // responsible for parsing these arguments? From c75078aa7a2f3daa748d21d970f191bce65746f5 Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 8 Aug 2024 15:18:12 +0200 Subject: [PATCH 3/4] Fix calling docusaurus CLI with no command --- packages/docusaurus/bin/docusaurus.mjs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/docusaurus/bin/docusaurus.mjs b/packages/docusaurus/bin/docusaurus.mjs index 3e773b9f2929..d1cf8ad7d654 100755 --- a/packages/docusaurus/bin/docusaurus.mjs +++ b/packages/docusaurus/bin/docusaurus.mjs @@ -254,6 +254,14 @@ function isExternalCommand(command) { return !!(command && !isInternalCommand(command) && !command.startsWith('-')); } +// No command? We print the help message because Commander doesn't +// Note argv looks like this: ['../node','../docusaurus.mjs','',...rest] +if (process.argv.length < 3) { + logger.error("You haven't provided any Docusaurus CLI command."); + cli.outputHelp(); + process.exit(1); +} + // There is an unrecognized subcommand // Let plugins extend the CLI before parsing if (isExternalCommand(process.argv[2])) { From 556df66c468007b20e1c01d8e912fbc8efe124c6 Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 8 Aug 2024 15:24:19 +0200 Subject: [PATCH 4/4] add exit(1) for bad command names --- packages/docusaurus/bin/docusaurus.mjs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus/bin/docusaurus.mjs b/packages/docusaurus/bin/docusaurus.mjs index d1cf8ad7d654..11ac62cadbfb 100755 --- a/packages/docusaurus/bin/docusaurus.mjs +++ b/packages/docusaurus/bin/docusaurus.mjs @@ -222,7 +222,8 @@ cli cli.arguments('').action((cmd) => { cli.outputHelp(); - logger.error` Unknown command name=${cmd}.`; + logger.error`Unknown Docusaurus CLI command name=${cmd}.`; + process.exit(1); }); // === The above is the commander configuration === @@ -257,8 +258,8 @@ function isExternalCommand(command) { // No command? We print the help message because Commander doesn't // Note argv looks like this: ['../node','../docusaurus.mjs','',...rest] if (process.argv.length < 3) { - logger.error("You haven't provided any Docusaurus CLI command."); cli.outputHelp(); + logger.error`Please provide a Docusaurus CLI command.`; process.exit(1); }