fix: 将 highlight.js 改为静态导入以兼容 Bun --compile 模式#335
Conversation
- cliHighlight.ts: 使用静态 import 替换 dynamic import('highlight.js'),
因为编译模式下模块解析指向内部 bunfs 路径导致无法找到
- color-diff-napi/src/index.ts: 同样改为静态导入,移除 createRequire 延迟加载
📝 WalkthroughWalkthroughBoth files transition from runtime dynamic imports to static imports of Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 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
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/color-diff-napi/src/index.ts`:
- Line 21: The file imports highlight.js via "import hljs from 'highlight.js'"
making it a runtime dependency; add "highlight.js" to the dependencies section
of packages/color-diff-napi/package.json (pick a compatible semver version, e.g.
the latest stable), run your package manager to update lockfile, and verify the
build/tests so the runtime importer (hljs) resolves correctly.
🪄 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
Run ID: 7872d6c9-cd38-43c1-b18e-0a95b148f67d
📒 Files selected for processing (2)
packages/color-diff-napi/src/index.tssrc/utils/cliHighlight.ts
| import { createRequire } from 'node:module' | ||
| import { diffArrays } from 'diff' | ||
| import type * as hljsNamespace from 'highlight.js' | ||
| import hljs from 'highlight.js' |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
pkg="$(fd -t f '^package\.json$' packages/color-diff-napi | head -n 1)"
if [ -z "${pkg}" ]; then
printf 'packages/color-diff-napi/package.json was not found\n' >&2
exit 1
fi
printf 'Checking %s\n' "$pkg"
jq '{
name,
dependencies: .dependencies["highlight.js"],
optionalDependencies: .optionalDependencies["highlight.js"],
peerDependencies: .peerDependencies["highlight.js"],
devDependencies: .devDependencies["highlight.js"]
}' "$pkg"Repository: claude-code-best/claude-code
Length of output: 265
Add highlight.js to runtime dependencies.
The static import on line 21 makes highlight.js a direct runtime requirement, but it is not declared in package.json dependencies. This will cause resolution failures under strict package managers or isolated builds. Add highlight.js to the dependencies field in packages/color-diff-napi/package.json.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/color-diff-napi/src/index.ts` at line 21, The file imports
highlight.js via "import hljs from 'highlight.js'" making it a runtime
dependency; add "highlight.js" to the dependencies section of
packages/color-diff-napi/package.json (pick a compatible semver version, e.g.
the latest stable), run your package manager to update lockfile, and verify the
build/tests so the runtime importer (hljs) resolves correctly.
…li-highlight fix: 将 highlight.js 改为静态导入以兼容 Bun --compile 模式
Summary by CodeRabbit