Skip to content

Commit 6774141

Browse files
perf: rimraf coverage directories in --mode migrate (#1248)
<!-- 👋 Hi, thanks for sending a PR to create-typescript-app! 💖. Please fill out all fields below and make sure each item is true and [x] checked. Otherwise we may not be able to review your PR. --> ## PR Checklist - [x] Addresses an existing open issue: fixes #1221 - [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 Cleans `coverage*` directories as a part of `--mode migrate` so that format and lint runs don't take forever going through them. Also cleans the directories at the beginning of all three end-to-end test formats. Sometimes I run them locally and it's a pain to have forgotten to clear the coverage directories in that case. Thanks to @NanderTGA for suggesting using `rimraf` for Windows support. I would have used the *nix-only `rm -rf` by myself. 😄 Co-authored-by: @NanderTGA
1 parent cdbe271 commit 6774141

15 files changed

+84
-73
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"prettier-plugin-curly": "^0.1.3",
100100
"prettier-plugin-packagejson": "^2.4.7",
101101
"release-it": "^17.0.0",
102+
"rimraf": "^5.0.5",
102103
"sentences-per-line": "^0.2.1",
103104
"should-semantic-release": "^0.2.1",
104105
"tsup": "^8.0.1",

pnpm-lock.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

script/create-test-e2e.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { $, execaCommand } from "execa";
22
import { strict as assert } from "node:assert";
3+
import { rimraf } from "rimraf";
34

45
const author = "Test Author";
56
const description = "Test description.";
@@ -8,7 +9,7 @@ const repository = "create-typescript-app";
89
const owner = "TestOwner";
910
const title = "Test Title";
1011

11-
await $`rm -rf ${repository}`;
12+
await rimraf(["coverage*", repository]);
1213

1314
// Fist we run with --mode create to create a new new local repository,
1415
// asserting that pnpm i passes in that repository's directory.

script/initialize-test-e2e.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ import { $ } from "execa";
22
import { globby } from "globby";
33
import { strict as assert } from "node:assert";
44
import * as fs from "node:fs/promises";
5+
import { rimraf } from "rimraf";
56

67
const description = "New Description Test";
78
const owner = "RNR1";
89
const title = "New Title Test";
910
const repository = "new-repository-test";
1011

12+
await rimraf("coverage*");
13+
1114
// Fist we run with --mode initialize to modify the local repository files,
1215
// asserting that the created package.json keeps the general description.
1316
await $({

script/migrate-test-e2e.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import chalk from "chalk";
22
import { $, execaCommand } from "execa";
33
import * as fs from "node:fs/promises";
4+
import { rimraf } from "rimraf";
45
import { assert, describe, expect, test } from "vitest";
56

67
import packageData from "../package.json" assert { type: "json" };
@@ -37,6 +38,8 @@ const logoAlt = `Project logo: the TypeScript blue square with rounded corners,
3738
const owner = "JoshuaKGoldberg";
3839
const title = "Create TypeScript App";
3940

41+
await rimraf("coverage*");
42+
4043
const originalReadme = (await fs.readFile("README.md")).toString();
4144

4245
const originalSnapshots = (

src/create/createWithOptions.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { addToolAllContributors } from "../steps/addToolAllContributors.js";
88
import { finalizeDependencies } from "../steps/finalizeDependencies.js";
99
import { initializeGitHubRepository } from "../steps/initializeGitHubRepository/index.js";
1010
import { populateCSpellDictionary } from "../steps/populateCSpellDictionary.js";
11-
import { runCommands } from "../steps/runCommands.js";
11+
import { runCleanup } from "../steps/runCleanup.js";
1212
import { createWithOptions } from "./createWithOptions.js";
1313

1414
const optionsBase: Options = {
@@ -63,7 +63,7 @@ vi.mock("../steps/finalizeDependencies.js");
6363

6464
vi.mock("../steps/populateCSpellDictionary.js");
6565

66-
vi.mock("../steps/runCommands.js");
66+
vi.mock("../steps/runCleanup.js");
6767

6868
vi.mock("../shared/doesRepositoryExist.js", () => ({
6969
doesRepositoryExist: vi.fn().mockResolvedValue(true),
@@ -114,7 +114,7 @@ describe("createWithOptions", () => {
114114
expect(addToolAllContributors).not.toHaveBeenCalled();
115115
});
116116

117-
it("does not call finalizeDependencies, populateCSpellDictionary, or runCommands when skipInstall is true", async () => {
117+
it("does not call finalizeDependencies, populateCSpellDictionary, or runCleanup when skipInstall is true", async () => {
118118
const options = {
119119
...optionsBase,
120120
skipInstall: true,
@@ -123,10 +123,10 @@ describe("createWithOptions", () => {
123123
await createWithOptions({ github, options });
124124
expect(finalizeDependencies).not.toHaveBeenCalled();
125125
expect(populateCSpellDictionary).not.toHaveBeenCalled();
126-
expect(runCommands).not.toHaveBeenCalled();
126+
expect(runCleanup).not.toHaveBeenCalled();
127127
});
128128

129-
it("calls finalizeDependencies, populateCSpellDictionary, and runCommands when skipInstall is false", async () => {
129+
it("calls finalizeDependencies, populateCSpellDictionary, and runCleanup when skipInstall is false", async () => {
130130
const options = {
131131
...optionsBase,
132132
skipInstall: false,
@@ -136,7 +136,7 @@ describe("createWithOptions", () => {
136136

137137
expect(finalizeDependencies).toHaveBeenCalledWith(options);
138138
expect(populateCSpellDictionary).toHaveBeenCalled();
139-
expect(runCommands).toHaveBeenCalled();
139+
expect(runCleanup).toHaveBeenCalled();
140140
});
141141

142142
it("does not initialize GitHub repository if repository does not exist", async () => {

src/create/createWithOptions.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { $ } from "execa";
22

33
import { withSpinner, withSpinners } from "../shared/cli/spinners.js";
4-
import { createCleanUpFilesCommands } from "../shared/createCleanUpFilesCommands.js";
4+
import { createCleanupCommands } from "../shared/createCleanupCommands.js";
55
import { doesRepositoryExist } from "../shared/doesRepositoryExist.js";
66
import { GitHubAndOptions } from "../shared/options/readOptions.js";
77
import { addToolAllContributors } from "../steps/addToolAllContributors.js";
88
import { finalizeDependencies } from "../steps/finalizeDependencies.js";
99
import { initializeGitHubRepository } from "../steps/initializeGitHubRepository/index.js";
1010
import { populateCSpellDictionary } from "../steps/populateCSpellDictionary.js";
11-
import { runCommands } from "../steps/runCommands.js";
11+
import { runCleanup } from "../steps/runCleanup.js";
1212
import { writeReadme } from "../steps/writeReadme/index.js";
1313
import { writeStructure } from "../steps/writing/writeStructure.js";
1414

@@ -46,13 +46,7 @@ export async function createWithOptions({ github, options }: GitHubAndOptions) {
4646
);
4747
}
4848

49-
await runCommands(
50-
"Cleaning up files",
51-
createCleanUpFilesCommands({
52-
bin: !!options.bin,
53-
dedupe: true,
54-
}),
55-
);
49+
await runCleanup(createCleanupCommands(options), options.mode);
5650
}
5751

5852
const sendToGitHub =

src/initialize/initializeWithOptions.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { withSpinner, withSpinners } from "../shared/cli/spinners.js";
2-
import { createCleanUpFilesCommands } from "../shared/createCleanUpFilesCommands.js";
2+
import { createCleanupCommands } from "../shared/createCleanupCommands.js";
33
import { GitHubAndOptions } from "../shared/options/readOptions.js";
44
import { addOwnerAsAllContributor } from "../steps/addOwnerAsAllContributor.js";
55
import { clearChangelog } from "../steps/clearChangelog.js";
66
import { initializeGitHubRepository } from "../steps/initializeGitHubRepository/index.js";
77
import { removeSetupScripts } from "../steps/removeSetupScripts.js";
88
import { resetGitTags } from "../steps/resetGitTags.js";
9-
import { runCommands } from "../steps/runCommands.js";
9+
import { runCleanup } from "../steps/runCleanup.js";
1010
import { uninstallPackages } from "../steps/uninstallPackages.js";
1111
import { updateAllContributorsTable } from "../steps/updateAllContributorsTable.js";
1212
import { updateLocalFiles } from "../steps/updateLocalFiles.js";
@@ -61,10 +61,5 @@ export async function initializeWithOptions({
6161
);
6262
}
6363

64-
await runCommands(
65-
"Cleaning up files",
66-
createCleanUpFilesCommands({
67-
bin: !!options.bin,
68-
}),
69-
);
64+
await runCleanup(createCleanupCommands(options), options.mode);
7065
}

src/migrate/migrateWithOptions.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { withSpinner, withSpinners } from "../shared/cli/spinners.js";
2-
import { createCleanUpFilesCommands } from "../shared/createCleanUpFilesCommands.js";
2+
import { createCleanupCommands } from "../shared/createCleanupCommands.js";
33
import { GitHubAndOptions } from "../shared/options/readOptions.js";
44
import { clearUnnecessaryFiles } from "../steps/clearUnnecessaryFiles.js";
55
import { detectExistingContributors } from "../steps/detectExistingContributors.js";
66
import { finalizeDependencies } from "../steps/finalizeDependencies.js";
77
import { initializeGitHubRepository } from "../steps/initializeGitHubRepository/index.js";
88
import { populateCSpellDictionary } from "../steps/populateCSpellDictionary.js";
9-
import { runCommands } from "../steps/runCommands.js";
9+
import { runCleanup } from "../steps/runCleanup.js";
1010
import { updateAllContributorsTable } from "../steps/updateAllContributorsTable.js";
1111
import { updateLocalFiles } from "../steps/updateLocalFiles.js";
1212
import { writeReadme } from "../steps/writeReadme/index.js";
@@ -66,11 +66,5 @@ export async function migrateWithOptions({
6666
await withSpinner("Populating CSpell dictionary", populateCSpellDictionary);
6767
}
6868

69-
await runCommands(
70-
"Cleaning up files",
71-
createCleanUpFilesCommands({
72-
bin: !!options.bin,
73-
dedupe: true,
74-
}),
75-
);
69+
await runCleanup(createCleanupCommands(options), options.mode);
7670
}

src/shared/createCleanUpFilesCommands.test.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)