Skip to content

Commit a678d4f

Browse files
feat: add ignoreDeps Addon to blockRenovate (#2180)
## PR Checklist - [x] Addresses an existing open issue: fixes #2179 - [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 Also standardizes `blockTypeScript` to use the newer `intakeFileAsJson`, while I'm in the area. 🎁
1 parent 651cd15 commit a678d4f

File tree

6 files changed

+179
-14
lines changed

6 files changed

+179
-14
lines changed

src/blocks/blockAllContributors.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe("blockAllContributors", () => {
8989
"scripts": [
9090
{
9191
"commands": [
92-
"pnpx all-contributors-cli add test-owner code,content,doc,ideas,infra,maintenance,projectManagement,tool",
92+
"pnpx all-contributors-cli@6.23.0 add test-owner code,content,doc,ideas,infra,maintenance,projectManagement,tool",
9393
],
9494
"phase": 3,
9595
},
@@ -231,7 +231,7 @@ describe("blockAllContributors", () => {
231231
"scripts": [
232232
{
233233
"commands": [
234-
"pnpx all-contributors-cli add JoshuaKGoldberg bug,code,design,doc,test,tool,content,ideas,infra,maintenance,projectManagement",
234+
"pnpx all-contributors-cli@6.23.0 add JoshuaKGoldberg bug,code,design,doc,test,tool,content,ideas,infra,maintenance,projectManagement",
235235
],
236236
"phase": 3,
237237
},
@@ -372,7 +372,7 @@ describe("blockAllContributors", () => {
372372
"scripts": [
373373
{
374374
"commands": [
375-
"pnpx all-contributors-cli add test-owner code,content,doc,ideas,infra,maintenance,projectManagement,tool",
375+
"pnpx all-contributors-cli@6.23.0 add test-owner code,content,doc,ideas,infra,maintenance,projectManagement,tool",
376376
],
377377
"phase": 3,
378378
},

src/blocks/blockAllContributors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const blockAllContributors = base.createBlock({
112112
scripts: [
113113
{
114114
commands: [
115-
`pnpx all-contributors-cli add ${options.owner} ${ownerContributions.join(",")}`,
115+
`pnpx all-contributors-cli@6.23.0 add ${options.owner} ${ownerContributions.join(",")}`,
116116
],
117117
phase: CommandPhase.Process,
118118
},

src/blocks/blockRenovate.test.ts

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import { testBlock, testIntake } from "bingo-stratum-testers";
2+
import { describe, expect, it, test } from "vitest";
3+
4+
import { blockRenovate } from "./blockRenovate.js";
5+
import { optionsBase } from "./options.fakes.js";
6+
7+
describe("blockRenovate", () => {
8+
test("without addons", () => {
9+
const creation = testBlock(blockRenovate, {
10+
options: optionsBase,
11+
});
12+
13+
expect(creation).toMatchInlineSnapshot(`
14+
{
15+
"addons": [
16+
{
17+
"addons": {
18+
"apps": [
19+
{
20+
"name": "Renovate",
21+
"url": "https://github.com/apps/renovate",
22+
},
23+
],
24+
},
25+
"block": [Function],
26+
},
27+
],
28+
"files": {
29+
".github": {
30+
"renovate.json": "{"$schema":"https://docs.renovatebot.com/renovate-schema.json","automerge":true,"extends":[":preserveSemverRanges","config:best-practices","replacements:all"],"ignoreDeps":["codecov/codecov-action"],"labels":["dependencies"],"minimumReleaseAge":"7 days","patch":{"enabled":false},"postUpdateOptions":["pnpmDedupe"]}",
31+
},
32+
},
33+
}
34+
`);
35+
});
36+
37+
test("with addons", () => {
38+
const creation = testBlock(blockRenovate, {
39+
addons: {
40+
ignoreDeps: ["all-contributors-cli"],
41+
},
42+
options: optionsBase,
43+
});
44+
45+
expect(creation).toMatchInlineSnapshot(`
46+
{
47+
"addons": [
48+
{
49+
"addons": {
50+
"apps": [
51+
{
52+
"name": "Renovate",
53+
"url": "https://github.com/apps/renovate",
54+
},
55+
],
56+
},
57+
"block": [Function],
58+
},
59+
],
60+
"files": {
61+
".github": {
62+
"renovate.json": "{"$schema":"https://docs.renovatebot.com/renovate-schema.json","automerge":true,"extends":[":preserveSemverRanges","config:best-practices","replacements:all"],"ignoreDeps":["all-contributors-cli","codecov/codecov-action"],"labels":["dependencies"],"minimumReleaseAge":"7 days","patch":{"enabled":false},"postUpdateOptions":["pnpmDedupe"]}",
63+
},
64+
},
65+
}
66+
`);
67+
});
68+
69+
describe("intake", () => {
70+
it("returns no ignoreDeps when .github/renovate.json does not exist", () => {
71+
const actual = testIntake(blockRenovate, {
72+
files: {},
73+
});
74+
75+
expect(actual).toEqual({ ignoreDeps: [] });
76+
});
77+
78+
it("returns no ignoreDeps when .github/renovate.json does not contain truthy data", () => {
79+
const actual = testIntake(blockRenovate, {
80+
files: {
81+
".github": {
82+
"renovate.json": [JSON.stringify(null)],
83+
},
84+
},
85+
});
86+
87+
expect(actual).toEqual({ ignoreDeps: [] });
88+
});
89+
90+
it("returns no ignoreDeps when .github/renovate.json contains only unrelated data", () => {
91+
const actual = testIntake(blockRenovate, {
92+
files: {
93+
".github": {
94+
"renovate.json": [JSON.stringify({ other: true })],
95+
},
96+
},
97+
});
98+
99+
expect(actual).toEqual({ ignoreDeps: [] });
100+
});
101+
102+
it("returns ignoreDeps when .github/renovate.json contains ignoreDeps", () => {
103+
const ignoreDeps = ["all-contributors-cli", "codecov/codecov-action"];
104+
105+
const actual = testIntake(blockRenovate, {
106+
files: {
107+
".github": {
108+
"renovate.json": [JSON.stringify({ ignoreDeps })],
109+
},
110+
},
111+
});
112+
113+
expect(actual).toEqual({ ignoreDeps });
114+
});
115+
116+
it("returns ignoreDeps when .github/renovate.json contains ignoreDeps and other data", () => {
117+
const ignoreDeps = ["all-contributors-cli", "codecov/codecov-action"];
118+
119+
const actual = testIntake(blockRenovate, {
120+
files: {
121+
".github": {
122+
"renovate.json": [
123+
JSON.stringify({
124+
ignoreDeps,
125+
other: true,
126+
}),
127+
],
128+
},
129+
},
130+
});
131+
132+
expect(actual).toEqual({ ignoreDeps });
133+
});
134+
});
135+
});

src/blocks/blockRenovate.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1+
import { z } from "zod";
2+
13
import { base } from "../base.js";
24
import { blockGitHubApps } from "./blockGitHubApps.js";
5+
import { intakeFileAsJson } from "./intake/intakeFileAsJson.js";
6+
7+
const zIgnoreDeps = z.array(z.string()).default([]);
38

49
export const blockRenovate = base.createBlock({
510
about: {
611
name: "Renovate",
712
},
8-
produce() {
13+
addons: {
14+
ignoreDeps: zIgnoreDeps,
15+
},
16+
intake({ files }) {
17+
const raw = intakeFileAsJson(files, [".github", "renovate.json"]);
18+
19+
return {
20+
ignoreDeps: zIgnoreDeps.safeParse(raw?.ignoreDeps).data,
21+
};
22+
},
23+
produce({ addons }) {
24+
const { ignoreDeps } = addons;
25+
926
return {
1027
addons: [
1128
blockGitHubApps({
@@ -27,7 +44,9 @@ export const blockRenovate = base.createBlock({
2744
"config:best-practices",
2845
"replacements:all",
2946
],
30-
ignoreDeps: ["codecov/codecov-action"],
47+
ignoreDeps: Array.from(
48+
new Set(["codecov/codecov-action", ...ignoreDeps]),
49+
).sort(),
3150
labels: ["dependencies"],
3251
minimumReleaseAge: "7 days",
3352
patch: { enabled: false },

src/blocks/blockTypeScript.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,5 +693,22 @@ describe("blockTypeScript", () => {
693693

694694
expect(actual).toEqual({ compilerOptions });
695695
});
696+
697+
it("returns compilerOptions when tsconfig.json contains compilerOptions and other data", () => {
698+
const compilerOptions = { module: "ESNext" };
699+
700+
const actual = testIntake(blockTypeScript, {
701+
files: {
702+
"tsconfig.json": [
703+
JSON.stringify({
704+
compilerOptions,
705+
other: true,
706+
}),
707+
],
708+
},
709+
});
710+
711+
expect(actual).toEqual({ compilerOptions });
712+
});
696713
});
697714
});

src/blocks/blockTypeScript.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import JSON5 from "json5";
21
import sortKeys from "sort-keys";
32
import { CompilerOptionsSchema } from "zod-tsconfig";
43

@@ -15,7 +14,7 @@ import { blockPackageJson } from "./blockPackageJson.js";
1514
import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js";
1615
import { blockVitest } from "./blockVitest.js";
1716
import { blockVSCode } from "./blockVSCode.js";
18-
import { intakeFile } from "./intake/intakeFile.js";
17+
import { intakeFileAsJson } from "./intake/intakeFileAsJson.js";
1918

2019
export const blockTypeScript = base.createBlock({
2120
about: {
@@ -25,12 +24,7 @@ export const blockTypeScript = base.createBlock({
2524
compilerOptions: CompilerOptionsSchema.optional(),
2625
},
2726
intake({ files }) {
28-
const tsconfig = intakeFile(files, ["tsconfig.json"]);
29-
if (!tsconfig) {
30-
return undefined;
31-
}
32-
33-
const raw = JSON5.parse<Record<string, undefined> | undefined>(tsconfig[0]);
27+
const raw = intakeFileAsJson(files, ["tsconfig.json"]);
3428
const { data } = CompilerOptionsSchema.safeParse(raw?.compilerOptions);
3529
if (!data) {
3630
return undefined;

0 commit comments

Comments
 (0)