|
1 | | -import { execSync } from "node:child_process"; |
2 | 1 | import { mkdir, readFile, writeFile } from "node:fs/promises"; |
3 | 2 |
|
4 | 3 | import { addDevDependency, dlxCommand } from "nypm"; |
5 | 4 | import type { PackageManager, PackageManagerName } from "nypm"; |
6 | 5 |
|
| 6 | +import { runCommandSync } from "../run-command"; |
7 | 7 | import { exists, isMonorepo, updatePackageJson } from "../utils"; |
8 | 8 |
|
9 | 9 | const createLintStagedHookScript = (lintStagedCommand: string) => `#!/bin/sh |
@@ -68,13 +68,13 @@ export const husky = { |
68 | 68 | exists: () => exists(path), |
69 | 69 | init: (packageManager: PackageManagerName) => { |
70 | 70 | // Initialize husky - this sets up git hooks infrastructure |
71 | | - const initCommand = dlxCommand(packageManager, "husky", { |
| 71 | + const [command, ...args] = dlxCommand(packageManager, "husky", { |
72 | 72 | args: ["init"], |
73 | | - }); |
| 73 | + }).split(" "); |
| 74 | + |
| 75 | + const result = runCommandSync(command, args, { stdio: "pipe" }); |
74 | 76 |
|
75 | | - try { |
76 | | - execSync(initCommand, { stdio: "pipe" }); |
77 | | - } catch { |
| 77 | + if (result.error || (result.status !== null && result.status !== 0)) { |
78 | 78 | // If init fails, it might be because it's already initialized |
79 | 79 | // Continue anyway as we'll create the hook file next |
80 | 80 | } |
|
0 commit comments