Skip to content

Commit 1f1e989

Browse files
fix: perserve peerDependencies, peerDependenciesMeta in transition mode (#2061)
## PR Checklist - [x] Addresses an existing open issue: fixes #2059 - [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 Expands the `options.packageData` schema to allow them. These are the first allowlisted `package.json` properties that aren't manually combined with addons, so they're generally spread in `blockPackageJson`. 🎁
1 parent 91824c6 commit 1f1e989

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/base.ts

+2
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ export const base = createBase({
135135
.object({
136136
dependencies: z.record(z.string(), z.string()).optional(),
137137
devDependencies: z.record(z.string(), z.string()).optional(),
138+
peerDependencies: z.record(z.string(), z.string()).optional(),
139+
peerDependenciesMeta: z.record(z.unknown()).optional(),
138140
scripts: z.record(z.string(), z.string()).optional(),
139141
})
140142
.optional()

src/blocks/blockPackageJson.test.ts

+35
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,41 @@ describe("blockPackageJson", () => {
237237
`);
238238
});
239239

240+
test("with peerDependencies and peerDependenciesMeta", () => {
241+
const creation = testBlock(blockPackageJson, {
242+
options: {
243+
...options,
244+
packageData: {
245+
peerDependencies: {
246+
"@types/estree": ">=1",
247+
eslint: ">=8",
248+
},
249+
peerDependenciesMeta: {
250+
"@types/estree": {
251+
optional: true,
252+
},
253+
},
254+
},
255+
},
256+
});
257+
258+
expect(creation).toMatchInlineSnapshot(`
259+
{
260+
"files": {
261+
"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","files":["README.md","package.json"],"peerDependencies":{"@types/estree":">=1","eslint":">=8"},"peerDependenciesMeta":{"@types/estree":{"optional":true}}}",
262+
},
263+
"scripts": [
264+
{
265+
"commands": [
266+
"pnpm install --no-frozen-lockfile",
267+
],
268+
"phase": 1,
269+
},
270+
],
271+
}
272+
`);
273+
});
274+
240275
test("offline mode", () => {
241276
const creation = testBlock(blockPackageJson, {
242277
offline: true,

src/blocks/blockPackageJson.ts

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const blockPackageJson = base.createBlock({
4242
"package.json": sortPackageJson(
4343
JSON.stringify(
4444
removeUndefinedObjects({
45+
...options.packageData,
4546
...addons.properties,
4647
author: { email: options.email.npm, name: options.author },
4748
bin: options.bin,

0 commit comments

Comments
 (0)