From 857783b4eee04ebe2297fd182bc3d95d323cd031 Mon Sep 17 00:00:00 2001 From: chenxsan Date: Mon, 1 Mar 2021 18:38:02 +0800 Subject: [PATCH] use prepare to run husky install --- .husky/.gitignore | 2 +- package.json | 1 + setup/setup.js | 23 ----------------------- 3 files changed, 2 insertions(+), 24 deletions(-) diff --git a/.husky/.gitignore b/.husky/.gitignore index c9cdc63b070..31354ec1389 100644 --- a/.husky/.gitignore +++ b/.husky/.gitignore @@ -1 +1 @@ -_ \ No newline at end of file +_ diff --git a/package.json b/package.json index 9bc543d4648..ee557603fbe 100644 --- a/package.json +++ b/package.json @@ -154,6 +154,7 @@ "special-lint": "node node_modules/tooling/lockfile-lint && node node_modules/tooling/schemas-lint && node node_modules/tooling/inherit-types && node node_modules/tooling/format-schemas && node tooling/generate-runtime-code.js && node node_modules/tooling/format-file-header && node node_modules/tooling/compile-to-definitions && node node_modules/tooling/generate-types --no-template-literals", "special-lint-fix": "node node_modules/tooling/inherit-types --write && node node_modules/tooling/format-schemas --write && node tooling/generate-runtime-code.js --write && node node_modules/tooling/format-file-header --write && node node_modules/tooling/compile-to-definitions --write && node node_modules/tooling/generate-types --no-template-literals --write", "fix": "yarn code-lint --fix && yarn special-lint-fix && yarn pretty-lint-fix", + "prepare": "husky install", "pretty-lint-base": "prettier \"*.{ts,json,yml,yaml,md}\" \"{setup,lib,bin,hot,benchmark,tooling,schemas}/**/*.json\" \"examples/*.md\"", "pretty-lint-base-all": "yarn pretty-lint-base \"*.js\" \"{setup,lib,bin,hot,benchmark,tooling,schemas}/**/*.js\" \"test/*.js\" \"test/helpers/*.js\" \"test/{configCases,watchCases,statsCases,hotCases,benchmarkCases}/**/webpack.config.js\" \"examples/**/webpack.config.js\"", "pretty-lint-fix": "yarn pretty-lint-base-all --loglevel warn --write", diff --git a/setup/setup.js b/setup/setup.js index ed5addb63c2..d1b4de9da6d 100644 --- a/setup/setup.js +++ b/setup/setup.js @@ -4,19 +4,10 @@ const fs = require("fs"); const path = require("path"); const root = process.cwd(); const node_modulesFolder = path.resolve(root, "node_modules"); -const huskyFolder = path.resolve(root, ".husky", "_"); const webpackDependencyFolder = path.resolve(root, "node_modules/webpack"); function setup() { return Promise.all([ - checkGitHooksInstalledAsync().then(async hasGitHooks => { - if (!hasGitHooks) { - await runSetupGitHooksAsync(); - if (!(await checkGitHooksInstalledAsync())) { - throw new Error("Git hooks were not successfully installed"); - } - } - }), checkSymlinkExistsAsync().then(async hasSymlink => { if (!hasSymlink) { await ensureYarnInstalledAsync(); @@ -42,10 +33,6 @@ async function runSetupSymlinkAsync() { await exec("yarn", ["link", "webpack"], "Link webpack into itself"); } -async function runSetupGitHooksAsync() { - await exec("yarn", ["run", "husky", "install"], "Enable Git hooks"); -} - function checkSymlinkExistsAsync() { return new Promise((resolve, reject) => { if ( @@ -60,16 +47,6 @@ function checkSymlinkExistsAsync() { }); } -function checkGitHooksInstalledAsync() { - return new Promise((resolve, reject) => { - if (fs.existsSync(huskyFolder)) { - resolve(true); - } else { - resolve(false); - } - }); -} - async function ensureYarnInstalledAsync() { const semverPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$/; let hasYarn = false;