Skip to content

Commit 308d44a

Browse files
authored
feat: debugging in vs code (#1153)
<!-- 👋 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 #1145 - [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 <!-- Description of what is changed and how the code change does that. --> This PR enables debugging by adding a `tasks.json` ```json { "version": "2.0.0", "tasks": [ { "type": "npm", "script": "build", "problemMatcher": [], "label": "build", "detail": "Build the project" } ] } ``` and the below configuration to the `launch.json`: ```json { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Debug Program", "skipFiles": ["<node_internals>/**"], "program": "lib/index.js", "preLaunchTask": "build" } ] } ``` Here's an example of debugging using it: ![screenshot of VS Code debugging](https://github.com/JoshuaKGoldberg/create-typescript-app/assets/1010525/09046b0e-16cc-4a3c-90ab-c81de044e17d)
1 parent 07c0abc commit 308d44a

File tree

4 files changed

+368
-18
lines changed

4 files changed

+368
-18
lines changed

.vscode/launch.json

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
"skipFiles": ["<node_internals>/**", "**/node_modules/**"],
1111
"smartStep": true,
1212
"type": "node"
13+
},
14+
{
15+
"name": "Debug Program",
16+
"preLaunchTask": "build",
17+
"program": "./bin/index.js",
18+
"request": "launch",
19+
"skipFiles": ["<node_internals>/**"],
20+
"type": "node"
1321
}
1422
],
1523
"version": "0.2.0"

.vscode/tasks.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"tasks": [
3+
{
4+
"detail": "Build the project",
5+
"label": "build",
6+
"script": "build",
7+
"type": "npm"
8+
}
9+
],
10+
"version": "2.0.0"
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import { Options } from "../../../shared/types.js";
4+
import { createDotVSCode } from "./dotVSCode.js";
5+
6+
/* spellchecker: disable */
7+
function fakeOptions(
8+
getExcludeValue: (exclusionName: string) => boolean,
9+
bin?: string | undefined,
10+
) {
11+
return {
12+
access: "public",
13+
author: "TestAuthor",
14+
base: "everything",
15+
...(bin ? { bin } : {}),
16+
description: "Test description.",
17+
directory: ".",
18+
email: {
19+
github: "[email protected]",
20+
21+
},
22+
...Object.fromEntries(
23+
[
24+
"excludeCompliance",
25+
"excludeAllContributors",
26+
"excludeLintDeprecation",
27+
"excludeLintESLint",
28+
"excludeLintJSDoc",
29+
"excludeLintJson",
30+
"excludeLintKnip",
31+
"excludeLintMd",
32+
"excludeLintPackageJson",
33+
"excludeLintPackages",
34+
"excludeLintPerfectionist",
35+
"excludeLintRegex",
36+
"excludeLintSpelling",
37+
"excludeLintStrict",
38+
"excludeLintStylistic",
39+
"excludeLintYml",
40+
"excludeReleases",
41+
"excludeRenovate",
42+
"excludeTests",
43+
].map((key) => [key, getExcludeValue(key)]),
44+
),
45+
mode: "create",
46+
owner: "TestOwner",
47+
repository: "test-repository",
48+
skipGitHubApi: true,
49+
skipInstall: true,
50+
skipRemoval: true,
51+
title: "Test Title",
52+
} satisfies Options;
53+
}
54+
55+
describe("createDotVSCode", () => {
56+
it("creates a minimal config when all exclusions are enabled", async () => {
57+
expect(await createDotVSCode(fakeOptions(() => true)))
58+
.toMatchInlineSnapshot(`
59+
{
60+
"extensions.json": "{
61+
"recommendations": [
62+
"DavidAnson.vscode-markdownlint",
63+
"dbaeumer.vscode-eslint",
64+
"esbenp.prettier-vscode"
65+
]
66+
}
67+
",
68+
"settings.json": "{
69+
"editor.codeActionsOnSave": { "source.fixAll.eslint": "explicit" },
70+
"editor.defaultFormatter": "esbenp.prettier-vscode",
71+
"editor.formatOnSave": true,
72+
"editor.rulers": [80],
73+
"eslint.probe": [
74+
"javascript",
75+
"javascriptreact",
76+
"json",
77+
"jsonc",
78+
"markdown",
79+
"typescript",
80+
"typescriptreact",
81+
"yaml"
82+
],
83+
"eslint.rules.customizations": [{ "rule": "*", "severity": "warn" }],
84+
"typescript.tsdk": "node_modules/typescript/lib"
85+
}
86+
",
87+
"tasks.json": "{
88+
"tasks": [
89+
{
90+
"detail": "Build the project",
91+
"label": "build",
92+
"script": "build",
93+
"type": "npm"
94+
}
95+
],
96+
"version": "2.0.0"
97+
}
98+
",
99+
}
100+
`);
101+
});
102+
103+
it("creates a full config when all exclusions are disabled and bin is provided", async () => {
104+
expect(await createDotVSCode(fakeOptions(() => false, "bin/index.js")))
105+
.toMatchInlineSnapshot(`
106+
{
107+
"extensions.json": "{
108+
"recommendations": [
109+
"DavidAnson.vscode-markdownlint",
110+
"dbaeumer.vscode-eslint",
111+
"esbenp.prettier-vscode",
112+
"streetsidesoftware.code-spell-checker"
113+
]
114+
}
115+
",
116+
"launch.json": "{
117+
"configurations": [
118+
{
119+
"args": ["run", "\${relativeFile}"],
120+
"autoAttachChildProcesses": true,
121+
"console": "integratedTerminal",
122+
"name": "Debug Current Test File",
123+
"program": "\${workspaceRoot}/node_modules/vitest/vitest.mjs",
124+
"request": "launch",
125+
"skipFiles": ["<node_internals>/**", "**/node_modules/**"],
126+
"smartStep": true,
127+
"type": "node"
128+
},
129+
{
130+
"name": "Debug Program",
131+
"preLaunchTask": "build",
132+
"program": "bin/index.js",
133+
"request": "launch",
134+
"skipFiles": ["<node_internals>/**"],
135+
"type": "node"
136+
}
137+
],
138+
"version": "0.2.0"
139+
}
140+
",
141+
"settings.json": "{
142+
"editor.codeActionsOnSave": { "source.fixAll.eslint": "explicit" },
143+
"editor.defaultFormatter": "esbenp.prettier-vscode",
144+
"editor.formatOnSave": true,
145+
"editor.rulers": [80],
146+
"eslint.probe": [
147+
"javascript",
148+
"javascriptreact",
149+
"json",
150+
"jsonc",
151+
"markdown",
152+
"typescript",
153+
"typescriptreact",
154+
"yaml"
155+
],
156+
"eslint.rules.customizations": [{ "rule": "*", "severity": "warn" }],
157+
"typescript.tsdk": "node_modules/typescript/lib"
158+
}
159+
",
160+
"tasks.json": "{
161+
"tasks": [
162+
{
163+
"detail": "Build the project",
164+
"label": "build",
165+
"script": "build",
166+
"type": "npm"
167+
}
168+
],
169+
"version": "2.0.0"
170+
}
171+
",
172+
}
173+
`);
174+
});
175+
176+
it("creates a full config when all exclusions are disabled and bin is not provided", async () => {
177+
expect(await createDotVSCode(fakeOptions(() => false)))
178+
.toMatchInlineSnapshot(`
179+
{
180+
"extensions.json": "{
181+
"recommendations": [
182+
"DavidAnson.vscode-markdownlint",
183+
"dbaeumer.vscode-eslint",
184+
"esbenp.prettier-vscode",
185+
"streetsidesoftware.code-spell-checker"
186+
]
187+
}
188+
",
189+
"launch.json": "{
190+
"configurations": [
191+
{
192+
"args": ["run", "\${relativeFile}"],
193+
"autoAttachChildProcesses": true,
194+
"console": "integratedTerminal",
195+
"name": "Debug Current Test File",
196+
"program": "\${workspaceRoot}/node_modules/vitest/vitest.mjs",
197+
"request": "launch",
198+
"skipFiles": ["<node_internals>/**", "**/node_modules/**"],
199+
"smartStep": true,
200+
"type": "node"
201+
}
202+
],
203+
"version": "0.2.0"
204+
}
205+
",
206+
"settings.json": "{
207+
"editor.codeActionsOnSave": { "source.fixAll.eslint": "explicit" },
208+
"editor.defaultFormatter": "esbenp.prettier-vscode",
209+
"editor.formatOnSave": true,
210+
"editor.rulers": [80],
211+
"eslint.probe": [
212+
"javascript",
213+
"javascriptreact",
214+
"json",
215+
"jsonc",
216+
"markdown",
217+
"typescript",
218+
"typescriptreact",
219+
"yaml"
220+
],
221+
"eslint.rules.customizations": [{ "rule": "*", "severity": "warn" }],
222+
"typescript.tsdk": "node_modules/typescript/lib"
223+
}
224+
",
225+
"tasks.json": "{
226+
"tasks": [
227+
{
228+
"detail": "Build the project",
229+
"label": "build",
230+
"script": "build",
231+
"type": "npm"
232+
}
233+
],
234+
"version": "2.0.0"
235+
}
236+
",
237+
}
238+
`);
239+
});
240+
241+
it("creates a minimal config including launch.json when all exclusions are enabled and bin is provided", async () => {
242+
expect(await createDotVSCode(fakeOptions(() => true, "bin/index.js")))
243+
.toMatchInlineSnapshot(`
244+
{
245+
"extensions.json": "{
246+
"recommendations": [
247+
"DavidAnson.vscode-markdownlint",
248+
"dbaeumer.vscode-eslint",
249+
"esbenp.prettier-vscode"
250+
]
251+
}
252+
",
253+
"launch.json": "{
254+
"configurations": [
255+
{
256+
"name": "Debug Program",
257+
"preLaunchTask": "build",
258+
"program": "bin/index.js",
259+
"request": "launch",
260+
"skipFiles": ["<node_internals>/**"],
261+
"type": "node"
262+
}
263+
],
264+
"version": "0.2.0"
265+
}
266+
",
267+
"settings.json": "{
268+
"editor.codeActionsOnSave": { "source.fixAll.eslint": "explicit" },
269+
"editor.defaultFormatter": "esbenp.prettier-vscode",
270+
"editor.formatOnSave": true,
271+
"editor.rulers": [80],
272+
"eslint.probe": [
273+
"javascript",
274+
"javascriptreact",
275+
"json",
276+
"jsonc",
277+
"markdown",
278+
"typescript",
279+
"typescriptreact",
280+
"yaml"
281+
],
282+
"eslint.rules.customizations": [{ "rule": "*", "severity": "warn" }],
283+
"typescript.tsdk": "node_modules/typescript/lib"
284+
}
285+
",
286+
"tasks.json": "{
287+
"tasks": [
288+
{
289+
"detail": "Build the project",
290+
"label": "build",
291+
"script": "build",
292+
"type": "npm"
293+
}
294+
],
295+
"version": "2.0.0"
296+
}
297+
",
298+
}
299+
`);
300+
});
301+
});

0 commit comments

Comments
 (0)