Skip to content
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: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"git-url-parse": "^16.0.1",
"github-default-labels": "^0.1.0",
"html-to-text": "^9.0.5",
"image-size": "^1.2.0",
"image-size": "^2.0.0",
"input-from-file": "^0.5.4",
"input-from-file-json": "^0.5.4",
"input-from-script": "^0.5.4",
Expand Down
19 changes: 5 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/options/readLogo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { describe, expect, it, vi } from "vitest";

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

vi.mock("node:fs/promises", () => ({
readFile: vi.fn(() => Promise.resolve(Buffer.from([0]))),
}));

const mockReadLogoSizing = vi.fn().mockResolvedValue({});

vi.mock("./readLogoSizing.js", () => ({
Expand Down
9 changes: 8 additions & 1 deletion src/options/readLogo.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as fs from "node:fs/promises";

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

export async function readLogo(getReadme: () => Promise<string>) {
Expand All @@ -24,9 +26,14 @@ export async function readLogo(getReadme: () => Promise<string>) {
return undefined;
}

// TODO: imageSize does not go through take(input*), making it harder to test.
// It takes either a string (fs access) or buffer data (not in bingo-fs).
// https://github.com/JoshuaKGoldberg/create-typescript-app/issues/1993
const bufferData = await fs.readFile(src);

return {
alt,
src,
...readLogoSizing(src),
...readLogoSizing(bufferData),
};
}
2 changes: 1 addition & 1 deletion src/options/readLogoSizing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ vi.mock("image-size", () => ({
},
}));

const src = "img.jpg";
const src = Buffer.from([0]);

describe(readLogoSizing, () => {
it("returns undefined when imageSize throws an error", () => {
Expand Down
6 changes: 2 additions & 4 deletions src/options/readLogoSizing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ export interface OptionsLogoSizing {
width?: number;
}

export function readLogoSizing(
src: string | Uint8Array,
): OptionsLogoSizing | undefined {
export function readLogoSizing(src: Uint8Array): OptionsLogoSizing | undefined {
const size = imageSizeSafe(src);
if (!size) {
return undefined;
Expand All @@ -32,7 +30,7 @@ export function readLogoSizing(
: { height: (size.height / size.width) * maximum, width: maximum };
}

function imageSizeSafe(src: string | Uint8Array) {
function imageSizeSafe(src: Uint8Array) {
try {
// TODO: imageSize does not go through take(input*), making it harder to test.
// It takes either a string (fs access) or buffer data (not in bingo-fs).
Expand Down
Loading