From e9d426d8be4de9fff9fe388a8f9b4dc74af7c8ab Mon Sep 17 00:00:00 2001 From: ev1stensberg Date: Thu, 30 May 2019 18:57:20 +0200 Subject: [PATCH] chore: format and revise code w.r.t style --- bin/opencollective.js | 6 +++++- bin/utils/prompt-command.js | 19 ++++++++--------- package-lock.json | 41 ++++++++++++++++++++++++++---------- package.json | 3 +-- packages/utils/path-utils.ts | 15 +------------ 5 files changed, 46 insertions(+), 38 deletions(-) diff --git a/bin/opencollective.js b/bin/opencollective.js index a6266a25b4e..16207dc7575 100644 --- a/bin/opencollective.js +++ b/bin/opencollective.js @@ -26,7 +26,11 @@ function printBadge() { print(`Please consider donating to our ${chalk.bold.blue("Open Collective")}`); print("to help us maintain this package."); console.log("\n\n"); - print(`${emoji("👉")} ${chalk.bold.yellow(" Donate:")} ${chalk.reset.underline.yellow("https://opencollective.com/webpack/donate")}`); + print( + `${emoji("👉")} ${chalk.bold.yellow(" Donate:")} ${chalk.reset.underline.yellow( + "https://opencollective.com/webpack/donate" + )}` + ); console.log("\n"); } diff --git a/bin/utils/prompt-command.js b/bin/utils/prompt-command.js index 907434c6c71..1ee4beab8c6 100644 --- a/bin/utils/prompt-command.js +++ b/bin/utils/prompt-command.js @@ -31,20 +31,20 @@ const npmGlobalRoot = () => { const cp = require("child_process"); return new Promise((resolve, reject) => { const command = cp.spawn("npm", ["root", "-g"]); - command.on("error", (error) => reject(error)); - command.stdout.on("data", (data) => resolve(data.toString())); - command.stderr.on("data", (data) => reject(data)); + command.on("error", error => reject(error)); + command.stdout.on("data", data => resolve(data.toString())); + command.stderr.on("data", data => reject(data)); }); }; const runWhenInstalled = (packages, pathForCmd, ...args) => { const package = require(pathForCmd); const func = package.default; - if (typeof func !== 'function') { + if (typeof func !== "function") { throw new Error(`@webpack-cli/${packages} failed to export a default function`); } return func(...args); -} +}; module.exports = function promptForInstallation(packages, ...args) { const nameOfPackage = "@webpack-cli/" + packages; @@ -102,19 +102,18 @@ module.exports = function promptForInstallation(packages, ...args) { case "y": case "yes": case "1": { - runCommand(packageManager, options) - .then(_=> { + .then(_ => { if (packages === "init") { npmGlobalRoot() - .then((root) => { + .then(root => { const pathtoInit = path.resolve(root.trim(), "@webpack-cli", "init"); return pathtoInit; }) - .then((pathForInit) => { + .then(pathForInit => { return require(pathForInit).default(...args); }) - .catch((error) => { + .catch(error => { console.error(error); process.exitCode = 1; }); diff --git a/package-lock.json b/package-lock.json index 3fa90818763..7be88ee429b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7480,7 +7480,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -7501,12 +7502,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -7521,17 +7524,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -7648,7 +7654,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -7660,6 +7667,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -7674,6 +7682,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -7681,12 +7690,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -7705,6 +7716,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -7785,7 +7797,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -7797,6 +7810,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -7882,7 +7896,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -7918,6 +7933,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -7937,6 +7953,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -7980,12 +7997,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, diff --git a/package.json b/package.json index a3d62ea17cc..b9ed22b9862 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,7 @@ "clean:all": "rimraf node_modules packages/*/{node_modules}", "commit": "git-cz", "docs": "typedoc", - "format": "prettier-eslint ./bin/*.js ./test/**/*.js ./packages/**/*.js --write", - "lint:codeOnly": "eslint \"{bin}/**/!(__testfixtures__)/*.js\" \"{bin}/**.js\"", + "format": "prettier-eslint ./bin/*.js ./bin/**/*.js ./test/**/*.js ./packages/**/*.js ./packages/**/**/*.js --write", "lint": "eslint \"./bin/*.js\" \"./test/**/*.js\" \"packages/**/!(node_modules)/*.test.js\"", "postinstall": "node ./bin/opencollective.js", "pretest": "npm run build && npm run lint && npm run tslint", diff --git a/packages/utils/path-utils.ts b/packages/utils/path-utils.ts index 468572a59b9..29def6d2257 100644 --- a/packages/utils/path-utils.ts +++ b/packages/utils/path-utils.ts @@ -17,19 +17,6 @@ export function isLocalPath(str: string): boolean { return path.isAbsolute(str) || /^\./.test(str) || fs.existsSync(str); } -/** - * Get absolute path of a webpack config in a project. - * - * @param {String[]} str - array of extensions to look for. - * @returns {String} Absolute path of the config. - */ - -export function webpackConfigPath(extensions: string[]): string { - const defaultConfigFileNames = ["webpack.config", "webpackfile"].join("|"); - const webpackConfigFileRegExp = `(${defaultConfigFileNames})(${extensions.join("|")})`; - return findup(webpackConfigFileRegExp); -} - /** * Find the root directory path of a project. * @@ -37,7 +24,7 @@ export function webpackConfigPath(extensions: string[]): string { */ export function findProjectRoot(): string { - const rootFilePath = findup(`package.json`); + const rootFilePath = findup("package.json"); const projectRoot = path.dirname(rootFilePath); return projectRoot; }