From d5803aae759544685abbcd4eab6ec5cd1f454c99 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 26 Mar 2025 09:50:16 -0400 Subject: [PATCH 1/2] feat: assorted transition mode removals --- src/blocks/blockCSpell.test.ts | 16 ----- src/blocks/blockCSpell.ts | 11 +++- src/blocks/blockESLint.test.ts | 25 +++----- src/blocks/blockESLint.ts | 5 +- src/blocks/blockESLintPackageJson.test.ts | 17 ------ src/blocks/blockESLintPackageJson.ts | 18 ++++-- src/blocks/blockGitHubActionsCI.ts | 12 +--- src/blocks/blockKnip.test.ts | 21 +++---- src/blocks/blockKnip.ts | 5 +- src/blocks/blockMarkdownlint.test.ts | 12 ---- src/blocks/blockMarkdownlint.ts | 21 +++++-- src/blocks/blockPnpmDedupe.test.ts | 3 - src/blocks/blockPnpmDedupe.ts | 11 +++- src/blocks/blockPrettier.test.ts | 30 ++++++---- src/blocks/blockPrettier.ts | 9 ++- src/blocks/blockRemoveWorkflows.test.ts | 73 +++++++++++++++++++++++ src/blocks/blockRemoveWorkflows.ts | 31 ++++++++++ src/blocks/blockTSup.test.ts | 23 ++++--- src/blocks/blockTSup.ts | 12 +++- src/blocks/blockTypeScript.test.ts | 6 -- src/blocks/blockTypeScript.ts | 11 +++- src/blocks/blockVitest.test.ts | 18 +++--- src/blocks/blockVitest.ts | 6 +- src/presets/minimal.ts | 2 + 24 files changed, 254 insertions(+), 144 deletions(-) create mode 100644 src/blocks/blockRemoveWorkflows.test.ts create mode 100644 src/blocks/blockRemoveWorkflows.ts diff --git a/src/blocks/blockCSpell.test.ts b/src/blocks/blockCSpell.test.ts index 24ac7df7d..6cd71f034 100644 --- a/src/blocks/blockCSpell.test.ts +++ b/src/blocks/blockCSpell.test.ts @@ -51,10 +51,6 @@ describe("blockCSpell", () => { ], }, ], - "removedWorkflows": [ - "lint-spelling", - "spelling", - ], }, "block": [Function], }, @@ -125,10 +121,6 @@ describe("blockCSpell", () => { ], }, ], - "removedWorkflows": [ - "lint-spelling", - "spelling", - ], }, "block": [Function], }, @@ -198,10 +190,6 @@ describe("blockCSpell", () => { ], }, ], - "removedWorkflows": [ - "lint-spelling", - "spelling", - ], }, "block": [Function], }, @@ -269,10 +257,6 @@ describe("blockCSpell", () => { ], }, ], - "removedWorkflows": [ - "lint-spelling", - "spelling", - ], }, "block": [Function], }, diff --git a/src/blocks/blockCSpell.ts b/src/blocks/blockCSpell.ts index 0ff52800c..767069897 100644 --- a/src/blocks/blockCSpell.ts +++ b/src/blocks/blockCSpell.ts @@ -7,6 +7,7 @@ import { resolveBin } from "../utils/resolveBin.js"; import { blockDevelopmentDocs } from "./blockDevelopmentDocs.js"; import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js"; import { blockPackageJson } from "./blockPackageJson.js"; +import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js"; import { blockVSCode } from "./blockVSCode.js"; import { CommandPhase } from "./phases.js"; @@ -50,7 +51,6 @@ export const blockCSpell = base.createBlock({ steps: [{ run: "pnpm lint:spelling" }], }, ], - removedWorkflows: ["lint-spelling", "spelling"], }), blockPackageJson({ properties: { @@ -93,4 +93,13 @@ export const blockCSpell = base.createBlock({ ], }; }, + transition() { + return { + addons: [ + blockRemoveWorkflows({ + workflows: ["lint-spelling", "spelling"], + }), + ], + }; + }, }); diff --git a/src/blocks/blockESLint.test.ts b/src/blocks/blockESLint.test.ts index 681288921..b5100cbd9 100644 --- a/src/blocks/blockESLint.test.ts +++ b/src/blocks/blockESLint.test.ts @@ -61,10 +61,6 @@ describe("blockESLint", () => { ], }, ], - "removedWorkflows": [ - "eslint", - "lint", - ], }, "block": [Function], }, @@ -194,10 +190,6 @@ describe("blockESLint", () => { ], }, ], - "removedWorkflows": [ - "eslint", - "lint", - ], }, "block": [Function], }, @@ -271,6 +263,15 @@ describe("blockESLint", () => { }, "block": [Function], }, + { + "addons": { + "workflows": [ + "eslint", + "lint", + ], + }, + "block": [Function], + }, ], "files": { "eslint.config.js": "import eslint from "@eslint/js"; @@ -388,10 +389,6 @@ describe("blockESLint", () => { ], }, ], - "removedWorkflows": [ - "eslint", - "lint", - ], }, "block": [Function], }, @@ -538,10 +535,6 @@ describe("blockESLint", () => { ], }, ], - "removedWorkflows": [ - "eslint", - "lint", - ], }, "block": [Function], }, diff --git a/src/blocks/blockESLint.ts b/src/blocks/blockESLint.ts index 3cd51ec07..215f374e1 100644 --- a/src/blocks/blockESLint.ts +++ b/src/blocks/blockESLint.ts @@ -11,6 +11,7 @@ import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js"; import { blockPackageJson } from "./blockPackageJson.js"; import { blockRemoveDependencies } from "./blockRemoveDependencies.js"; import { blockRemoveFiles } from "./blockRemoveFiles.js"; +import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js"; import { blockVSCode } from "./blockVSCode.js"; import { CommandPhase } from "./phases.js"; @@ -161,7 +162,6 @@ Each should be shown in VS Code, and can be run manually on the command-line: ], }, ], - removedWorkflows: ["eslint", "lint"], }), blockPackageJson({ properties: { @@ -239,6 +239,9 @@ export default tseslint.config( blockRemoveFiles({ files: [".eslintrc*", ".eslintignore", "eslint.config.{cjs,mjs}"], }), + blockRemoveWorkflows({ + workflows: ["eslint", "lint"], + }), ], }; }, diff --git a/src/blocks/blockESLintPackageJson.test.ts b/src/blocks/blockESLintPackageJson.test.ts index 9635e800f..e17bbc9f6 100644 --- a/src/blocks/blockESLintPackageJson.test.ts +++ b/src/blocks/blockESLintPackageJson.test.ts @@ -27,14 +27,6 @@ describe("blockESLintPackageJson", () => { }, "block": [Function], }, - { - "addons": { - "removedWorkflows": [ - "lint-package-json", - ], - }, - "block": [Function], - }, { "addons": { "properties": { @@ -45,15 +37,6 @@ describe("blockESLintPackageJson", () => { }, "block": [Function], }, - { - "addons": { - "dependencies": [ - "npm-package-json-lint", - "npm-package-json-lint-config-default", - ], - }, - "block": [Function], - }, ], } `); diff --git a/src/blocks/blockESLintPackageJson.ts b/src/blocks/blockESLintPackageJson.ts index 94c91916e..c21426067 100644 --- a/src/blocks/blockESLintPackageJson.ts +++ b/src/blocks/blockESLintPackageJson.ts @@ -1,8 +1,9 @@ import { base } from "../base.js"; import { blockESLint } from "./blockESLint.js"; -import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js"; import { blockPackageJson } from "./blockPackageJson.js"; import { blockRemoveDependencies } from "./blockRemoveDependencies.js"; +import { blockRemoveFiles } from "./blockRemoveFiles.js"; +import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js"; export const blockESLintPackageJson = base.createBlock({ about: { @@ -20,9 +21,6 @@ export const blockESLintPackageJson = base.createBlock({ }, ], }), - blockGitHubActionsCI({ - removedWorkflows: ["lint-package-json"], - }), blockPackageJson({ properties: { scripts: { @@ -30,12 +28,24 @@ export const blockESLintPackageJson = base.createBlock({ }, }, }), + ], + }; + }, + transition() { + return { + addons: [ + blockRemoveFiles({ + files: [".npmpackagejsonlintrc*"], + }), blockRemoveDependencies({ dependencies: [ "npm-package-json-lint", "npm-package-json-lint-config-default", ], }), + blockRemoveWorkflows({ + workflows: ["lint-package-json"], + }), ], }; }, diff --git a/src/blocks/blockGitHubActionsCI.ts b/src/blocks/blockGitHubActionsCI.ts index 6aa5985d3..e4c1bd218 100644 --- a/src/blocks/blockGitHubActionsCI.ts +++ b/src/blocks/blockGitHubActionsCI.ts @@ -32,7 +32,6 @@ export const blockGitHubActionsCI = base.createBlock({ }), ) .optional(), - removedWorkflows: z.array(z.string()).optional(), }, produce({ addons, options }) { const { jobs } = addons; @@ -145,18 +144,11 @@ export const blockGitHubActionsCI = base.createBlock({ }, }; }, - transition({ addons }) { - const { removedWorkflows = [] } = addons; + transition() { return { addons: [ blockRemoveFiles({ - files: [ - ".circleci", - "travis.yml", - ...removedWorkflows.map( - (removedWorkflow) => `.github/workflows/${removedWorkflow}.yml`, - ), - ], + files: [".circleci", "travis.yml"], }), ], }; diff --git a/src/blocks/blockKnip.test.ts b/src/blocks/blockKnip.test.ts index 1236c8c34..1403c4d58 100644 --- a/src/blocks/blockKnip.test.ts +++ b/src/blocks/blockKnip.test.ts @@ -43,10 +43,6 @@ describe("blockKnip", () => { ], }, ], - "removedWorkflows": [ - "knip", - "lint-knip", - ], }, "block": [Function], }, @@ -108,10 +104,6 @@ describe("blockKnip", () => { ], }, ], - "removedWorkflows": [ - "knip", - "lint-knip", - ], }, "block": [Function], }, @@ -171,10 +163,6 @@ describe("blockKnip", () => { ], }, ], - "removedWorkflows": [ - "knip", - "lint-knip", - ], }, "block": [Function], }, @@ -202,6 +190,15 @@ describe("blockKnip", () => { }, "block": [Function], }, + { + "addons": { + "workflows": [ + "knip", + "lint-knip", + ], + }, + "block": [Function], + }, ], "files": { "knip.json": "{"$schema":"https://unpkg.com/knip@5.46.0/schema.json","entry":["src/index.ts","src/**/*.test.*"],"ignoreExportsUsedInFile":{"interface":true,"type":true},"project":["src/**/*.ts"]}", diff --git a/src/blocks/blockKnip.ts b/src/blocks/blockKnip.ts index 30c66d2a4..87680d47b 100644 --- a/src/blocks/blockKnip.ts +++ b/src/blocks/blockKnip.ts @@ -9,6 +9,7 @@ import { blockDevelopmentDocs } from "./blockDevelopmentDocs.js"; import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js"; import { blockPackageJson } from "./blockPackageJson.js"; import { blockRemoveFiles } from "./blockRemoveFiles.js"; +import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js"; export const blockKnip = base.createBlock({ about: { @@ -39,7 +40,6 @@ export const blockKnip = base.createBlock({ steps: [{ run: "pnpm lint:knip" }], }, ], - removedWorkflows: ["knip", "lint-knip"], }), blockPackageJson({ properties: { @@ -70,6 +70,9 @@ export const blockKnip = base.createBlock({ blockRemoveFiles({ files: [".knip*", "knip.{c,m,t}*", "knip.js", "knip.jsonc"], }), + blockRemoveWorkflows({ + workflows: ["knip", "lint-knip"], + }), ], }; }, diff --git a/src/blocks/blockMarkdownlint.test.ts b/src/blocks/blockMarkdownlint.test.ts index fd8e64e3e..4355986a6 100644 --- a/src/blocks/blockMarkdownlint.test.ts +++ b/src/blocks/blockMarkdownlint.test.ts @@ -47,12 +47,6 @@ describe("blockMarkdownlint", () => { ], }, ], - "removedWorkflows": [ - "lint-md", - "lint-markdown", - "lint-markdownlint", - "markdownlint", - ], }, "block": [Function], }, @@ -144,12 +138,6 @@ describe("blockMarkdownlint", () => { ], }, ], - "removedWorkflows": [ - "lint-md", - "lint-markdown", - "lint-markdownlint", - "markdownlint", - ], }, "block": [Function], }, diff --git a/src/blocks/blockMarkdownlint.ts b/src/blocks/blockMarkdownlint.ts index 17100a048..95e45ed9a 100644 --- a/src/blocks/blockMarkdownlint.ts +++ b/src/blocks/blockMarkdownlint.ts @@ -6,6 +6,7 @@ import { blockCSpell } from "./blockCSpell.js"; import { blockDevelopmentDocs } from "./blockDevelopmentDocs.js"; import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js"; import { blockPackageJson } from "./blockPackageJson.js"; +import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js"; import { blockVSCode } from "./blockVSCode.js"; import { formatIgnoreFile } from "./files/formatIgnoreFile.js"; import { CommandPhase } from "./phases.js"; @@ -43,12 +44,6 @@ export const blockMarkdownlint = base.createBlock({ steps: [{ run: "pnpm lint:md" }], }, ], - removedWorkflows: [ - "lint-md", - "lint-markdown", - "lint-markdownlint", - "markdownlint", - ], }), blockPackageJson({ properties: { @@ -90,4 +85,18 @@ export const blockMarkdownlint = base.createBlock({ ], }; }, + transition() { + return { + addons: [ + blockRemoveWorkflows({ + workflows: [ + "lint-md", + "lint-markdown", + "lint-markdownlint", + "markdownlint", + ], + }), + ], + }; + }, }); diff --git a/src/blocks/blockPnpmDedupe.test.ts b/src/blocks/blockPnpmDedupe.test.ts index 1c8855e3e..4fcb06d45 100644 --- a/src/blocks/blockPnpmDedupe.test.ts +++ b/src/blocks/blockPnpmDedupe.test.ts @@ -39,9 +39,6 @@ describe("blockPnpmDedupe", () => { ], }, ], - "removedWorkflows": [ - "lint-packages", - ], }, "block": [Function], }, diff --git a/src/blocks/blockPnpmDedupe.ts b/src/blocks/blockPnpmDedupe.ts index 033f67368..ba785dda4 100644 --- a/src/blocks/blockPnpmDedupe.ts +++ b/src/blocks/blockPnpmDedupe.ts @@ -2,6 +2,7 @@ import { base } from "../base.js"; import { blockDevelopmentDocs } from "./blockDevelopmentDocs.js"; import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js"; import { blockPackageJson } from "./blockPackageJson.js"; +import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js"; export const blockPnpmDedupe = base.createBlock({ about: { @@ -28,7 +29,6 @@ export const blockPnpmDedupe = base.createBlock({ steps: [{ run: "pnpm lint:packages" }], }, ], - removedWorkflows: ["lint-packages"], }), blockPackageJson({ cleanupCommands: ["pnpm dedupe"], @@ -41,4 +41,13 @@ export const blockPnpmDedupe = base.createBlock({ ], }; }, + transition() { + return { + addons: [ + blockRemoveWorkflows({ + workflows: ["lint-packages"], + }), + ], + }; + }, }); diff --git a/src/blocks/blockPrettier.test.ts b/src/blocks/blockPrettier.test.ts index 49a612545..802722239 100644 --- a/src/blocks/blockPrettier.test.ts +++ b/src/blocks/blockPrettier.test.ts @@ -52,10 +52,6 @@ describe("blockPrettier", () => { ], }, ], - "removedWorkflows": [ - "format", - "prettier", - ], }, "block": [Function], }, @@ -168,10 +164,6 @@ describe("blockPrettier", () => { ], }, ], - "removedWorkflows": [ - "format", - "prettier", - ], }, "block": [Function], }, @@ -205,6 +197,15 @@ describe("blockPrettier", () => { }, "block": [Function], }, + { + "addons": { + "dependencies": [ + "eslint-config-prettier", + "eslint-plugin-prettier", + ], + }, + "block": [Function], + }, { "addons": { "files": [ @@ -214,6 +215,15 @@ describe("blockPrettier", () => { }, "block": [Function], }, + { + "addons": { + "workflows": [ + "format", + "prettier", + ], + }, + "block": [Function], + }, ], "files": { ".husky": { @@ -301,10 +311,6 @@ describe("blockPrettier", () => { ], }, ], - "removedWorkflows": [ - "format", - "prettier", - ], }, "block": [Function], }, diff --git a/src/blocks/blockPrettier.ts b/src/blocks/blockPrettier.ts index d0a9c6461..48f60a61e 100644 --- a/src/blocks/blockPrettier.ts +++ b/src/blocks/blockPrettier.ts @@ -6,7 +6,9 @@ import { blockCSpell } from "./blockCSpell.js"; import { blockDevelopmentDocs } from "./blockDevelopmentDocs.js"; import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js"; import { blockPackageJson } from "./blockPackageJson.js"; +import { blockRemoveDependencies } from "./blockRemoveDependencies.js"; import { blockRemoveFiles } from "./blockRemoveFiles.js"; +import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js"; import { blockVSCode } from "./blockVSCode.js"; import { formatIgnoreFile } from "./files/formatIgnoreFile.js"; import { CommandPhase } from "./phases.js"; @@ -60,7 +62,6 @@ pnpm format --write steps: [{ run: "pnpm format --list-different" }], }, ], - removedWorkflows: ["format", "prettier"], }), blockPackageJson({ properties: { @@ -110,9 +111,15 @@ pnpm format --write transition() { return { addons: [ + blockRemoveDependencies({ + dependencies: ["eslint-config-prettier", "eslint-plugin-prettier"], + }), blockRemoveFiles({ files: [".prettierrc.{c*,js,m*,t*}", "prettier.config*"], }), + blockRemoveWorkflows({ + workflows: ["format", "prettier"], + }), ], }; }, diff --git a/src/blocks/blockRemoveWorkflows.test.ts b/src/blocks/blockRemoveWorkflows.test.ts new file mode 100644 index 000000000..76808b783 --- /dev/null +++ b/src/blocks/blockRemoveWorkflows.test.ts @@ -0,0 +1,73 @@ +import { testBlock } from "bingo-stratum-testers"; +import { describe, expect, test, vi } from "vitest"; + +import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js"; +import { optionsBase } from "./options.fakes.js"; + +describe("blockRemoveWorkflows", () => { + test("without addons or mode", () => { + const creation = testBlock(blockRemoveWorkflows, { + options: optionsBase, + }); + + expect(creation).toMatchInlineSnapshot(`{}`); + }); + + test("with addons", () => { + const creation = testBlock(blockRemoveWorkflows, { + addons: { + workflows: ["a", "b", "c"], + }, + options: optionsBase, + }); + + expect(creation).toMatchInlineSnapshot(`{}`); + }); + + test("with mode", () => { + const creation = testBlock(blockRemoveWorkflows, { + mode: "transition", + options: optionsBase, + }); + + expect(creation).toMatchInlineSnapshot(` + { + "addons": [ + { + "addons": { + "files": undefined, + }, + "block": [Function], + }, + ], + } + `); + }); + + test("with addons and mode", () => { + const creation = testBlock(blockRemoveWorkflows, { + addons: { + workflows: ["a", "b", "c"], + }, + mode: "transition", + options: optionsBase, + }); + + expect(creation).toMatchInlineSnapshot(` + { + "addons": [ + { + "addons": { + "files": [ + ".github/workflows/a.yml", + ".github/workflows/b.yml", + ".github/workflows/c.yml", + ], + }, + "block": [Function], + }, + ], + } + `); + }); +}); diff --git a/src/blocks/blockRemoveWorkflows.ts b/src/blocks/blockRemoveWorkflows.ts new file mode 100644 index 000000000..0cc7daec8 --- /dev/null +++ b/src/blocks/blockRemoveWorkflows.ts @@ -0,0 +1,31 @@ +import { z } from "zod"; + +import { base } from "../base.js"; +import { blockRemoveFiles } from "./blockRemoveFiles.js"; + +export const blockRemoveWorkflows = base.createBlock({ + about: { + name: "Remove Workflows", + }, + addons: { + workflows: z.array(z.string()).optional(), + }, + // TODO: Make produce() optional, so this empty-ish produce() can be removed + // https://github.com/JoshuaKGoldberg/bingo/issues/295 + produce() { + return {}; + }, + transition({ addons }) { + const { workflows } = addons; + + return { + addons: [ + blockRemoveFiles({ + files: workflows?.map( + (workflow) => `.github/workflows/${workflow}.yml`, + ), + }), + ], + }; + }, +}); diff --git a/src/blocks/blockTSup.test.ts b/src/blocks/blockTSup.test.ts index 97589f4b7..e567b0d84 100644 --- a/src/blocks/blockTSup.test.ts +++ b/src/blocks/blockTSup.test.ts @@ -60,10 +60,6 @@ describe("blockTSup", () => { ], }, ], - "removedWorkflows": [ - "build", - "tsup", - ], }, "block": [Function], }, @@ -151,10 +147,6 @@ describe("blockTSup", () => { ], }, ], - "removedWorkflows": [ - "build", - "tsup", - ], }, "block": [Function], }, @@ -174,7 +166,9 @@ describe("blockTSup", () => { { "addons": { "dependencies": [ + "@babel/cli", "@babel/core", + "@babel/preset-typescript", "babel", ], }, @@ -191,6 +185,15 @@ describe("blockTSup", () => { }, "block": [Function], }, + { + "addons": { + "workflows": [ + "build", + "tsup", + ], + }, + "block": [Function], + }, ], "files": { "tsup.config.ts": "import { defineConfig } from "tsup"; @@ -263,10 +266,6 @@ describe("blockTSup", () => { ], }, ], - "removedWorkflows": [ - "build", - "tsup", - ], }, "block": [Function], }, diff --git a/src/blocks/blockTSup.ts b/src/blocks/blockTSup.ts index 320be2347..8c0625519 100644 --- a/src/blocks/blockTSup.ts +++ b/src/blocks/blockTSup.ts @@ -8,6 +8,7 @@ import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js"; import { blockPackageJson } from "./blockPackageJson.js"; import { blockRemoveDependencies } from "./blockRemoveDependencies.js"; import { blockRemoveFiles } from "./blockRemoveFiles.js"; +import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js"; import { CommandPhase } from "./phases.js"; export const blockTSup = base.createBlock({ @@ -57,7 +58,6 @@ pnpm build --watch ], }, ], - removedWorkflows: ["build", "tsup"], }), blockPackageJson({ properties: { @@ -95,11 +95,19 @@ export default defineConfig({ return { addons: [ blockRemoveDependencies({ - dependencies: ["@babel/core", "babel"], + dependencies: [ + "@babel/cli", + "@babel/core", + "@babel/preset-typescript", + "babel", + ], }), blockRemoveFiles({ files: [".babelrc*", "babel.config.*", "dist", "lib"], }), + blockRemoveWorkflows({ + workflows: ["build", "tsup"], + }), ], }; }, diff --git a/src/blocks/blockTypeScript.test.ts b/src/blocks/blockTypeScript.test.ts index 6fbd81f60..6466d48f2 100644 --- a/src/blocks/blockTypeScript.test.ts +++ b/src/blocks/blockTypeScript.test.ts @@ -87,9 +87,6 @@ describe("blockTypeScript", () => { ], }, ], - "removedWorkflows": [ - "tsc", - ], }, "block": [Function], }, @@ -241,9 +238,6 @@ describe("blockTypeScript", () => { ], }, ], - "removedWorkflows": [ - "tsc", - ], }, "block": [Function], }, diff --git a/src/blocks/blockTypeScript.ts b/src/blocks/blockTypeScript.ts index 12c660f79..3a14fed74 100644 --- a/src/blocks/blockTypeScript.ts +++ b/src/blocks/blockTypeScript.ts @@ -6,6 +6,7 @@ import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js"; import { blockGitignore } from "./blockGitignore.js"; import { blockMarkdownlint } from "./blockMarkdownlint.js"; import { blockPackageJson } from "./blockPackageJson.js"; +import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js"; import { blockVitest } from "./blockVitest.js"; import { blockVSCode } from "./blockVSCode.js"; @@ -69,7 +70,6 @@ export * from "./types.js"; }), blockGitHubActionsCI({ jobs: [{ name: "Type Check", steps: [{ run: "pnpm tsc" }] }], - removedWorkflows: ["tsc"], }), blockMarkdownlint({ ignores: ["lib/"], @@ -130,4 +130,13 @@ export * from "./types.js"; }, }; }, + transition() { + return { + addons: [ + blockRemoveWorkflows({ + workflows: ["tsc"], + }), + ], + }; + }, }); diff --git a/src/blocks/blockVitest.test.ts b/src/blocks/blockVitest.test.ts index 456d54069..07786753f 100644 --- a/src/blocks/blockVitest.test.ts +++ b/src/blocks/blockVitest.test.ts @@ -162,9 +162,6 @@ describe("blockVitest", () => { ], }, ], - "removedWorkflows": [ - "test", - ], }, "block": [Function], }, @@ -403,9 +400,6 @@ describe("blockVitest", () => { ], }, ], - "removedWorkflows": [ - "test", - ], }, "block": [Function], }, @@ -471,6 +465,7 @@ describe("blockVitest", () => { { "addons": { "dependencies": [ + "@vitest/coverage-istanbul", "eslint-plugin-jest", "eslint-plugin-mocha", "eslint-plugin-vitest", @@ -489,6 +484,14 @@ describe("blockVitest", () => { }, "block": [Function], }, + { + "addons": { + "workflows": [ + "test", + ], + }, + "block": [Function], + }, ], "files": { "vitest.config.ts": "import { defineConfig } from "vitest/config"; @@ -671,9 +674,6 @@ describe("blockVitest", () => { ], }, ], - "removedWorkflows": [ - "test", - ], }, "block": [Function], }, diff --git a/src/blocks/blockVitest.ts b/src/blocks/blockVitest.ts index ba69f9b56..a81024e53 100644 --- a/src/blocks/blockVitest.ts +++ b/src/blocks/blockVitest.ts @@ -12,6 +12,7 @@ import { blockPackageJson } from "./blockPackageJson.js"; import { blockPrettier } from "./blockPrettier.js"; import { blockRemoveDependencies } from "./blockRemoveDependencies.js"; import { blockRemoveFiles } from "./blockRemoveFiles.js"; +import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js"; import { blockTSup } from "./blockTSup.js"; import { blockVSCode } from "./blockVSCode.js"; @@ -142,7 +143,6 @@ describe(greet, () => { steps: [{ run: "pnpm run test --coverage" }, ...actionSteps], }, ], - removedWorkflows: ["test"], }), blockPackageJson({ properties: { @@ -209,6 +209,7 @@ export default defineConfig({ addons: [ blockRemoveDependencies({ dependencies: [ + "@vitest/coverage-istanbul", "eslint-plugin-jest", "eslint-plugin-mocha", "eslint-plugin-vitest", @@ -218,6 +219,9 @@ export default defineConfig({ blockRemoveFiles({ files: [".mocha*", "jest.config.*", "vitest.config.{c,j,m}*"], }), + blockRemoveWorkflows({ + workflows: ["test"], + }), ], }; }, diff --git a/src/presets/minimal.ts b/src/presets/minimal.ts index 38d5eeada..233bf082f 100644 --- a/src/presets/minimal.ts +++ b/src/presets/minimal.ts @@ -15,6 +15,7 @@ import { blockPrettier } from "../blocks/blockPrettier.js"; import { blockREADME } from "../blocks/blockREADME.js"; import { blockRemoveDependencies } from "../blocks/blockRemoveDependencies.js"; import { blockRemoveFiles } from "../blocks/blockRemoveFiles.js"; +import { blockRemoveWorkflows } from "../blocks/blockRemoveWorkflows.js"; import { blockRepositoryBranchRuleset } from "../blocks/blockRepositoryBranchRuleset.js"; import { blockRepositoryLabels } from "../blocks/blockRepositoryLabels.js"; import { blockRepositorySecrets } from "../blocks/blockRepositorySecrets.js"; @@ -47,6 +48,7 @@ export const presetMinimal = base.createPreset({ blockREADME, blockRemoveDependencies, blockRemoveFiles, + blockRemoveWorkflows, blockRepositoryBranchRuleset, blockRepositoryLabels, blockRepositorySecrets, From 33a6fd993efee29c1472060db88e48d734a7ae7e Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 26 Mar 2025 10:08:42 -0400 Subject: [PATCH 2/2] lint and test --- src/blocks/blockCSpell.test.ts | 76 +++++++++++ src/blocks/blockESLintPackageJson.test.ts | 65 ++++++++- src/blocks/blockMarkdownlint.test.ts | 102 +++++++++++++- src/blocks/blockPnpmDedupe.test.ts | 66 ++++++++- src/blocks/blockRemoveWorkflows.test.ts | 2 +- src/blocks/blockTypeScript.test.ts | 157 ++++++++++++++++++++++ 6 files changed, 464 insertions(+), 4 deletions(-) diff --git a/src/blocks/blockCSpell.test.ts b/src/blocks/blockCSpell.test.ts index 6cd71f034..b6c9a1724 100644 --- a/src/blocks/blockCSpell.test.ts +++ b/src/blocks/blockCSpell.test.ts @@ -288,4 +288,80 @@ describe("blockCSpell", () => { } `); }); + + test("transition mode", () => { + const creation = testBlock(blockCSpell, { + mode: "transition", + options: optionsBase, + }); + + expect(creation).toMatchInlineSnapshot(` + { + "addons": [ + { + "addons": { + "sections": { + "Linting": { + "contents": { + "items": [ + "- \`pnpm lint:spelling\` ([cspell](https://cspell.org)): Spell checks across all source files", + ], + }, + }, + }, + }, + "block": [Function], + }, + { + "addons": { + "extensions": [ + "streetsidesoftware.code-spell-checker", + ], + }, + "block": [Function], + }, + { + "addons": { + "jobs": [ + { + "name": "Lint Spelling", + "steps": [ + { + "run": "pnpm lint:spelling", + }, + ], + }, + ], + }, + "block": [Function], + }, + { + "addons": { + "properties": { + "devDependencies": { + "cspell": "8.17.5", + }, + "scripts": { + "lint:spelling": "cspell "**" ".github/**/*"", + }, + }, + }, + "block": [Function], + }, + { + "addons": { + "workflows": [ + "lint-spelling", + "spelling", + ], + }, + "block": [Function], + }, + ], + "files": { + "cspell.json": "{"dictionaries":["npm","node","typescript"],"ignorePaths":[".github","CHANGELOG.md","lib","node_modules","pnpm-lock.yaml"]}", + }, + } + `); + }); }); diff --git a/src/blocks/blockESLintPackageJson.test.ts b/src/blocks/blockESLintPackageJson.test.ts index e17bbc9f6..541788ae7 100644 --- a/src/blocks/blockESLintPackageJson.test.ts +++ b/src/blocks/blockESLintPackageJson.test.ts @@ -5,7 +5,7 @@ import { blockESLintPackageJson } from "./blockESLintPackageJson.js"; import { optionsBase } from "./options.fakes.js"; describe("blockESLintPackageJson", () => { - test("production", () => { + test("without mode", () => { const creation = testBlock(blockESLintPackageJson, { options: optionsBase, }); @@ -41,4 +41,67 @@ describe("blockESLintPackageJson", () => { } `); }); + + test("transition mode", () => { + const creation = testBlock(blockESLintPackageJson, { + mode: "transition", + options: optionsBase, + }); + + expect(creation).toMatchInlineSnapshot(` + { + "addons": [ + { + "addons": { + "extensions": [ + "packageJson.configs.recommended", + ], + "imports": [ + { + "source": "eslint-plugin-package-json", + "specifier": "packageJson", + }, + ], + }, + "block": [Function], + }, + { + "addons": { + "properties": { + "scripts": { + "lint:package-json": undefined, + }, + }, + }, + "block": [Function], + }, + { + "addons": { + "files": [ + ".npmpackagejsonlintrc*", + ], + }, + "block": [Function], + }, + { + "addons": { + "dependencies": [ + "npm-package-json-lint", + "npm-package-json-lint-config-default", + ], + }, + "block": [Function], + }, + { + "addons": { + "workflows": [ + "lint-package-json", + ], + }, + "block": [Function], + }, + ], + } + `); + }); }); diff --git a/src/blocks/blockMarkdownlint.test.ts b/src/blocks/blockMarkdownlint.test.ts index 4355986a6..2b5777933 100644 --- a/src/blocks/blockMarkdownlint.test.ts +++ b/src/blocks/blockMarkdownlint.test.ts @@ -5,7 +5,7 @@ import { blockMarkdownlint } from "./blockMarkdownlint.js"; import { optionsBase } from "./options.fakes.js"; describe("blockMarkdownlint", () => { - test("without addons", () => { + test("without addons or mode", () => { const creation = testBlock(blockMarkdownlint, { options: optionsBase, }); @@ -184,4 +184,104 @@ describe("blockMarkdownlint", () => { } `); }); + + test("transition mode", () => { + const creation = testBlock(blockMarkdownlint, { + mode: "transition", + options: optionsBase, + }); + + expect(creation).toMatchInlineSnapshot(` + { + "addons": [ + { + "addons": { + "words": [ + "markdownlintignore", + ], + }, + "block": [Function], + }, + { + "addons": { + "sections": { + "Linting": { + "contents": { + "items": [ + "- \`pnpm lint:md\` ([Markdownlint](https://github.com/DavidAnson/markdownlint)): Checks Markdown source files", + ], + }, + }, + }, + }, + "block": [Function], + }, + { + "addons": { + "jobs": [ + { + "name": "Lint Markdown", + "steps": [ + { + "run": "pnpm lint:md", + }, + ], + }, + ], + }, + "block": [Function], + }, + { + "addons": { + "properties": { + "devDependencies": { + "markdownlint": "0.37.4", + "markdownlint-cli": "0.44.0", + "sentences-per-line": "0.3.0", + }, + "scripts": { + "lint:md": "markdownlint "**/*.md" ".github/**/*.md" --rules sentences-per-line", + }, + }, + }, + "block": [Function], + }, + { + "addons": { + "extensions": [ + "DavidAnson.vscode-markdownlint", + ], + }, + "block": [Function], + }, + { + "addons": { + "workflows": [ + "lint-md", + "lint-markdown", + "lint-markdownlint", + "markdownlint", + ], + }, + "block": [Function], + }, + ], + "files": { + ".markdownlint.json": "{"extends":"markdownlint/style/prettier","first-line-h1":false,"no-inline-html":false}", + ".markdownlintignore": ".github/CODE_OF_CONDUCT.md + CHANGELOG.md + node_modules/ + ", + }, + "scripts": [ + { + "commands": [ + "pnpm lint:md --fix", + ], + "phase": 3, + }, + ], + } + `); + }); }); diff --git a/src/blocks/blockPnpmDedupe.test.ts b/src/blocks/blockPnpmDedupe.test.ts index 4fcb06d45..8ecd957d1 100644 --- a/src/blocks/blockPnpmDedupe.test.ts +++ b/src/blocks/blockPnpmDedupe.test.ts @@ -5,7 +5,7 @@ import { blockPnpmDedupe } from "./blockPnpmDedupe.js"; import { optionsBase } from "./options.fakes.js"; describe("blockPnpmDedupe", () => { - test("production", () => { + test("without mode", () => { const creation = testBlock(blockPnpmDedupe, { options: optionsBase, }); @@ -59,4 +59,68 @@ describe("blockPnpmDedupe", () => { } `); }); + + test("transition mode", () => { + const creation = testBlock(blockPnpmDedupe, { + mode: "transition", + options: optionsBase, + }); + + expect(creation).toMatchInlineSnapshot(` + { + "addons": [ + { + "addons": { + "sections": { + "Linting": { + "contents": { + "items": [ + "- \`pnpm lint:packages\` ([pnpm dedupe --check](https://pnpm.io/cli/dedupe)): Checks for unnecessarily duplicated packages in the \`pnpm-lock.yml\` file", + ], + }, + }, + }, + }, + "block": [Function], + }, + { + "addons": { + "jobs": [ + { + "name": "Lint Packages", + "steps": [ + { + "run": "pnpm lint:packages", + }, + ], + }, + ], + }, + "block": [Function], + }, + { + "addons": { + "cleanupCommands": [ + "pnpm dedupe", + ], + "properties": { + "scripts": { + "lint:packages": "pnpm dedupe --check", + }, + }, + }, + "block": [Function], + }, + { + "addons": { + "workflows": [ + "lint-packages", + ], + }, + "block": [Function], + }, + ], + } + `); + }); }); diff --git a/src/blocks/blockRemoveWorkflows.test.ts b/src/blocks/blockRemoveWorkflows.test.ts index 76808b783..41978025f 100644 --- a/src/blocks/blockRemoveWorkflows.test.ts +++ b/src/blocks/blockRemoveWorkflows.test.ts @@ -1,5 +1,5 @@ import { testBlock } from "bingo-stratum-testers"; -import { describe, expect, test, vi } from "vitest"; +import { describe, expect, test } from "vitest"; import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js"; import { optionsBase } from "./options.fakes.js"; diff --git a/src/blocks/blockTypeScript.test.ts b/src/blocks/blockTypeScript.test.ts index 6466d48f2..62928b8fc 100644 --- a/src/blocks/blockTypeScript.test.ts +++ b/src/blocks/blockTypeScript.test.ts @@ -314,4 +314,161 @@ describe("blockTypeScript", () => { } `); }); + + test("transition mode", () => { + const creation = testBlock(blockTypeScript, { + mode: "transition", + options: optionsBase, + }); + + expect(creation).toMatchInlineSnapshot(` + { + "addons": [ + { + "addons": { + "sections": { + "Type Checking": { + "contents": " + You should be able to see suggestions from [TypeScript](https://typescriptlang.org) in your editor for all open files. + + However, it can be useful to run the TypeScript command-line (\`tsc\`) to type check all files in \`src/\`: + + \`\`\`shell + pnpm tsc + \`\`\` + + Add \`--watch\` to keep the type checker running in a watch mode that updates the display as you save files: + + \`\`\`shell + pnpm tsc --watch + \`\`\` + ", + }, + }, + }, + "block": [Function], + }, + { + "addons": { + "files": { + "greet.ts": "import { GreetOptions } from "./types.js"; + + export function greet(options: GreetOptions | string) { + const { + logger = console.log.bind(console), + message, + times = 1, + } = typeof options === "string" ? { message: options } : options; + + for (let i = 0; i < times; i += 1) { + logger(message); + } + } + ", + "index.ts": "export * from "./greet.js"; + export * from "./types.js"; + ", + "types.ts": "export interface GreetOptions { + logger?: (message: string) => void; + message: string; + times?: number; + } + ", + }, + }, + "block": [Function], + }, + { + "addons": { + "ignores": [ + "/lib", + ], + }, + "block": [Function], + }, + { + "addons": { + "jobs": [ + { + "name": "Type Check", + "steps": [ + { + "run": "pnpm tsc", + }, + ], + }, + ], + }, + "block": [Function], + }, + { + "addons": { + "ignores": [ + "lib/", + ], + }, + "block": [Function], + }, + { + "addons": { + "properties": { + "devDependencies": { + "typescript": "5.8.2", + }, + "files": [ + "lib/", + ], + "main": "lib/index.js", + "scripts": { + "tsc": "tsc", + }, + }, + }, + "block": [Function], + }, + { + "addons": { + "coverage": { + "include": [ + "src", + ], + }, + "exclude": [ + "lib", + ], + }, + "block": [Function], + }, + { + "addons": { + "debuggers": [], + "settings": { + "typescript.tsdk": "node_modules/typescript/lib", + }, + "tasks": [ + { + "detail": "Build the project", + "label": "build", + "script": "build", + "type": "npm", + }, + ], + }, + "block": [Function], + }, + { + "addons": { + "workflows": [ + "tsc", + ], + }, + "block": [Function], + }, + ], + "files": { + "tsconfig.json": "{"compilerOptions":{"declaration":true,"declarationMap":true,"esModuleInterop":true,"module":"NodeNext","moduleResolution":"NodeNext","noEmit":true,"resolveJsonModule":true,"skipLibCheck":true,"strict":true,"target":"ES2022"},"include":["src"]}", + }, + } + `); + }); });