Skip to content

fix: Enable plugin usage in ESM projects by replacing require.resolve with hybrid resolver#255

Open
francesco-carrella wants to merge 2 commits intowd-David:mainfrom
sparkncraft:feat/esm-cjs-dual-support
Open

fix: Enable plugin usage in ESM projects by replacing require.resolve with hybrid resolver#255
francesco-carrella wants to merge 2 commits intowd-David:mainfrom
sparkncraft:feat/esm-cjs-dual-support

Conversation

@francesco-carrella
Copy link

Summary

  • Replace require.resolve() calls with hybrid resolver that works in both CommonJS and ESM environments
  • Add comprehensive dual module support tests
  • Maintain 100% backward compatibility with existing usage

Changes

  • Added hybrid resolver using Node.js createRequire() API for ESM compatibility
  • Updated 3 require.resolve() calls to use hybridResolve()
  • Added comprehensive test coverage for dual module scenarios

Test plan

  • All existing 41 tests pass
  • New dual module tests verify ESM and CJS compatibility
  • Plugin works in both module contexts without breaking changes

Francesco added 2 commits August 24, 2025 12:54
… with hybrid resolver

- Replace require.resolve() calls with hybrid resolver that works in both CJS and ESM
- Use Node.js createRequire() API for proper ESM compatibility
- Remove broken ESM fallback code that caused syntax errors
- Add comprehensive tests for dual module compatibility
- Maintain full backward compatibility with existing CJS usage

Fixes plugin usage in modern ESM-based build setups where require.resolve() is not available.
- Add prepare script that runs build automatically when installing from GitHub
- Ensures dist/ files are generated even when not committed to repo
- Enables direct GitHub installation with 'npm install github:user/repo'
@Bram-dc
Copy link

Bram-dc commented Jan 10, 2026

@wd-David Could you take a look, I need this in my projects aswell.

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

Comments