Skip to content

refactor(logo-bimi): read the record through bimi-url - #863

Merged
Kikobeats merged 5 commits into
masterfrom
refactor/bimi-url
Jul 29, 2026
Merged

refactor(logo-bimi): read the record through bimi-url#863
Kikobeats merged 5 commits into
masterfrom
refactor/bimi-url

Conversation

@Kikobeats

@Kikobeats Kikobeats commented Jul 29, 2026

Copy link
Copy Markdown
Member

Moves the BIMI logic out to bimi-url and consumes it here. No behaviour change: 517 lines deleted, 36 added.

Why

Nothing in the resolver was metascraper-shaped. It is a DNS lookup, a tag parser and an SVG-over-https check, and the two @metascraper/helpers calls it did make were protocol() and mimeExtension(). Keeping it here meant anything else wanting a domain logo (unavatar, a mail UI, a CLI) had to install a scraper to get one.

What stays is the part that is a rule: mapping a scraped URL to its registrable domain, and running the result through the logo validator.

module.exports = options => {
  const getLogo = createGetLogo(options)
  const rules = { logo: [toLogo((_, url) => getLogo(parseUrl(url).domain))] }
  rules.pkgName = 'metascraper-logo-bimi'
  return rules
}

Compatibility

The surface published as 5.52.0 is unchanged. createGetLogo, resolveLogoUrl and toLogoUrl are re-exported by identity, and test/exports.js pins that with t.is so it cannot drift:

t.is(metascraperLogoBimi.createGetLogo, createGetLogo)
t.is(metascraperLogoBimi.resolveLogoUrl, createGetLogo.resolveLogoUrl)
t.is(metascraperLogoBimi.toLogoUrl, createGetLogo.toLogoUrl)

src/index.d.ts stopped restating the options and derives them from the dependency, so the two can no longer disagree:

type CreateGetLogo = typeof import('bimi-url')
type Options = Parameters<CreateGetLogo>[0]

The two helper calls

bimi-url is a leaf package, so depending on @metascraper/helpers would have dragged jsdom, chrono-node and lodash into it for two checks. Both were replaced with equivalents, not approximations:

here in bimi-url
protocol(url) === 'https' new URL(url).protocol === 'https:' in a try/catch
mimeExtension(ct) === 'svg' exact image/svg+xml compare after stripping params

The mime table was checked before swapping: image/svg+xml is the only content type that maps to svg (image/svg and application/svg+xml both return null), and it already strips ;charset=utf-8, which the charset test covers. bimi-url ships 30 tests at 100% statements, branches, functions and lines.

Its dependencies are @keyvhq/memoize and reachable-url, both of which this package already had.

Tests

The resolver tests moved to bimi-url with it. What remains here is what exercises the rule: test/index.js (precedence over markup, fallback to the next rule, null when nothing resolves) plus the new test/exports.js. All 5 pass, lint clean.

Verified downstream too: microlink/api resolves the same logos through this package before and after.

Note on pnpm-workspace.yaml

minimumReleaseAgeExclude:
  - bimi-url@1.0.0

minimumReleaseAge is a pnpm 11 default and this repo runs with lockfile=false, so a clean install resolves fresh and would otherwise refuse a package this newly published. The entry can be dropped once 1.0.0 ages past the threshold.


Note

Medium Risk
Large logic move into a new external package; public API is preserved via identity re-exports, but any behavioral drift in bimi-url would affect logo resolution everywhere this rule runs.

Overview
BIMI resolution is delegated to the new bimi-url dependency instead of living in this package. metascraper-logo-bimi now only wires createGetLogo(options) into the logo rule (registrable domain from the scraped URL) and re-exports createGetLogo, resolveLogoUrl, and toLogoUrl by reference from bimi-url; TypeScript options are Parameters<typeof import('bimi-url')>[0] so they stay in sync.

Local DNS parsing, memoization, and SVG-over-HTTPS checks (~500 lines) are removed along with @keyvhq/memoize and reachable-url; resolver-focused tests are dropped in favor of test/exports.js and existing rule tests. The README points option docs at bimi-url.

The blogger integration test still expects an https logo but omits logo from the metadata snapshot. pnpm-workspace.yaml sets minimumReleaseAge: 0 so the new bimi-url@~1.0.0 dependency can install under pnpm’s release-age policy.

Reviewed by Cursor Bugbot for commit e7c193f. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Improvements
    • BIMI logo resolution now uses the shared bimi-url implementation.
    • createGetLogo, resolveLogoUrl, and toLogoUrl are now re-exported from bimi-url.
  • Documentation
    • Simplified the metascraper-logo-bimi README and updated the customization example.
  • Tests
    • Removed tests covering the previous standalone parsing/resolution logic.
    • Added a test to verify bimi-url re-exports.
    • Updated Blogger integration assertions and snapshots to omit the logo field.
  • Chores
    • Disabled minimum release age enforcement for workspace packages.

The BIMI logic has no metascraper in it: a DNS lookup, a tag parser and an
SVG-over-https check. It now lives in bimi-url, so anything that wants a
domain logo can resolve one without pulling a scraper in.

What stays here is the rule: mapping a scraped URL to its registrable domain
and running the result through the `logo` validator. `createGetLogo`,
`resolveLogoUrl` and `toLogoUrl` are re-exported by identity, so the surface
published as 5.52.0 is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LDmGejCQnrpy5FDBjs6cyW
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0c79c3ff-4374-47d3-81a4-1beaaa2fc142

📥 Commits

Reviewing files that changed from the base of the PR and between 53e1fe3 and e7c193f.

📒 Files selected for processing (1)
  • packages/metascraper-logo-bimi/README.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/metascraper-logo-bimi/README.md

📝 Walkthrough

Walkthrough

The BIMI logo package now delegates logo discovery and URL resolution to bimi-url, derives TypeScript declarations from that module, updates documentation and dependencies, and verifies direct helper re-exports. The Blogger integration test separately validates its HTTPS logo.

Changes

BIMI resolver integration

Layer / File(s) Summary
Delegate BIMI resolution to bimi-url
packages/metascraper-logo-bimi/package.json, pnpm-workspace.yaml, packages/metascraper-logo-bimi/src/index.js
The package adds bimi-url, replaces local BIMI resolution logic with createGetLogo, and re-exports its resolver helpers.
Align declarations and documentation
packages/metascraper-logo-bimi/src/index.d.ts, packages/metascraper-logo-bimi/README.md
Options and exported helper types are derived from bimi-url, and the README documents delegated options and re-exports.
Update export validation helpers
packages/metascraper-logo-bimi/test/exports.js, packages/metascraper-logo-bimi/test/helpers.js
Tests verify direct re-exports, while shared fixtures and DNS error handling are simplified.
Adjust Blogger integration assertions
packages/metascraper/test/integration/blogger/index.js, packages/metascraper/test/integration/blogger/snapshots/index.js.md
The integration test asserts the HTTPS logo separately and removes it from the metadata snapshot.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: moving BIMI record reading to bimi-url.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/bimi-url

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/metascraper-logo-bimi/README.md`:
- Around line 56-63: Add the missing KeyvRedis import from `@keyv/redis` to the
README usage example before it instantiates KeyvRedis, while preserving the
existing metascraper configuration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 225c92b1-05de-4c6d-8fa5-8926cfffc9e9

📥 Commits

Reviewing files that changed from the base of the PR and between 15039a2 and 9df1fc3.

📒 Files selected for processing (11)
  • packages/metascraper-logo-bimi/README.md
  • packages/metascraper-logo-bimi/package.json
  • packages/metascraper-logo-bimi/src/index.d.ts
  • packages/metascraper-logo-bimi/src/index.js
  • packages/metascraper-logo-bimi/test/dns.js
  • packages/metascraper-logo-bimi/test/exports.js
  • packages/metascraper-logo-bimi/test/get-logo.js
  • packages/metascraper-logo-bimi/test/helpers.js
  • packages/metascraper-logo-bimi/test/record.js
  • packages/metascraper-logo-bimi/test/resolve-logo-url.js
  • pnpm-workspace.yaml
💤 Files with no reviewable changes (4)
  • packages/metascraper-logo-bimi/test/resolve-logo-url.js
  • packages/metascraper-logo-bimi/test/dns.js
  • packages/metascraper-logo-bimi/test/record.js
  • packages/metascraper-logo-bimi/test/get-logo.js

Comment thread packages/metascraper-logo-bimi/README.md
Kikobeats and others added 2 commits July 29, 2026 19:07
The fixture declares no logo, so metascraper-logo-favicon resolves it by
probing the live site. A probe that times out from the runner demotes to the
Google favicon service, and the snapshot then mismatches on a value that says
nothing about the fixture.

It is not drift: no snapshot in the suite records a Google URL, so the
fallback is only ever the symptom of a failed probe. Asserting the shape keeps
the rest of the fixture pinned exactly.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LDmGejCQnrpy5FDBjs6cyW
The assertion says what it does, and why it is not snapshotted is already in
the commit that introduced it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LDmGejCQnrpy5FDBjs6cyW
@coveralls

coveralls commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Coverage Status

Coverage is 94.155%refactor/bimi-url into master. No base build found for master.

Both identifiers in the snippet were undefined, so pasting it threw. Dropping
the keyvOpts line takes the Redis import with it, leaving an example that
shows the one option the paragraph is about.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LDmGejCQnrpy5FDBjs6cyW
@Kikobeats
Kikobeats merged commit e5f98bc into master Jul 29, 2026
29 of 30 checks passed
@Kikobeats
Kikobeats deleted the refactor/bimi-url branch July 29, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants