Skip to content

Commit 4568cb9

Browse files
fix: allow chmod to fail in setup (#1197)
## PR Checklist - [x] Addresses an existing open issue: fixes #1195 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview Wraps the `chmod` with a `try`/`catch`. I figure if it fails then that's probably a sign the running OS doesn't have it and therefore doesn't need it.
1 parent ff5f7fd commit 4568cb9

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { describe, expect, it, vi } from "vitest";
2+
3+
import { Options } from "../../shared/types.js";
4+
import { writeStructure } from "./writeStructure.js";
5+
6+
const mock$ = vi.fn();
7+
8+
vi.mock("execa", () => ({
9+
get $() {
10+
return mock$;
11+
},
12+
}));
13+
14+
vi.mock("./creation/index.js");
15+
vi.mock("./writeStructureWorker.js");
16+
17+
const options = {
18+
access: "public",
19+
author: "TestAuthor",
20+
base: "everything",
21+
description: "Test description.",
22+
directory: ".",
23+
email: {
24+
github: "[email protected]",
25+
26+
},
27+
keywords: ["abc", "def ghi", "jkl mno pqr"],
28+
mode: "create",
29+
owner: "TestOwner",
30+
repository: "test-repository",
31+
title: "Test Title",
32+
} satisfies Options;
33+
34+
describe("writeStructure", () => {
35+
it("resolves when chmod resolves", async () => {
36+
mock$.mockResolvedValue(undefined);
37+
38+
await expect(writeStructure(options)).resolves.toBeUndefined();
39+
});
40+
41+
it("resolves when chmod rejects", async () => {
42+
mock$.mockRejectedValue(new Error("Oh no!"));
43+
44+
await expect(writeStructure(options)).resolves.toBeUndefined();
45+
});
46+
});

src/steps/writing/writeStructure.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { writeStructureWorker } from "./writeStructureWorker.js";
77
export async function writeStructure(options: Options) {
88
await writeStructureWorker(await createStructure(options), ".");
99

10-
// https://github.com/JoshuaKGoldberg/create-typescript-app/issues/718
11-
await $`chmod ug+x .husky/pre-commit`;
10+
try {
11+
// https://github.com/JoshuaKGoldberg/create-typescript-app/issues/718
12+
await $`chmod ug+x .husky/pre-commit`;
13+
} catch {
14+
// https://github.com/JoshuaKGoldberg/create-typescript-app/issues/1195
15+
}
1216
}

0 commit comments

Comments
 (0)