Skip to content

Update documentation on custom CJS/ESM plugins#2876

Open
Harjun751 wants to merge 1 commit intoMarkBind:masterfrom
Harjun751:plugin-pains
Open

Update documentation on custom CJS/ESM plugins#2876
Harjun751 wants to merge 1 commit intoMarkBind:masterfrom
Harjun751:plugin-pains

Conversation

@Harjun751
Copy link
Copy Markdown
Contributor

What is the purpose of this pull request?

  • Documentation update
  • Bug fix
  • Feature addition or enhancement
  • Code maintenance
  • DevOps
  • Improve developer experience
  • Others, please explain:

Resolves #2867

Overview of changes:
Adds documentation on how to manage the different module systems with plugins. Check out the deploy preview's "Writing Plugins" page for the changes

Details image

Anything you'd like to highlight/discuss:

Testing instructions:

Proposed commit message: (wrap lines at 72 characters)

Update documentation on custom CJS/ESM plugins


Checklist: ☑️

  • Updated the documentation for feature additions and enhancements
  • Added tests for bug fixes or features
  • Linked all related issues
  • No unrelated changes

Reviewer checklist:

Indicate the SEMVER impact of the PR:

  • Major (when you make incompatible API changes)
  • Minor (when you add functionality in a backward compatible manner)
  • Patch (when you make backward compatible bug fixes)

At the end of the review, please label the PR with the appropriate label: r.Major, r.Minor, r.Patch.

Breaking change release note preparation (if applicable):

  • To be included in the release note for any feature that is made obsolete/breaking

Give a brief explanation note about:

  • what was the old feature that was made obsolete
  • any replacement feature (if any), and
  • how the author should modify his website to migrate from the old feature to the replacement feature (if possible).

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.04%. Comparing base (2228bbb) to head (eaf2619).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2876   +/-   ##
=======================================
  Coverage   71.04%   71.04%           
=======================================
  Files         131      131           
  Lines        7117     7117           
  Branches     1586     1621   +35     
=======================================
  Hits         5056     5056           
- Misses       1961     2055   +94     
+ Partials      100        6   -94     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Harjun751 Harjun751 requested a review from a team March 28, 2026 05:25
Copy link
Copy Markdown
Member

@gerteck gerteck left a comment

Choose a reason for hiding this comment

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

LGTM! thanks for the PR, just some notes or possible nits


Generally, if your plugin has `require(...)` and `module.exports`, it is **CJS**.

Alternatively, if your plugin has `import { ... }` and `export { ... }` it is **ESM**.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

just wondering, is it possible to mix and match? Or to mix and match, i need to be explicit and use .cjs and .mjs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's 2 cases:


1. No package.json or package.json without "type": "module" set

In this case, CJS/ESM is inferred on a per-file basis, see the third rule of loading ESM with require.

2. package.json with "type":"module"

In this case all code is simply inferred to be ESM. Using CJS with this is invalid, and the import process will skip over CJS plugins.

Using the .cjs extension will not help either, as we currently hardcode to use .js:

// Check in current (__dirname) folder
const markbindPluginPath = path.join(MARKBIND_PLUGIN_DIRECTORY, `${pluginName}.js`);


Do you think it's worth noting?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hmm, should we remove the hardcode to make it such that .cjs and .mjs filenames work as expected? I think it's worth nothing it, if it is not too much work i suppose

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.

Accept both CJS and ESM for MarkBind plugins or just ESM

2 participants