Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add entry addon for blockNcc #2155

Merged
merged 1 commit into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"dependencies": {
"bingo": "^0.5.14",
"bingo-fs": "^0.5.5",
"bingo-stratum": "^0.5.10",
"bingo-stratum": "^0.5.11",
"cached-factory": "^0.1.0",
"cspell-populate-words": "^0.3.0",
"execa": "^9.5.2",
Expand Down Expand Up @@ -88,7 +88,7 @@
"@vitest/eslint-plugin": "1.1.38",
"all-contributors-cli": "6.26.1",
"bingo-requests": "0.5.5",
"bingo-stratum-testers": "0.5.8",
"bingo-stratum-testers": "0.5.9",
"bingo-testers": "0.5.7",
"console-fail-test": "0.5.0",
"cspell": "8.17.5",
Expand Down
30 changes: 15 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

189 changes: 186 additions & 3 deletions src/blocks/blockNcc.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { testBlock } from "bingo-stratum-testers";
import { describe, expect, test } from "vitest";
import { testBlock, testIntake } from "bingo-stratum-testers";
import { describe, expect, it, test } from "vitest";

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

describe("blockNcc", () => {
test("production", () => {
test("without addons", () => {
const creation = testBlock(blockNcc, {
options: optionsBase,
});
Expand Down Expand Up @@ -100,6 +100,72 @@ describe("blockNcc", () => {
},
"block": [Function],
},
{
"addons": {
"ignores": [
"/dist",
],
},
"block": [Function],
},
],
}
`);
});

test("with addons", () => {
const creation = testBlock(blockNcc, {
addons: {
entry: "src/action/index.ts",
},
options: optionsBase,
});

expect(creation).toMatchInlineSnapshot(`
{
"addons": [
{
"addons": {
"ignores": [
"dist",
],
},
"block": [Function],
},
{
"addons": {
"sections": {
"Building": {
"contents": "
Run [TypeScript](https://typescriptlang.org) locally to type check and build source files from \`src/\` into output files in \`lib/\`:

\`\`\`shell
pnpm build
\`\`\`

Add \`--watch\` to run the builder in a watch mode that continuously cleans and recreates \`lib/\` as you save files:

\`\`\`shell
pnpm build --watch
\`\`\`
",
"innerSections": [
{
"contents": "
Run [\`@vercel/ncc\`](https://github.com/vercel/ncc) to create an output \`dist/\` to be used in production.

\`\`\`shell
pnpm build:release
\`\`\`
",
"heading": "Building for Release",
},
],
},
},
},
"block": [Function],
},
{
"addons": {
"ignores": [
Expand All @@ -108,8 +174,125 @@ describe("blockNcc", () => {
},
"block": [Function],
},
{
"addons": {
"jobs": [
{
"name": "Build",
"steps": [
{
"run": "pnpm build",
},
],
},
{
"name": "Build (Release)",
"steps": [
{
"run": "pnpm build:release",
},
],
},
],
},
"block": [Function],
},
{
"addons": {
"properties": {
"devDependencies": {
"@vercel/ncc": "^0.38.3",
},
"scripts": {
"build": "tsc",
"build:release": "ncc build src/action/index.ts -o dist",
},
},
},
"block": [Function],
},
{
"addons": {
"ignores": [
"/dist",
],
},
"block": [Function],
},
],
}
`);
});

describe("intake", () => {
it("returns an undefined entry when options.packageData does not exist", () => {
const actual = testIntake(blockNcc, {
files: {},
options: {
...optionsBase,
packageData: undefined,
},
});

expect(actual).toEqual({ entry: undefined });
});

it("returns an undefined entry when options.packageData does not contain scripts", () => {
const actual = testIntake(blockNcc, {
files: {},
options: {
...optionsBase,
packageData: {},
},
});

expect(actual).toEqual({ entry: undefined });
});

it("returns an undefined entry when options.packageData does not contain a build:release script", () => {
const actual = testIntake(blockNcc, {
files: {},
options: {
...optionsBase,
packageData: {
scripts: {},
},
},
});

expect(actual).toEqual({ entry: undefined });
});

it("returns an undefined entry when options.packageData contains an unrelated build:release script", () => {
const actual = testIntake(blockNcc, {
files: {},
options: {
...optionsBase,
packageData: {
scripts: {
"build:release": "tsup",
},
},
},
});

expect(actual).toEqual({ entry: undefined });
});

it("returns a parsed entry when options.packageData contains a matching build:release script", () => {
const actual = testIntake(blockNcc, {
files: {},
options: {
...optionsBase,
packageData: {
scripts: {
"build:release": "ncc build src/action/index.ts -o dist",
},
},
},
});

expect(actual).toEqual({ entry: "src/action/index.ts" });
});
});
});
20 changes: 17 additions & 3 deletions src/blocks/blockNcc.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { z } from "zod";

import { base } from "../base.js";
import { blockCSpell } from "./blockCSpell.js";
import { blockDevelopmentDocs } from "./blockDevelopmentDocs.js";
Expand All @@ -10,7 +12,19 @@ export const blockNcc = base.createBlock({
about: {
name: "ncc",
},
produce() {
addons: {
entry: z.string().optional(),
},
intake({ options }) {
return {
entry: options.packageData?.scripts?.["build:release"]?.match(
/ncc build (.+) -o dist/,
)?.[1],
};
},
produce({ addons }) {
const { entry = "src/index.ts" } = addons;

return {
addons: [
blockCSpell({
Expand Down Expand Up @@ -69,12 +83,12 @@ pnpm build:release
},
scripts: {
build: "tsc",
"build:release": "ncc build src/index.ts -o dist",
"build:release": `ncc build ${entry} -o dist`,
},
},
}),
blockPrettier({
ignores: ["dist"],
ignores: ["/dist"],
}),
],
};
Expand Down