Skip to content

Conversation

@village-way
Copy link
Contributor

Context

The JetBrains plugin build fails on macOS due to a compilation error in @vscode/policy-watcher. The package uses std::optional in PreferencesPolicy.hh but doesn't include the <optional> header, causing the build to fail during native module compilation.

This fix adds an automated patch application system that:

  1. Patches the PreferencesPolicy.hh file to include <optional> header
  2. Integrates seamlessly into the existing build process
  3. Follows the same pattern as other patches in the codebase (e.g., deps/patches/vscode/jetbrains.patch)

Implementation

Changes Made

  1. Created patch file (deps/patches/policy-watcher/macos-optional-fix.patch)

    • Adds #include <optional> to PreferencesPolicy.hh after the CoreFoundation include
  2. Created patch application script (scripts/apply-policy-watcher-patch.js)

    • Automatically finds and patches @vscode/policy-watcher files in both pnpm and npm node_modules structures
    • Handles both the pnpm store format and regular npm installs
    • Includes safety checks to avoid duplicate patching
  3. Updated build script (jetbrains/plugin/package.json)

    • Modified copy:resource-nodemodules to:
      • Install dependencies with --ignore-scripts to skip native compilation
      • Apply the patch before compilation
      • Rebuild @vscode/policy-watcher after patching
  4. Added documentation (deps/patches/policy-watcher/README.md)

    • Documents the issue and fix
    • Explains the patch application process

Technical Details

The patch script:

  • Searches for PreferencesPolicy.hh files in both pnpm and npm structures
  • Checks if the patch is already applied to avoid duplicates
  • Inserts #include <optional> after #include <CoreFoundation/CoreFoundation.h>
  • Works with the existing build pipeline without requiring manual intervention

The build process now:

  1. Installs packages without running build scripts (--ignore-scripts)
  2. Applies the patch to fix the missing header
  3. Rebuilds the native module with the patch in place

Screenshots

before after
Build fails with std::optional compilation errors Build completes successfully

How to Test

  1. Clean build test:

    cd jetbrains/plugin
    pnpm run clean:resource-nodemodules
    pnpm run copy:resource-nodemodules

    Verify that the build completes without errors.

  2. Full build test:

    cd jetbrains/plugin
    pnpm run bundle

    Verify that the complete plugin bundle builds successfully.

  3. Patch verification:
    After running copy:resource-nodemodules, check that the patch was applied:

    grep -A 2 "CoreFoundation" ../resources/node_modules/@vscode/policy-watcher/src/macos/PreferencesPolicy.hh

    Should show #include <optional> after the CoreFoundation include.

  4. Multiple runs test:
    Run copy:resource-nodemodules multiple times to ensure the patch script handles already-patched files correctly.

@changeset-bot
Copy link

changeset-bot bot commented Dec 19, 2025

⚠️ No Changeset found

Latest commit: 7b46882

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@marius-kilocode
Copy link
Contributor

@catrielmuller would you take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants