Skip to content

Commit f92166a

Browse files
feat: add addons.ignoreDependencies to blockKnip (#1863)
## PR Checklist - [x] Addresses an existing open issue: fixes #1851 - [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 💖
1 parent 772f34f commit f92166a

File tree

2 files changed

+138
-1
lines changed

2 files changed

+138
-1
lines changed

src/next/blocks/blockKnip.test.ts

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import { testBlock } from "create-testers";
2+
import { describe, expect, test, vi } from "vitest";
3+
4+
import { blockKnip } from "./blockKnip.js";
5+
import { optionsBase } from "./options.fakes.js";
6+
7+
vi.mock("../utils/resolveBin.js", () => ({
8+
resolveBin: (bin: string) => `path/to/${bin}`,
9+
}));
10+
11+
describe("blockKnip", () => {
12+
test("without addons", () => {
13+
const creation = testBlock(blockKnip, {
14+
options: optionsBase,
15+
});
16+
17+
expect(creation).toMatchInlineSnapshot(`
18+
{
19+
"addons": [
20+
{
21+
"addons": {
22+
"sections": {
23+
"Linting": {
24+
"contents": {
25+
"items": [
26+
"- \`pnpm lint:knip\` ([knip](https://github.com/webpro/knip)): Detects unused files, dependencies, and code exports",
27+
],
28+
},
29+
},
30+
},
31+
},
32+
"block": [Function],
33+
},
34+
{
35+
"addons": {
36+
"jobs": [
37+
{
38+
"name": "Lint Knip",
39+
"steps": [
40+
{
41+
"run": "pnpm lint:knip",
42+
},
43+
],
44+
},
45+
],
46+
},
47+
"block": [Function],
48+
},
49+
{
50+
"addons": {
51+
"properties": {
52+
"devDependencies": {
53+
"knip": "5.41.1",
54+
},
55+
"scripts": {
56+
"lint:knip": "knip",
57+
},
58+
},
59+
},
60+
"block": [Function],
61+
},
62+
],
63+
"files": {
64+
"knip.json": "{"$schema":"https://unpkg.com/[email protected]/schema.json","entry":["src/index.ts"],"ignoreExportsUsedInFile":{"interface":true,"type":true},"project":["src/**/*.ts"]}",
65+
},
66+
}
67+
`);
68+
});
69+
70+
test("with addons", () => {
71+
const creation = testBlock(blockKnip, {
72+
addons: {
73+
ignoreDependencies: ["abc", "def"],
74+
},
75+
options: optionsBase,
76+
});
77+
78+
expect(creation).toMatchInlineSnapshot(`
79+
{
80+
"addons": [
81+
{
82+
"addons": {
83+
"sections": {
84+
"Linting": {
85+
"contents": {
86+
"items": [
87+
"- \`pnpm lint:knip\` ([knip](https://github.com/webpro/knip)): Detects unused files, dependencies, and code exports",
88+
],
89+
},
90+
},
91+
},
92+
},
93+
"block": [Function],
94+
},
95+
{
96+
"addons": {
97+
"jobs": [
98+
{
99+
"name": "Lint Knip",
100+
"steps": [
101+
{
102+
"run": "pnpm lint:knip",
103+
},
104+
],
105+
},
106+
],
107+
},
108+
"block": [Function],
109+
},
110+
{
111+
"addons": {
112+
"properties": {
113+
"devDependencies": {
114+
"knip": "5.41.1",
115+
},
116+
"scripts": {
117+
"lint:knip": "knip",
118+
},
119+
},
120+
},
121+
"block": [Function],
122+
},
123+
],
124+
"files": {
125+
"knip.json": "{"$schema":"https://unpkg.com/[email protected]/schema.json","entry":["src/index.ts"],"ignoreDependencies":["abc","def"],"ignoreExportsUsedInFile":{"interface":true,"type":true},"project":["src/**/*.ts"]}",
126+
},
127+
}
128+
`);
129+
});
130+
});

src/next/blocks/blockKnip.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { z } from "zod";
2+
13
import { base } from "../base.js";
24
import { blockDevelopmentDocs } from "./blockDevelopmentDocs.js";
35
import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js";
@@ -9,6 +11,9 @@ export const blockKnip = base.createBlock({
911
about: {
1012
name: "Knip",
1113
},
14+
addons: {
15+
ignoreDependencies: z.array(z.string()).optional(),
16+
},
1217
migrate() {
1318
return {
1419
scripts: [
@@ -19,7 +24,8 @@ export const blockKnip = base.createBlock({
1924
],
2025
};
2126
},
22-
produce() {
27+
produce({ addons }) {
28+
const { ignoreDependencies } = addons;
2329
return {
2430
addons: [
2531
blockDevelopmentDocs({
@@ -54,6 +60,7 @@ export const blockKnip = base.createBlock({
5460
"knip.json": JSON.stringify({
5561
$schema: `https://unpkg.com/knip@${getPackageDependency("knip")}/schema.json`,
5662
entry: ["src/index.ts"],
63+
ignoreDependencies,
5764
ignoreExportsUsedInFile: {
5865
interface: true,
5966
type: true,

0 commit comments

Comments
 (0)