Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/fix husky upgrade #12739

Merged
merged 6 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install lint-staged
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@
"cover:types": "node node_modules/tooling/type-coverage",
"cover:report": "istanbul report"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js|{lib,setup,bin,hot,tooling,schemas}/**/*.js|test/*.js|{test,examples}/**/webpack.config.js}": [
"eslint --cache"
Expand Down
62 changes: 44 additions & 18 deletions setup/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,29 @@ 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 checkSymlinkExistsAsync()
.then(hasSymlink => {
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) {
return ensureYarnInstalledAsync().then(() => {
return runSetupAsync().then(() => {
return checkSymlinkExistsAsync();
});
});
await ensureYarnInstalledAsync();
await runSetupSymlinkAsync();
if (!(await checkSymlinkExistsAsync())) {
throw new Error("windows symlink was not successfully created");
}
}
})
])
.then(() => {
process.exitCode = 0;
})
Expand All @@ -26,10 +36,14 @@ function setup() {
});
}

function runSetupAsync() {
return exec("yarn", ["install"], "Install dependencies")
.then(() => exec("yarn", ["link"], "Create webpack symlink"))
.then(() => exec("yarn", ["link", "webpack"], "Link webpack into itself"));
async function runSetupSymlinkAsync() {
await exec("yarn", ["install"], "Install dependencies");
await exec("yarn", ["link"], "Create webpack symlink");
await exec("yarn", ["link", "webpack"], "Link webpack into itself");
}

async function runSetupGitHooksAsync() {
await exec("yarn", ["run", "husky", "install"], "Enable Git hooks");
}

function checkSymlinkExistsAsync() {
Expand All @@ -46,14 +60,26 @@ function checkSymlinkExistsAsync() {
});
}

function ensureYarnInstalledAsync() {
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-]+)*)?$/;
return execGetOutput("yarn", ["-v"], "Check yarn version")
.then(
stdout => semverPattern.test(stdout),
() => false
)
.then(hasYarn => hasYarn || installYarnAsync());
let hasYarn = false;
try {
const stdout = await execGetOutput("yarn", ["-v"], "Check yarn version");
hasYarn = semverPattern.test(stdout);
} catch (e) {
hasYarn = false;
}
if (!hasYarn) await installYarnAsync();
}

function installYarnAsync() {
Expand Down