Skip to content

Commit 016fc0d

Browse files
fix: update image-size to v2 (#2232)
## PR Checklist - [x] Addresses an existing open issue: fixes #2231 - [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 Branches off #1948 for some code changes. This also copies the comment noting that `imageSize` doesn't go through Bingo's `take()`. 🎁 --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 parent 41c20af commit 016fc0d

File tree

6 files changed

+21
-21
lines changed

6 files changed

+21
-21
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"git-url-parse": "^16.0.1",
4848
"github-default-labels": "^0.1.0",
4949
"html-to-text": "^9.0.5",
50-
"image-size": "^1.2.0",
50+
"image-size": "^2.0.0",
5151
"input-from-file": "^0.5.4",
5252
"input-from-file-json": "^0.5.4",
5353
"input-from-script": "^0.5.4",

pnpm-lock.yaml

Lines changed: 5 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/options/readLogo.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { describe, expect, it, vi } from "vitest";
22

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

5+
vi.mock("node:fs/promises", () => ({
6+
readFile: vi.fn(() => Promise.resolve(Buffer.from([0]))),
7+
}));
8+
59
const mockReadLogoSizing = vi.fn().mockResolvedValue({});
610

711
vi.mock("./readLogoSizing.js", () => ({

src/options/readLogo.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as fs from "node:fs/promises";
2+
13
import { readLogoSizing } from "./readLogoSizing.js";
24

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

29+
// TODO: imageSize does not go through take(input*), making it harder to test.
30+
// It takes either a string (fs access) or buffer data (not in bingo-fs).
31+
// https://github.com/JoshuaKGoldberg/create-typescript-app/issues/1993
32+
const bufferData = await fs.readFile(src);
33+
2734
return {
2835
alt,
2936
src,
30-
...readLogoSizing(src),
37+
...readLogoSizing(bufferData),
3138
};
3239
}

src/options/readLogoSizing.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ vi.mock("image-size", () => ({
1010
},
1111
}));
1212

13-
const src = "img.jpg";
13+
const src = Buffer.from([0]);
1414

1515
describe(readLogoSizing, () => {
1616
it("returns undefined when imageSize throws an error", () => {

src/options/readLogoSizing.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ export interface OptionsLogoSizing {
77
width?: number;
88
}
99

10-
export function readLogoSizing(
11-
src: string | Uint8Array,
12-
): OptionsLogoSizing | undefined {
10+
export function readLogoSizing(src: Uint8Array): OptionsLogoSizing | undefined {
1311
const size = imageSizeSafe(src);
1412
if (!size) {
1513
return undefined;
@@ -32,7 +30,7 @@ export function readLogoSizing(
3230
: { height: (size.height / size.width) * maximum, width: maximum };
3331
}
3432

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

0 commit comments

Comments
 (0)