Skip to content

Adjust build script to work with isolated node modules (bun 1.3)#172

Merged
saddlepaddle merged 1 commit intomainfrom
violet-peak-7
Nov 28, 2025
Merged

Adjust build script to work with isolated node modules (bun 1.3)#172
saddlepaddle merged 1 commit intomainfrom
violet-peak-7

Conversation

@saddlepaddle
Copy link
Copy Markdown
Collaborator

@saddlepaddle saddlepaddle commented Nov 28, 2025

Description

Related Issues

Type of Change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Other (please describe):

Testing

Screenshots (if applicable)

Additional Notes

Summary by CodeRabbit

  • Chores
    • Updated build configuration to improve native module handling during application packaging and distribution.
    • Added automated native module preparation to ensure more reliable production builds.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link
Copy Markdown

vercel Bot commented Nov 28, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
website Ready Ready Preview Comment Nov 28, 2025 7:34pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 28, 2025

Walkthrough

The changes introduce automation for handling native modules in the Electron desktop build process, specifically targeting Bun 1.3+ isolated installs. A new script is added to convert symlinked native modules (node-pty) into real copied files. Build pipeline scripts and Electron builder configuration are updated to incorporate this preparation step before packaging.

Changes

Cohort / File(s) Summary
Build Configuration
apps/desktop/electron-builder.ts
Replaced single-string glob pattern for node-pty inclusion with explicit copy configuration object using from/to mapping and filter, accompanied by comments on native module handling for Bun 1.3+.
Package Scripts
apps/desktop/package.json
Added copy:native-modules script; updated prebuild to include the new copy step; added prepackage script that runs the copy step.
Native Module Automation
apps/desktop/scripts/copy-native-modules.ts
New script that detects and replaces symlinked native modules (node-pty) with real copied files, resolving paths and handling symlink removal for Bun 1.3+ isolated installs.
Gitignore
apps/desktop/.gitignore
Added /.native-modules entry to production section.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review symlink detection, resolution, and file copying logic in copy-native-modules.ts for correctness and edge cases
  • Verify electron-builder file copy configuration matches expected behavior and module paths
  • Confirm script integration points in package.json prebuild/prepackage hooks work as intended

Poem

🐰 Symlinks beware, we copy you fair,
From virtual paths to real, debonair,
Bun's 1.3 dance, now handled with care,
Native modules bundled beyond compare!

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is entirely empty, containing only the template placeholders with no actual content filled in for any required sections. Complete the description by providing a clear summary of changes, linking related issues, specifying the type of change, describing testing steps, and adding any relevant context about the Bun 1.3 isolated module handling.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main objective of the changeset: adjusting the build script to work with isolated node modules in Bun 1.3, which is reflected in all file modifications.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch violet-peak-7

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
apps/desktop/scripts/copy-native-modules.ts (2)

24-24: Consider more conventional path resolution.

While dirname(import.meta.dirname) works correctly to navigate up one level, the more conventional approach would be:

-  const nodeModulesDir = join(dirname(import.meta.dirname), "node_modules");
+  const nodeModulesDir = join(import.meta.dirname, "..", "node_modules");

This makes the intent (going up one directory) more explicit.


36-48: Add error handling for filesystem operations.

The script lacks error handling around rmSync and cpSync. If these operations fail due to permissions, disk space, or other issues, the error messages may be unclear.

Consider wrapping the filesystem operations in a try-catch:

     if (stats.isSymbolicLink()) {
       // Resolve symlink to get real path
       const realPath = realpathSync(modulePath);
       console.log(`  ${moduleName}: symlink -> replacing with real files`);
       console.log(`    Real path: ${realPath}`);
 
-      // Remove the symlink
-      rmSync(modulePath);
-
-      // Copy the actual files
-      cpSync(realPath, modulePath, { recursive: true });
-
-      console.log(`    Copied to: ${modulePath}`);
+      try {
+        // Remove the symlink
+        rmSync(modulePath);
+
+        // Copy the actual files
+        cpSync(realPath, modulePath, { recursive: true });
+
+        console.log(`    Copied to: ${modulePath}`);
+      } catch (error) {
+        console.error(`  [ERROR] Failed to copy ${moduleName}:`, error);
+        process.exit(1);
+      }
     } else {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a71d23 and 92dd1c3.

📒 Files selected for processing (4)
  • apps/desktop/.gitignore (1 hunks)
  • apps/desktop/electron-builder.ts (1 hunks)
  • apps/desktop/package.json (1 hunks)
  • apps/desktop/scripts/copy-native-modules.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
apps/desktop/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)

For Electron interprocess communication, ALWAYS use tRPC as defined in src/lib/trpc

Files:

  • apps/desktop/electron-builder.ts
  • apps/desktop/scripts/copy-native-modules.ts
apps/desktop/**/*.{ts,tsx}

📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)

apps/desktop/**/*.{ts,tsx}: Please use alias as defined in tsconfig.json when possible
Prefer zustand for state management if it makes sense. Do not use effect unless absolutely necessary

Files:

  • apps/desktop/electron-builder.ts
  • apps/desktop/scripts/copy-native-modules.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Avoid using any type - use explicit types instead for type safety
Use camelCase for variable and function names following existing codebase patterns
Keep diffs minimal with targeted edits only - avoid unnecessary changes when making modifications
Follow existing patterns and match the codebase style when writing new code

Files:

  • apps/desktop/electron-builder.ts
  • apps/desktop/scripts/copy-native-modules.ts
🧠 Learnings (7)
📓 Common learnings
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-28T01:03:47.951Z
Learning: Use Bun as the package manager - no npm, yarn, or pnpm
📚 Learning: 2025-11-28T01:03:47.951Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-28T01:03:47.951Z
Learning: Applies to apps/desktop/src/renderer/**/*.{ts,tsx} : Never import Node.js modules (fs, path, os, net, etc.) in renderer process code - browser environment only

Applied to files:

  • apps/desktop/.gitignore
  • apps/desktop/electron-builder.ts
  • apps/desktop/scripts/copy-native-modules.ts
📚 Learning: 2025-11-28T01:03:47.951Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-28T01:03:47.951Z
Learning: Applies to apps/desktop/src/lib/**/*.ts : Never import Node.js modules in shared code like `src/lib/electron-router-dom.ts` - this code runs in both main and renderer processes

Applied to files:

  • apps/desktop/.gitignore
  • apps/desktop/scripts/copy-native-modules.ts
📚 Learning: 2025-11-28T01:03:47.951Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-28T01:03:47.951Z
Learning: Use Bun as the package manager - no npm, yarn, or pnpm

Applied to files:

  • apps/desktop/package.json
  • apps/desktop/scripts/copy-native-modules.ts
📚 Learning: 2025-11-28T01:03:47.951Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-28T01:03:47.951Z
Learning: Applies to **/*.{ts,tsx} : Keep diffs minimal with targeted edits only - avoid unnecessary changes when making modifications

Applied to files:

  • apps/desktop/electron-builder.ts
📚 Learning: 2025-11-24T21:33:13.244Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: apps/desktop/AGENTS.md:0-0
Timestamp: 2025-11-24T21:33:13.244Z
Learning: Applies to apps/desktop/**/*.{ts,tsx} : Please use alias as defined in `tsconfig.json` when possible

Applied to files:

  • apps/desktop/electron-builder.ts
📚 Learning: 2025-11-28T01:03:47.951Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-28T01:03:47.951Z
Learning: Applies to apps/desktop/src/main/**/*.{ts,tsx} : Node.js modules (fs, path, os, net, etc.) can be used in main process code only

Applied to files:

  • apps/desktop/electron-builder.ts
🔇 Additional comments (4)
apps/desktop/package.json (1)

21-24: LGTM! Scripts correctly integrated.

The new scripts are properly wired into the build pipeline:

  • copy:native-modules runs the native module preparation script
  • prebuild includes the copy step after compilation
  • prepackage ensures native modules are copied before packaging

This correctly handles the Bun 1.3+ isolated install scenario.

apps/desktop/scripts/copy-native-modules.ts (2)

16-19: LGTM! Imports and constants well-defined.

The use of Node.js APIs is appropriate for a build script, and the as const assertion provides type safety for the module list.


26-52: LGTM! Core logic correctly handles symlinked modules.

The script correctly:

  • Uses lstatSync to detect symlinks without following them
  • Resolves the real path before copying
  • Handles both symlink and non-symlink cases appropriately

This properly addresses the Bun 1.3+ isolated install scenario where native modules are symlinked.

apps/desktop/electron-builder.ts (1)

41-48: electron-builder syntax is correct and properly documented.

Verification confirms that electron-builder 26.0.12 fully supports the FileSet configuration with from, to, and filter properties as shown in lines 41–48. The explicit filter: ["**/*"] is valid (though redundant with the documented default). This is the correct approach for copying native modules in the build configuration.

Comment thread apps/desktop/.gitignore
# production
/build
/dist
/.native-modules
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check 1: Look for .native-modules directory references
fd -t d "^.native-modules$" -d 1 2>/dev/null || echo "No .native-modules dir found in root"

# Check 2: Search for .native-modules references in the codebase
rg "\.native-modules" --type-list | head -5
rg "\.native-modules" -n 2>/dev/null | head -20

# Check 3: Find the copy-native-modules.ts script
fd "copy-native-modules" -t f

Repository: superset-sh/superset

Length of output: 514


🏁 Script executed:

#!/bin/bash
# Check script size first
wc -l apps/desktop/scripts/copy-native-modules.ts

# Read the script
cat -n apps/desktop/scripts/copy-native-modules.ts

# Search for .native-modules references (corrected)
echo "=== .native-modules references ==="
rg "native-modules" -n 2>/dev/null || echo "No matches found"

# Check if it's mentioned in package.json
echo "=== Checking package.json ==="
fd "package.json" -t f | xargs grep -l "native-modules" 2>/dev/null || echo "Not found in package.json"

Repository: superset-sh/superset

Length of output: 2685


🏁 Script executed:

#!/bin/bash
# Comprehensive search for actual .native-modules directory references
echo "=== Searching for .native-modules directory (not script name) ==="
rg "\.native-modules" --type-list | head -5 && echo "---" || true
rg "\.native-modules" -n 2>/dev/null || echo "No exact matches"

# Check .gitignore content around line 12
echo ""
echo "=== .gitignore content ==="
cat -n apps/desktop/.gitignore

# Check if there are any build or dist patterns
echo ""
echo "=== Checking build/output related configs ==="
fd "tsconfig|webpack|vite|build" -t f apps/desktop/ | head -10

Repository: superset-sh/superset

Length of output: 1226


The .native-modules entry is unnecessary and can be removed.

The copy-native-modules.ts script works with node_modules/node-pty, which is already covered by the /node_modules ignore pattern on line 2. No part of the codebase creates or references a .native-modules directory—this entry appears to be unused dead code in .gitignore.

🤖 Prompt for AI Agents
In apps/desktop/.gitignore around line 12 the entry "/.native-modules" is
dead/unnecessary because node-native artifacts are already ignored via
"/node_modules" and no code creates or references a ".native-modules" directory;
remove the "/.native-modules" line from the .gitignore to clean up unused
entries and keep the file minimal.

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.

1 participant