refactor: Migrate build process from npm run build to esbuild for…#336
refactor: Migrate build process from npm run build to esbuild for…#336
npm run build to esbuild for…#336Conversation
… bundling and dependency management.
|
CodeAnt AI is reviewing your PR. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
📝 WalkthroughWalkthroughThis pull request introduces esbuild as a build dependency and refactors the MCPB bundling script to use esbuild for bundling, adds manifest template interpolation, implements production dependency installation within the bundle directory, and introduces cross-platform ripgrep setup with binary copying and runtime wrapper configuration. Changes
Sequence DiagramsequenceDiagram
participant Build as Build Script
participant FS as File System
participant Bundler as esbuild
participant Manifest as manifest.json
participant Deps as npm Dependencies
participant Ripgrep as ripgrep Setup
Build->>FS: Clean and create bundle dir
Build->>FS: Ensure dist folder exists
Build->>Bundler: Run esbuild with config
Bundler->>FS: Output to mcpb-bundle/dist/index.js
Build->>FS: Copy template files to bundle
Build->>Manifest: Read manifest.template.json
Build->>Manifest: Interpolate version from package.json
Build->>Manifest: Validate and write manifest.json
Build->>FS: Write bundle package.json (native deps only)
Build->>Deps: Install production deps in bundle
Deps->>FS: node_modules created in bundle
Build->>Ripgrep: Copy ripgrep binaries
Ripgrep->>FS: Set executable permissions
Ripgrep->>FS: Replace index.js with runtime wrapper
Build->>Build: Output completion guidance
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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 |
Sequence DiagramThe PR replaces the previous "npm run build" step with an esbuild-based bundling flow. The script now cleans/creates the bundle directory, runs esbuild to produce a self-contained dist, writes a minimal bundle package.json with only native deps, and installs ripgrep runtime assets into the bundle. sequenceDiagram
participant CI as Developer/CI
participant Script as scripts/build-mcpb.cjs
participant Esbuild as esbuild
participant FS as File System (bundle/)
CI->>Script: run build script
Script->>FS: Clean & create bundle directory
Script->>Esbuild: npx esbuild src/index.ts -> mcpb-bundle/dist/index.js
Esbuild-->>Script: bundled dist files
Script->>FS: Create manifest + bundle package.json (only native deps: sharp, @vscode/ripgrep)
Script->>FS: Copy ripgrep binaries & install wrapper
Script-->>CI: Bundle ready (mcpb-bundle with dist and runtime deps)
Generated by CodeAnt AI |
Nitpicks 🔍
|
|
CodeAnt AI finished reviewing your PR. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
scripts/build-mcpb.cjs (2)
76-76:⚠️ Potential issue | 🟡 MinorUse
replaceAll()for more robust string replacement.The manifest template currently contains only one
{{VERSION}}placeholder, so the existing code works. However, usingreplaceAll()is a better defensive practice and ensures the code handles multiple occurrences correctly if the template is modified in the future.Proposed fix
-const manifestContent = manifestTemplate.replace('{{VERSION}}', packageJson.version); +const manifestContent = manifestTemplate.replaceAll('{{VERSION}}', packageJson.version);
151-185:⚠️ Potential issue | 🟡 MinorAdd a guard to fail fast if no ripgrep binaries are found.
The paths in
build-mcpb.cjsanddownload-all-ripgrep.cjsare correctly aligned (both referencenode_modules/@vscode/ripgrep/bin), and the binary naming matches the expectedrg-*pattern. However, ifdownload-all-ripgrep.cjshas not been run or the directory doesn't exist,fs.readdirSync(ripgrepBinSrc).filter(f => f.startsWith('rg-'))would silently return an empty array, causing theforEachloop to be a no-op and resulting in a broken bundle with no ripgrep binaries.Proposed fix — fail fast if no binaries found
const binaries = fs.readdirSync(ripgrepBinSrc).filter(f => f.startsWith('rg-')); + if (binaries.length === 0) { + throw new Error('No ripgrep binaries found in ' + ripgrepBinSrc); + } binaries.forEach(binary => {
🧹 Nitpick comments (2)
scripts/build-mcpb.cjs (2)
91-98:package.jsonis copied in Step 5 (line 94) then overwritten in Step 6 (line 137).The copy of
package.jsonfrom the project root is immediately overwritten by the bundle-specificpackage.json. Remove it fromfilesToCopyto avoid confusion — the commented-outdistentry already sets the precedent for skipping files handled differently.Proposed fix
const filesToCopy = [ // 'dist', // Skipped because we generate dist via esbuild directly into bundle - - 'package.json', 'README.md', 'LICENSE', 'PRIVACY.md', 'icon.png' ];Also applies to: 119-139
144-144:--omit=devand--productionare redundant.Both flags achieve the same effect (skip devDependencies).
--productionis the legacy form;--omit=devis the modern equivalent. Pick one.Proposed fix
- execSync('npm install --omit=dev --production', { cwd: BUNDLE_DIR, stdio: 'inherit' }); + execSync('npm install --omit=dev', { cwd: BUNDLE_DIR, stdio: 'inherit' });
User description
… bundling and dependency management.
CodeAnt-AI Description
Switch MCPB build to esbuild and bundle only native runtime dependencies
What Changed
Impact
✅ Faster local bundling with esbuild✅ Smaller MCPB bundle by embedding non-native code✅ Reliable ripgrep runtime across platforms💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.
Summary by CodeRabbit
Release Notes