Skip to content

Commit 825cec1

Browse files
committed
Minor tweak
1 parent d9ee4df commit 825cec1

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/run-prettier.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,7 @@ async function runPrettierWithVersion({
3535
// if another packages is required to run Prettier
3636
// e.g. excalidraw: https://github.com/excalidraw/excalidraw/blob/a21db08cae608692d9525fff97f109fb24fec20c/package.json#L83
3737
if (shouldInstallDependencies(error)) {
38-
await spawn("yarn", ["install"], {
39-
cwd,
40-
env: { YARN_ENABLE_IMMUTABLE_INSTALLS: "false" },
41-
});
42-
await fs.rm(path.join(cwd, "yarn.lock"), { force: true });
43-
await spawn("git", ["reset", "--hard"], { cwd });
38+
await installDependencies(cwd);
4439
await run();
4540
} else {
4641
throw error;
@@ -55,6 +50,15 @@ async function runPrettierWithVersion({
5550
return commitHash;
5651
}
5752

53+
async function installDependencies(cwd) {
54+
await spawn("yarn", ["install"], {
55+
cwd,
56+
env: { YARN_ENABLE_IMMUTABLE_INSTALLS: "false" },
57+
});
58+
await fs.rm(path.join(cwd, "yarn.lock"), { force: true });
59+
await spawn("git", ["reset", "--hard"], { cwd });
60+
}
61+
5862
function shouldInstallDependencies(error: SubprocessError) {
5963
const { message, stderr } = error;
6064
return [message, stderr].some(

0 commit comments

Comments
 (0)