-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't infer --description if it's the source default (#1803)
## PR Checklist - [x] Addresses an existing open issue: fixes #1363 - [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 Applies both in the legacy mode and new create mode. 💖
- Loading branch information
1 parent
d64e3ab
commit 442cb3b
Showing
7 changed files
with
86 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { createRequire } from "node:module"; | ||
|
||
const require = createRequire(import.meta.url); | ||
|
||
export const sourcePackageJson = | ||
// Importing from above src/ would expand the TS build rootDir | ||
require("../../../package.json") as typeof import("../../../package.json"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { describe, expect, it, vi } from "vitest"; | ||
|
||
import { readDescription } from "./readDescription.js"; | ||
|
||
const mockSourcePackageJsonDescription = vi.fn<() => string>(); | ||
|
||
vi.mock("./blocks/sourcePackageJson", () => ({ | ||
sourcePackageJson: { | ||
get description() { | ||
return mockSourcePackageJsonDescription(); | ||
}, | ||
}, | ||
})); | ||
|
||
describe("finalize", () => { | ||
it("returns undefined when the description matches the current package.json description", async () => { | ||
const existing = "Same description."; | ||
|
||
mockSourcePackageJsonDescription.mockReturnValueOnce(existing); | ||
|
||
const documentation = await readDescription(() => | ||
Promise.resolve({ | ||
description: existing, | ||
}), | ||
); | ||
|
||
expect(documentation).toBeUndefined(); | ||
}); | ||
|
||
it("filters known headings when .github/DEVELOPMENT.md exists", async () => { | ||
const updated = "Updated description."; | ||
|
||
mockSourcePackageJsonDescription.mockReturnValueOnce( | ||
"Existing description", | ||
); | ||
|
||
const documentation = await readDescription(() => | ||
Promise.resolve({ | ||
description: updated, | ||
}), | ||
); | ||
|
||
expect(documentation).toBe(updated); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { PartialPackageData } from "../shared/types.js"; | ||
import { sourcePackageJson } from "./blocks/sourcePackageJson.js"; | ||
|
||
export async function readDescription( | ||
getPackageData: () => Promise<PartialPackageData>, | ||
) { | ||
const { description: inferred } = await getPackageData(); | ||
const { description: existing } = sourcePackageJson; | ||
|
||
return existing === inferred ? undefined : inferred; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters