From bed3c77990116e9919c6f72628d20a79160ddfe2 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 2 Apr 2025 17:40:45 -0400 Subject: [PATCH] fix: allow overriding package.json type --- src/blocks/blockPackageJson.test.ts | 27 +++++++++++++++++++++++++++ src/blocks/blockPackageJson.ts | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/blocks/blockPackageJson.test.ts b/src/blocks/blockPackageJson.test.ts index 3d8c5cbf7..793244ea9 100644 --- a/src/blocks/blockPackageJson.test.ts +++ b/src/blocks/blockPackageJson.test.ts @@ -131,6 +131,33 @@ describe("blockPackageJson", () => { `); }); + test("with addons adding type", () => { + const creation = testBlock(blockPackageJson, { + addons: { + properties: { + type: "commonjs", + }, + }, + options, + }); + + 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"},"author":{"email":"npm@email.com"},"type":"commonjs","files":["README.md","package.json"],"engines":{"node":">=20.12.0"}}", + }, + "scripts": [ + { + "commands": [ + "pnpm install --no-frozen-lockfile", + ], + "phase": 1, + }, + ], + } + `); + }); + test("with addons adding overlapping files", () => { const creation = testBlock(blockPackageJson, { addons: { diff --git a/src/blocks/blockPackageJson.ts b/src/blocks/blockPackageJson.ts index 24458de55..72c49adc3 100644 --- a/src/blocks/blockPackageJson.ts +++ b/src/blocks/blockPackageJson.ts @@ -42,6 +42,7 @@ export const blockPackageJson = base.createBlock({ "package.json": sortPackageJson( JSON.stringify( removeUndefinedObjects({ + type: "module", ...options.packageData, ...addons.properties, author: { email: options.email.npm, name: options.author }, @@ -75,7 +76,6 @@ export const blockPackageJson = base.createBlock({ ...options.packageData?.scripts, ...addons.properties.scripts, }, - type: "module", version: options.version ?? "0.0.0", }), ),