Skip to content

Feature/dual module support #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

zkabyken
Copy link

@zkabyken zkabyken commented Jul 11, 2025

Description

Adds CommonJS build support alongside existing ES module support, enabling the library to work in both CommonJS and ES module environments while maintaining full backward compatibility. This enhancement allows the library to be used in a wider range of Node.js environments and build systems

The changes include:

  • Added "require" export and updated "main" entry point in package.json
  • Added build:cjs and build:all scripts for CommonJS compilation
  • Created tsconfig.cjs.json for CommonJS TypeScript configuration
  • Added dist-cjs/package.json with "type": "commonjs" for proper module resolution
  • Moved index.ts to src/index.ts for better code organization

Big fan of the project and would love to see it succeed! The dual module support will make the library more accessible to different development environments and build systems.

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • The title of my pull request follows the conventional commits standard
  • Changes have been documented in the README/documentation (if applicable)

@zkabyken
Copy link
Author

@Pederzh @pietrozullo Would appreciate it if you could take a look when you have a moment. Let me know if there's anything you'd like me to change or improve!

@Pederzh Pederzh requested a review from Copilot July 16, 2025 03:07
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds support for CommonJS builds while retaining existing ES module output and reorganizes the project root.

  • Introduces a new tsconfig.cjs.json for CJS compilation into dist-cjs
  • Updates package.json to wire up "require" exports, switch main to CJS, and add build scripts
  • Moves the primary entry file into src/ and removes the old root index.ts

Reviewed Changes

Copilot reviewed 4 out of 7 changed files in this pull request and generated 1 comment.

File Description
tsconfig.cjs.json Add CJS compiler config targeting dist-cjs
src/index.ts New consolidated entry point exporting all public APIs
package.json Update exports, main, add CJS build scripts and files
index.ts Remove root entry file in favor of src/index.ts
Comments suppressed due to low confidence (2)

tsconfig.cjs.json:10

  • The CJS tsconfig still includes a top-level "index.ts" which has been removed. This will prevent the compiler from picking up src/index.ts. Update the include to refer to src/index.ts or remove the root index.ts entry.
  "include": ["index.ts", "src/**/*.ts"],

package.json:86

  • [nitpick] The lodash dependency appears unused in the new code paths. If you’re not importing it anywhere, removing it will reduce package bloat.
    "lodash": "^4.17.21",

package.json Outdated
@@ -46,6 +48,8 @@
},
"scripts": {
"build": "rm -rf dist && tsc",
"build:cjs": "rm -rf dist-cjs && tsc --project tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > dist-cjs/package.json",
Copy link
Preview

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

[nitpick] The build:cjs script uses Unix-only commands (rm, shell redirection) which may break on Windows. Consider using a cross-platform tool like rimraf or a Node-based script to ensure compatibility.

Copilot uses AI. Check for mistakes.

Copy link
Contributor

Choose a reason for hiding this comment

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

@zkabyken, can you also have a look at this please?

Copy link
Author

@zkabyken zkabyken Jul 16, 2025

Choose a reason for hiding this comment

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

Thanks @Pederzh! Added a script to support cross-platform CommonJS build support using shx that is then executed from package.json. Also made sure to resolve merge conflicts and double checked npm build runs (:cjs and :all)

Copy link
Author

@zkabyken zkabyken Jul 16, 2025

Choose a reason for hiding this comment

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

Thanks for the discord link! mcp-use is brilliant and I see it being very widely used soon!

@Pederzh
Copy link
Contributor

Pederzh commented Jul 16, 2025

Adds CommonJS build support alongside existing ES module support, enabling the library to work in both CommonJS and ES module environments while maintaining full backward compatibility. This enhancement allows the library to be used in a wider range of Node.js environments and build systems

The changes include:

  • Added "require" export and updated "main" entry point in package.json
  • Added build:cjs and build:all scripts for CommonJS compilation
  • Created tsconfig.cjs.json for CommonJS TypeScript configuration
  • Added dist-cjs/package.json with "type": "commonjs" for proper module resolution
  • Moved index.ts to src/index.ts for better code organization

Big fan of the project and would love to see it succeed! The dual module support will make the library more accessible to different development environments and build systems.

Hi @zkabyken we're glad that you are a fan of the project, thanks for your support :)

Thanks for taking the time to create this PR!
I've made some changes to the library.
Can you please resolve the merge conflicts?

We'd love to have you join our Discord community to chat about how you're planning to use mcp-use!
https://discord.gg/XkNkSkMz3V

@zkabyken
Copy link
Author

Hi @Pederzh, I’ve addressed all the comments, this PR should be fully ready now. Let me know if there’s anything else you’d like me to tweak. Super excited to see it get merged!

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