Skip to content

Commit f9c230c

Browse files
feat: add packageManager back to package.json, and set to pnpm 10.4.0 in CI (#1961)
## PR Checklist - [x] Addresses an existing open issue: fixes #1906 - [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 Adds a `pnpm` option to the Base, which defaults to the existing `packageManager`'s pnpm version if it exists. 🎁
1 parent 51b3ea8 commit f9c230c

11 files changed

+82
-9
lines changed

.github/actions/prepare/action.yml

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ name: Prepare
55
runs:
66
steps:
77
- uses: pnpm/action-setup@v4
8-
with:
9-
version: 9
108
- uses: actions/setup-node@v4
119
with:
1210
cache: pnpm

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
"typescript-eslint": "8.26.0",
109109
"vitest": "3.0.7"
110110
},
111+
"packageManager": "[email protected]",
111112
"engines": {
112113
"node": ">=18.3.0"
113114
},

src/base.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe("base", () => {
4747
},
4848
owner: "JoshuaKGoldberg",
4949
packageData: expect.any(Object),
50+
pnpm: expect.any(String),
5051
repository: "create-typescript-app",
5152
title: "Create TypeScript App",
5253
usage: expect.any(String),

src/base.ts

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { readFileSafe } from "./options/readFileSafe.js";
1919
import { readFunding } from "./options/readFunding.js";
2020
import { readGuide } from "./options/readGuide.js";
2121
import { readPackageData } from "./options/readPackageData.js";
22+
import { readPnpm } from "./options/readPnpm.js";
2223
import { swallowError } from "./utils/swallowError.js";
2324
import { tryCatchLazyValueAsync } from "./utils/tryCatchLazyValueAsync.js";
2425

@@ -122,6 +123,10 @@ export const base = createBase({
122123
})
123124
.optional()
124125
.describe("additional properties to include in `package.json`"),
126+
pnpm: z
127+
.string()
128+
.optional()
129+
.describe("pnpm version for package.json's packageManager field"),
125130
repository: z
126131
.string()
127132
.describe("'kebab-case' or 'PascalCase' title of the repository"),
@@ -207,6 +212,8 @@ export const base = createBase({
207212
};
208213
});
209214

215+
const pnpm = lazyValue(async () => readPnpm(packageData));
216+
210217
const version = lazyValue(async () => (await packageData()).version);
211218

212219
const owner = lazyValue(
@@ -248,6 +255,7 @@ export const base = createBase({
248255
scripts: original.scripts,
249256
};
250257
},
258+
pnpm,
251259
repository,
252260
rulesetId,
253261
...readDefaultsFromReadme(readme, repository),

src/blocks/blockGitHubActionsCI.test.ts

-6
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ describe("blockGitHubActionsCI", () => {
3131
runs:
3232
steps:
3333
- uses: pnpm/action-setup@v4
34-
with:
35-
version: 9
3634
- uses: actions/setup-node@v4
3735
with:
3836
cache: pnpm
@@ -128,8 +126,6 @@ describe("blockGitHubActionsCI", () => {
128126
runs:
129127
steps:
130128
- uses: pnpm/action-setup@v4
131-
with:
132-
version: 9
133129
- uses: actions/setup-node@v4
134130
with:
135131
cache: pnpm
@@ -250,8 +246,6 @@ describe("blockGitHubActionsCI", () => {
250246
runs:
251247
steps:
252248
- uses: pnpm/action-setup@v4
253-
with:
254-
version: 9
255249
- uses: actions/setup-node@v4
256250
with:
257251
cache: pnpm

src/blocks/blockGitHubActionsCI.ts

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export const blockGitHubActionsCI = base.createBlock({
5151
steps: [
5252
{
5353
uses: "pnpm/action-setup@v4",
54-
with: { version: 9 },
5554
},
5655
{
5756
uses: "actions/setup-node@v4",

src/blocks/blockPackageJson.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,32 @@ describe("blockPackageJson", () => {
126126
}
127127
`);
128128
});
129+
130+
test("with node and pnpm versions", () => {
131+
const creation = testBlock(blockPackageJson, {
132+
options: {
133+
...options,
134+
node: {
135+
minimum: "22.0.0",
136+
},
137+
pnpm: "10.4.0",
138+
},
139+
});
140+
141+
expect(creation).toMatchInlineSnapshot(`
142+
{
143+
"files": {
144+
"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"}}",
145+
},
146+
"scripts": [
147+
{
148+
"commands": [
149+
"pnpm install",
150+
],
151+
"phase": 1,
152+
},
153+
],
154+
}
155+
`);
156+
});
129157
});

src/blocks/blockPackageJson.ts

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ export const blockPackageJson = base.createBlock({
5959
node: `>=${options.node.minimum}`,
6060
},
6161
}),
62+
...(options.pnpm && {
63+
packageManager: `pnpm@${options.pnpm}`,
64+
}),
6265
files: [
6366
options.bin?.replace(/^\.\//, ""),
6467
...(addons.properties.files ?? []),

src/options/readPnpm.test.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import { readPnpm } from "./readPnpm.js";
4+
5+
describe(readPnpm, () => {
6+
it("returns 10.4.0 when there is no existing packageManager", async () => {
7+
const actual = await readPnpm(() => Promise.resolve({}));
8+
9+
expect(actual).toEqual("10.4.0");
10+
});
11+
12+
it("returns 10.4.0 when an existing packageManager is not pnpm", async () => {
13+
const actual = await readPnpm(() =>
14+
Promise.resolve({
15+
packageManager: "[email protected]",
16+
}),
17+
);
18+
19+
expect(actual).toEqual("10.4.0");
20+
});
21+
22+
it("returns the existing pnpm version when an existing packageManager is pnpm", async () => {
23+
const actual = await readPnpm(() =>
24+
Promise.resolve({
25+
packageManager: "[email protected]",
26+
}),
27+
);
28+
29+
expect(actual).toEqual("10.11.12");
30+
});
31+
});

src/options/readPnpm.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { PartialPackageData } from "../types.js";
2+
3+
export async function readPnpm(packageData: () => Promise<PartialPackageData>) {
4+
const { packageManager } = await packageData();
5+
6+
return packageManager?.startsWith("pnpm@")
7+
? packageManager.slice("pnpm@".length)
8+
: "10.4.0";
9+
}

src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface PartialPackageData {
1919
email?: string;
2020
engines?: { node?: string };
2121
name?: string;
22+
packageManager?: string;
2223
repository?: string | { type: string; url: string };
2324
scripts?: Record<string, string>;
2425
version?: string;

0 commit comments

Comments
 (0)