Replace image-size with probe-image-size#4456
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughReplaces the ChangesSwitch to probe-image-size
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/less/lib/less-node/image-size.js (1)
31-32:⚠️ Potential issue | 🟠 MajorUse
fileSync.contentsinstead of re-reading from disk.At line 42, probing
readFileSync(fileSync.filename)bypasses the file manager that already resolved and loaded the asset at line 31. This fails with non-filesystem/custom file managers and introduces unnecessary I/O. Theprobe()function fromprobe-image-size/syncaccepts Buffer inputs directly.Suggested fix
-import { readFileSync } from 'fs'; @@ - const size = probe(readFileSync(fileSync.filename)); + const size = probe(Buffer.from(fileSync.contents));🤖 Prompt for 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. In `@packages/less/lib/less-node/image-size.js` around lines 31 - 32, The code is unnecessarily re-reading the file from disk at line 42 by calling readFileSync(fileSync.filename) instead of using the already-loaded file contents from the fileSync object created at line 31 via fileManager.loadFileSync(). Replace the readFileSync call with fileSync.contents when passing the data to the probe() function to avoid redundant I/O and ensure compatibility with custom file managers that may not use the filesystem directly.
🤖 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/less/lib/less-node/image-size.js`:
- Around line 37-40: The require statement for 'probe-image-size/sync' throws an
error when the optional dependency is not installed, preventing the fallback
logic from ever executing. Wrap the require('probe-image-size/sync') statement
in a try-catch block so that when the module is unavailable and an error is
thrown, the catch block can return the default value { width: 0, height: 0 }
instead of allowing the error to propagate.
---
Outside diff comments:
In `@packages/less/lib/less-node/image-size.js`:
- Around line 31-32: The code is unnecessarily re-reading the file from disk at
line 42 by calling readFileSync(fileSync.filename) instead of using the
already-loaded file contents from the fileSync object created at line 31 via
fileManager.loadFileSync(). Replace the readFileSync call with fileSync.contents
when passing the data to the probe() function to avoid redundant I/O and ensure
compatibility with custom file managers that may not use the filesystem
directly.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6273adf3-7832-4d68-a0c5-a11dd8c3841a
⛔ Files ignored due to path filters (2)
package-lock.jsonis excluded by!**/package-lock.jsonpnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (2)
packages/less/lib/less-node/image-size.jspackages/less/package.json
There was a problem hiding this comment.
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/less/lib/less-node/image-size.js`:
- Around line 44-50: The code is bypassing the FileManager by directly calling
fs.readFileSync(fileSync.filename) instead of using the contents already loaded
by the FileManager. Replace the fs.readFileSync(fileSync.filename) call in the
image-size.js file with logic that first checks if fileSync.contents exists and
uses it directly, and only falls back to fs.readFileSync(fileSync.filename) when
contents are not available. This ensures compatibility with non-filesystem
FileManager implementations while still supporting cases where filename fallback
is necessary.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ee197d07-9b7a-4a36-b039-78112345e775
📒 Files selected for processing (1)
packages/less/lib/less-node/image-size.js
|
Verified the suggestion locally. Replacing readFileSync(fileSync.filename) with fileSync.contents causes the existing tests-unit/urls/urls.less image-size PNG test to fail with "Unrecognised image format". Since loadFileSync does not appear to guarantee binary-safe Buffer contents for this path, I kept readFileSync to avoid a regression. |
|
@matthew-dean, could you please review this PR? |
Summary
This PR replaces the archived
image-sizedependency withprobe-image-size.Changes
image-sizewithprobe-image-sizepackages/less/lib/less-node/image-size.jsto useprobe-image-size/syncTypeErrorMotivation
image-sizeis archived and has known security concerns (e.g. CVE-2025-71329).probe-image-sizeis actively maintained and provides equivalent image dimension detection functionality.Notes
probe-image-size/syncreturnsnullwhen the image format is not recognized. This PR adds a guard to handle that case gracefully and return a proper Less file error rather than throwing:TypeError: Cannot read properties of null (reading 'width')Summary by CodeRabbit
probe-image-size/syncfor more reliable dimension extraction.image-sizeand addingprobe-image-size.