Skip to content

Commit

Permalink
Unbreak installing from Git
Browse files Browse the repository at this point in the history
`save-git-history.ts` breaks installing BCD from Git (in a fit of irony,
there won't be a `.git` if you use `npm install
github:mdn/browser-compat-data`).

While I'm here, I've stopped the script from running if you, like me,
have `HUSKY=0` set.
  • Loading branch information
ddbeck committed Mar 5, 2024
1 parent 8386cba commit 9e8a6a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
"yargs": "~17.7.0"
},
"scripts": {
"postinstall": "node --loader=ts-node/esm --no-warnings=ExperimentalWarning scripts/save-git-history.ts",
"postinstall": "(test HUSKY = 0 || (husky || true)) && echo 'not in worktree, skipping save-git-history') || npm run save-git-history",
"save-git-history": "node --loader=ts-node/esm --no-warnings=ExperimentalWarning scripts/save-git-history.ts",
"prepare": "(husky || true) && npm run gentypes && npm run build",
"diff": "node --loader=ts-node/esm --no-warnings=ExperimentalWarning scripts/diff.ts",
"unittest": "NODE_ENV=test c8 mocha index.test.ts --recursive \"{,!(node_modules)/**}/*.test.ts\"",
Expand Down
6 changes: 5 additions & 1 deletion scripts/save-git-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import { getBranchName, getHashOfHEAD } from './lib/git.js';
const HUSKY_ROOT = '.husky/_/';
const HISTORY_FILE = HUSKY_ROOT + 'history';

if ('main' === getBranchName() && fs.existsSync(HUSKY_ROOT)) {
if (
'main' === getBranchName() &&
fs.existsSync(HUSKY_ROOT) &&
process.env['HUSKY'] !== '0'
) {
fs.writeFileSync(HISTORY_FILE, getHashOfHEAD());
}

0 comments on commit 9e8a6a6

Please sign in to comment.