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 packageManager back to package.json, and set to pnpm 10.4.0 in CI #1961

Merged
merged 4 commits into from
Mar 6, 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
2 changes: 0 additions & 2 deletions .github/actions/prepare/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ name: Prepare
runs:
steps:
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
cache: pnpm
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"typescript-eslint": "8.26.0",
"vitest": "3.0.7"
},
"packageManager": "[email protected]",
"engines": {
"node": ">=18.3.0"
},
Expand Down
1 change: 1 addition & 0 deletions src/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe("base", () => {
},
owner: "JoshuaKGoldberg",
packageData: expect.any(Object),
pnpm: expect.any(String),
repository: "create-typescript-app",
title: "Create TypeScript App",
usage: expect.any(String),
Expand Down
8 changes: 8 additions & 0 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { readFileSafe } from "./options/readFileSafe.js";
import { readFunding } from "./options/readFunding.js";
import { readGuide } from "./options/readGuide.js";
import { readPackageData } from "./options/readPackageData.js";
import { readPnpm } from "./options/readPnpm.js";
import { swallowError } from "./utils/swallowError.js";
import { tryCatchLazyValueAsync } from "./utils/tryCatchLazyValueAsync.js";

Expand Down Expand Up @@ -122,6 +123,10 @@ export const base = createBase({
})
.optional()
.describe("additional properties to include in `package.json`"),
pnpm: z
.string()
.optional()
.describe("pnpm version for package.json's packageManager field"),
repository: z
.string()
.describe("'kebab-case' or 'PascalCase' title of the repository"),
Expand Down Expand Up @@ -207,6 +212,8 @@ export const base = createBase({
};
});

const pnpm = lazyValue(async () => readPnpm(packageData));

const version = lazyValue(async () => (await packageData()).version);

const owner = lazyValue(
Expand Down Expand Up @@ -248,6 +255,7 @@ export const base = createBase({
scripts: original.scripts,
};
},
pnpm,
repository,
rulesetId,
...readDefaultsFromReadme(readme, repository),
Expand Down
6 changes: 0 additions & 6 deletions src/blocks/blockGitHubActionsCI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ describe("blockGitHubActionsCI", () => {
runs:
steps:
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
cache: pnpm
Expand Down Expand Up @@ -128,8 +126,6 @@ describe("blockGitHubActionsCI", () => {
runs:
steps:
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
cache: pnpm
Expand Down Expand Up @@ -250,8 +246,6 @@ describe("blockGitHubActionsCI", () => {
runs:
steps:
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
cache: pnpm
Expand Down
1 change: 0 additions & 1 deletion src/blocks/blockGitHubActionsCI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export const blockGitHubActionsCI = base.createBlock({
steps: [
{
uses: "pnpm/action-setup@v4",
with: { version: 9 },
},
{
uses: "actions/setup-node@v4",
Expand Down
28 changes: 28 additions & 0 deletions src/blocks/blockPackageJson.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,32 @@ describe("blockPackageJson", () => {
}
`);
});

test("with node and pnpm versions", () => {
const creation = testBlock(blockPackageJson, {
options: {
...options,
node: {
minimum: "22.0.0",
},
pnpm: "10.4.0",
},
});

expect(creation).toMatchInlineSnapshot(`
{
"files": {
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","main":"lib/index.js","files":["README.md","package.json"],"packageManager":"[email protected]","engines":{"node":">=22.0.0"}}",
},
"scripts": [
{
"commands": [
"pnpm install",
],
"phase": 1,
},
],
}
`);
});
});
3 changes: 3 additions & 0 deletions src/blocks/blockPackageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export const blockPackageJson = base.createBlock({
node: `>=${options.node.minimum}`,
},
}),
...(options.pnpm && {
packageManager: `pnpm@${options.pnpm}`,
}),
files: [
options.bin?.replace(/^\.\//, ""),
...(addons.properties.files ?? []),
Expand Down
31 changes: 31 additions & 0 deletions src/options/readPnpm.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { describe, expect, it } from "vitest";

import { readPnpm } from "./readPnpm.js";

describe(readPnpm, () => {
it("returns 10.4.0 when there is no existing packageManager", async () => {
const actual = await readPnpm(() => Promise.resolve({}));

expect(actual).toEqual("10.4.0");
});

it("returns 10.4.0 when an existing packageManager is not pnpm", async () => {
const actual = await readPnpm(() =>
Promise.resolve({
packageManager: "[email protected]",
}),
);

expect(actual).toEqual("10.4.0");
});

it("returns the existing pnpm version when an existing packageManager is pnpm", async () => {
const actual = await readPnpm(() =>
Promise.resolve({
packageManager: "[email protected]",
}),
);

expect(actual).toEqual("10.11.12");
});
});
9 changes: 9 additions & 0 deletions src/options/readPnpm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { PartialPackageData } from "../types.js";

export async function readPnpm(packageData: () => Promise<PartialPackageData>) {
const { packageManager } = await packageData();

return packageManager?.startsWith("pnpm@")
? packageManager.slice("pnpm@".length)
: "10.4.0";
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface PartialPackageData {
email?: string;
engines?: { node?: string };
name?: string;
packageManager?: string;
repository?: string | { type: string; url: string };
scripts?: Record<string, string>;
version?: string;
Expand Down
Loading