Skip to content

Commit 813e48d

Browse files
feat: add entry addon for blockNcc (#2155)
## PR Checklist - [x] Addresses an existing open issue: fixes #2154 - [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 Includes bumps of `bingo-stratum` and `bingo-stratum-testers` so its `intake` can include `options` per bingo-js/bingo#345. 🎁
1 parent d0f4edd commit 813e48d

File tree

4 files changed

+220
-23
lines changed

4 files changed

+220
-23
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"dependencies": {
4040
"bingo": "^0.5.14",
4141
"bingo-fs": "^0.5.5",
42-
"bingo-stratum": "^0.5.10",
42+
"bingo-stratum": "^0.5.11",
4343
"cached-factory": "^0.1.0",
4444
"cspell-populate-words": "^0.3.0",
4545
"execa": "^9.5.2",
@@ -88,7 +88,7 @@
8888
"@vitest/eslint-plugin": "1.1.38",
8989
"all-contributors-cli": "6.26.1",
9090
"bingo-requests": "0.5.5",
91-
"bingo-stratum-testers": "0.5.8",
91+
"bingo-stratum-testers": "0.5.9",
9292
"bingo-testers": "0.5.7",
9393
"console-fail-test": "0.5.0",
9494
"cspell": "8.17.5",

pnpm-lock.yaml

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

src/blocks/blockNcc.test.ts

Lines changed: 186 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { testBlock } from "bingo-stratum-testers";
2-
import { describe, expect, test } from "vitest";
1+
import { testBlock, testIntake } from "bingo-stratum-testers";
2+
import { describe, expect, it, test } from "vitest";
33

44
import { blockNcc } from "./blockNcc.js";
55
import { optionsBase } from "./options.fakes.js";
66

77
describe("blockNcc", () => {
8-
test("production", () => {
8+
test("without addons", () => {
99
const creation = testBlock(blockNcc, {
1010
options: optionsBase,
1111
});
@@ -100,6 +100,72 @@ describe("blockNcc", () => {
100100
},
101101
"block": [Function],
102102
},
103+
{
104+
"addons": {
105+
"ignores": [
106+
"/dist",
107+
],
108+
},
109+
"block": [Function],
110+
},
111+
],
112+
}
113+
`);
114+
});
115+
116+
test("with addons", () => {
117+
const creation = testBlock(blockNcc, {
118+
addons: {
119+
entry: "src/action/index.ts",
120+
},
121+
options: optionsBase,
122+
});
123+
124+
expect(creation).toMatchInlineSnapshot(`
125+
{
126+
"addons": [
127+
{
128+
"addons": {
129+
"ignores": [
130+
"dist",
131+
],
132+
},
133+
"block": [Function],
134+
},
135+
{
136+
"addons": {
137+
"sections": {
138+
"Building": {
139+
"contents": "
140+
Run [TypeScript](https://typescriptlang.org) locally to type check and build source files from \`src/\` into output files in \`lib/\`:
141+
142+
\`\`\`shell
143+
pnpm build
144+
\`\`\`
145+
146+
Add \`--watch\` to run the builder in a watch mode that continuously cleans and recreates \`lib/\` as you save files:
147+
148+
\`\`\`shell
149+
pnpm build --watch
150+
\`\`\`
151+
",
152+
"innerSections": [
153+
{
154+
"contents": "
155+
Run [\`@vercel/ncc\`](https://github.com/vercel/ncc) to create an output \`dist/\` to be used in production.
156+
157+
\`\`\`shell
158+
pnpm build:release
159+
\`\`\`
160+
",
161+
"heading": "Building for Release",
162+
},
163+
],
164+
},
165+
},
166+
},
167+
"block": [Function],
168+
},
103169
{
104170
"addons": {
105171
"ignores": [
@@ -108,8 +174,125 @@ describe("blockNcc", () => {
108174
},
109175
"block": [Function],
110176
},
177+
{
178+
"addons": {
179+
"jobs": [
180+
{
181+
"name": "Build",
182+
"steps": [
183+
{
184+
"run": "pnpm build",
185+
},
186+
],
187+
},
188+
{
189+
"name": "Build (Release)",
190+
"steps": [
191+
{
192+
"run": "pnpm build:release",
193+
},
194+
],
195+
},
196+
],
197+
},
198+
"block": [Function],
199+
},
200+
{
201+
"addons": {
202+
"properties": {
203+
"devDependencies": {
204+
"@vercel/ncc": "^0.38.3",
205+
},
206+
"scripts": {
207+
"build": "tsc",
208+
"build:release": "ncc build src/action/index.ts -o dist",
209+
},
210+
},
211+
},
212+
"block": [Function],
213+
},
214+
{
215+
"addons": {
216+
"ignores": [
217+
"/dist",
218+
],
219+
},
220+
"block": [Function],
221+
},
111222
],
112223
}
113224
`);
114225
});
226+
227+
describe("intake", () => {
228+
it("returns an undefined entry when options.packageData does not exist", () => {
229+
const actual = testIntake(blockNcc, {
230+
files: {},
231+
options: {
232+
...optionsBase,
233+
packageData: undefined,
234+
},
235+
});
236+
237+
expect(actual).toEqual({ entry: undefined });
238+
});
239+
240+
it("returns an undefined entry when options.packageData does not contain scripts", () => {
241+
const actual = testIntake(blockNcc, {
242+
files: {},
243+
options: {
244+
...optionsBase,
245+
packageData: {},
246+
},
247+
});
248+
249+
expect(actual).toEqual({ entry: undefined });
250+
});
251+
252+
it("returns an undefined entry when options.packageData does not contain a build:release script", () => {
253+
const actual = testIntake(blockNcc, {
254+
files: {},
255+
options: {
256+
...optionsBase,
257+
packageData: {
258+
scripts: {},
259+
},
260+
},
261+
});
262+
263+
expect(actual).toEqual({ entry: undefined });
264+
});
265+
266+
it("returns an undefined entry when options.packageData contains an unrelated build:release script", () => {
267+
const actual = testIntake(blockNcc, {
268+
files: {},
269+
options: {
270+
...optionsBase,
271+
packageData: {
272+
scripts: {
273+
"build:release": "tsup",
274+
},
275+
},
276+
},
277+
});
278+
279+
expect(actual).toEqual({ entry: undefined });
280+
});
281+
282+
it("returns a parsed entry when options.packageData contains a matching build:release script", () => {
283+
const actual = testIntake(blockNcc, {
284+
files: {},
285+
options: {
286+
...optionsBase,
287+
packageData: {
288+
scripts: {
289+
"build:release": "ncc build src/action/index.ts -o dist",
290+
},
291+
},
292+
},
293+
});
294+
295+
expect(actual).toEqual({ entry: "src/action/index.ts" });
296+
});
297+
});
115298
});

src/blocks/blockNcc.ts

Lines changed: 17 additions & 3 deletions
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 { blockCSpell } from "./blockCSpell.js";
35
import { blockDevelopmentDocs } from "./blockDevelopmentDocs.js";
@@ -10,7 +12,19 @@ export const blockNcc = base.createBlock({
1012
about: {
1113
name: "ncc",
1214
},
13-
produce() {
15+
addons: {
16+
entry: z.string().optional(),
17+
},
18+
intake({ options }) {
19+
return {
20+
entry: options.packageData?.scripts?.["build:release"]?.match(
21+
/ncc build (.+) -o dist/,
22+
)?.[1],
23+
};
24+
},
25+
produce({ addons }) {
26+
const { entry = "src/index.ts" } = addons;
27+
1428
return {
1529
addons: [
1630
blockCSpell({
@@ -69,12 +83,12 @@ pnpm build:release
6983
},
7084
scripts: {
7185
build: "tsc",
72-
"build:release": "ncc build src/index.ts -o dist",
86+
"build:release": `ncc build ${entry} -o dist`,
7387
},
7488
},
7589
}),
7690
blockPrettier({
77-
ignores: ["dist"],
91+
ignores: ["/dist"],
7892
}),
7993
],
8094
};

0 commit comments

Comments
 (0)