From 463bf5e220766a4a99e5f88f1ca572da819ebf9c Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Fri, 20 Aug 2021 21:05:56 +0300 Subject: [PATCH] feat: allow to run commands not requiring webpack without webpack installation --- packages/configtest/src/index.ts | 15 +-- packages/generators/src/index.ts | 8 +- packages/info/src/index.ts | 6 +- packages/serve/src/index.ts | 27 +++-- packages/webpack-cli/bin/cli.js | 25 +--- packages/webpack-cli/lib/webpack-cli.js | 69 +++++++---- smoketests/helpers.js | 22 ++-- smoketests/index.js | 4 + .../webpack-dev-server.test.js | 3 +- smoketests/missing-packages/webpack.test.js | 73 +++++++++++- .../help.test.js.snap.devServer3.webpack4 | 4 +- .../help.test.js.snap.devServer3.webpack5 | 4 +- .../help.test.js.snap.devServer4.webpack4 | 4 +- .../help.test.js.snap.devServer4.webpack5 | 4 +- .../version.test.js.snap.webpack4 | 108 +++++++++--------- .../version.test.js.snap.webpack5 | 108 +++++++++--------- 16 files changed, 281 insertions(+), 203 deletions(-) diff --git a/packages/configtest/src/index.ts b/packages/configtest/src/index.ts index 025ef647d29..8f66fdbaccc 100644 --- a/packages/configtest/src/index.ts +++ b/packages/configtest/src/index.ts @@ -1,14 +1,13 @@ class ConfigTestCommand { // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any async apply(cli: any): Promise { - const { logger, webpack } = cli; - await cli.makeCommand( { name: "configtest [config-path]", alias: "t", description: "Validate a webpack configuration.", pkg: "@webpack-cli/configtest", + dependencies: ["webpack"], }, [], async (configPath: string | undefined): Promise => { @@ -28,11 +27,13 @@ class ConfigTestCommand { } if (configPaths.size === 0) { - logger.error("No configuration found."); + cli.logger.error("No configuration found."); process.exit(2); } - logger.info(`Validate '${Array.from(configPaths).join(" ,")}'.`); + cli.logger.info(`Validate '${Array.from(configPaths).join(" ,")}'.`); + + const webpack = await cli.loadWebpack(); try { // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -44,15 +45,15 @@ class ConfigTestCommand { } } catch (error) { if (cli.isValidationError(error)) { - logger.error(error.message); + cli.logger.error(error.message); } else { - logger.error(error); + cli.logger.error(error); } process.exit(2); } - logger.success( + cli.logger.success( "There are no validation errors in the given webpack configuration.", ); }, diff --git a/packages/generators/src/index.ts b/packages/generators/src/index.ts index f6aa7b5f339..89c86ed6757 100644 --- a/packages/generators/src/index.ts +++ b/packages/generators/src/index.ts @@ -7,8 +7,6 @@ import initGenerator from "./init-generator"; class GeneratorsCommand { // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any async apply(cli: any): Promise { - const { logger } = cli; - await cli.makeCommand( { name: "init [generation-path]", @@ -51,7 +49,7 @@ class GeneratorsCommand { env.registerStub(initGenerator, generatorName); env.run(generatorName, { cli, options }, () => { - logger.success("Project has been initialised with webpack!"); + cli.logger.success("Project has been initialised with webpack!"); }); }, ); @@ -83,7 +81,7 @@ class GeneratorsCommand { env.registerStub(loaderGenerator, generatorName); env.run(generatorName, { cli, options }, () => { - logger.success("Loader template has been successfully scaffolded."); + cli.logger.success("Loader template has been successfully scaffolded."); }); }, ); @@ -115,7 +113,7 @@ class GeneratorsCommand { env.registerStub(pluginGenerator, generatorName); env.run(generatorName, { cli, options }, () => { - logger.success("Plugin template has been successfully scaffolded."); + cli.logger.success("Plugin template has been successfully scaffolded."); }); }, ); diff --git a/packages/info/src/index.ts b/packages/info/src/index.ts index fddf308f01c..e5666eec1ad 100644 --- a/packages/info/src/index.ts +++ b/packages/info/src/index.ts @@ -32,8 +32,6 @@ const DEFAULT_DETAILS: Information = { class InfoCommand { // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any async apply(cli: any): Promise { - const { logger } = cli; - await cli.makeCommand( { name: "info", @@ -72,7 +70,7 @@ class InfoCommand { envinfoConfig["json"] = true; break; default: - logger.error(`'${output}' is not a valid value for output`); + cli.logger.error(`'${output}' is not a valid value for output`); process.exit(2); } } @@ -82,7 +80,7 @@ class InfoCommand { info = info.replace(/npmPackages/g, "Packages"); info = info.replace(/npmGlobalPackages/g, "Global Packages"); - logger.raw(info); + cli.logger.raw(info); }, ); } diff --git a/packages/serve/src/index.ts b/packages/serve/src/index.ts index 99aa17473c2..4f55ee10fbb 100644 --- a/packages/serve/src/index.ts +++ b/packages/serve/src/index.ts @@ -3,8 +3,6 @@ import { devServerOptionsType } from "./types"; class ServeCommand { // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any async apply(cli: any): Promise { - const { logger, webpack } = cli; - const loadDevServerOptions = () => { // TODO simplify this after drop webpack v4 and webpack-dev-server v3 // eslint-disable-next-line @typescript-eslint/no-var-requires, node/no-extraneous-require @@ -14,8 +12,8 @@ class ServeCommand { let options = {}; if (isNewDevServerCLIAPI) { - if (webpack.cli && typeof webpack.cli.getArguments === "function") { - options = webpack.cli.getArguments(devServer.schema); + if (cli.webpack.cli && typeof cli.webpack.cli.getArguments === "function") { + options = cli.webpack.cli.getArguments(devServer.schema); } else { options = devServer.cli.getArguments(); } @@ -50,15 +48,19 @@ class ServeCommand { description: "Run the webpack dev server.", usage: "[entries...] [options]", pkg: "@webpack-cli/serve", - dependencies: ["webpack-dev-server"], + dependencies: ["webpack", "webpack-dev-server"], }, - () => { + async () => { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + cli.webpack = await cli.loadWebpack(); + let devServerFlags = []; try { devServerFlags = loadDevServerOptions(); } catch (error) { - logger.error( + cli.logger.error( `You need to install 'webpack-dev-server' for running 'webpack serve'.\n${error}`, ); process.exit(2); @@ -173,7 +175,7 @@ class ServeCommand { // eslint-disable-next-line node/no-extraneous-require, @typescript-eslint/no-var-requires devServerVersion = require("webpack-dev-server/package.json").version; } catch (err) { - logger.error( + cli.logger.error( `You need to install 'webpack-dev-server' for running 'webpack serve'.\n${err}`, ); process.exit(2); @@ -209,8 +211,9 @@ class ServeCommand { ); const result = { ...(compilerForDevServer.options.devServer || {}) }; const problems = ( - webpack.cli && typeof webpack.cli.processArguments === "function" - ? webpack.cli + cli.webpack.cli && + typeof cli.webpack.cli.processArguments === "function" + ? cli.webpack.cli : DevServer.cli ).processArguments(args, result, values); @@ -356,9 +359,9 @@ class ServeCommand { servers.push(server); } catch (error) { if (cli.isValidationError(error)) { - logger.error(error.message); + cli.logger.error(error.message); } else { - logger.error(error); + cli.logger.error(error); } process.exit(2); diff --git a/packages/webpack-cli/bin/cli.js b/packages/webpack-cli/bin/cli.js index d62a625831c..a6e34f35e58 100755 --- a/packages/webpack-cli/bin/cli.js +++ b/packages/webpack-cli/bin/cli.js @@ -10,7 +10,6 @@ require("v8-compile-cache"); const importLocal = require("import-local"); const runCLI = require("../lib/bootstrap"); -const utils = require("../lib/utils"); if (!process.env.WEBPACK_CLI_SKIP_IMPORT_LOCAL) { // Prefer the local installation of `webpack-cli` @@ -21,26 +20,4 @@ if (!process.env.WEBPACK_CLI_SKIP_IMPORT_LOCAL) { process.title = "webpack"; -if (utils.packageExists("webpack")) { - runCLI(process.argv, originalModuleCompile); -} else { - const { promptInstallation, logger, colors } = utils; - - promptInstallation("webpack", () => { - utils.logger.error(`It looks like ${colors.bold("webpack")} is not installed.`); - }) - .then(() => { - logger.success(`${colors.bold("webpack")} was installed successfully.`); - - runCLI(process.argv, originalModuleCompile); - }) - .catch(() => { - logger.error( - `Action Interrupted, Please try once again or install ${colors.bold( - "webpack", - )} manually.`, - ); - - process.exit(2); - }); -} +runCLI(process.argv, originalModuleCompile); diff --git a/packages/webpack-cli/lib/webpack-cli.js b/packages/webpack-cli/lib/webpack-cli.js index 168d75d45da..89c3535535a 100644 --- a/packages/webpack-cli/lib/webpack-cli.js +++ b/packages/webpack-cli/lib/webpack-cli.js @@ -8,8 +8,6 @@ const utils = require("./utils"); class WebpackCLI { constructor() { - // Global - this.webpack = require(process.env.WEBPACK_PACKAGE || "webpack"); this.logger = utils.logger; this.utils = utils; @@ -76,19 +74,27 @@ class WebpackCLI { return result; } - loadJSONFile(pathToFile) { + loadJSONFile(pathToFile, handleError = true) { let result; try { result = require(pathToFile); } catch (error) { - this.logger.error(error); - process.exit(2); + if (handleError) { + this.logger.error(error); + process.exit(2); + } else { + throw error; + } } return result; } + async loadWebpack(handleError = true) { + return this.tryRequireThenImport(process.env.WEBPACK_PACKAGE || "webpack", handleError); + } + async makeCommand(commandOptions, options, action) { const alreadyLoaded = this.program.commands.find( (command) => @@ -148,7 +154,7 @@ class WebpackCLI { this.logger.error( `For using '${colors.green( commandOptions.name.split(" ")[0], - )}' command you need to install: '${colors.green(dependency)}' package`, + )}' command you need to install: '${colors.green(dependency)}' package.`, ); }); } @@ -162,11 +168,11 @@ class WebpackCLI { commandOptions.description } To see all available options you need to install ${commandOptions.dependencies .map((dependency) => `'${dependency}'`) - .join(",")}.`, + .join(", ")}.`, ); options = []; } else { - options = options(); + options = await options(); } } @@ -727,12 +733,14 @@ class WebpackCLI { alias: ["bundle", "b"], description: "Run webpack (default command, can be omitted).", usage: "[entries...] [options]", + dependencies: ["webpack"], }; const watchCommandOptions = { name: "watch [entries...]", alias: "w", description: "Run webpack and watch for files changes.", usage: "[entries...] [options]", + dependencies: ["webpack"], }; const versionCommandOptions = { name: "version [commands...]", @@ -835,13 +843,15 @@ class WebpackCLI { const isWatchCommandUsed = isCommand(commandName, watchCommandOptions); if (isBuildCommandUsed || isWatchCommandUsed) { - const options = this.getBuiltInOptions(); - await this.makeCommand( isBuildCommandUsed ? buildCommandOptions : watchCommandOptions, - isWatchCommandUsed - ? options.filter((option) => option.name !== "watch") - : options, + async () => { + this.webpack = await this.loadWebpack(); + + return isWatchCommandUsed + ? this.getBuiltInOptions().filter((option) => option.name !== "watch") + : this.getBuiltInOptions(); + }, async (entries, options) => { if (entries.length > 0) { options.entry = [...entries, ...(options.entry || [])]; @@ -854,7 +864,7 @@ class WebpackCLI { // Stub for the `help` command this.makeCommand(helpCommandOptions, [], () => {}); } else if (isCommand(commandName, versionCommandOptions)) { - // Stub for the `help` command + // Stub for the `version` command this.makeCommand(versionCommandOptions, [], () => {}); } else { const builtInExternalCommandInfo = externalBuiltInCommandsInfo.find( @@ -884,7 +894,7 @@ class WebpackCLI { this.logger.error( `For using this command you need to install: '${colors.green( pkg, - )}' package`, + )}' package.`, ); }); } @@ -1048,17 +1058,32 @@ class WebpackCLI { } } + let webpack; + + try { + webpack = await this.loadWebpack(false); + } catch (_error) { + // Nothing + } + + this.logger.raw(`webpack: ${webpack ? webpack.version : "not installed"}`); + const pkgJSON = this.loadJSONFile("../package.json"); - this.logger.raw(`webpack ${this.webpack.version}`); - this.logger.raw(`webpack-cli ${pkgJSON.version}`); + this.logger.raw(`webpack-cli: ${pkgJSON.version}`); - if (this.utils.packageExists("webpack-dev-server")) { - const { version } = this.loadJSONFile("webpack-dev-server/package.json"); + let devServer; - this.logger.raw(`webpack-dev-server ${version}`); + try { + devServer = await this.loadJSONFile("webpack-dev-server/package.json", false); + } catch (_error) { + // Nothing } + this.logger.raw( + `webpack-dev-server ${devServer ? devServer.version : "not installed"}`, + ); + process.exit(0); }; this.program.option( @@ -1276,12 +1301,12 @@ class WebpackCLI { ); if (typeof builtInCommandUsed !== "undefined") { this.logger.error( - `For using '${name}' command you need to install '${builtInCommandUsed.pkg}' package`, + `For using '${name}' command you need to install '${builtInCommandUsed.pkg}' package.`, ); } else { this.logger.error(`Can't find and load command '${name}'`); this.logger.error( - "Run 'webpack --help' to see available commands and options", + "Run 'webpack --help' to see available commands and options.", ); } process.exit(2); diff --git a/smoketests/helpers.js b/smoketests/helpers.js index 7af0cc10990..626171375db 100644 --- a/smoketests/helpers.js +++ b/smoketests/helpers.js @@ -11,21 +11,24 @@ const ROOT_PATH = process.env.GITHUB_WORKSPACE const getPkgPath = (pkg, isSubPackage) => { const pkgPath = isSubPackage ? `./node_modules/@webpack-cli/${pkg}` : `./node_modules/${pkg}`; + return path.resolve(ROOT_PATH, pkgPath); }; const swapPkgName = (current, isSubPackage = false) => { // info -> .info and vice-versa const next = current.startsWith(".") ? current.substr(1) : `.${current}`; + console.log(` swapping ${current} with ${next}`); + fs.renameSync(getPkgPath(current, isSubPackage), getPkgPath(next, isSubPackage)); }; const CLI_ENTRY_PATH = path.resolve(ROOT_PATH, "./packages/webpack-cli/bin/cli.js"); -const runTest = (package, cliArgs = [], logMessage, isSubPackage = false) => { +const runTest = (pkg, cliArgs = [], logMessage, isSubPackage = false) => { // Simulate package missing - swapPkgName(package, isSubPackage); + swapPkgName(pkg, isSubPackage); const proc = execa(CLI_ENTRY_PATH, cliArgs, { cwd: __dirname, @@ -50,6 +53,7 @@ const runTest = (package, cliArgs = [], logMessage, isSubPackage = false) => { proc.stderr.on("data", (chunk) => { const data = stripAnsi(chunk.toString()); + console.log(` stderr: ${data}`); if (data.includes(logMessage)) { @@ -67,13 +71,13 @@ const runTest = (package, cliArgs = [], logMessage, isSubPackage = false) => { }); proc.on("exit", () => { - swapPkgName(`.${package}`, isSubPackage); + swapPkgName(`.${pkg}`, isSubPackage); clearTimeout(timeout); resolve(hasPassed); }); proc.on("error", () => { - swapPkgName(`.${package}`, isSubPackage); + swapPkgName(`.${pkg}`, isSubPackage); clearTimeout(timeout); resolve(false); }); @@ -100,6 +104,7 @@ const runTestStdout = ({ packageName, cliArgs, logMessage, isSubPackage } = {}) proc.stdout.on("data", (chunk) => { const data = stripAnsi(chunk.toString()); + console.log(` stdout: ${data}`); if (data.includes(logMessage)) { @@ -186,9 +191,9 @@ const runTestStdoutWithInput = ({ }); }; -const runTestWithHelp = (package, cliArgs = [], logMessage, isSubPackage = false) => { +const runTestWithHelp = (pkg, cliArgs = [], logMessage, isSubPackage = false) => { // Simulate package missing - swapPkgName(package, isSubPackage); + swapPkgName(pkg, isSubPackage); const proc = execa(CLI_ENTRY_PATH, cliArgs, { cwd: __dirname, @@ -214,6 +219,7 @@ const runTestWithHelp = (package, cliArgs = [], logMessage, isSubPackage = false proc.stderr.on("data", (chunk) => { const data = stripAnsi(chunk.toString()); + console.log(` stderr: ${data}`); if (data.includes(logMessage)) { @@ -231,13 +237,13 @@ const runTestWithHelp = (package, cliArgs = [], logMessage, isSubPackage = false }); proc.on("exit", () => { - swapPkgName(`.${package}`, isSubPackage); + swapPkgName(`.${pkg}`, isSubPackage); clearTimeout(timeout); resolve(hasPassed); }); proc.on("error", () => { - swapPkgName(`.${package}`, isSubPackage); + swapPkgName(`.${pkg}`, isSubPackage); clearTimeout(timeout); resolve(false); }); diff --git a/smoketests/index.js b/smoketests/index.js index c734be20948..7da691dad2f 100644 --- a/smoketests/index.js +++ b/smoketests/index.js @@ -11,10 +11,12 @@ const tests = [ (async () => { let isAllPassed = true; + for await (const test of tests) { console.log(`\nRUN ${test.name}`); let isPass = true; + for await (const testCase of test.run) { isPass = isPass && (await testCase()); } @@ -26,8 +28,10 @@ const tests = [ console.log(`PASS ${test.name}`); } } + if (!isAllPassed) { process.exit(2); } + process.exit(0); })(); diff --git a/smoketests/missing-packages/webpack-dev-server.test.js b/smoketests/missing-packages/webpack-dev-server.test.js index e053a970a1d..12cba566593 100644 --- a/smoketests/missing-packages/webpack-dev-server.test.js +++ b/smoketests/missing-packages/webpack-dev-server.test.js @@ -14,7 +14,8 @@ const webpackDevServerTest = () => { const webpackDevServerWithHelpTest = () => { const packageName = "webpack-dev-server"; const cliArgs = ["help", "serve"]; - const logMessage = "To see all available options you need to install 'webpack-dev-server'"; + const logMessage = + "To see all available options you need to install 'webpack', 'webpack-dev-server'."; return runTestStdout({ packageName, cliArgs, logMessage }); }; diff --git a/smoketests/missing-packages/webpack.test.js b/smoketests/missing-packages/webpack.test.js index 3c8f0ecfaed..e1f9b244a37 100644 --- a/smoketests/missing-packages/webpack.test.js +++ b/smoketests/missing-packages/webpack.test.js @@ -1,14 +1,79 @@ "use strict"; -const { runTest } = require("../helpers"); +const { runTest, runTestStdout } = require("../helpers"); -const webpackTest = () => { +const noCommand = () => { const packageName = "webpack"; const args = []; - const logMessage = "It looks like webpack is not installed."; + const logMessage = "For using 'build' command you need to install: 'webpack' package."; return runTest(packageName, args, logMessage); }; -module.exports.run = [webpackTest]; +const buildCommand = () => { + const packageName = "webpack"; + const args = ["build"]; + const logMessage = "For using 'build' command you need to install: 'webpack' package."; + + return runTest(packageName, args, logMessage); +}; + +const watchCommand = () => { + const packageName = "webpack"; + const args = ["watch"]; + const logMessage = "For using 'watch' command you need to install: 'webpack' package."; + + return runTest(packageName, args, logMessage); +}; + +const serveCommand = () => { + const packageName = "webpack"; + const args = ["serve"]; + const logMessage = "For using 'serve' command you need to install: 'webpack' package."; + + return runTest(packageName, args, logMessage); +}; + +const versionCommand = () => { + const packageName = "webpack"; + const args = ["version"]; + const logMessage = "webpack-cli:"; + + return runTestStdout({ packageName, cliArgs: args, logMessage }); +}; + +const helpCommand = () => { + const packageName = "webpack"; + const args = ["help"]; + const logMessage = "The build tool for modern web applications."; + + return runTestStdout({ packageName, cliArgs: args, logMessage }); +}; + +const infoCommand = () => { + const packageName = "webpack"; + const args = ["info"]; + const logMessage = "System:"; + + return runTestStdout({ packageName, cliArgs: args, logMessage }); +}; + +const configtestCommand = () => { + const packageName = "webpack"; + const args = ["configtest"]; + const logMessage = "For using 'configtest' command you need to install: 'webpack' package."; + + return runTest(packageName, args, logMessage); +}; + +module.exports.run = [ + noCommand, + buildCommand, + watchCommand, + serveCommand, + configtestCommand, + versionCommand, + infoCommand, + helpCommand, +]; module.exports.name = "Missing webpack"; diff --git a/test/help/__snapshots__/help.test.js.snap.devServer3.webpack4 b/test/help/__snapshots__/help.test.js.snap.devServer3.webpack4 index c8b13330a95..fe305e2bd43 100644 --- a/test/help/__snapshots__/help.test.js.snap.devServer3.webpack4 +++ b/test/help/__snapshots__/help.test.js.snap.devServer3.webpack4 @@ -52,14 +52,14 @@ exports[`help should log error for invalid flag with the "--help" option: stdout exports[`help should log error for unknown command using command syntax #2: stderr 1`] = ` "[webpack-cli] Can't find and load command 'verbose' -[webpack-cli] Run 'webpack --help' to see available commands and options" +[webpack-cli] Run 'webpack --help' to see available commands and options." `; exports[`help should log error for unknown command using command syntax #2: stdout 1`] = `""`; exports[`help should log error for unknown command using command syntax: stderr 1`] = ` "[webpack-cli] Can't find and load command 'myCommand' -[webpack-cli] Run 'webpack --help' to see available commands and options" +[webpack-cli] Run 'webpack --help' to see available commands and options." `; exports[`help should log error for unknown command using command syntax: stdout 1`] = `""`; diff --git a/test/help/__snapshots__/help.test.js.snap.devServer3.webpack5 b/test/help/__snapshots__/help.test.js.snap.devServer3.webpack5 index 37c30d8aefb..5dd3e3d69c6 100644 --- a/test/help/__snapshots__/help.test.js.snap.devServer3.webpack5 +++ b/test/help/__snapshots__/help.test.js.snap.devServer3.webpack5 @@ -52,14 +52,14 @@ exports[`help should log error for invalid flag with the "--help" option: stdout exports[`help should log error for unknown command using command syntax #2: stderr 1`] = ` "[webpack-cli] Can't find and load command 'verbose' -[webpack-cli] Run 'webpack --help' to see available commands and options" +[webpack-cli] Run 'webpack --help' to see available commands and options." `; exports[`help should log error for unknown command using command syntax #2: stdout 1`] = `""`; exports[`help should log error for unknown command using command syntax: stderr 1`] = ` "[webpack-cli] Can't find and load command 'myCommand' -[webpack-cli] Run 'webpack --help' to see available commands and options" +[webpack-cli] Run 'webpack --help' to see available commands and options." `; exports[`help should log error for unknown command using command syntax: stdout 1`] = `""`; diff --git a/test/help/__snapshots__/help.test.js.snap.devServer4.webpack4 b/test/help/__snapshots__/help.test.js.snap.devServer4.webpack4 index 8e6d3c6e502..0ba6c2bf8d9 100644 --- a/test/help/__snapshots__/help.test.js.snap.devServer4.webpack4 +++ b/test/help/__snapshots__/help.test.js.snap.devServer4.webpack4 @@ -52,14 +52,14 @@ exports[`help should log error for invalid flag with the "--help" option: stdout exports[`help should log error for unknown command using command syntax #2: stderr 1`] = ` "[webpack-cli] Can't find and load command 'verbose' -[webpack-cli] Run 'webpack --help' to see available commands and options" +[webpack-cli] Run 'webpack --help' to see available commands and options." `; exports[`help should log error for unknown command using command syntax #2: stdout 1`] = `""`; exports[`help should log error for unknown command using command syntax: stderr 1`] = ` "[webpack-cli] Can't find and load command 'myCommand' -[webpack-cli] Run 'webpack --help' to see available commands and options" +[webpack-cli] Run 'webpack --help' to see available commands and options." `; exports[`help should log error for unknown command using command syntax: stdout 1`] = `""`; diff --git a/test/help/__snapshots__/help.test.js.snap.devServer4.webpack5 b/test/help/__snapshots__/help.test.js.snap.devServer4.webpack5 index 56259dec98e..710a6ec9751 100644 --- a/test/help/__snapshots__/help.test.js.snap.devServer4.webpack5 +++ b/test/help/__snapshots__/help.test.js.snap.devServer4.webpack5 @@ -52,14 +52,14 @@ exports[`help should log error for invalid flag with the "--help" option: stdout exports[`help should log error for unknown command using command syntax #2: stderr 1`] = ` "[webpack-cli] Can't find and load command 'verbose' -[webpack-cli] Run 'webpack --help' to see available commands and options" +[webpack-cli] Run 'webpack --help' to see available commands and options." `; exports[`help should log error for unknown command using command syntax #2: stdout 1`] = `""`; exports[`help should log error for unknown command using command syntax: stderr 1`] = ` "[webpack-cli] Can't find and load command 'myCommand' -[webpack-cli] Run 'webpack --help' to see available commands and options" +[webpack-cli] Run 'webpack --help' to see available commands and options." `; exports[`help should log error for unknown command using command syntax: stdout 1`] = `""`; diff --git a/test/version/__snapshots__/version.test.js.snap.webpack4 b/test/version/__snapshots__/version.test.js.snap.webpack4 index eb5f5200f1f..7ee6aa6b9f8 100644 --- a/test/version/__snapshots__/version.test.js.snap.webpack4 +++ b/test/version/__snapshots__/version.test.js.snap.webpack4 @@ -3,24 +3,24 @@ exports[`single version flag outputs version with b: stderr 1`] = `""`; exports[`single version flag outputs version with b: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs version with build: stderr 1`] = `""`; exports[`single version flag outputs version with build: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs version with bundle: stderr 1`] = `""`; exports[`single version flag outputs version with bundle: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -28,8 +28,8 @@ exports[`single version flag outputs version with info using command alias: stde exports[`single version flag outputs version with info using command alias: stdout 1`] = ` "@webpack-cli/info x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -37,8 +37,8 @@ exports[`single version flag outputs version with info using command syntax: std exports[`single version flag outputs version with info using command syntax: stdout 1`] = ` "@webpack-cli/info x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -46,8 +46,8 @@ exports[`single version flag outputs version with info using option alias: stder exports[`single version flag outputs version with info using option alias: stdout 1`] = ` "@webpack-cli/info x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -55,8 +55,8 @@ exports[`single version flag outputs version with info: stderr 1`] = `""`; exports[`single version flag outputs version with info: stdout 1`] = ` "@webpack-cli/info x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -64,8 +64,8 @@ exports[`single version flag outputs version with init: stderr 1`] = `""`; exports[`single version flag outputs version with init: stdout 1`] = ` "@webpack-cli/generators x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -73,8 +73,8 @@ exports[`single version flag outputs version with loader: stderr 1`] = `""`; exports[`single version flag outputs version with loader: stdout 1`] = ` "@webpack-cli/generators x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -82,8 +82,8 @@ exports[`single version flag outputs version with migrate: stderr 1`] = `""`; exports[`single version flag outputs version with migrate: stdout 1`] = ` "@webpack-cli/migrate x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -91,8 +91,8 @@ exports[`single version flag outputs version with plugin: stderr 1`] = `""`; exports[`single version flag outputs version with plugin: stdout 1`] = ` "@webpack-cli/generators x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -100,8 +100,8 @@ exports[`single version flag outputs version with serve: stderr 1`] = `""`; exports[`single version flag outputs version with serve: stdout 1`] = ` "@webpack-cli/serve x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -109,80 +109,80 @@ exports[`single version flag outputs version with the alias c for init: stderr 1 exports[`single version flag outputs version with the alias c for init: stdout 1`] = ` "@webpack-cli/generators x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs version with w: stderr 1`] = `""`; exports[`single version flag outputs version with w: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs version with watch: stderr 1`] = `""`; exports[`single version flag outputs version with watch: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs versions with --color using command syntax: stderr 1`] = `""`; exports[`single version flag outputs versions with --color using command syntax: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs versions with --color using option syntax: stderr 1`] = `""`; exports[`single version flag outputs versions with --color using option syntax: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs versions with --no-color using command syntax: stderr 1`] = `""`; exports[`single version flag outputs versions with --no-color using command syntax: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs versions with --no-color using option syntax: stderr 1`] = `""`; exports[`single version flag outputs versions with --no-color using option syntax: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs versions with alias syntax: stderr 1`] = `""`; exports[`single version flag outputs versions with alias syntax: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs versions with command syntax: stderr 1`] = `""`; exports[`single version flag outputs versions with command syntax: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs versions with dashed syntax: stderr 1`] = `""`; exports[`single version flag outputs versions with dashed syntax: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -281,16 +281,16 @@ exports[`single version flag should output versions for multiple commands using exports[`single version flag should output versions for multiple commands using command syntax: stdout 1`] = ` "@webpack-cli/info x.x.x @webpack-cli/serve x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag should output versions with help command using command syntax: stderr 1`] = `""`; exports[`single version flag should output versions with help command using command syntax: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -299,24 +299,24 @@ exports[`single version flag should work for multiple commands: stderr 1`] = `"" exports[`single version flag should work for multiple commands: stdout 1`] = ` "@webpack-cli/info x.x.x @webpack-cli/serve x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag should work using command syntax and the "--version" argument: stderr 1`] = `""`; exports[`single version flag should work using command syntax and the "--version" argument: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag should work using command syntax with the "version" value: stderr 1`] = `""`; exports[`single version flag should work using command syntax with the "version" value: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; diff --git a/test/version/__snapshots__/version.test.js.snap.webpack5 b/test/version/__snapshots__/version.test.js.snap.webpack5 index eb5f5200f1f..7ee6aa6b9f8 100644 --- a/test/version/__snapshots__/version.test.js.snap.webpack5 +++ b/test/version/__snapshots__/version.test.js.snap.webpack5 @@ -3,24 +3,24 @@ exports[`single version flag outputs version with b: stderr 1`] = `""`; exports[`single version flag outputs version with b: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs version with build: stderr 1`] = `""`; exports[`single version flag outputs version with build: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs version with bundle: stderr 1`] = `""`; exports[`single version flag outputs version with bundle: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -28,8 +28,8 @@ exports[`single version flag outputs version with info using command alias: stde exports[`single version flag outputs version with info using command alias: stdout 1`] = ` "@webpack-cli/info x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -37,8 +37,8 @@ exports[`single version flag outputs version with info using command syntax: std exports[`single version flag outputs version with info using command syntax: stdout 1`] = ` "@webpack-cli/info x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -46,8 +46,8 @@ exports[`single version flag outputs version with info using option alias: stder exports[`single version flag outputs version with info using option alias: stdout 1`] = ` "@webpack-cli/info x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -55,8 +55,8 @@ exports[`single version flag outputs version with info: stderr 1`] = `""`; exports[`single version flag outputs version with info: stdout 1`] = ` "@webpack-cli/info x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -64,8 +64,8 @@ exports[`single version flag outputs version with init: stderr 1`] = `""`; exports[`single version flag outputs version with init: stdout 1`] = ` "@webpack-cli/generators x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -73,8 +73,8 @@ exports[`single version flag outputs version with loader: stderr 1`] = `""`; exports[`single version flag outputs version with loader: stdout 1`] = ` "@webpack-cli/generators x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -82,8 +82,8 @@ exports[`single version flag outputs version with migrate: stderr 1`] = `""`; exports[`single version flag outputs version with migrate: stdout 1`] = ` "@webpack-cli/migrate x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -91,8 +91,8 @@ exports[`single version flag outputs version with plugin: stderr 1`] = `""`; exports[`single version flag outputs version with plugin: stdout 1`] = ` "@webpack-cli/generators x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -100,8 +100,8 @@ exports[`single version flag outputs version with serve: stderr 1`] = `""`; exports[`single version flag outputs version with serve: stdout 1`] = ` "@webpack-cli/serve x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -109,80 +109,80 @@ exports[`single version flag outputs version with the alias c for init: stderr 1 exports[`single version flag outputs version with the alias c for init: stdout 1`] = ` "@webpack-cli/generators x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs version with w: stderr 1`] = `""`; exports[`single version flag outputs version with w: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs version with watch: stderr 1`] = `""`; exports[`single version flag outputs version with watch: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs versions with --color using command syntax: stderr 1`] = `""`; exports[`single version flag outputs versions with --color using command syntax: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs versions with --color using option syntax: stderr 1`] = `""`; exports[`single version flag outputs versions with --color using option syntax: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs versions with --no-color using command syntax: stderr 1`] = `""`; exports[`single version flag outputs versions with --no-color using command syntax: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs versions with --no-color using option syntax: stderr 1`] = `""`; exports[`single version flag outputs versions with --no-color using option syntax: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs versions with alias syntax: stderr 1`] = `""`; exports[`single version flag outputs versions with alias syntax: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs versions with command syntax: stderr 1`] = `""`; exports[`single version flag outputs versions with command syntax: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag outputs versions with dashed syntax: stderr 1`] = `""`; exports[`single version flag outputs versions with dashed syntax: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -281,16 +281,16 @@ exports[`single version flag should output versions for multiple commands using exports[`single version flag should output versions for multiple commands using command syntax: stdout 1`] = ` "@webpack-cli/info x.x.x @webpack-cli/serve x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag should output versions with help command using command syntax: stderr 1`] = `""`; exports[`single version flag should output versions with help command using command syntax: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; @@ -299,24 +299,24 @@ exports[`single version flag should work for multiple commands: stderr 1`] = `"" exports[`single version flag should work for multiple commands: stdout 1`] = ` "@webpack-cli/info x.x.x @webpack-cli/serve x.x.x -webpack x.x.x -webpack-cli x.x.x +webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag should work using command syntax and the "--version" argument: stderr 1`] = `""`; exports[`single version flag should work using command syntax and the "--version" argument: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `; exports[`single version flag should work using command syntax with the "version" value: stderr 1`] = `""`; exports[`single version flag should work using command syntax with the "version" value: stdout 1`] = ` -"webpack x.x.x -webpack-cli x.x.x +"webpack: x.x.x +webpack-cli: x.x.x webpack-dev-server x.x.x" `;