diff --git a/package.json b/package.json index 13b9c2d7f..bcbfb4339 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d7d1e6495..6528a9862 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -39,8 +39,8 @@ importers: specifier: ^9.0.5 version: 9.0.5 image-size: - specifier: ^1.2.0 - version: 1.2.0 + specifier: ^2.0.0 + version: 2.0.2 input-from-file: specifier: ^0.5.4 version: 0.5.4(bingo@0.5.16) @@ -2678,8 +2678,8 @@ packages: resolution: {integrity: sha512-bAH5jbK/F3T3Jls4I0SO1hmPR0dKU0a7+SY6n1yzRtG54FLO8d6w/nxLFX2Nb7dBu6cCWXPaAME6cYqFUMmuCA==} engines: {node: '>= 4'} - image-size@1.2.0: - resolution: {integrity: sha512-4S8fwbO6w3GeCVN6OPtA9I5IGKkcDMPcKndtUlpJuCwu7JLjtj7JZpwqLuyY2nrmQT3AWsCJLSKPsc2mPBSl3w==} + image-size@2.0.2: + resolution: {integrity: sha512-IRqXKlaXwgSMAMtpNzZa1ZAe8m+Sa1770Dhk8VkSsP9LS+iHD62Zd8FQKs8fbPiagBE7BzoFX23cxFnwshpV6w==} engines: {node: '>=16.x'} hasBin: true @@ -3682,9 +3682,6 @@ packages: queue-microtask@1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} - queue@6.0.2: - resolution: {integrity: sha512-iHZWu+q3IdFZFX36ro/lKBkSvfkztY5Y7HMiPlOUjhupPcG2JMfst2KKEpu5XndviX/3UhFbRngUPNKtgvtZiA==} - rc@1.2.8: resolution: {integrity: sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==} hasBin: true @@ -6998,9 +6995,7 @@ snapshots: ignore@7.0.3: {} - image-size@1.2.0: - dependencies: - queue: 6.0.2 + image-size@2.0.2: {} import-fresh@3.3.1: dependencies: @@ -8083,10 +8078,6 @@ snapshots: queue-microtask@1.2.3: {} - queue@6.0.2: - dependencies: - inherits: 2.0.4 - rc@1.2.8: dependencies: deep-extend: 0.6.0 diff --git a/src/options/readLogo.test.ts b/src/options/readLogo.test.ts index e1bf702d7..6d4a01258 100644 --- a/src/options/readLogo.test.ts +++ b/src/options/readLogo.test.ts @@ -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", () => ({ diff --git a/src/options/readLogo.ts b/src/options/readLogo.ts index 3abdbf19e..9d7a0964a 100644 --- a/src/options/readLogo.ts +++ b/src/options/readLogo.ts @@ -1,3 +1,5 @@ +import * as fs from "node:fs/promises"; + import { readLogoSizing } from "./readLogoSizing.js"; export async function readLogo(getReadme: () => Promise) { @@ -24,9 +26,14 @@ export async function readLogo(getReadme: () => Promise) { 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), }; } diff --git a/src/options/readLogoSizing.test.ts b/src/options/readLogoSizing.test.ts index a7789677b..6e910a7e9 100644 --- a/src/options/readLogoSizing.test.ts +++ b/src/options/readLogoSizing.test.ts @@ -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", () => { diff --git a/src/options/readLogoSizing.ts b/src/options/readLogoSizing.ts index 0f255f237..b1d2a0391 100644 --- a/src/options/readLogoSizing.ts +++ b/src/options/readLogoSizing.ts @@ -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; @@ -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).