Skip to content

Commit 80d3920

Browse files
committed
fix(ci): guard optional hook tooling
Keep dev-dependency-free installs working. Prevent hooks from downloading fallback packages. Generated-by: OpenAI Codex Signed-off-by: Jiawei Zhao <Phoenix500526@163.com>
1 parent 8bddf27 commit 80d3920

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
npm exec -- biome check --staged --no-errors-on-unmatched
18+
npx --no -- biome check --staged --no-errors-on-unmatched
1919
node scripts/asf-license-headers.mjs check-staged
2020
node scripts/protocol-epoch-check.mjs --staged
2121
git diff --cached --check

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"apps/desktop"
2727
],
2828
"scripts": {
29-
"prepare": "husky",
29+
"prepare": "node scripts/install-husky.mjs",
3030
"postinstall": "node scripts/apply-dependency-patches.mjs && node scripts/install-electron-with-retry.mjs",
3131
"lint": "biome lint .",
3232
"format": "biome format --write .",

scripts/install-husky.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env node
2+
/*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*/
20+
21+
try {
22+
const install = (await import('husky')).default;
23+
process.stdout.write(install());
24+
} catch (error) {
25+
if (
26+
error instanceof Error &&
27+
'code' in error &&
28+
error.code === 'ERR_MODULE_NOT_FOUND' &&
29+
error.message.includes("package 'husky'")
30+
) {
31+
console.warn('husky is not installed; skipping Git hook setup.');
32+
} else {
33+
throw error;
34+
}
35+
}

0 commit comments

Comments
 (0)