Skip to content

Fix yargs import compatibility for Bun environment - #38

Open
konard wants to merge 3 commits into
mainfrom
issue-31-8ad67a82
Open

Fix yargs import compatibility for Bun environment#38
konard wants to merge 3 commits into
mainfrom
issue-31-8ad67a82

Conversation

@konard

@konard konard commented Sep 10, 2025

Copy link
Copy Markdown
Contributor

🐛 Bug Fix

Fixes #31 - claude-profiles does not work in bun-only environment

🔍 Problem

The issue was that in Bun environments, dynamically loaded CommonJS modules like yargs may be imported as module objects rather than directly as functions. This caused the error:

TypeError: yargs is not a function. (In 'yargs(hideBin(process.argv))', 'yargs' is an instance of Module)

✅ Solution

Added a compatibility layer that handles both cases:

  • When yargs is imported as a function (typical Node.js behavior)
  • When yargs is imported as a module object (Bun behavior)

Changes made:

  1. Renamed the imported module to yargsModule to clearly indicate it's the raw module
  2. Added compatibility logic: const yargs = typeof yargsModule === 'function' ? yargsModule : yargsModule.default || yargsModule;
  3. Added a test script to verify the fix works correctly

🧪 Testing

  • ✅ Created test script that verifies yargs import and usage
  • ✅ Confirmed main script works with --help option
  • ✅ No breaking changes for existing Node.js environments

📁 Files Changed

  • claude-profiles.mjs: Added yargs compatibility layer
  • examples/test-yargs-import.mjs: Added test script for verification

This fix maintains backward compatibility while ensuring the tool works correctly in Bun environments.


🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #31
@konard konard self-assigned this Sep 10, 2025
konard and others added 2 commits September 10, 2025 20:53
- Handle both CommonJS and ES module exports for yargs
- Add compatibility layer to work with different module loading behaviors
- Add test script to verify yargs import functionality

Fixes #31

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] claude-profiles does not work in bun-only environment Fix yargs import compatibility for Bun environment Sep 10, 2025
@konard
konard marked this pull request as ready for review September 10, 2025 17:55
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.

claude-profiles does not work in bun-only environment

1 participant