Skip to content

Conversation

@nsrCodes
Copy link
Collaborator

@nsrCodes nsrCodes commented Oct 29, 2025

Summary by CodeRabbit

  • New Features

    • Added support for native modules to enable extended capabilities and improved performance through native code integration.
  • Chores

    • Updated Setapp framework wrapper to v4.3.4.
    • Enhanced build to load native addons and added related tooling.
    • Moved Setapp integration reporting to startup timing to ensure consistent reporting.
    • General dependency updates and maintenance.

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

@coderabbitai
Copy link

coderabbitai bot commented Oct 29, 2025

Walkthrough

Adds handling for Node native addons to the webpack build by adding a module rule for *.node files using node-loader and adding node-loader@^2.1.0 as a devDependency. Updates release/app/package.json to bump optionalDependencies["@setapp/framework-wrapper"] from ^4.3.3 to ^4.3.4. Moves Setapp integration startup code in src/main/main.ts from inside app.whenReady().then() to a top-level IS_SETAPP_BUILD === "true" guard that reports a usage event and logs integration steps.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review the new webpack rule and verify it does not conflict with existing loaders or packaging pipelines.
  • Verify adding node-loader devDependency matches the build/runtime expectations.
  • Inspect the timing change for Setapp integration in src/main/main.ts for potential race conditions or state assumptions now executed outside app.whenReady().
  • Check release/app/package.json optional dependency bump for compatibility.

Possibly related PRs

Suggested reviewers

  • wrongsahil
  • sagarsoni7
  • Aarushsr12

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: adding webpack configuration for .node files (bundling configs for .node) and updating Setapp framework integration in the build process.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 draft-setapp-wrapper-support

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0e7260d and cf405f7.

📒 Files selected for processing (3)
  • package.json (2 hunks)
  • release/app/package.json (2 hunks)
  • src/main/main.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • package.json
  • release/app/package.json
🔇 Additional comments (1)
src/main/main.ts (1)

33-38: Based on my verification, I can now provide the rewritten review comment.


Setapp initialization timing is correct per framework documentation.

The @setapp/framework-wrapper documentation explicitly requires the module to be loaded in the main process entry file at startup (before or when app becomes ready) to capture activation/license events correctly. The current implementation at module load time in src/main/main.ts follows the documented best practice and will not fail.


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.

@nsrCodes nsrCodes force-pushed the draft-setapp-wrapper-support branch from eaf00bf to 98b74d9 Compare November 5, 2025 12:25
@nsrCodes nsrCodes force-pushed the draft-setapp-wrapper-support branch from 98b74d9 to 4858c06 Compare November 10, 2025 11:25
@nsrCodes nsrCodes marked this pull request as ready for review November 10, 2025 11:29
@nsrCodes nsrCodes changed the title draft: bundling configs for .node setapp package build: bundling configs for .node + proper import of setapp package Nov 10, 2025
Copy link

@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: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9715cff and 0e7260d.

📒 Files selected for processing (4)
  • .erb/configs/webpack.config.base.ts (1 hunks)
  • package.json (3 hunks)
  • release/app/package.json (3 hunks)
  • src/main/main.ts (1 hunks)
🔇 Additional comments (5)
package.json (2)

4-4: LGTM: Version bump is consistent.

The version bump to 25.11.10 matches the corresponding change in release/app/package.json, maintaining version consistency across the project.


246-246: No issues found — node-loader version is compatible.

The latest published version of node-loader is 2.1.0, which is exactly what's specified in the PR. node-loader is maintained for Webpack 5 and is compatible with Webpack v5.x, including the webpack 5.58.2 version in the project. No action needed.

release/app/package.json (2)

4-4: LGTM: Version consistency maintained.

The version bump to 25.11.10 is consistent with the main package.json, ensuring version alignment across the application.


27-27: LGTM: Minor patch update for Setapp framework.

The patch update from ^4.3.3 to ^4.3.4 is appropriate. Note that as an optionalDependency, this package may not be installed in all environments, which is relevant to the usage in src/main/main.ts.

.erb/configs/webpack.config.base.ts (1)

23-26: LGTM: Appropriate configuration for native Node.js addons.

The new webpack rule correctly handles .node native addon files using node-loader. This configuration aligns with the asarUnpack pattern in package.json (line 44) and is essential for bundling native modules.

Comment on lines +35 to +40
if (process.env.IS_SETAPP_BUILD === "true") {
log.log("[SETAPP] build identified")
const setappFramework = require("@setapp/framework-wrapper");
setappFramework.SetappManager.shared.reportUsageEvent(setappFramework.SETAPP_USAGE_EVENT.USER_INTERACTION);
log.log("[SETAPP] integration complete")
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Critical: Add error handling for optional dependency.

The dynamic require("@setapp/framework-wrapper") at line 37 will crash the application if the optional dependency is not installed. Since @setapp/framework-wrapper is listed as an optionalDependency in release/app/package.json, it may not be present in all environments.

Apply this diff to add proper error handling:

 if (process.env.IS_SETAPP_BUILD === "true") {
   log.log("[SETAPP] build identified")
-  const setappFramework = require("@setapp/framework-wrapper");
-  setappFramework.SetappManager.shared.reportUsageEvent(setappFramework.SETAPP_USAGE_EVENT.USER_INTERACTION);
-  log.log("[SETAPP] integration complete")
+  try {
+    const setappFramework = require("@setapp/framework-wrapper");
+    setappFramework.SetappManager.shared.reportUsageEvent(setappFramework.SETAPP_USAGE_EVENT.USER_INTERACTION);
+    log.log("[SETAPP] integration complete")
+  } catch (error) {
+    log.error("[SETAPP] Failed to initialize Setapp framework:", error);
+  }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (process.env.IS_SETAPP_BUILD === "true") {
log.log("[SETAPP] build identified")
const setappFramework = require("@setapp/framework-wrapper");
setappFramework.SetappManager.shared.reportUsageEvent(setappFramework.SETAPP_USAGE_EVENT.USER_INTERACTION);
log.log("[SETAPP] integration complete")
}
if (process.env.IS_SETAPP_BUILD === "true") {
log.log("[SETAPP] build identified")
try {
const setappFramework = require("@setapp/framework-wrapper");
setappFramework.SetappManager.shared.reportUsageEvent(setappFramework.SETAPP_USAGE_EVENT.USER_INTERACTION);
log.log("[SETAPP] integration complete")
} catch (error) {
log.error("[SETAPP] Failed to initialize Setapp framework:", error);
}
}
🤖 Prompt for AI Agents
In src/main/main.ts around lines 35 to 40 the dynamic require of
"@setapp/framework-wrapper" can throw if the optional dependency is not
installed; wrap the require and all usage of setappFramework in a try/catch
block so a missing module or runtime error won’t crash the app, log a clear
warning on failure (including the error message) and continue without calling
SetappManager; optionally guard calls with a truthy check (e.g., if
(setappFramework && setappFramework.SetappManager)) before invoking
reportUsageEvent.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify webpack bundling of optional dependency.

The dynamic require() at line 37 may not work correctly with webpack bundling. Webpack might not include optional dependencies in the bundle, or may require additional configuration. Please verify that @setapp/framework-wrapper is correctly bundled and accessible at runtime in production builds.

Run the following script to check if the Setapp framework is properly bundled in production builds:


🏁 Script executed:

#!/bin/bash
# Description: Verify that @setapp/framework-wrapper is available in production builds

# Check if the package is present in release/app/node_modules
if [ -d "release/app/node_modules/@setapp/framework-wrapper" ]; then
  echo "✓ @setapp/framework-wrapper found in release/app/node_modules"
  ls -la release/app/node_modules/@setapp/framework-wrapper/
else
  echo "✗ @setapp/framework-wrapper NOT found in release/app/node_modules"
fi

# Check webpack externals configuration
echo "Checking webpack externals configuration..."
rg -n "externals" .erb/configs/webpack.config.base.ts -A 5

# Check if @setapp/framework-wrapper is in the externals list
echo "Verifying if @setapp/framework-wrapper is externalized..."
rg -n "@setapp/framework-wrapper" release/app/package.json

Length of output: 429



🏁 Script executed:

#!/bin/bash
# Check if @setapp/framework-wrapper is in root node_modules
echo "=== Checking root node_modules ==="
if [ -d "node_modules/@setapp/framework-wrapper" ]; then
  echo "✓ @setapp/framework-wrapper found in root node_modules"
else
  echo "✗ @setapp/framework-wrapper NOT found in root node_modules"
fi

# Check main package.json
echo ""
echo "=== Checking root package.json for @setapp/framework-wrapper ==="
rg -n "@setapp/framework-wrapper" package.json

# Check release/app package.json structure
echo ""
echo "=== Checking release/app/package.json dependencies section ==="
rg -n "dependencies" release/app/package.json -A 20 | head -30

# Check webpack config for how externals are handled in the actual build
echo ""
echo "=== Checking if there are webpack plugins or special handling for externals ==="
rg -n "externals|optional|@setapp" .erb/configs/ -B 2 -A 2

Length of output: 1673



🏁 Script executed:

#!/bin/bash
# Check the actual code context around the require statement
echo "=== Checking code context for error handling ==="
rg -n "require.*@setapp" src/main/main.ts -B 10 -A 5

# Check if there's a try-catch or conditional check
echo ""
echo "=== Checking for error handling patterns ==="
rg -n "try|catch|optional|IS_SETAPP_BUILD" src/main/main.ts -B 2 -A 2

# Check webpack config to see if optionalDependencies should be included
echo ""
echo "=== Full webpack externals configuration ==="
rg -n "externals" .erb/configs/webpack.config.base.ts -B 5 -A 10

Length of output: 2721


🏁 Script executed:

#!/bin/bash
# Check the actual code context around the require statement
echo "=== Checking code context for error handling ==="
rg -n "require.*@setapp" src/main/main.ts -B 10 -A 5

# Check if there's a try-catch or conditional check
echo ""
echo "=== Checking for error handling patterns ==="
rg -n "try|catch|optional|IS_SETAPP_BUILD" src/main/main.ts -B 2 -A 2

# Check webpack config to see if optionalDependencies should be included
echo ""
echo "=== Full webpack externals configuration ==="
rg -n "externals" .erb/configs/webpack.config.base.ts -B 5 -A 10

Length of output: 2721


Wrap require() in try-catch or update webpack config to handle optional dependencies.

The code lacks error handling for a dynamic require of an optional dependency. The package @setapp/framework-wrapper is listed in release/app/package.json as an optionalDependency (line 27) but the webpack configuration at .erb/configs/webpack.config.base.ts only marks dependencies as externals (line 7-10), excluding optional ones. This means webpack will attempt to bundle the package, but since it's not installed in node_modules, the require at line 37 will fail at runtime without error handling.

Fix one of:

  • Wrap the require and Setapp calls in a try-catch block, or
  • Update webpack externals config to include optionalDependencies alongside dependencies
🤖 Prompt for AI Agents
In src/main/main.ts around lines 35 to 40, the dynamic require of
"@setapp/framework-wrapper" is unprotected and will throw at runtime if the
optional dependency is absent; wrap the require and subsequent SetappManager
calls in a try-catch that safely logs or ignores the failure, ensuring the app
continues to run, or alternatively update .erb/configs/webpack.config.base.ts to
treat optionalDependencies as externals alongside dependencies so the module is
not bundled and runtime require behaves as expected.

if (process.env.IS_SETAPP_BUILD === "true") {
log.log("[SETAPP] build identified")
const setappFramework = require("@setapp/framework-wrapper");
setappFramework.SetappManager.shared.reportUsageEvent(setappFramework.SETAPP_USAGE_EVENT.USER_INTERACTION);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Major: Reconsider USER_INTERACTION event timing.

Reporting a USER_INTERACTION usage event immediately on app startup (before any actual user interaction) seems semantically incorrect. This event type typically signifies actual user engagement with the application. Consider either:

  1. Reporting a different event type more appropriate for app initialization (e.g., APP_LAUNCH or similar)
  2. Deferring this event until an actual user interaction occurs
🤖 Prompt for AI Agents
In src/main/main.ts around line 38, calling
setappFramework.SetappManager.shared.reportUsageEvent(setappFramework.SETAPP_USAGE_EVENT.USER_INTERACTION)
at startup is semantically incorrect; change the reported event to an
initialization/launch event (e.g., SETAPP_USAGE_EVENT.APP_LAUNCH or similar) or
remove this startup call and move it into actual user interaction handlers
(mouse/keyboard/menu/action listeners) so USER_INTERACTION is only reported when
real user input occurs; update the single call accordingly and ensure any new
event constant exists and is imported/used consistently.

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